##// END OF EJS Templates
Added custom user name (other than "pi")
Stephen A. Brandli -
r84:05011ab6987a
parent child
Show More
@@ -1,300 +1,303
1 # rpi2-gen-image
1 # rpi2-gen-image
2 ## Introduction
2 ## Introduction
3 `rpi2-gen-image.sh` is an advanced Debian Linux bootstrapping shell script for generating Debian OS images for the Raspberry 2 (RPi2) computer. The script at this time only supports the bootstrapping of the current stable Debian 8 "jessie" release.
3 `rpi2-gen-image.sh` is an advanced Debian Linux bootstrapping shell script for generating Debian OS images for the Raspberry 2 (RPi2) computer. The script at this time only supports the bootstrapping of the current stable Debian 8 "jessie" release.
4
4
5 ## Build dependencies
5 ## Build dependencies
6 The following list of Debian packages must be installed on the build system because they are essentially required for the bootstrapping process. The script will check if all required packages are installed and missing packages will be installed automatically if confirmed by the user.
6 The following list of Debian packages must be installed on the build system because they are essentially required for the bootstrapping process. The script will check if all required packages are installed and missing packages will be installed automatically if confirmed by the user.
7
7
8 ```debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git```
8 ```debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git```
9
9
10 ## Command-line parameters
10 ## Command-line parameters
11 The script accepts certain command-line parameters to enable or disable specific OS features, services and configuration settings. These parameters are passed to the `rpi2-gen-image.sh` script via (simple) shell-variables. Unlike environment shell-variables (simple) shell-variables are defined at the beginning of the command-line call of the `rpi2-gen-image.sh` script.
11 The script accepts certain command-line parameters to enable or disable specific OS features, services and configuration settings. These parameters are passed to the `rpi2-gen-image.sh` script via (simple) shell-variables. Unlike environment shell-variables (simple) shell-variables are defined at the beginning of the command-line call of the `rpi2-gen-image.sh` script.
12
12
13 #####Command-line examples:
13 #####Command-line examples:
14 ```shell
14 ```shell
15 ENABLE_UBOOT=true ./rpi2-gen-image.sh
15 ENABLE_UBOOT=true ./rpi2-gen-image.sh
16 ENABLE_CONSOLE=false ENABLE_IPV6=false ./rpi2-gen-image.sh
16 ENABLE_CONSOLE=false ENABLE_IPV6=false ./rpi2-gen-image.sh
17 ENABLE_WM=xfce4 ENABLE_FBTURBO=true ENABLE_MINBASE=true ./rpi2-gen-image.sh
17 ENABLE_WM=xfce4 ENABLE_FBTURBO=true ENABLE_MINBASE=true ./rpi2-gen-image.sh
18 ENABLE_HARDNET=true ENABLE_IPTABLES=true /rpi2-gen-image.sh
18 ENABLE_HARDNET=true ENABLE_IPTABLES=true /rpi2-gen-image.sh
19 APT_SERVER=ftp.de.debian.org APT_PROXY="http://127.0.0.1:3142/" ./rpi2-gen-image.sh
19 APT_SERVER=ftp.de.debian.org APT_PROXY="http://127.0.0.1:3142/" ./rpi2-gen-image.sh
20 ENABLE_MINBASE=true ./rpi2-gen-image.sh
20 ENABLE_MINBASE=true ./rpi2-gen-image.sh
21 BUILD_KERNEL=true ENABLE_MINBASE=true ENABLE_IPV6=false ./rpi2-gen-image.sh
21 BUILD_KERNEL=true ENABLE_MINBASE=true ENABLE_IPV6=false ./rpi2-gen-image.sh
22 BUILD_KERNEL=true KERNELSRC_DIR=/tmp/linux ./rpi2-gen-image.sh
22 BUILD_KERNEL=true KERNELSRC_DIR=/tmp/linux ./rpi2-gen-image.sh
23 ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi2-gen-image.sh
23 ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi2-gen-image.sh
24 ENABLE_CRYPTFS=true CRYPTFS_PASSWORD=changeme EXPANDROOT=false ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi2-gen-image.sh
24 ENABLE_CRYPTFS=true CRYPTFS_PASSWORD=changeme EXPANDROOT=false ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi2-gen-image.sh
25 ```
25 ```
26
26
27 #### APT settings:
27 #### APT settings:
28 ##### `APT_SERVER`="ftp.debian.org"
28 ##### `APT_SERVER`="ftp.debian.org"
29 Set Debian packages server address. Choose a server from the list of Debian worldwide [mirror sites](https://www.debian.org/mirror/list). Using a nearby server will probably speed-up all required downloads within the bootstrapping process.
29 Set Debian packages server address. Choose a server from the list of Debian worldwide [mirror sites](https://www.debian.org/mirror/list). Using a nearby server will probably speed-up all required downloads within the bootstrapping process.
30
30
31 ##### `APT_PROXY`=""
31 ##### `APT_PROXY`=""
32 Set Proxy server address. Using a local Proxy-Cache like `apt-cacher-ng` will speed-up the bootstrapping process because all required Debian packages will only be downloaded from the Debian mirror site once.
32 Set Proxy server address. Using a local Proxy-Cache like `apt-cacher-ng` will speed-up the bootstrapping process because all required Debian packages will only be downloaded from the Debian mirror site once.
33
33
34 ##### `APT_INCLUDES`=""
34 ##### `APT_INCLUDES`=""
35 A comma separated list of additional packages to be installed during bootstrapping.
35 A comma separated list of additional packages to be installed during bootstrapping.
36
36
37 #### General system settings:
37 #### General system settings:
38 ##### `HOSTNAME`="rpi2-jessie"
38 ##### `HOSTNAME`="rpi2-jessie"
39 Set system host name. It's recommended that the host name is unique in the corresponding subnet.
39 Set system host name. It's recommended that the host name is unique in the corresponding subnet.
40
40
41 ##### `PASSWORD`="raspberry"
41 ##### `PASSWORD`="raspberry"
42 Set system `root` password. The same password is used for the created user `pi`. It's **STRONGLY** recommended that you choose a custom password.
42 Set system `root` password. The same password is used for the created user `pi`. It's **STRONGLY** recommended that you choose a custom password.
43
43
44 ##### `DEFLOCAL`="en_US.UTF-8"
44 ##### `DEFLOCAL`="en_US.UTF-8"
45 Set default system locale. This setting can also be changed inside the running OS using the `dpkg-reconfigure locales` command. The script variant `minbase` (ENABLE_MINBASE=true) doesn't install `locales`.
45 Set default system locale. This setting can also be changed inside the running OS using the `dpkg-reconfigure locales` command. The script variant `minbase` (ENABLE_MINBASE=true) doesn't install `locales`.
46
46
47 ##### `TIMEZONE`="Europe/Berlin"
47 ##### `TIMEZONE`="Europe/Berlin"
48 Set default system timezone. All available timezones can be found in the `/usr/share/zoneinfo/` directory. This setting can also be changed inside the running OS using the `dpkg-reconfigure tzdata` command.
48 Set default system timezone. All available timezones can be found in the `/usr/share/zoneinfo/` directory. This setting can also be changed inside the running OS using the `dpkg-reconfigure tzdata` command.
49
49
50 ##### `EXPANDROOT`=true
50 ##### `EXPANDROOT`=true
51 Expand the root partition and filesystem automatically on first boot.
51 Expand the root partition and filesystem automatically on first boot.
52
52
53 #### Keyboard settings:
53 #### Keyboard settings:
54 These options are used to configure keyboard layout in `/etc/default/keyboard` for console and Xorg. These settings can also be changed inside the running OS using the `dpkg-reconfigure keyboard-configuration` command.
54 These options are used to configure keyboard layout in `/etc/default/keyboard` for console and Xorg. These settings can also be changed inside the running OS using the `dpkg-reconfigure keyboard-configuration` command.
55
55
56 ##### `XKB_MODEL`=""
56 ##### `XKB_MODEL`=""
57 Set the name of the model of your keyboard type.
57 Set the name of the model of your keyboard type.
58
58
59 ##### `XKB_LAYOUT`=""
59 ##### `XKB_LAYOUT`=""
60 Set the supported keyboard layout(s).
60 Set the supported keyboard layout(s).
61
61
62 ##### `XKB_VARIANT`=""
62 ##### `XKB_VARIANT`=""
63 Set the supported variant(s) of the keyboard layout(s).
63 Set the supported variant(s) of the keyboard layout(s).
64
64
65 ##### `XKB_OPTIONS`=""
65 ##### `XKB_OPTIONS`=""
66 Set extra xkb configuration options.
66 Set extra xkb configuration options.
67
67
68 #### Networking settings (DHCP):
68 #### Networking settings (DHCP):
69 This parameter is used to set up networking auto configuration in `/etc/systemd/network/eth.network`.
69 This parameter is used to set up networking auto configuration in `/etc/systemd/network/eth.network`.
70
70
71 #####`ENABLE_DHCP`=true
71 #####`ENABLE_DHCP`=true
72 Set the system to use DHCP. This requires an DHCP server.
72 Set the system to use DHCP. This requires an DHCP server.
73
73
74 #### Networking settings (static):
74 #### Networking settings (static):
75 These parameters are used to set up a static networking configuration in /etc/systemd/network/eth.network. The following static networking parameters are only supported if `ENABLE_DHCP` was set to `false`.
75 These parameters are used to set up a static networking configuration in /etc/systemd/network/eth.network. The following static networking parameters are only supported if `ENABLE_DHCP` was set to `false`.
76
76
77 #####`NET_ADDRESS`=""
77 #####`NET_ADDRESS`=""
78 Set a static IPv4 or IPv6 address and its prefix, separated by "/", eg. "192.169.0.3/24".
78 Set a static IPv4 or IPv6 address and its prefix, separated by "/", eg. "192.169.0.3/24".
79
79
80 #####`NET_GATEWAY`=""
80 #####`NET_GATEWAY`=""
81 Set the IP address for the default gateway.
81 Set the IP address for the default gateway.
82
82
83 #####`NET_DNS_1`=""
83 #####`NET_DNS_1`=""
84 Set the IP address for the first DNS server.
84 Set the IP address for the first DNS server.
85
85
86 #####`NET_DNS_2`=""
86 #####`NET_DNS_2`=""
87 Set the IP address for the second DNS server.
87 Set the IP address for the second DNS server.
88
88
89 #####`NET_DNS_DOMAINS`=""
89 #####`NET_DNS_DOMAINS`=""
90 Set the default DNS search domains to use for non fully qualified host names.
90 Set the default DNS search domains to use for non fully qualified host names.
91
91
92 #####`NET_NTP_1`=""
92 #####`NET_NTP_1`=""
93 Set the IP address for the first NTP server.
93 Set the IP address for the first NTP server.
94
94
95 #####`NET_NTP_2`=""
95 #####`NET_NTP_2`=""
96 Set the IP address for the second NTP server.
96 Set the IP address for the second NTP server.
97
97
98 #### Basic system features:
98 #### Basic system features:
99 ##### `ENABLE_CONSOLE`=true
99 ##### `ENABLE_CONSOLE`=true
100 Enable serial console interface. Recommended if no monitor or keyboard is connected to the RPi2. In case of problems fe. if the network (auto) configuration failed - the serial console can be used to access the system.
100 Enable serial console interface. Recommended if no monitor or keyboard is connected to the RPi2. In case of problems fe. if the network (auto) configuration failed - the serial console can be used to access the system.
101
101
102 ##### `ENABLE_IPV6`=true
102 ##### `ENABLE_IPV6`=true
103 Enable IPv6 support. The network interface configuration is managed via systemd-networkd.
103 Enable IPv6 support. The network interface configuration is managed via systemd-networkd.
104
104
105 ##### `ENABLE_SSHD`=true
105 ##### `ENABLE_SSHD`=true
106 Install and enable OpenSSH service. The default configuration of the service doesn't allow `root` to login. Please use the user `pi` instead and `su -` or `sudo` to execute commands as root.
106 Install and enable OpenSSH service. The default configuration of the service doesn't allow `root` to login. Please use the user `pi` instead and `su -` or `sudo` to execute commands as root.
107
107
108 ##### `ENABLE_RSYSLOG`=true
108 ##### `ENABLE_RSYSLOG`=true
109 If set to false, disable and uninstall rsyslog (so logs will be available only
109 If set to false, disable and uninstall rsyslog (so logs will be available only
110 in journal files)
110 in journal files)
111
111
112 ##### `ENABLE_SOUND`=true
112 ##### `ENABLE_SOUND`=true
113 Enable sound hardware and install Advanced Linux Sound Architecture.
113 Enable sound hardware and install Advanced Linux Sound Architecture.
114
114
115 ##### `ENABLE_HWRANDOM`=true
115 ##### `ENABLE_HWRANDOM`=true
116 Enable Hardware Random Number Generator. Strong random numbers are important for most network based communications that use encryption. It's recommended to be enabled.
116 Enable Hardware Random Number Generator. Strong random numbers are important for most network based communications that use encryption. It's recommended to be enabled.
117
117
118 ##### `ENABLE_MINGPU`=false
118 ##### `ENABLE_MINGPU`=false
119 Minimize the amount of shared memory reserved for the GPU. It doesn't seem to be possible to fully disable the GPU.
119 Minimize the amount of shared memory reserved for the GPU. It doesn't seem to be possible to fully disable the GPU.
120
120
121 ##### `ENABLE_DBUS`=true
121 ##### `ENABLE_DBUS`=true
122 Install and enable D-Bus message bus. Please note that systemd should work without D-bus but it's recommended to be enabled.
122 Install and enable D-Bus message bus. Please note that systemd should work without D-bus but it's recommended to be enabled.
123
123
124 ##### `ENABLE_XORG`=false
124 ##### `ENABLE_XORG`=false
125 Install Xorg open-source X Window System.
125 Install Xorg open-source X Window System.
126
126
127 ##### `ENABLE_WM`=""
127 ##### `ENABLE_WM`=""
128 Install a user defined window manager for the X Window System. To make sure all X related package dependencies are getting installed `ENABLE_XORG` will automatically get enabled if `ENABLE_WM` is used. The `rpi2-gen-image.sh` script has been tested with the following list of window managers: `blackbox`, `openbox`, `fluxbox`, `jwm`, `dwm`, `xfce4`, `awesome`.
128 Install a user defined window manager for the X Window System. To make sure all X related package dependencies are getting installed `ENABLE_XORG` will automatically get enabled if `ENABLE_WM` is used. The `rpi2-gen-image.sh` script has been tested with the following list of window managers: `blackbox`, `openbox`, `fluxbox`, `jwm`, `dwm`, `xfce4`, `awesome`.
129
129
130 #### Advanced system features:
130 #### Advanced system features:
131 ##### `ENABLE_MINBASE`=false
131 ##### `ENABLE_MINBASE`=false
132 Use debootstrap script variant `minbase` which only includes essential packages and apt. This will reduce the disk usage by about 65 MB.
132 Use debootstrap script variant `minbase` which only includes essential packages and apt. This will reduce the disk usage by about 65 MB.
133
133
134 ##### `ENABLE_REDUCE`=false
134 ##### `ENABLE_REDUCE`=false
135 Reduce the disk space usage by deleting packages and files. See `REDUCE_*` parameters for detailed information.
135 Reduce the disk space usage by deleting packages and files. See `REDUCE_*` parameters for detailed information.
136
136
137 ##### `ENABLE_UBOOT`=false
137 ##### `ENABLE_UBOOT`=false
138 Replace default RPi2 second stage bootloader (bootcode.bin) with U-Boot bootloader. U-Boot can boot images via the network using the BOOTP/TFTP protocol.
138 Replace default RPi2 second stage bootloader (bootcode.bin) with U-Boot bootloader. U-Boot can boot images via the network using the BOOTP/TFTP protocol.
139
139
140 ##### `ENABLE_FBTURBO`=false
140 ##### `ENABLE_FBTURBO`=false
141 Install and enable the hardware accelerated Xorg video driver `fbturbo`. Please note that this driver is currently limited to hardware accelerated window moving and scrolling.
141 Install and enable the hardware accelerated Xorg video driver `fbturbo`. Please note that this driver is currently limited to hardware accelerated window moving and scrolling.
142
142
143 ##### `ENABLE_IPTABLES`=false
143 ##### `ENABLE_IPTABLES`=false
144 Enable iptables IPv4/IPv6 firewall. Simplified ruleset: Allow all outgoing connections. Block all incoming connections except to OpenSSH service.
144 Enable iptables IPv4/IPv6 firewall. Simplified ruleset: Allow all outgoing connections. Block all incoming connections except to OpenSSH service.
145
145
146 ##### `ENABLE_USER`=true
146 ##### `ENABLE_USER`=true
147 Create pi user with password raspberry
147 Create non-root user with password raspberry. Unless overridden with `USER_NAME`=user, username will be `pi`.
148
149 ##### `USER_NAME`=pi
150 Non-root user to create. Ignored if `ENABLE_USER`=false
148
151
149 ##### `ENABLE_ROOT`=true
152 ##### `ENABLE_ROOT`=true
150 Set root user password so root login will be enabled
153 Set root user password so root login will be enabled
151
154
152 ##### `ENABLE_ROOT_SSH`=true
155 ##### `ENABLE_ROOT_SSH`=true
153 Enable password root login via SSH. May be a security risk with default
156 Enable password root login via SSH. May be a security risk with default
154 password, use only in trusted environments.
157 password, use only in trusted environments.
155
158
156 ##### `ENABLE_HARDNET`=false
159 ##### `ENABLE_HARDNET`=false
157 Enable IPv4/IPv6 network stack hardening settings.
160 Enable IPv4/IPv6 network stack hardening settings.
158
161
159 ##### `ENABLE_SPLITFS`=false
162 ##### `ENABLE_SPLITFS`=false
160 Enable having root partition on an USB drive by creating two image files: one for the `/boot/firmware` mount point, and another for `/`.
163 Enable having root partition on an USB drive by creating two image files: one for the `/boot/firmware` mount point, and another for `/`.
161
164
162 ##### `CHROOT_SCRIPTS`=""
165 ##### `CHROOT_SCRIPTS`=""
163 Path to a directory with scripts that should be run in the chroot before the image is finally built. Every executable file in this directory is run in lexicographical order.
166 Path to a directory with scripts that should be run in the chroot before the image is finally built. Every executable file in this directory is run in lexicographical order.
164
167
165 ##### `ENABLE_INITRAMFS`=false
168 ##### `ENABLE_INITRAMFS`=false
166 Create an initramfs that that will be loaded during the Linux startup process. `ENABLE_INITRAMFS` will automatically get enabled if `ENABLE_CRYPTFS`=true. This parameter will be ignored if `BUILD_KERNEL`=false.
169 Create an initramfs that that will be loaded during the Linux startup process. `ENABLE_INITRAMFS` will automatically get enabled if `ENABLE_CRYPTFS`=true. This parameter will be ignored if `BUILD_KERNEL`=false.
167
170
168 #### Kernel compilation:
171 #### Kernel compilation:
169 ##### `BUILD_KERNEL`=false
172 ##### `BUILD_KERNEL`=false
170 Build and install the latest RPi2 Linux kernel. Currently only the default RPi2 kernel configuration is used.
173 Build and install the latest RPi2 Linux kernel. Currently only the default RPi2 kernel configuration is used.
171
174
172 ##### `KERNEL_REDUCE`=false
175 ##### `KERNEL_REDUCE`=false
173 Reduce the size of the generated kernel by removing unwanted device, network and filesystem drivers (experimental).
176 Reduce the size of the generated kernel by removing unwanted device, network and filesystem drivers (experimental).
174
177
175 ##### `KERNEL_THREADS`=1
178 ##### `KERNEL_THREADS`=1
176 Number of parallel kernel building threads. If the parameter is left untouched the script will automatically determine the number of CPU cores to set the number of parallel threads to speed the kernel compilation.
179 Number of parallel kernel building threads. If the parameter is left untouched the script will automatically determine the number of CPU cores to set the number of parallel threads to speed the kernel compilation.
177
180
178 ##### `KERNEL_HEADERS`=true
181 ##### `KERNEL_HEADERS`=true
179 Install kernel headers with built kernel.
182 Install kernel headers with built kernel.
180
183
181 ##### `KERNEL_MENUCONFIG`=false
184 ##### `KERNEL_MENUCONFIG`=false
182 Start `make menuconfig` interactive menu-driven kernel configuration. The script will continue after `make menuconfig` was terminated.
185 Start `make menuconfig` interactive menu-driven kernel configuration. The script will continue after `make menuconfig` was terminated.
183
186
184 ##### `KERNEL_REMOVESRC`=true
187 ##### `KERNEL_REMOVESRC`=true
185 Remove all kernel sources from the generated OS image after it was built and installed.
188 Remove all kernel sources from the generated OS image after it was built and installed.
186
189
187 ##### `KERNELSRC_DIR`=""
190 ##### `KERNELSRC_DIR`=""
188 Path to a directory of [RaspberryPi Linux kernel sources](https://github.com/raspberrypi/linux) that will be copied, configured, build and installed inside the chroot.
191 Path to a directory of [RaspberryPi Linux kernel sources](https://github.com/raspberrypi/linux) that will be copied, configured, build and installed inside the chroot.
189
192
190 ##### `KERNELSRC_CLEAN`=false
193 ##### `KERNELSRC_CLEAN`=false
191 Clean the existing kernel sources directory `KERNELSRC_DIR` (using `make mrproper`) after it was copied to the chroot and before the compilation of the kernel has started. This parameter will be ignored if no `KERNELSRC_DIR` was specified or if `KERNELSRC_PREBUILT`=true.
194 Clean the existing kernel sources directory `KERNELSRC_DIR` (using `make mrproper`) after it was copied to the chroot and before the compilation of the kernel has started. This parameter will be ignored if no `KERNELSRC_DIR` was specified or if `KERNELSRC_PREBUILT`=true.
192
195
193 ##### `KERNELSRC_CONFIG`=true
196 ##### `KERNELSRC_CONFIG`=true
194 Run `make bcm2709_defconfig` (and optional `make menuconfig`) to configure the kernel sources before building. This parameter is automatically set to `true` if no existing kernel sources directory was specified using `KERNELSRC_DIR`. This parameter is ignored if `KERNELSRC_PREBUILT`=true.
197 Run `make bcm2709_defconfig` (and optional `make menuconfig`) to configure the kernel sources before building. This parameter is automatically set to `true` if no existing kernel sources directory was specified using `KERNELSRC_DIR`. This parameter is ignored if `KERNELSRC_PREBUILT`=true.
195
198
196 ##### `KERNELSRC_PREBUILT`=false
199 ##### `KERNELSRC_PREBUILT`=false
197 With this parameter set to true the script expects the existing kernel sources directory to be already successfully cross-compiled. The parameters `KERNELSRC_CLEAN`, `KERNELSRC_CONFIG` and `KERNEL_MENUCONFIG` are ignored and no kernel compilation tasks are performed.
200 With this parameter set to true the script expects the existing kernel sources directory to be already successfully cross-compiled. The parameters `KERNELSRC_CLEAN`, `KERNELSRC_CONFIG` and `KERNEL_MENUCONFIG` are ignored and no kernel compilation tasks are performed.
198
201
199 ##### `FIRMWAREDIR`=""
202 ##### `FIRMWAREDIR`=""
200 The directory containing a local copy of the firmware from the [RaspberryPi firmware project](https://github.com/raspberrypi/firmware). Default is to download the latest firmware directly from the project.
203 The directory containing a local copy of the firmware from the [RaspberryPi firmware project](https://github.com/raspberrypi/firmware). Default is to download the latest firmware directly from the project.
201
204
202 #### Reduce disk usage:
205 #### Reduce disk usage:
203 The following list of parameters is ignored if `ENABLE_REDUCE`=false.
206 The following list of parameters is ignored if `ENABLE_REDUCE`=false.
204
207
205 ##### `REDUCE_APT`=true
208 ##### `REDUCE_APT`=true
206 Configure APT to use compressed package repository lists and no package caching files.
209 Configure APT to use compressed package repository lists and no package caching files.
207
210
208 ##### `REDUCE_DOC`=true
211 ##### `REDUCE_DOC`=true
209 Remove all doc files (harsh). Configure APT to not include doc files on future `apt-get` package installations.
212 Remove all doc files (harsh). Configure APT to not include doc files on future `apt-get` package installations.
210
213
211 ##### `REDUCE_MAN`=true
214 ##### `REDUCE_MAN`=true
212 Remove all man pages and info files (harsh). Configure APT to not include man pages on future `apt-get` package installations.
215 Remove all man pages and info files (harsh). Configure APT to not include man pages on future `apt-get` package installations.
213
216
214 ##### `REDUCE_VIM`=false
217 ##### `REDUCE_VIM`=false
215 Replace `vim-tiny` package by `levee` a tiny vim clone.
218 Replace `vim-tiny` package by `levee` a tiny vim clone.
216
219
217 ##### `REDUCE_BASH`=false
220 ##### `REDUCE_BASH`=false
218 Remove `bash` package and switch to `dash` shell (experimental).
221 Remove `bash` package and switch to `dash` shell (experimental).
219
222
220 ##### `REDUCE_HWDB`=true
223 ##### `REDUCE_HWDB`=true
221 Remove PCI related hwdb files (experimental).
224 Remove PCI related hwdb files (experimental).
222
225
223 ##### `REDUCE_SSHD`=true
226 ##### `REDUCE_SSHD`=true
224 Replace `openssh-server` with `dropbear`.
227 Replace `openssh-server` with `dropbear`.
225
228
226 ##### `REDUCE_LOCALE`=true
229 ##### `REDUCE_LOCALE`=true
227 Remove all `locale` translation files.
230 Remove all `locale` translation files.
228
231
229 #### Encrypted root partition:
232 #### Encrypted root partition:
230
233
231 ##### `ENABLE_CRYPTFS`=false
234 ##### `ENABLE_CRYPTFS`=false
232 Enable full system encryption with dm-crypt. Setup a fully LUKS encrypted root partition (aes-xts-plain64:sha512) and generate required initramfs. The /boot directory will not be encrypted. This parameter will be ignored if `BUILD_KERNEL`=false. `ENABLE_CRYPTFS` is experimental. SSH-to-initramfs is currently not supported but will be soon - feel free to help.
235 Enable full system encryption with dm-crypt. Setup a fully LUKS encrypted root partition (aes-xts-plain64:sha512) and generate required initramfs. The /boot directory will not be encrypted. This parameter will be ignored if `BUILD_KERNEL`=false. `ENABLE_CRYPTFS` is experimental. SSH-to-initramfs is currently not supported but will be soon - feel free to help.
233
236
234 ##### `CRYPTFS_PASSWORD`=""
237 ##### `CRYPTFS_PASSWORD`=""
235 Set password of the encrypted root partition. This parameter is mandatory if `ENABLE_CRYPTFS`=true.
238 Set password of the encrypted root partition. This parameter is mandatory if `ENABLE_CRYPTFS`=true.
236
239
237 ##### `CRYPTFS_MAPPING`="secure"
240 ##### `CRYPTFS_MAPPING`="secure"
238 Set name of dm-crypt managed device-mapper mapping.
241 Set name of dm-crypt managed device-mapper mapping.
239
242
240 ##### `CRYPTFS_CIPHER`="aes-xts-plain64:sha512"
243 ##### `CRYPTFS_CIPHER`="aes-xts-plain64:sha512"
241 Set cipher specification string. `aes-xts*` ciphers are strongly recommended.
244 Set cipher specification string. `aes-xts*` ciphers are strongly recommended.
242
245
243 ##### `CRYPTFS_XTSKEYSIZE`=512
246 ##### `CRYPTFS_XTSKEYSIZE`=512
244 Sets key size in bits. The argument has to be a multiple of 8.
247 Sets key size in bits. The argument has to be a multiple of 8.
245
248
246 ## Understanding the script
249 ## Understanding the script
247 The functions of this script that are required for the different stages of the bootstrapping are split up into single files located inside the `bootstrap.d` directory. During the bootstrapping every script in this directory gets executed in lexicographical order:
250 The functions of this script that are required for the different stages of the bootstrapping are split up into single files located inside the `bootstrap.d` directory. During the bootstrapping every script in this directory gets executed in lexicographical order:
248
251
249 | Script | Description |
252 | Script | Description |
250 | --- | --- |
253 | --- | --- |
251 | `10-bootstrap.sh` | Debootstrap basic system |
254 | `10-bootstrap.sh` | Debootstrap basic system |
252 | `11-apt.sh` | Setup APT repositories |
255 | `11-apt.sh` | Setup APT repositories |
253 | `12-locale.sh` | Setup Locales and keyboard settings |
256 | `12-locale.sh` | Setup Locales and keyboard settings |
254 | `13-kernel.sh` | Build and install RPi2 Kernel |
257 | `13-kernel.sh` | Build and install RPi2 Kernel |
255 | `20-networking.sh` | Setup Networking |
258 | `20-networking.sh` | Setup Networking |
256 | `21-firewall.sh` | Setup Firewall |
259 | `21-firewall.sh` | Setup Firewall |
257 | `30-security.sh` | Setup Users and Security settings |
260 | `30-security.sh` | Setup Users and Security settings |
258 | `31-logging.sh` | Setup Logging |
261 | `31-logging.sh` | Setup Logging |
259 | `41-uboot.sh` | Build and Setup U-Boot |
262 | `41-uboot.sh` | Build and Setup U-Boot |
260 | `42-fbturbo.sh` | Build and Setup fbturbo Xorg driver |
263 | `42-fbturbo.sh` | Build and Setup fbturbo Xorg driver |
261 | `50-firstboot.sh` | First boot actions |
264 | `50-firstboot.sh` | First boot actions |
262 | `99-reduce.sh` | Reduce the disk space usage |
265 | `99-reduce.sh` | Reduce the disk space usage |
263
266
264 All the required configuration files that will be copied to the generated OS image are located inside the `files` directory. It is not recommended to modify these configuration files manually.
267 All the required configuration files that will be copied to the generated OS image are located inside the `files` directory. It is not recommended to modify these configuration files manually.
265
268
266 | Directory | Description |
269 | Directory | Description |
267 | --- | --- |
270 | --- | --- |
268 | `apt` | APT management configuration files |
271 | `apt` | APT management configuration files |
269 | `boot` | Boot and RPi2 configuration files |
272 | `boot` | Boot and RPi2 configuration files |
270 | `dpkg` | Package Manager configuration |
273 | `dpkg` | Package Manager configuration |
271 | `firstboot` | Scripts that get executed on first boot |
274 | `firstboot` | Scripts that get executed on first boot |
272 | `initramfs` | Initramfs scripts |
275 | `initramfs` | Initramfs scripts |
273 | `iptables` | Firewall configuration files |
276 | `iptables` | Firewall configuration files |
274 | `locales` | Locales configuration |
277 | `locales` | Locales configuration |
275 | `modules` | Kernel Modules configuration |
278 | `modules` | Kernel Modules configuration |
276 | `mount` | Fstab configuration |
279 | `mount` | Fstab configuration |
277 | `network` | Networking configuration files |
280 | `network` | Networking configuration files |
278 | `sysctl.d` | Swapping and Network Hardening configuration |
281 | `sysctl.d` | Swapping and Network Hardening configuration |
279 | `xorg` | fbturbo Xorg driver configuration |
282 | `xorg` | fbturbo Xorg driver configuration |
280
283
281 ## Logging of the bootstrapping process
284 ## Logging of the bootstrapping process
282 All information related to the bootstrapping process and the commands executed by the `rpi2-gen-image.sh` script can easily be saved into a logfile. The common shell command `script` can be used for this purpose:
285 All information related to the bootstrapping process and the commands executed by the `rpi2-gen-image.sh` script can easily be saved into a logfile. The common shell command `script` can be used for this purpose:
283
286
284 ```shell
287 ```shell
285 script -c 'APT_SERVER=ftp.de.debian.org ./rpi2-gen-image.sh' ./build.log
288 script -c 'APT_SERVER=ftp.de.debian.org ./rpi2-gen-image.sh' ./build.log
286 ```
289 ```
287
290
288 ## Flashing the image file
291 ## Flashing the image file
289 After the image file was successfully created by the `rpi2-gen-image.sh` script it can be copied to the microSD card that will be used by the RPi2 computer. This can be performed by using the tools `bmaptool` or `dd`. Using `bmaptool` will probably speed-up the copy process because `bmaptool` copies more wisely than `dd`.
292 After the image file was successfully created by the `rpi2-gen-image.sh` script it can be copied to the microSD card that will be used by the RPi2 computer. This can be performed by using the tools `bmaptool` or `dd`. Using `bmaptool` will probably speed-up the copy process because `bmaptool` copies more wisely than `dd`.
290
293
291 #####Flashing examples:
294 #####Flashing examples:
292 ```shell
295 ```shell
293 bmaptool copy ./images/jessie/2015-12-13-debian-jessie.img /dev/mmcblk0
296 bmaptool copy ./images/jessie/2015-12-13-debian-jessie.img /dev/mmcblk0
294 dd bs=4M if=./images/jessie/2015-12-13-debian-jessie.img of=/dev/mmcblk0
297 dd bs=4M if=./images/jessie/2015-12-13-debian-jessie.img of=/dev/mmcblk0
295 ```
298 ```
296 If you have set `ENABLE_SPLITFS`, copy the `-frmw` image on the microSD card, then the `-root` one on the USB drive:
299 If you have set `ENABLE_SPLITFS`, copy the `-frmw` image on the microSD card, then the `-root` one on the USB drive:
297 ```shell
300 ```shell
298 bmaptool copy ./images/jessie/2015-12-13-debian-jessie-frmw.img /dev/mmcblk0
301 bmaptool copy ./images/jessie/2015-12-13-debian-jessie-frmw.img /dev/mmcblk0
299 bmaptool copy ./images/jessie/2015-12-13-debian-jessie-root.img /dev/sdc
302 bmaptool copy ./images/jessie/2015-12-13-debian-jessie-root.img /dev/sdc
300 ```
303 ```
@@ -1,32 +1,33
1 #
1 #
2 # Setup users and security settings
2 # Setup users and security settings
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 # Generate crypt(3) password string
8 # Generate crypt(3) password string
9 ENCRYPTED_PASSWORD=`mkpasswd -m sha-512 "${PASSWORD}"`
9 ENCRYPTED_PASSWORD=`mkpasswd -m sha-512 "${PASSWORD}"`
10
10
11 # Setup default user
11 # Setup default user
12 if [ "$ENABLE_USER" = true ] ; then
12 if [ "$ENABLE_USER" = true ] ; then
13 chroot_exec adduser --gecos pi --add_extra_groups --disabled-password pi
13 chroot_exec adduser --gecos $USER_NAME --add_extra_groups \
14 chroot_exec usermod -a -G sudo -p "${ENCRYPTED_PASSWORD}" pi
14 --disabled-password $USER_NAME
15 chroot_exec usermod -a -G sudo -p "${ENCRYPTED_PASSWORD}" $USER_NAME
15 fi
16 fi
16
17
17 # Setup root password or not
18 # Setup root password or not
18 if [ "$ENABLE_ROOT" = true ] ; then
19 if [ "$ENABLE_ROOT" = true ] ; then
19 chroot_exec usermod -p "${ENCRYPTED_PASSWORD}" root
20 chroot_exec usermod -p "${ENCRYPTED_PASSWORD}" root
20
21
21 if [ "$ENABLE_ROOT_SSH" = true ] ; then
22 if [ "$ENABLE_ROOT_SSH" = true ] ; then
22 sed -i "s|[#]*PermitRootLogin.*|PermitRootLogin yes|g" "${ETCDIR}/ssh/sshd_config"
23 sed -i "s|[#]*PermitRootLogin.*|PermitRootLogin yes|g" "${ETCDIR}/ssh/sshd_config"
23 fi
24 fi
24 else
25 else
25 # Set no root password to disable root login
26 # Set no root password to disable root login
26 chroot_exec usermod -p \'!\' root
27 chroot_exec usermod -p \'!\' root
27 fi
28 fi
28
29
29 # Enable serial console systemd style
30 # Enable serial console systemd style
30 if [ "$ENABLE_CONSOLE" = true ] ; then
31 if [ "$ENABLE_CONSOLE" = true ] ; then
31 chroot_exec systemctl enable serial-getty\@ttyAMA0.service
32 chroot_exec systemctl enable serial-getty\@ttyAMA0.service
32 fi
33 fi
@@ -1,516 +1,517
1 #!/bin/sh
1 #!/bin/sh
2
2
3 ########################################################################
3 ########################################################################
4 # rpi2-gen-image.sh ver2a 12/2015
4 # rpi2-gen-image.sh ver2a 12/2015
5 #
5 #
6 # Advanced debian "jessie" bootstrap script for RPi2
6 # Advanced debian "jessie" bootstrap script for RPi2
7 #
7 #
8 # This program is free software; you can redistribute it and/or
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
11 # of the License, or (at your option) any later version.
12 #
12 #
13 # some parts based on rpi2-build-image:
13 # some parts based on rpi2-build-image:
14 # Copyright (C) 2015 Ryan Finnie <ryan@finnie.org>
14 # Copyright (C) 2015 Ryan Finnie <ryan@finnie.org>
15 # Copyright (C) 2015 Luca Falavigna <dktrkranz@debian.org>
15 # Copyright (C) 2015 Luca Falavigna <dktrkranz@debian.org>
16 ########################################################################
16 ########################################################################
17
17
18 # Are we running as root?
18 # Are we running as root?
19 if [ "$(id -u)" -ne "0" ] ; then
19 if [ "$(id -u)" -ne "0" ] ; then
20 echo "error: this script must be executed with root privileges!"
20 echo "error: this script must be executed with root privileges!"
21 exit 1
21 exit 1
22 fi
22 fi
23
23
24 # Check if ./functions.sh script exists
24 # Check if ./functions.sh script exists
25 if [ ! -r "./functions.sh" ] ; then
25 if [ ! -r "./functions.sh" ] ; then
26 echo "error: './functions.sh' required script not found!"
26 echo "error: './functions.sh' required script not found!"
27 exit 1
27 exit 1
28 fi
28 fi
29
29
30 # Load utility functions
30 # Load utility functions
31 . ./functions.sh
31 . ./functions.sh
32
32
33 # Introduce settings
33 # Introduce settings
34 set -e
34 set -e
35 echo -n -e "\n#\n# RPi2 Bootstrap Settings\n#\n"
35 echo -n -e "\n#\n# RPi2 Bootstrap Settings\n#\n"
36 set -x
36 set -x
37
37
38 # Debian release
38 # Debian release
39 RELEASE=${RELEASE:=jessie}
39 RELEASE=${RELEASE:=jessie}
40 KERNEL_ARCH=${KERNEL_ARCH:=arm}
40 KERNEL_ARCH=${KERNEL_ARCH:=arm}
41 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
41 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
42 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
42 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
43 COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2}
43 COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2}
44 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
44 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
45 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
45 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
46 DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
46 DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
47 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
47 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
48 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
48 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
49
49
50 # Build directories
50 # Build directories
51 BASEDIR="$(pwd)/images/${RELEASE}"
51 BASEDIR="$(pwd)/images/${RELEASE}"
52 BUILDDIR="${BASEDIR}/build"
52 BUILDDIR="${BASEDIR}/build"
53
53
54 # Chroot directories
54 # Chroot directories
55 R="${BUILDDIR}/chroot"
55 R="${BUILDDIR}/chroot"
56 ETCDIR="${R}/etc"
56 ETCDIR="${R}/etc"
57 BOOTDIR="${R}/boot/firmware"
57 BOOTDIR="${R}/boot/firmware"
58 KERNELDIR="${R}/usr/src/linux"
58 KERNELDIR="${R}/usr/src/linux"
59
59
60 # Firmware directory: Blank if download from github
60 # Firmware directory: Blank if download from github
61 FIRMWAREDIR=${FIRMWAREDIR:=""}
61 FIRMWAREDIR=${FIRMWAREDIR:=""}
62
62
63 # General settings
63 # General settings
64 HOSTNAME=${HOSTNAME:=rpi2-${RELEASE}}
64 HOSTNAME=${HOSTNAME:=rpi2-${RELEASE}}
65 PASSWORD=${PASSWORD:=raspberry}
65 PASSWORD=${PASSWORD:=raspberry}
66 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
66 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
67 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
67 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
68 EXPANDROOT=${EXPANDROOT:=true}
68 EXPANDROOT=${EXPANDROOT:=true}
69
69
70 # Keyboard settings
70 # Keyboard settings
71 XKB_MODEL=${XKB_MODEL:=""}
71 XKB_MODEL=${XKB_MODEL:=""}
72 XKB_LAYOUT=${XKB_LAYOUT:=""}
72 XKB_LAYOUT=${XKB_LAYOUT:=""}
73 XKB_VARIANT=${XKB_VARIANT:=""}
73 XKB_VARIANT=${XKB_VARIANT:=""}
74 XKB_OPTIONS=${XKB_OPTIONS:=""}
74 XKB_OPTIONS=${XKB_OPTIONS:=""}
75
75
76 # Network settings (DHCP)
76 # Network settings (DHCP)
77 ENABLE_DHCP=${ENABLE_DHCP:=true}
77 ENABLE_DHCP=${ENABLE_DHCP:=true}
78
78
79 # Network settings (static)
79 # Network settings (static)
80 NET_ADDRESS=${NET_ADDRESS:=""}
80 NET_ADDRESS=${NET_ADDRESS:=""}
81 NET_GATEWAY=${NET_GATEWAY:=""}
81 NET_GATEWAY=${NET_GATEWAY:=""}
82 NET_DNS_1=${NET_DNS_1:=""}
82 NET_DNS_1=${NET_DNS_1:=""}
83 NET_DNS_2=${NET_DNS_2:=""}
83 NET_DNS_2=${NET_DNS_2:=""}
84 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
84 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
85 NET_NTP_1=${NET_NTP_1:=""}
85 NET_NTP_1=${NET_NTP_1:=""}
86 NET_NTP_2=${NET_NTP_2:=""}
86 NET_NTP_2=${NET_NTP_2:=""}
87
87
88 # APT settings
88 # APT settings
89 APT_PROXY=${APT_PROXY:=""}
89 APT_PROXY=${APT_PROXY:=""}
90 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
90 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
91
91
92 # Feature settings
92 # Feature settings
93 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
93 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
94 ENABLE_IPV6=${ENABLE_IPV6:=true}
94 ENABLE_IPV6=${ENABLE_IPV6:=true}
95 ENABLE_SSHD=${ENABLE_SSHD:=true}
95 ENABLE_SSHD=${ENABLE_SSHD:=true}
96 ENABLE_SOUND=${ENABLE_SOUND:=true}
96 ENABLE_SOUND=${ENABLE_SOUND:=true}
97 ENABLE_DBUS=${ENABLE_DBUS:=true}
97 ENABLE_DBUS=${ENABLE_DBUS:=true}
98 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
98 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
99 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
99 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
100 ENABLE_XORG=${ENABLE_XORG:=false}
100 ENABLE_XORG=${ENABLE_XORG:=false}
101 ENABLE_WM=${ENABLE_WM:=""}
101 ENABLE_WM=${ENABLE_WM:=""}
102 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
102 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
103 ENABLE_USER=${ENABLE_USER:=true}
103 ENABLE_USER=${ENABLE_USER:=true}
104 USER_NAME=${USER_NAME:="pi"}
104 ENABLE_ROOT=${ENABLE_ROOT:=false}
105 ENABLE_ROOT=${ENABLE_ROOT:=false}
105 ENABLE_ROOT_SSH=${ENABLE_ROOT_SSH:=false}
106 ENABLE_ROOT_SSH=${ENABLE_ROOT_SSH:=false}
106
107
107 # Advanced settings
108 # Advanced settings
108 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
109 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
109 ENABLE_REDUCE=${ENABLE_REDUCE:=flase}
110 ENABLE_REDUCE=${ENABLE_REDUCE:=flase}
110 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
111 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
111 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
112 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
112 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
113 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
113 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
114 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
114 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
115 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
115 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
116 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
116
117
117 # Kernel compilation settings
118 # Kernel compilation settings
118 BUILD_KERNEL=${BUILD_KERNEL:=false}
119 BUILD_KERNEL=${BUILD_KERNEL:=false}
119 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
120 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
120 KERNEL_THREADS=${KERNEL_THREADS:=1}
121 KERNEL_THREADS=${KERNEL_THREADS:=1}
121 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
122 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
122 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
123 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
123 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
124 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
124
125
125 # Kernel compilation from source directory settings
126 # Kernel compilation from source directory settings
126 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
127 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
127 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
128 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
128 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
129 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
129 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
130 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
130
131
131 # Reduce disk usage settings
132 # Reduce disk usage settings
132 REDUCE_APT=${REDUCE_APT:=true}
133 REDUCE_APT=${REDUCE_APT:=true}
133 REDUCE_DOC=${REDUCE_DOC:=true}
134 REDUCE_DOC=${REDUCE_DOC:=true}
134 REDUCE_MAN=${REDUCE_MAN:=true}
135 REDUCE_MAN=${REDUCE_MAN:=true}
135 REDUCE_VIM=${REDUCE_VIM:=false}
136 REDUCE_VIM=${REDUCE_VIM:=false}
136 REDUCE_BASH=${REDUCE_BASH:=false}
137 REDUCE_BASH=${REDUCE_BASH:=false}
137 REDUCE_HWDB=${REDUCE_HWDB:=true}
138 REDUCE_HWDB=${REDUCE_HWDB:=true}
138 REDUCE_SSHD=${REDUCE_SSHD:=true}
139 REDUCE_SSHD=${REDUCE_SSHD:=true}
139 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
140 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
140
141
141 # Encrypted filesystem settings
142 # Encrypted filesystem settings
142 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
143 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
143 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
144 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
144 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
145 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
145 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
146 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
146 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
147 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
147
148
148 # Stop the Crypto Wars
149 # Stop the Crypto Wars
149 DISABLE_FBI=${DISABLE_FBI:=false}
150 DISABLE_FBI=${DISABLE_FBI:=false}
150
151
151 # Chroot scripts directory
152 # Chroot scripts directory
152 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
153 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
153
154
154 # Packages required in the chroot build environment
155 # Packages required in the chroot build environment
155 APT_INCLUDES=${APT_INCLUDES:=""}
156 APT_INCLUDES=${APT_INCLUDES:=""}
156 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo"
157 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo"
157
158
158 # Packages required for bootstrapping
159 # Packages required for bootstrapping
159 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git"
160 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git"
160 MISSING_PACKAGES=""
161 MISSING_PACKAGES=""
161
162
162 set +x
163 set +x
163
164
164 # Add packages required for kernel cross compilation
165 # Add packages required for kernel cross compilation
165 if [ "$BUILD_KERNEL" = true ] ; then
166 if [ "$BUILD_KERNEL" = true ] ; then
166 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
167 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
167 fi
168 fi
168
169
169 # Add libncurses5 to enable kernel menuconfig
170 # Add libncurses5 to enable kernel menuconfig
170 if [ "$KERNEL_MENUCONFIG" = true ] ; then
171 if [ "$KERNEL_MENUCONFIG" = true ] ; then
171 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
172 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
172 fi
173 fi
173
174
174 # Stop the Crypto Wars
175 # Stop the Crypto Wars
175 if [ "$DISABLE_FBI" = true ] ; then
176 if [ "$DISABLE_FBI" = true ] ; then
176 ENABLE_CRYPTFS=true
177 ENABLE_CRYPTFS=true
177 fi
178 fi
178
179
179 # Add cryptsetup package to enable filesystem encryption
180 # Add cryptsetup package to enable filesystem encryption
180 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
181 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
181 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
182 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
182 APT_INCLUDES="${APT_INCLUDES},cryptsetup"
183 APT_INCLUDES="${APT_INCLUDES},cryptsetup"
183
184
184 if [ -z "$CRYPTFS_PASSWORD" ] ; then
185 if [ -z "$CRYPTFS_PASSWORD" ] ; then
185 echo "error: no password defined (CRYPTFS_PASSWORD)!"
186 echo "error: no password defined (CRYPTFS_PASSWORD)!"
186 exit 1
187 exit 1
187 fi
188 fi
188 ENABLE_INITRAMFS=true
189 ENABLE_INITRAMFS=true
189 fi
190 fi
190
191
191 # Add initramfs generation tools
192 # Add initramfs generation tools
192 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
193 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
193 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
194 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
194 fi
195 fi
195
196
196 # Check if all required packages are installed on the build system
197 # Check if all required packages are installed on the build system
197 for package in $REQUIRED_PACKAGES ; do
198 for package in $REQUIRED_PACKAGES ; do
198 if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then
199 if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then
199 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
200 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
200 fi
201 fi
201 done
202 done
202
203
203 # Ask if missing packages should get installed right now
204 # Ask if missing packages should get installed right now
204 if [ -n "$MISSING_PACKAGES" ] ; then
205 if [ -n "$MISSING_PACKAGES" ] ; then
205 echo "the following packages needed by this script are not installed:"
206 echo "the following packages needed by this script are not installed:"
206 echo "$MISSING_PACKAGES"
207 echo "$MISSING_PACKAGES"
207
208
208 echo -n "\ndo you want to install the missing packages right now? [y/n] "
209 echo -n "\ndo you want to install the missing packages right now? [y/n] "
209 read confirm
210 read confirm
210 [ "$confirm" != "y" ] && exit 1
211 [ "$confirm" != "y" ] && exit 1
211 fi
212 fi
212
213
213 # Make sure all required packages are installed
214 # Make sure all required packages are installed
214 apt-get -qq -y install ${REQUIRED_PACKAGES}
215 apt-get -qq -y install ${REQUIRED_PACKAGES}
215
216
216 # Check if ./bootstrap.d directory exists
217 # Check if ./bootstrap.d directory exists
217 if [ ! -d "./bootstrap.d/" ] ; then
218 if [ ! -d "./bootstrap.d/" ] ; then
218 echo "error: './bootstrap.d' required directory not found!"
219 echo "error: './bootstrap.d' required directory not found!"
219 exit 1
220 exit 1
220 fi
221 fi
221
222
222 # Check if ./files directory exists
223 # Check if ./files directory exists
223 if [ ! -d "./files/" ] ; then
224 if [ ! -d "./files/" ] ; then
224 echo "error: './files' required directory not found!"
225 echo "error: './files' required directory not found!"
225 exit 1
226 exit 1
226 fi
227 fi
227
228
228 # Check if specified KERNELSRC_DIR directory exists
229 # Check if specified KERNELSRC_DIR directory exists
229 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
230 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
230 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
231 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
231 exit 1
232 exit 1
232 fi
233 fi
233
234
234 # Check if specified CHROOT_SCRIPTS directory exists
235 # Check if specified CHROOT_SCRIPTS directory exists
235 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
236 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
236 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
237 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
237 exit 1
238 exit 1
238 fi
239 fi
239
240
240 # Check if specified device mapping already exists (will be used by cryptsetup)
241 # Check if specified device mapping already exists (will be used by cryptsetup)
241 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
242 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
242 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
243 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
243 exit 1
244 exit 1
244 fi
245 fi
245
246
246 # Don't clobber an old build
247 # Don't clobber an old build
247 if [ -e "$BUILDDIR" ] ; then
248 if [ -e "$BUILDDIR" ] ; then
248 echo "error: directory ${BUILDDIR} already exists, not proceeding"
249 echo "error: directory ${BUILDDIR} already exists, not proceeding"
249 exit 1
250 exit 1
250 fi
251 fi
251
252
252 # Setup chroot directory
253 # Setup chroot directory
253 mkdir -p "${R}"
254 mkdir -p "${R}"
254
255
255 # Check if build directory has enough of free disk space >512MB
256 # Check if build directory has enough of free disk space >512MB
256 if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then
257 if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then
257 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
258 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
258 exit 1
259 exit 1
259 fi
260 fi
260
261
261 set -x
262 set -x
262
263
263 # Call "cleanup" function on various signals and errors
264 # Call "cleanup" function on various signals and errors
264 trap cleanup 0 1 2 3 6
265 trap cleanup 0 1 2 3 6
265
266
266 # Add required packages for the minbase installation
267 # Add required packages for the minbase installation
267 if [ "$ENABLE_MINBASE" = true ] ; then
268 if [ "$ENABLE_MINBASE" = true ] ; then
268 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
269 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
269 else
270 else
270 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
271 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
271 fi
272 fi
272
273
273 # Add parted package, required to get partprobe utility
274 # Add parted package, required to get partprobe utility
274 if [ "$EXPANDROOT" = true ] ; then
275 if [ "$EXPANDROOT" = true ] ; then
275 APT_INCLUDES="${APT_INCLUDES},parted"
276 APT_INCLUDES="${APT_INCLUDES},parted"
276 fi
277 fi
277
278
278 # Add dbus package, recommended if using systemd
279 # Add dbus package, recommended if using systemd
279 if [ "$ENABLE_DBUS" = true ] ; then
280 if [ "$ENABLE_DBUS" = true ] ; then
280 APT_INCLUDES="${APT_INCLUDES},dbus"
281 APT_INCLUDES="${APT_INCLUDES},dbus"
281 fi
282 fi
282
283
283 # Add iptables IPv4/IPv6 package
284 # Add iptables IPv4/IPv6 package
284 if [ "$ENABLE_IPTABLES" = true ] ; then
285 if [ "$ENABLE_IPTABLES" = true ] ; then
285 APT_INCLUDES="${APT_INCLUDES},iptables"
286 APT_INCLUDES="${APT_INCLUDES},iptables"
286 fi
287 fi
287
288
288 # Add openssh server package
289 # Add openssh server package
289 if [ "$ENABLE_SSHD" = true ] ; then
290 if [ "$ENABLE_SSHD" = true ] ; then
290 APT_INCLUDES="${APT_INCLUDES},openssh-server"
291 APT_INCLUDES="${APT_INCLUDES},openssh-server"
291 fi
292 fi
292
293
293 # Add alsa-utils package
294 # Add alsa-utils package
294 if [ "$ENABLE_SOUND" = true ] ; then
295 if [ "$ENABLE_SOUND" = true ] ; then
295 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
296 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
296 fi
297 fi
297
298
298 # Add rng-tools package
299 # Add rng-tools package
299 if [ "$ENABLE_HWRANDOM" = true ] ; then
300 if [ "$ENABLE_HWRANDOM" = true ] ; then
300 APT_INCLUDES="${APT_INCLUDES},rng-tools"
301 APT_INCLUDES="${APT_INCLUDES},rng-tools"
301 fi
302 fi
302
303
303 # Add fbturbo video driver
304 # Add fbturbo video driver
304 if [ "$ENABLE_FBTURBO" = true ] ; then
305 if [ "$ENABLE_FBTURBO" = true ] ; then
305 # Enable xorg package dependencies
306 # Enable xorg package dependencies
306 ENABLE_XORG=true
307 ENABLE_XORG=true
307 fi
308 fi
308
309
309 # Add user defined window manager package
310 # Add user defined window manager package
310 if [ -n "$ENABLE_WM" ] ; then
311 if [ -n "$ENABLE_WM" ] ; then
311 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
312 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
312
313
313 # Enable xorg package dependencies
314 # Enable xorg package dependencies
314 ENABLE_XORG=true
315 ENABLE_XORG=true
315 fi
316 fi
316
317
317 # Add xorg package
318 # Add xorg package
318 if [ "$ENABLE_XORG" = true ] ; then
319 if [ "$ENABLE_XORG" = true ] ; then
319 APT_INCLUDES="${APT_INCLUDES},xorg"
320 APT_INCLUDES="${APT_INCLUDES},xorg"
320 fi
321 fi
321
322
322 # Replace selected packages with smaller clones
323 # Replace selected packages with smaller clones
323 if [ "$ENABLE_REDUCE" = true ] ; then
324 if [ "$ENABLE_REDUCE" = true ] ; then
324 # Add levee package instead of vim-tiny
325 # Add levee package instead of vim-tiny
325 if [ "$REDUCE_VIM" = true ] ; then
326 if [ "$REDUCE_VIM" = true ] ; then
326 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
327 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
327 fi
328 fi
328
329
329 # Add dropbear package instead of openssh-server
330 # Add dropbear package instead of openssh-server
330 if [ "$REDUCE_SSHD" = true ] ; then
331 if [ "$REDUCE_SSHD" = true ] ; then
331 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")"
332 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")"
332 fi
333 fi
333 fi
334 fi
334
335
335 # Configure kernel sources if no KERNELSRC_DIR
336 # Configure kernel sources if no KERNELSRC_DIR
336 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
337 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
337 KERNELSRC_CONFIG=true
338 KERNELSRC_CONFIG=true
338 fi
339 fi
339
340
340 # Configure reduced kernel
341 # Configure reduced kernel
341 if [ "$KERNEL_REDUCE" = true ] ; then
342 if [ "$KERNEL_REDUCE" = true ] ; then
342 KERNELSRC_CONFIG=false
343 KERNELSRC_CONFIG=false
343 fi
344 fi
344
345
345 # Execute bootstrap scripts
346 # Execute bootstrap scripts
346 for SCRIPT in bootstrap.d/*.sh; do
347 for SCRIPT in bootstrap.d/*.sh; do
347 head -n 3 "$SCRIPT"
348 head -n 3 "$SCRIPT"
348 . "$SCRIPT"
349 . "$SCRIPT"
349 done
350 done
350
351
351 ## Execute custom bootstrap scripts
352 ## Execute custom bootstrap scripts
352 if [ -d "custom.d" ] ; then
353 if [ -d "custom.d" ] ; then
353 for SCRIPT in custom.d/*.sh; do
354 for SCRIPT in custom.d/*.sh; do
354 . "$SCRIPT"
355 . "$SCRIPT"
355 done
356 done
356 fi
357 fi
357
358
358 # Execute custom scripts inside the chroot
359 # Execute custom scripts inside the chroot
359 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
360 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
360 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
361 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
361 chroot_exec /bin/bash -x <<'EOF'
362 chroot_exec /bin/bash -x <<'EOF'
362 for SCRIPT in /chroot_scripts/* ; do
363 for SCRIPT in /chroot_scripts/* ; do
363 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
364 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
364 $SCRIPT
365 $SCRIPT
365 fi
366 fi
366 done
367 done
367 EOF
368 EOF
368 rm -rf "${R}/chroot_scripts"
369 rm -rf "${R}/chroot_scripts"
369 fi
370 fi
370
371
371 # Remove apt-utils
372 # Remove apt-utils
372 chroot_exec apt-get purge -qq -y --force-yes apt-utils
373 chroot_exec apt-get purge -qq -y --force-yes apt-utils
373
374
374 # Generate required machine-id
375 # Generate required machine-id
375 MACHINE_ID=$(dbus-uuidgen)
376 MACHINE_ID=$(dbus-uuidgen)
376 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
377 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
377 echo -n "${MACHINE_ID}" > "${ETCDIR}/machine-id"
378 echo -n "${MACHINE_ID}" > "${ETCDIR}/machine-id"
378
379
379 # APT Cleanup
380 # APT Cleanup
380 chroot_exec apt-get -y clean
381 chroot_exec apt-get -y clean
381 chroot_exec apt-get -y autoclean
382 chroot_exec apt-get -y autoclean
382 chroot_exec apt-get -y autoremove
383 chroot_exec apt-get -y autoremove
383
384
384 # Unmount mounted filesystems
385 # Unmount mounted filesystems
385 umount -l "${R}/proc"
386 umount -l "${R}/proc"
386 umount -l "${R}/sys"
387 umount -l "${R}/sys"
387
388
388 # Clean up directories
389 # Clean up directories
389 rm -rf "${R}/run/*"
390 rm -rf "${R}/run/*"
390 rm -rf "${R}/tmp/*"
391 rm -rf "${R}/tmp/*"
391
392
392 # Clean up files
393 # Clean up files
393 rm -f "${ETCDIR}/ssh/ssh_host_*"
394 rm -f "${ETCDIR}/ssh/ssh_host_*"
394 rm -f "${ETCDIR}/dropbear/dropbear_*"
395 rm -f "${ETCDIR}/dropbear/dropbear_*"
395 rm -f "${ETCDIR}/apt/sources.list.save"
396 rm -f "${ETCDIR}/apt/sources.list.save"
396 rm -f "${ETCDIR}/resolvconf/resolv.conf.d/original"
397 rm -f "${ETCDIR}/resolvconf/resolv.conf.d/original"
397 rm -f "${ETCDIR}/*-"
398 rm -f "${ETCDIR}/*-"
398 rm -f "${ETCDIR}/apt/apt.conf.d/10proxy"
399 rm -f "${ETCDIR}/apt/apt.conf.d/10proxy"
399 rm -f "${ETCDIR}/resolv.conf"
400 rm -f "${ETCDIR}/resolv.conf"
400 rm -f "${R}/root/.bash_history"
401 rm -f "${R}/root/.bash_history"
401 rm -f "${R}/var/lib/urandom/random-seed"
402 rm -f "${R}/var/lib/urandom/random-seed"
402 rm -f "${R}/initrd.img"
403 rm -f "${R}/initrd.img"
403 rm -f "${R}/vmlinuz"
404 rm -f "${R}/vmlinuz"
404 rm -f "${R}${QEMU_BINARY}"
405 rm -f "${R}${QEMU_BINARY}"
405
406
406 # Calculate size of the chroot directory in KB
407 # Calculate size of the chroot directory in KB
407 CHROOT_SIZE=$(expr `du -s "${R}" | awk '{ print $1 }'`)
408 CHROOT_SIZE=$(expr `du -s "${R}" | awk '{ print $1 }'`)
408
409
409 # Calculate the amount of needed 512 Byte sectors
410 # Calculate the amount of needed 512 Byte sectors
410 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
411 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
411 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
412 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
412 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS})
413 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS})
413
414
414 # The root partition is EXT4
415 # The root partition is EXT4
415 # This means more space than the actual used space of the chroot is used.
416 # This means more space than the actual used space of the chroot is used.
416 # As overhead for journaling and reserved blocks 20% are added.
417 # As overhead for journaling and reserved blocks 20% are added.
417 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512)
418 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512)
418
419
419 # Calculate required image size in 512 Byte sectors
420 # Calculate required image size in 512 Byte sectors
420 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS})
421 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS})
421
422
422 # Prepare date string for image file name
423 # Prepare date string for image file name
423 DATE="$(date +%Y-%m-%d)"
424 DATE="$(date +%Y-%m-%d)"
424
425
425 # Prepare image file
426 # Prepare image file
426 if [ "$ENABLE_SPLITFS" = true ] ; then
427 if [ "$ENABLE_SPLITFS" = true ] ; then
427 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=${TABLE_SECTORS}
428 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=${TABLE_SECTORS}
428 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS}
429 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS}
429 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=${TABLE_SECTORS}
430 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=${TABLE_SECTORS}
430 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=0 seek=${ROOT_SECTORS}
431 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=0 seek=${ROOT_SECTORS}
431
432
432 # Write firmware/boot partition tables
433 # Write firmware/boot partition tables
433 sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" 2> /dev/null <<EOM
434 sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" 2> /dev/null <<EOM
434 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
435 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
435 EOM
436 EOM
436
437
437 # Write root partition table
438 # Write root partition table
438 sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}-root.img" 2> /dev/null <<EOM
439 sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}-root.img" 2> /dev/null <<EOM
439 ${TABLE_SECTORS},${ROOT_SECTORS},83
440 ${TABLE_SECTORS},${ROOT_SECTORS},83
440 EOM
441 EOM
441
442
442 # Setup temporary loop devices
443 # Setup temporary loop devices
443 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-frmw.img)"
444 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-frmw.img)"
444 ROOT_LOOP="$(losetup -o 1M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-root.img)"
445 ROOT_LOOP="$(losetup -o 1M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-root.img)"
445 else # ENABLE_SPLITFS=false
446 else # ENABLE_SPLITFS=false
446 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS}
447 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS}
447 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS}
448 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS}
448
449
449 # Write partition table
450 # Write partition table
450 sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" 2> /dev/null <<EOM
451 sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" 2> /dev/null <<EOM
451 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
452 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
452 ${ROOT_OFFSET},${ROOT_SECTORS},83
453 ${ROOT_OFFSET},${ROOT_SECTORS},83
453 EOM
454 EOM
454
455
455 # Setup temporary loop devices
456 # Setup temporary loop devices
456 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
457 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
457 ROOT_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
458 ROOT_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
458 fi
459 fi
459
460
460 if [ "$ENABLE_CRYPTFS" = true ] ; then
461 if [ "$ENABLE_CRYPTFS" = true ] ; then
461 # Create dummy ext4 fs
462 # Create dummy ext4 fs
462 mkfs.ext4 "$ROOT_LOOP"
463 mkfs.ext4 "$ROOT_LOOP"
463
464
464 # Setup password keyfile
465 # Setup password keyfile
465 echo -n ${CRYPTFS_PASSWORD} > .password
466 echo -n ${CRYPTFS_PASSWORD} > .password
466 chmod 600 .password
467 chmod 600 .password
467
468
468 # Initialize encrypted partition
469 # Initialize encrypted partition
469 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
470 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
470
471
471 # Open encrypted partition and setup mapping
472 # Open encrypted partition and setup mapping
472 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
473 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
473
474
474 # Secure delete password keyfile
475 # Secure delete password keyfile
475 shred -zu .password
476 shred -zu .password
476
477
477 # Update temporary loop device
478 # Update temporary loop device
478 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
479 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
479
480
480 # Wipe encrypted partition (encryption cipher is used for randomness)
481 # Wipe encrypted partition (encryption cipher is used for randomness)
481 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count=$(blockdev --getsz "${ROOT_LOOP}")
482 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count=$(blockdev --getsz "${ROOT_LOOP}")
482 fi
483 fi
483
484
484 # Build filesystems
485 # Build filesystems
485 mkfs.vfat "$FRMW_LOOP"
486 mkfs.vfat "$FRMW_LOOP"
486 mkfs.ext4 "$ROOT_LOOP"
487 mkfs.ext4 "$ROOT_LOOP"
487
488
488 # Mount the temporary loop devices
489 # Mount the temporary loop devices
489 mkdir -p "$BUILDDIR/mount"
490 mkdir -p "$BUILDDIR/mount"
490 mount "$ROOT_LOOP" "$BUILDDIR/mount"
491 mount "$ROOT_LOOP" "$BUILDDIR/mount"
491
492
492 mkdir -p "$BUILDDIR/mount/boot/firmware"
493 mkdir -p "$BUILDDIR/mount/boot/firmware"
493 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
494 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
494
495
495 # Copy all files from the chroot to the loop device mount point directory
496 # Copy all files from the chroot to the loop device mount point directory
496 rsync -a "${R}/" "$BUILDDIR/mount/"
497 rsync -a "${R}/" "$BUILDDIR/mount/"
497
498
498 # Unmount all temporary loop devices and mount points
499 # Unmount all temporary loop devices and mount points
499 cleanup
500 cleanup
500
501
501 # Create block map file(s) of image(s)
502 # Create block map file(s) of image(s)
502 if [ "$ENABLE_SPLITFS" = true ] ; then
503 if [ "$ENABLE_SPLITFS" = true ] ; then
503 # Create block map files for "bmaptool"
504 # Create block map files for "bmaptool"
504 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img"
505 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img"
505 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-root.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-root.img"
506 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-root.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-root.img"
506
507
507 # Image was successfully created
508 # Image was successfully created
508 echo "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
509 echo "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
509 echo "$BASEDIR/${DATE}-debian-${RELEASE}-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
510 echo "$BASEDIR/${DATE}-debian-${RELEASE}-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
510 else
511 else
511 # Create block map file for "bmaptool"
512 # Create block map file for "bmaptool"
512 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}.img"
513 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}.img"
513
514
514 # Image was successfully created
515 # Image was successfully created
515 echo "$BASEDIR/${DATE}-debian-${RELEASE}.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
516 echo "$BASEDIR/${DATE}-debian-${RELEASE}.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
516 fi
517 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant