@@ -1,297 +1,307 | |||
|
1 | 1 | # rpi2-gen-image |
|
2 | 2 | ## Introduction |
|
3 | 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 | 5 | ## Build dependencies |
|
6 | 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 | 8 | ```debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git``` |
|
9 | 9 | |
|
10 | 10 | ## Command-line parameters |
|
11 | 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 | 13 | #####Command-line examples: |
|
14 | 14 | ```shell |
|
15 | 15 | ENABLE_UBOOT=true ./rpi2-gen-image.sh |
|
16 | 16 | ENABLE_CONSOLE=false ENABLE_IPV6=false ./rpi2-gen-image.sh |
|
17 | 17 | ENABLE_WM=xfce4 ENABLE_FBTURBO=true ENABLE_MINBASE=true ./rpi2-gen-image.sh |
|
18 | 18 | ENABLE_HARDNET=true ENABLE_IPTABLES=true /rpi2-gen-image.sh |
|
19 | 19 | APT_SERVER=ftp.de.debian.org APT_PROXY="http://127.0.0.1:3142/" ./rpi2-gen-image.sh |
|
20 | 20 | ENABLE_MINBASE=true ./rpi2-gen-image.sh |
|
21 | 21 | BUILD_KERNEL=true ENABLE_MINBASE=true ENABLE_IPV6=false ./rpi2-gen-image.sh |
|
22 | 22 | BUILD_KERNEL=true KERNELSRC_DIR=/tmp/linux ./rpi2-gen-image.sh |
|
23 | 23 | ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi2-gen-image.sh |
|
24 | 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 | 27 | #### APT settings: |
|
28 | 28 | ##### `APT_SERVER`="ftp.debian.org" |
|
29 | 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 | 31 | ##### `APT_PROXY`="" |
|
32 | 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 | 34 | ##### `APT_INCLUDES`="" |
|
35 | 35 | A comma separated list of additional packages to be installed during bootstrapping. |
|
36 | 36 | |
|
37 | 37 | #### General system settings: |
|
38 | 38 | ##### `HOSTNAME`="rpi2-jessie" |
|
39 | 39 | Set system host name. It's recommended that the host name is unique in the corresponding subnet. |
|
40 | 40 | |
|
41 | 41 | ##### `PASSWORD`="raspberry" |
|
42 | 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 | 44 | ##### `DEFLOCAL`="en_US.UTF-8" |
|
45 | 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 | 47 | ##### `TIMEZONE`="Europe/Berlin" |
|
48 | 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 | 50 | ##### `EXPANDROOT`=true |
|
51 | 51 | Expand the root partition and filesystem automatically on first boot. |
|
52 | 52 | |
|
53 | 53 | #### Keyboard settings: |
|
54 | 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 | 56 | ##### `XKB_MODEL`="" |
|
57 | 57 | Set the name of the model of your keyboard type. |
|
58 | 58 | |
|
59 | 59 | ##### `XKB_LAYOUT`="" |
|
60 | 60 | Set the supported keyboard layout(s). |
|
61 | 61 | |
|
62 | 62 | ##### `XKB_VARIANT`="" |
|
63 | 63 | Set the supported variant(s) of the keyboard layout(s). |
|
64 | 64 | |
|
65 | 65 | ##### `XKB_OPTIONS`="" |
|
66 | 66 | Set extra xkb configuration options. |
|
67 | 67 | |
|
68 | 68 | #### Networking settings (DHCP): |
|
69 | 69 | This parameter is used to set up networking auto configuration in `/etc/systemd/network/eth.network`. |
|
70 | 70 | |
|
71 | 71 | #####`ENABLE_DHCP`=true |
|
72 | 72 | Set the system to use DHCP. This requires an DHCP server. |
|
73 | 73 | |
|
74 | 74 | #### Networking settings (static): |
|
75 | 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 | 77 | #####`NET_ADDRESS`="" |
|
78 | 78 | Set a static IPv4 or IPv6 address and its prefix, separated by "/", eg. "192.169.0.3/24". |
|
79 | 79 | |
|
80 | 80 | #####`NET_GATEWAY`="" |
|
81 | 81 | Set the IP address for the default gateway. |
|
82 | 82 | |
|
83 | 83 | #####`NET_DNS_1`="" |
|
84 | 84 | Set the IP address for the first DNS server. |
|
85 | 85 | |
|
86 | 86 | #####`NET_DNS_2`="" |
|
87 | 87 | Set the IP address for the second DNS server. |
|
88 | 88 | |
|
89 | 89 | #####`NET_DNS_DOMAINS`="" |
|
90 | 90 | Set the default DNS search domains to use for non fully qualified host names. |
|
91 | 91 | |
|
92 | 92 | #####`NET_NTP_1`="" |
|
93 | 93 | Set the IP address for the first NTP server. |
|
94 | 94 | |
|
95 | 95 | #####`NET_NTP_2`="" |
|
96 | 96 | Set the IP address for the second NTP server. |
|
97 | 97 | |
|
98 | 98 | #### Basic system features: |
|
99 | 99 | ##### `ENABLE_CONSOLE`=true |
|
100 | 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 | 102 | ##### `ENABLE_IPV6`=true |
|
103 | 103 | Enable IPv6 support. The network interface configuration is managed via systemd-networkd. |
|
104 | 104 | |
|
105 | 105 | ##### `ENABLE_SSHD`=true |
|
106 | 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 | 108 | ##### `ENABLE_RSYSLOG`=true |
|
109 | 109 | If set to false, disable and uninstall rsyslog (so logs will be available only |
|
110 | 110 | in journal files) |
|
111 | 111 | |
|
112 | 112 | ##### `ENABLE_SOUND`=true |
|
113 | 113 | Enable sound hardware and install Advanced Linux Sound Architecture. |
|
114 | 114 | |
|
115 | 115 | ##### `ENABLE_HWRANDOM`=true |
|
116 | 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 | 118 | ##### `ENABLE_MINGPU`=false |
|
119 | 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 | 121 | ##### `ENABLE_DBUS`=true |
|
122 | 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 | 124 | ##### `ENABLE_XORG`=false |
|
125 | 125 | Install Xorg open-source X Window System. |
|
126 | 126 | |
|
127 | 127 | ##### `ENABLE_WM`="" |
|
128 | 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 | 130 | #### Advanced system features: |
|
131 | 131 | ##### `ENABLE_MINBASE`=false |
|
132 | 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 | 134 | ##### `ENABLE_REDUCE`=false |
|
135 | 135 | Reduce the disk space usage by deleting packages and files. See `REDUCE_*` parameters for detailed information. |
|
136 | 136 | |
|
137 | 137 | ##### `ENABLE_UBOOT`=false |
|
138 | 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 | 140 | ##### `ENABLE_FBTURBO`=false |
|
141 | 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 | 143 | ##### `ENABLE_IPTABLES`=false |
|
144 | 144 | Enable iptables IPv4/IPv6 firewall. Simplified ruleset: Allow all outgoing connections. Block all incoming connections except to OpenSSH service. |
|
145 | 145 | |
|
146 | 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 | 152 | ##### `ENABLE_ROOT`=true |
|
150 | 153 | Set root user password so root login will be enabled |
|
151 | 154 | |
|
152 | 155 | ##### `ENABLE_ROOT_SSH`=true |
|
153 | 156 | Enable password root login via SSH. May be a security risk with default |
|
154 | 157 | password, use only in trusted environments. |
|
155 | 158 | |
|
156 | 159 | ##### `ENABLE_HARDNET`=false |
|
157 | 160 | Enable IPv4/IPv6 network stack hardening settings. |
|
158 | 161 | |
|
159 | 162 | ##### `ENABLE_SPLITFS`=false |
|
160 | 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 | 165 | ##### `CHROOT_SCRIPTS`="" |
|
163 | 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 | 168 | ##### `ENABLE_INITRAMFS`=false |
|
166 | 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 | 171 | #### Kernel compilation: |
|
169 | 172 | ##### `BUILD_KERNEL`=false |
|
170 | 173 | Build and install the latest RPi2 Linux kernel. Currently only the default RPi2 kernel configuration is used. |
|
171 | 174 | |
|
172 | 175 | ##### `KERNEL_REDUCE`=false |
|
173 | 176 | Reduce the size of the generated kernel by removing unwanted device, network and filesystem drivers (experimental). |
|
174 | 177 | |
|
175 | 178 | ##### `KERNEL_THREADS`=1 |
|
176 | 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 | 181 | ##### `KERNEL_HEADERS`=true |
|
179 | 182 | Install kernel headers with built kernel. |
|
180 | 183 | |
|
181 | 184 | ##### `KERNEL_MENUCONFIG`=false |
|
182 | 185 | Start `make menuconfig` interactive menu-driven kernel configuration. The script will continue after `make menuconfig` was terminated. |
|
183 | 186 | |
|
184 | 187 | ##### `KERNEL_REMOVESRC`=true |
|
185 | 188 | Remove all kernel sources from the generated OS image after it was built and installed. |
|
186 | 189 | |
|
187 | 190 | ##### `KERNELSRC_DIR`="" |
|
188 | 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 | 193 | ##### `KERNELSRC_CLEAN`=false |
|
191 | 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 | 196 | ##### `KERNELSRC_CONFIG`=true |
|
194 | 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 | 199 | ##### `KERNELSRC_PREBUILT`=false |
|
197 | 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 | |
|
202 | ##### `FIRMWAREDIR`="" | |
|
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. | |
|
204 | ||
|
199 | 205 | #### Reduce disk usage: |
|
200 | 206 | The following list of parameters is ignored if `ENABLE_REDUCE`=false. |
|
201 | 207 | |
|
202 | 208 | ##### `REDUCE_APT`=true |
|
203 | 209 | Configure APT to use compressed package repository lists and no package caching files. |
|
204 | 210 | |
|
205 | 211 | ##### `REDUCE_DOC`=true |
|
206 | 212 | Remove all doc files (harsh). Configure APT to not include doc files on future `apt-get` package installations. |
|
207 | 213 | |
|
208 | 214 | ##### `REDUCE_MAN`=true |
|
209 | 215 | Remove all man pages and info files (harsh). Configure APT to not include man pages on future `apt-get` package installations. |
|
210 | 216 | |
|
211 | 217 | ##### `REDUCE_VIM`=false |
|
212 | 218 | Replace `vim-tiny` package by `levee` a tiny vim clone. |
|
213 | 219 | |
|
214 | 220 | ##### `REDUCE_BASH`=false |
|
215 | 221 | Remove `bash` package and switch to `dash` shell (experimental). |
|
216 | 222 | |
|
217 | 223 | ##### `REDUCE_HWDB`=true |
|
218 | 224 | Remove PCI related hwdb files (experimental). |
|
219 | 225 | |
|
220 | 226 | ##### `REDUCE_SSHD`=true |
|
221 | 227 | Replace `openssh-server` with `dropbear`. |
|
222 | 228 | |
|
223 | 229 | ##### `REDUCE_LOCALE`=true |
|
224 | 230 | Remove all `locale` translation files. |
|
225 | 231 | |
|
226 | 232 | #### Encrypted root partition: |
|
227 | 233 | |
|
228 | 234 | ##### `ENABLE_CRYPTFS`=false |
|
229 | 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. |
|
230 | 236 | |
|
231 | 237 | ##### `CRYPTFS_PASSWORD`="" |
|
232 | 238 | Set password of the encrypted root partition. This parameter is mandatory if `ENABLE_CRYPTFS`=true. |
|
233 | 239 | |
|
234 | 240 | ##### `CRYPTFS_MAPPING`="secure" |
|
235 | 241 | Set name of dm-crypt managed device-mapper mapping. |
|
236 | 242 | |
|
237 | 243 | ##### `CRYPTFS_CIPHER`="aes-xts-plain64:sha512" |
|
238 | 244 | Set cipher specification string. `aes-xts*` ciphers are strongly recommended. |
|
239 | 245 | |
|
240 | 246 | ##### `CRYPTFS_XTSKEYSIZE`=512 |
|
241 | 247 | Sets key size in bits. The argument has to be a multiple of 8. |
|
242 | 248 | |
|
243 | 249 | ## Understanding the script |
|
244 | 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: |
|
245 | 251 | |
|
246 | 252 | | Script | Description | |
|
247 | 253 | | --- | --- | |
|
248 | 254 | | `10-bootstrap.sh` | Debootstrap basic system | |
|
249 | 255 | | `11-apt.sh` | Setup APT repositories | |
|
250 | 256 | | `12-locale.sh` | Setup Locales and keyboard settings | |
|
251 | 257 | | `13-kernel.sh` | Build and install RPi2 Kernel | |
|
252 | 258 | | `20-networking.sh` | Setup Networking | |
|
253 | 259 | | `21-firewall.sh` | Setup Firewall | |
|
254 | 260 | | `30-security.sh` | Setup Users and Security settings | |
|
255 | 261 | | `31-logging.sh` | Setup Logging | |
|
256 | 262 | | `41-uboot.sh` | Build and Setup U-Boot | |
|
257 | 263 | | `42-fbturbo.sh` | Build and Setup fbturbo Xorg driver | |
|
258 | 264 | | `50-firstboot.sh` | First boot actions | |
|
259 | 265 | | `99-reduce.sh` | Reduce the disk space usage | |
|
260 | 266 | |
|
261 | 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. |
|
262 | 268 | |
|
263 | 269 | | Directory | Description | |
|
264 | 270 | | --- | --- | |
|
265 | 271 | | `apt` | APT management configuration files | |
|
266 | 272 | | `boot` | Boot and RPi2 configuration files | |
|
267 | 273 | | `dpkg` | Package Manager configuration | |
|
268 | 274 | | `firstboot` | Scripts that get executed on first boot | |
|
269 | 275 | | `initramfs` | Initramfs scripts | |
|
270 | 276 | | `iptables` | Firewall configuration files | |
|
271 | 277 | | `locales` | Locales configuration | |
|
272 | 278 | | `modules` | Kernel Modules configuration | |
|
273 | 279 | | `mount` | Fstab configuration | |
|
274 | 280 | | `network` | Networking configuration files | |
|
275 | 281 | | `sysctl.d` | Swapping and Network Hardening configuration | |
|
276 | 282 | | `xorg` | fbturbo Xorg driver configuration | |
|
277 | 283 | |
|
284 | Debian custom packages, i.e. those not in the debian repositories, can be installed by placing them in the `packages` directory. They are installed immediately after packages from the repositories are installed. Any dependencies listed in the custom packages will be downloaded automatically from the repositories. Do not list these custom packages in `APT_INCLUDES`. | |
|
285 | ||
|
286 | Scripts in the custom.d directory will be executed after all other installation is complete but before the image is created. | |
|
287 | ||
|
278 | 288 | ## Logging of the bootstrapping process |
|
279 | 289 | 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: |
|
280 | 290 | |
|
281 | 291 | ```shell |
|
282 | 292 | script -c 'APT_SERVER=ftp.de.debian.org ./rpi2-gen-image.sh' ./build.log |
|
283 | 293 | ``` |
|
284 | 294 | |
|
285 | 295 | ## Flashing the image file |
|
286 | 296 | 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`. |
|
287 | 297 | |
|
288 | 298 | #####Flashing examples: |
|
289 | 299 | ```shell |
|
290 | 300 | bmaptool copy ./images/jessie/2015-12-13-debian-jessie.img /dev/mmcblk0 |
|
291 | 301 | dd bs=4M if=./images/jessie/2015-12-13-debian-jessie.img of=/dev/mmcblk0 |
|
292 | 302 | ``` |
|
293 | 303 | If you have set `ENABLE_SPLITFS`, copy the `-frmw` image on the microSD card, then the `-root` one on the USB drive: |
|
294 | 304 | ```shell |
|
295 | 305 | bmaptool copy ./images/jessie/2015-12-13-debian-jessie-frmw.img /dev/mmcblk0 |
|
296 | 306 | bmaptool copy ./images/jessie/2015-12-13-debian-jessie-root.img /dev/sdc |
|
297 | 307 | ``` |
@@ -1,37 +1,46 | |||
|
1 | 1 | # |
|
2 | 2 | # Setup APT repositories |
|
3 | 3 | # |
|
4 | 4 | |
|
5 | 5 | # Load utility functions |
|
6 | 6 | . ./functions.sh |
|
7 | 7 | |
|
8 | 8 | # Install and setup APT proxy configuration |
|
9 | 9 | if [ -z "$APT_PROXY" ] ; then |
|
10 | 10 | install_readonly files/apt/10proxy "${ETCDIR}/apt/apt.conf.d/10proxy" |
|
11 | 11 | sed -i "s/\"\"/\"${APT_PROXY}\"/" "${ETCDIR}/apt/apt.conf.d/10proxy" |
|
12 | 12 | fi |
|
13 | 13 | |
|
14 | 14 | if [ "$BUILD_KERNEL" = false ] ; then |
|
15 | 15 | # Install APT pinning configuration for flash-kernel package |
|
16 | 16 | install_readonly files/apt/flash-kernel "${ETCDIR}/apt/preferences.d/flash-kernel" |
|
17 | 17 | |
|
18 | 18 | # Install APT sources.list |
|
19 | 19 | install_readonly files/apt/sources.list "${ETCDIR}/apt/sources.list" |
|
20 | 20 | echo "deb https://repositories.collabora.co.uk/debian ${RELEASE} rpi2" >> "${ETCDIR}/apt/sources.list" |
|
21 | 21 | |
|
22 | 22 | # Upgrade collabora package index and install collabora keyring |
|
23 | 23 | chroot_exec apt-get -qq -y update |
|
24 | 24 | chroot_exec apt-get -qq -y --force-yes install collabora-obs-archive-keyring |
|
25 | 25 | else # BUILD_KERNEL=true |
|
26 | 26 | # Install APT sources.list |
|
27 | 27 | install_readonly files/apt/sources.list "${ETCDIR}/apt/sources.list" |
|
28 | 28 | |
|
29 | 29 | # Use specified APT server and release |
|
30 | 30 | sed -i "s/\/ftp.debian.org\//\/${APT_SERVER}\//" "${ETCDIR}/apt/sources.list" |
|
31 | 31 | sed -i "s/ jessie/ ${RELEASE}/" "${ETCDIR}/apt/sources.list" |
|
32 | 32 | fi |
|
33 | 33 | |
|
34 | 34 | # Upgrade package index and update all installed packages and changed dependencies |
|
35 | 35 | chroot_exec apt-get -qq -y update |
|
36 | 36 | chroot_exec apt-get -qq -y -u dist-upgrade |
|
37 | ||
|
38 | if [ -d packages ] ; then | |
|
39 | for package in packages/*.deb ; do | |
|
40 | cp $package ${R}/tmp | |
|
41 | chroot_exec dpkg --unpack /tmp/$(basename $package) | |
|
42 | done | |
|
43 | fi | |
|
44 | chroot_exec apt-get -qq -y -f install | |
|
45 | ||
|
37 | 46 | chroot_exec apt-get -qq -y check |
@@ -1,276 +1,287 | |||
|
1 | 1 | # |
|
2 | 2 | # Build and Setup RPi2 Kernel |
|
3 | 3 | # |
|
4 | 4 | |
|
5 | 5 | # Load utility functions |
|
6 | 6 | . ./functions.sh |
|
7 | 7 | |
|
8 | 8 | # Fetch and build latest raspberry kernel |
|
9 | 9 | if [ "$BUILD_KERNEL" = true ] ; then |
|
10 | 10 | # Setup source directory |
|
11 | 11 | mkdir -p "${R}/usr/src" |
|
12 | 12 | |
|
13 | 13 | # Copy existing kernel sources into chroot directory |
|
14 | 14 | if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then |
|
15 | 15 | # Copy kernel sources |
|
16 | 16 | cp -r "${KERNELSRC_DIR}" "${R}/usr/src" |
|
17 | 17 | |
|
18 | 18 | # Clean the kernel sources |
|
19 | 19 | if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then |
|
20 | 20 | make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" mrproper |
|
21 | 21 | fi |
|
22 | 22 | else # KERNELSRC_DIR="" |
|
23 | 23 | # Fetch current raspberrypi kernel sources |
|
24 | 24 | git -C "${R}/usr/src" clone --depth=1 https://github.com/raspberrypi/linux |
|
25 | 25 | fi |
|
26 | 26 | |
|
27 | 27 | # Calculate optimal number of kernel building threads |
|
28 | 28 | if [ "$KERNEL_THREADS" = "1" ] && [ -r /proc/cpuinfo ] ; then |
|
29 | 29 | KERNEL_THREADS=$(grep -c processor /proc/cpuinfo) |
|
30 | 30 | fi |
|
31 | 31 | |
|
32 | 32 | # Configure and build kernel |
|
33 | 33 | if [ "$KERNELSRC_PREBUILT" = false ] ; then |
|
34 | 34 | # Remove device, network and filesystem drivers from kernel configuration |
|
35 | 35 | if [ "$KERNEL_REDUCE" = true ] ; then |
|
36 | 36 | make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}" |
|
37 | 37 | sed -i\ |
|
38 | 38 | -e "s/\(^CONFIG_SND.*\=\).*/\1n/"\ |
|
39 | 39 | -e "s/\(^CONFIG_SOUND.*\=\).*/\1n/"\ |
|
40 | 40 | -e "s/\(^CONFIG_AC97.*\=\).*/\1n/"\ |
|
41 | 41 | -e "s/\(^CONFIG_VIDEO_.*\=\).*/\1n/"\ |
|
42 | 42 | -e "s/\(^CONFIG_MEDIA_TUNER.*\=\).*/\1n/"\ |
|
43 | 43 | -e "s/\(^CONFIG_DVB.*\=\)[ym]/\1n/"\ |
|
44 | 44 | -e "s/\(^CONFIG_REISERFS.*\=\).*/\1n/"\ |
|
45 | 45 | -e "s/\(^CONFIG_JFS.*\=\).*/\1n/"\ |
|
46 | 46 | -e "s/\(^CONFIG_XFS.*\=\).*/\1n/"\ |
|
47 | 47 | -e "s/\(^CONFIG_GFS2.*\=\).*/\1n/"\ |
|
48 | 48 | -e "s/\(^CONFIG_OCFS2.*\=\).*/\1n/"\ |
|
49 | 49 | -e "s/\(^CONFIG_BTRFS.*\=\).*/\1n/"\ |
|
50 | 50 | -e "s/\(^CONFIG_HFS.*\=\).*/\1n/"\ |
|
51 | 51 | -e "s/\(^CONFIG_JFFS2.*\=\)[ym]/\1n/"\ |
|
52 | 52 | -e "s/\(^CONFIG_UBIFS.*\=\).*/\1n/"\ |
|
53 | 53 | -e "s/\(^CONFIG_SQUASHFS.*\=\)[ym]/\1n/"\ |
|
54 | 54 | -e "s/\(^CONFIG_W1.*\=\)[ym]/\1n/"\ |
|
55 | 55 | -e "s/\(^CONFIG_HAMRADIO.*\=\).*/\1n/"\ |
|
56 | 56 | -e "s/\(^CONFIG_CAN.*\=\).*/\1n/"\ |
|
57 | 57 | -e "s/\(^CONFIG_IRDA.*\=\).*/\1n/"\ |
|
58 | 58 | -e "s/\(^CONFIG_BT_.*\=\).*/\1n/"\ |
|
59 | 59 | -e "s/\(^CONFIG_WIMAX.*\=\)[ym]/\1n/"\ |
|
60 | 60 | -e "s/\(^CONFIG_6LOWPAN.*\=\).*/\1n/"\ |
|
61 | 61 | -e "s/\(^CONFIG_IEEE802154.*\=\).*/\1n/"\ |
|
62 | 62 | -e "s/\(^CONFIG_NFC.*\=\).*/\1n/"\ |
|
63 | 63 | -e "s/\(^CONFIG_FB_TFT=.*\=\).*/\1n/"\ |
|
64 | 64 | -e "s/\(^CONFIG_TOUCHSCREEN.*\=\).*/\1n/"\ |
|
65 | 65 | -e "s/\(^CONFIG_USB_GSPCA_.*\=\).*/\1n/"\ |
|
66 | 66 | -e "s/\(^CONFIG_DRM.*\=\).*/\1n/"\ |
|
67 | 67 | "${KERNELDIR}/.config" |
|
68 | 68 | fi |
|
69 | 69 | |
|
70 | 70 | if [ "$KERNELSRC_CONFIG" = true ] ; then |
|
71 | 71 | # Load default raspberry kernel configuration |
|
72 | 72 | make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}" |
|
73 | 73 | |
|
74 | 74 | # Start menu-driven kernel configuration (interactive) |
|
75 | 75 | if [ "$KERNEL_MENUCONFIG" = true ] ; then |
|
76 | 76 | make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig |
|
77 | 77 | fi |
|
78 | 78 | fi |
|
79 | 79 | |
|
80 | 80 | # Cross compile kernel and modules |
|
81 | 81 | make -C "${KERNELDIR}" -j${KERNEL_THREADS} ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" zImage modules dtbs |
|
82 | 82 | fi |
|
83 | 83 | |
|
84 | 84 | # Check if kernel compilation was successful |
|
85 | 85 | if [ ! -r "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/zImage" ] ; then |
|
86 | 86 | echo "error: kernel compilation failed! (zImage not found)" |
|
87 | 87 | cleanup |
|
88 | 88 | exit 1 |
|
89 | 89 | fi |
|
90 | 90 | |
|
91 | 91 | # Install kernel modules |
|
92 | 92 | if [ "$ENABLE_REDUCE" = true ] ; then |
|
93 | 93 | make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install |
|
94 | 94 | else |
|
95 | 95 | make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install |
|
96 | 96 | |
|
97 | 97 | # Install kernel firmware |
|
98 | 98 | make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install |
|
99 | 99 | fi |
|
100 | 100 | |
|
101 | 101 | # Install kernel headers |
|
102 | 102 | if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then |
|
103 | 103 | make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install |
|
104 | 104 | fi |
|
105 | 105 | |
|
106 | 106 | # Prepare boot (firmware) directory |
|
107 | 107 | mkdir "${BOOTDIR}" |
|
108 | 108 | |
|
109 | 109 | # Get kernel release version |
|
110 | 110 | KERNEL_VERSION=`cat "${KERNELDIR}/include/config/kernel.release"` |
|
111 | 111 | |
|
112 | 112 | # Copy kernel configuration file to the boot directory |
|
113 | 113 | install_readonly "${KERNELDIR}/.config" "${R}/boot/config-${KERNEL_VERSION}" |
|
114 | 114 | |
|
115 | 115 | # Copy dts and dtb device tree sources and binaries |
|
116 | 116 | mkdir "${BOOTDIR}/overlays" |
|
117 | 117 | install_readonly "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb "${BOOTDIR}/" |
|
118 | 118 | install_readonly "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb* "${BOOTDIR}/overlays/" |
|
119 | 119 | install_readonly "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOTDIR}/overlays/README" |
|
120 | 120 | |
|
121 | 121 | if [ "$ENABLE_UBOOT" = false ] ; then |
|
122 | 122 | # Convert and copy zImage kernel to the boot directory |
|
123 | 123 | "${KERNELDIR}/scripts/mkknlimg" "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/zImage" "${BOOTDIR}/${KERNEL_IMAGE}" |
|
124 | 124 | else |
|
125 | 125 | # Copy zImage kernel to the boot directory |
|
126 | 126 | install_readonly "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/zImage" "${BOOTDIR}/${KERNEL_IMAGE}" |
|
127 | 127 | fi |
|
128 | 128 | |
|
129 | 129 | # Remove kernel sources |
|
130 | 130 | if [ "$KERNEL_REMOVESRC" = true ] ; then |
|
131 | 131 | rm -fr "${KERNELDIR}" |
|
132 | 132 | fi |
|
133 | 133 | |
|
134 | if [ -n "$FIRMWAREDIR" ] && [ -d "$FIRMWAREDIR" ] ; then | |
|
135 | # Install boot binaries from local directory | |
|
136 | cp ${FIRMWAREDIR}/boot/bootcode.bin ${BOOTDIR}/bootcode.bin | |
|
137 | cp ${FIRMWAREDIR}/boot/fixup.dat ${BOOTDIR}/fixup.dat | |
|
138 | cp ${FIRMWAREDIR}/boot/fixup_cd.dat ${BOOTDIR}/fixup_cd.dat | |
|
139 | cp ${FIRMWAREDIR}/boot/fixup_x.dat ${BOOTDIR}/fixup_x.dat | |
|
140 | cp ${FIRMWAREDIR}/boot/start.elf ${BOOTDIR}/start.elf | |
|
141 | cp ${FIRMWAREDIR}/boot/start_cd.elf ${BOOTDIR}/start_cd.elf | |
|
142 | cp ${FIRMWAREDIR}/boot/start_x.elf ${BOOTDIR}/start_x.elf | |
|
143 | else | |
|
134 | 144 | # Install latest boot binaries from raspberry/firmware github |
|
135 | 145 | wget -q -O "${BOOTDIR}/bootcode.bin" https://github.com/raspberrypi/firmware/raw/master/boot/bootcode.bin |
|
136 | 146 | wget -q -O "${BOOTDIR}/fixup.dat" https://github.com/raspberrypi/firmware/raw/master/boot/fixup.dat |
|
137 | 147 | wget -q -O "${BOOTDIR}/fixup_cd.dat" https://github.com/raspberrypi/firmware/raw/master/boot/fixup_cd.dat |
|
138 | 148 | wget -q -O "${BOOTDIR}/fixup_x.dat" https://github.com/raspberrypi/firmware/raw/master/boot/fixup_x.dat |
|
139 | 149 | wget -q -O "${BOOTDIR}/start.elf" https://github.com/raspberrypi/firmware/raw/master/boot/start.elf |
|
140 | 150 | wget -q -O "${BOOTDIR}/start_cd.elf" https://github.com/raspberrypi/firmware/raw/master/boot/start_cd.elf |
|
141 | 151 | wget -q -O "${BOOTDIR}/start_x.elf" https://github.com/raspberrypi/firmware/raw/master/boot/start_x.elf |
|
152 | fi | |
|
142 | 153 | |
|
143 | 154 | else # BUILD_KERNEL=false |
|
144 | 155 | # Kernel installation |
|
145 | 156 | chroot_exec apt-get -qq -y --no-install-recommends install linux-image-"${COLLABORA_KERNEL}" raspberrypi-bootloader-nokernel |
|
146 | 157 | |
|
147 | 158 | # Install flash-kernel last so it doesn't try (and fail) to detect the platform in the chroot |
|
148 | 159 | chroot_exec apt-get -qq -y install flash-kernel |
|
149 | 160 | |
|
150 | 161 | # Check if kernel installation was successful |
|
151 | 162 | VMLINUZ="$(ls -1 ${R}/boot/vmlinuz-* | sort | tail -n 1)" |
|
152 | 163 | if [ -z "$VMLINUZ" ] ; then |
|
153 | 164 | echo "error: kernel installation failed! (/boot/vmlinuz-* not found)" |
|
154 | 165 | cleanup |
|
155 | 166 | exit 1 |
|
156 | 167 | fi |
|
157 | 168 | # Copy vmlinuz kernel to the boot directory |
|
158 | 169 | install_readonly "${VMLINUZ}" "${BOOTDIR}/${KERNEL_IMAGE}" |
|
159 | 170 | fi |
|
160 | 171 | |
|
161 | 172 | # Setup firmware boot cmdline |
|
162 | 173 | if [ "$ENABLE_SPLITFS" = true ] ; then |
|
163 | 174 | CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait net.ifnames=1 console=tty1 ${CMDLINE}" |
|
164 | 175 | else |
|
165 | 176 | CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait net.ifnames=1 console=tty1 ${CMDLINE}" |
|
166 | 177 | fi |
|
167 | 178 | |
|
168 | 179 | # Add encrypted root partition to cmdline.txt |
|
169 | 180 | if [ "$ENABLE_CRYPTFS" = true ] ; then |
|
170 | 181 | if [ "$ENABLE_SPLITFS" = true ] ; then |
|
171 | 182 | CMDLINE=$(echo ${CMDLINE} | sed "s/sda1/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda1:${CRYPTFS_MAPPING}/") |
|
172 | 183 | else |
|
173 | 184 | CMDLINE=$(echo ${CMDLINE} | sed "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/mmcblk0p2:${CRYPTFS_MAPPING}/") |
|
174 | 185 | fi |
|
175 | 186 | fi |
|
176 | 187 | |
|
177 | 188 | # Add serial console support |
|
178 | 189 | if [ "$ENABLE_CONSOLE" = true ] ; then |
|
179 | 190 | CMDLINE="${CMDLINE} console=ttyAMA0,115200 kgdboc=ttyAMA0,115200" |
|
180 | 191 | fi |
|
181 | 192 | |
|
182 | 193 | # Remove IPv6 networking support |
|
183 | 194 | if [ "$ENABLE_IPV6" = false ] ; then |
|
184 | 195 | CMDLINE="${CMDLINE} ipv6.disable=1" |
|
185 | 196 | fi |
|
186 | 197 | |
|
187 | 198 | # Install firmware boot cmdline |
|
188 | 199 | echo "${CMDLINE}" > "${BOOTDIR}/cmdline.txt" |
|
189 | 200 | |
|
190 | 201 | # Install firmware config |
|
191 | 202 | install_readonly files/boot/config.txt "${BOOTDIR}/config.txt" |
|
192 | 203 | |
|
193 | 204 | # Setup minimal GPU memory allocation size: 16MB (no X) |
|
194 | 205 | if [ "$ENABLE_MINGPU" = true ] ; then |
|
195 | 206 | echo "gpu_mem=16" >> "${BOOTDIR}/config.txt" |
|
196 | 207 | fi |
|
197 | 208 | |
|
198 | 209 | # Setup boot with initramfs |
|
199 | 210 | if [ "$ENABLE_INITRAMFS" = true ] ; then |
|
200 | 211 | echo "initramfs initramfs-${KERNEL_VERSION} followkernel" >> "${BOOTDIR}/config.txt" |
|
201 | 212 | fi |
|
202 | 213 | |
|
203 | 214 | # Create firmware configuration and cmdline symlinks |
|
204 | 215 | ln -sf firmware/config.txt "${R}/boot/config.txt" |
|
205 | 216 | ln -sf firmware/cmdline.txt "${R}/boot/cmdline.txt" |
|
206 | 217 | |
|
207 | 218 | # Install and setup kernel modules to load at boot |
|
208 | 219 | mkdir -p "${R}/lib/modules-load.d/" |
|
209 | 220 | install_readonly files/modules/rpi2.conf "${R}/lib/modules-load.d/rpi2.conf" |
|
210 | 221 | |
|
211 | 222 | # Load hardware random module at boot |
|
212 | 223 | if [ "$ENABLE_HWRANDOM" = true ] && [ "$BUILD_KERNEL" = false ] ; then |
|
213 | 224 | sed -i "s/^# bcm2708_rng/bcm2708_rng/" "${R}/lib/modules-load.d/rpi2.conf" |
|
214 | 225 | fi |
|
215 | 226 | |
|
216 | 227 | # Load sound module at boot |
|
217 | 228 | if [ "$ENABLE_SOUND" = true ] ; then |
|
218 | 229 | sed -i "s/^# snd_bcm2835/snd_bcm2835/" "${R}/lib/modules-load.d/rpi2.conf" |
|
219 | 230 | fi |
|
220 | 231 | |
|
221 | 232 | # Install kernel modules blacklist |
|
222 | 233 | mkdir -p "${ETCDIR}/modprobe.d/" |
|
223 | 234 | install_readonly files/modules/raspi-blacklist.conf "${ETCDIR}/modprobe.d/raspi-blacklist.conf" |
|
224 | 235 | |
|
225 | 236 | # Install and setup fstab |
|
226 | 237 | install_readonly files/mount/fstab "${ETCDIR}/fstab" |
|
227 | 238 | |
|
228 | 239 | # Add usb/sda disk root partition to fstab |
|
229 | 240 | if [ "$ENABLE_SPLITFS" = true ] && [ "$ENABLE_CRYPTFS" = false ] ; then |
|
230 | 241 | sed -i "s/mmcblk0p2/sda1/" "${ETCDIR}/fstab" |
|
231 | 242 | fi |
|
232 | 243 | |
|
233 | 244 | # Add encrypted root partition to fstab and crypttab |
|
234 | 245 | if [ "$ENABLE_CRYPTFS" = true ] ; then |
|
235 | 246 | # Replace fstab root partition with encrypted partition mapping |
|
236 | 247 | sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING}/" "${ETCDIR}/fstab" |
|
237 | 248 | |
|
238 | 249 | # Add encrypted partition to crypttab and fstab |
|
239 | 250 | install_readonly files/mount/crypttab "${ETCDIR}/crypttab" |
|
240 | 251 | echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks" >> "${ETCDIR}/crypttab" |
|
241 | 252 | |
|
242 | 253 | if [ "$ENABLE_SPLITFS" = true ] ; then |
|
243 | 254 | # Add usb/sda disk to crypttab |
|
244 | 255 | sed -i "s/mmcblk0p2/sda1/" "${ETCDIR}/crypttab" |
|
245 | 256 | fi |
|
246 | 257 | fi |
|
247 | 258 | |
|
248 | 259 | # Generate initramfs file |
|
249 | 260 | if [ "$ENABLE_INITRAMFS" = true ] ; then |
|
250 | 261 | if [ "$ENABLE_CRYPTFS" = true ] ; then |
|
251 | 262 | # Include initramfs scripts to auto expand encrypted root partition |
|
252 | 263 | if [ "$EXPANDROOT" = true ] ; then |
|
253 | 264 | install_exec files/initramfs/expand_encrypted_rootfs "${ETCDIR}/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs" |
|
254 | 265 | install_exec files/initramfs/expand-premount "${ETCDIR}/initramfs-tools/scripts/local-premount/expand-premount" |
|
255 | 266 | install_exec files/initramfs/expand-tools "${ETCDIR}/initramfs-tools/hooks/expand-tools" |
|
256 | 267 | fi |
|
257 | 268 | |
|
258 | 269 | # Disable SSHD inside initramfs |
|
259 | 270 | printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=n\n" >> "${ETCDIR}/initramfs-tools/initramfs.conf" |
|
260 | 271 | |
|
261 | 272 | # Dummy mapping required by mkinitramfs |
|
262 | 273 | echo "0 1 crypt $(echo ${CRYPTFS_CIPHER} | cut -d ':' -f 1) ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0 7:0 4096" | chroot_exec dmsetup create "${CRYPTFS_MAPPING}" |
|
263 | 274 | |
|
264 | 275 | # Generate initramfs with encrypted root partition support |
|
265 | 276 | chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}" |
|
266 | 277 | |
|
267 | 278 | # Remove dummy mapping |
|
268 | 279 | chroot_exec cryptsetup close "${CRYPTFS_MAPPING}" |
|
269 | 280 | else |
|
270 | 281 | # Generate initramfs without encrypted root partition support |
|
271 | 282 | chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}" |
|
272 | 283 | fi |
|
273 | 284 | fi |
|
274 | 285 | |
|
275 | 286 | # Install sysctl.d configuration files |
|
276 | 287 | install_readonly files/sysctl.d/81-rpi-vm.conf "${ETCDIR}/sysctl.d/81-rpi-vm.conf" |
@@ -1,72 +1,77 | |||
|
1 | 1 | # |
|
2 | 2 | # Setup Networking |
|
3 | 3 | # |
|
4 | 4 | |
|
5 | 5 | # Load utility functions |
|
6 | 6 | . ./functions.sh |
|
7 | 7 | |
|
8 | 8 | # Install and setup hostname |
|
9 | 9 | install_readonly files/network/hostname "${ETCDIR}/hostname" |
|
10 | 10 | sed -i "s/^rpi2-jessie/${HOSTNAME}/" "${ETCDIR}/hostname" |
|
11 | 11 | |
|
12 | 12 | # Install and setup hosts |
|
13 | 13 | install_readonly files/network/hosts "${ETCDIR}/hosts" |
|
14 | 14 | sed -i "s/rpi2-jessie/${HOSTNAME}/" "${ETCDIR}/hosts" |
|
15 | 15 | |
|
16 | 16 | # Setup hostname entry with static IP |
|
17 | 17 | if [ "$NET_ADDRESS" != "" ] ; then |
|
18 | 18 | NET_IP=$(echo "${NET_ADDRESS}" | cut -f 1 -d'/') |
|
19 | 19 | sed -i "s/^127.0.1.1/${NET_IP}/" "${ETCDIR}/hosts" |
|
20 | 20 | fi |
|
21 | 21 | |
|
22 | 22 | # Remove IPv6 hosts |
|
23 | 23 | if [ "$ENABLE_IPV6" = false ] ; then |
|
24 | 24 | sed -i -e "/::[1-9]/d" -e "/^$/d" "${ETCDIR}/hosts" |
|
25 | 25 | fi |
|
26 | 26 | |
|
27 | 27 | # Install hint about network configuration |
|
28 | 28 | install_readonly files/network/interfaces "${ETCDIR}/network/interfaces" |
|
29 | 29 | |
|
30 | 30 | # Install configuration for interface eth0 |
|
31 | 31 | install_readonly files/network/eth.network "${ETCDIR}/systemd/network/eth.network" |
|
32 | 32 | |
|
33 | 33 | if [ "$ENABLE_DHCP" = true ] ; then |
|
34 | 34 | # Enable DHCP configuration for interface eth0 |
|
35 | 35 | sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" "${ETCDIR}/systemd/network/eth.network" |
|
36 | 36 | |
|
37 | 37 | # Set DHCP configuration to IPv4 only |
|
38 | 38 | if [ "$ENABLE_IPV6" = false ] ; then |
|
39 | 39 | sed -i "s/DHCP=.*/DHCP=v4/" "${ETCDIR}/systemd/network/eth.network" |
|
40 | 40 | fi |
|
41 | 41 | |
|
42 | 42 | else # ENABLE_DHCP=false |
|
43 | 43 | # Set static network configuration for interface eth0 |
|
44 | 44 | sed -i\ |
|
45 | 45 | -e "s|DHCP=.*|DHCP=no|"\ |
|
46 | 46 | -e "s|Address=\$|Address=${NET_ADDRESS}|"\ |
|
47 | 47 | -e "s|Gateway=\$|Gateway=${NET_GATEWAY}|"\ |
|
48 | 48 | -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_DNS_1}|"\ |
|
49 | 49 | -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_DNS_2}|"\ |
|
50 | 50 | -e "s|Domains=\$|Domains=${NET_DNS_DOMAINS}|"\ |
|
51 | 51 | -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_NTP_1}|"\ |
|
52 | 52 | -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_NTP_2}|"\ |
|
53 | 53 | "${ETCDIR}/systemd/network/eth.network" |
|
54 | 54 | fi |
|
55 | 55 | |
|
56 | 56 | # Remove empty settings from network configuration |
|
57 | 57 | sed -i "/.*=\$/d" "${ETCDIR}/systemd/network/eth.network" |
|
58 | 58 | |
|
59 | 59 | # Enable systemd-networkd service |
|
60 | 60 | chroot_exec systemctl enable systemd-networkd |
|
61 | 61 | |
|
62 | 62 | # Install host.conf resolver configuration |
|
63 | 63 | install_readonly files/network/host.conf "${ETCDIR}/host.conf" |
|
64 | 64 | |
|
65 | 65 | # Enable network stack hardening |
|
66 | 66 | if [ "$ENABLE_HARDNET" = true ] ; then |
|
67 | 67 | # Install sysctl.d configuration files |
|
68 | 68 | install_readonly files/sysctl.d/82-rpi-net-hardening.conf "${ETCDIR}/sysctl.d/82-rpi-net-hardening.conf" |
|
69 | 69 | |
|
70 | 70 | # Setup resolver warnings about spoofed addresses |
|
71 | 71 | sed -i "s/^# spoof warn/spoof warn/" "${ETCDIR}/host.conf" |
|
72 | 72 | fi |
|
73 | ||
|
74 | # Enable time sync | |
|
75 | if [ "NET_NTP_1" != "" ] ; then | |
|
76 | chroot_exec systemctl enable systemd-timesyncd.service | |
|
77 | fi |
@@ -1,32 +1,33 | |||
|
1 | 1 | # |
|
2 | 2 | # Setup users and security settings |
|
3 | 3 | # |
|
4 | 4 | |
|
5 | 5 | # Load utility functions |
|
6 | 6 | . ./functions.sh |
|
7 | 7 | |
|
8 | 8 | # Generate crypt(3) password string |
|
9 | 9 | ENCRYPTED_PASSWORD=`mkpasswd -m sha-512 "${PASSWORD}"` |
|
10 | 10 | |
|
11 | 11 | # Setup default user |
|
12 | 12 | if [ "$ENABLE_USER" = true ] ; then |
|
13 |
chroot_exec adduser --gecos |
|
|
14 | chroot_exec usermod -a -G sudo -p "${ENCRYPTED_PASSWORD}" pi | |
|
13 | chroot_exec adduser --gecos $USER_NAME --add_extra_groups \ | |
|
14 | --disabled-password $USER_NAME | |
|
15 | chroot_exec usermod -a -G sudo -p "${ENCRYPTED_PASSWORD}" $USER_NAME | |
|
15 | 16 | fi |
|
16 | 17 | |
|
17 | 18 | # Setup root password or not |
|
18 | 19 | if [ "$ENABLE_ROOT" = true ] ; then |
|
19 | 20 | chroot_exec usermod -p "${ENCRYPTED_PASSWORD}" root |
|
20 | 21 | |
|
21 | 22 | if [ "$ENABLE_ROOT_SSH" = true ] ; then |
|
22 | 23 | sed -i "s|[#]*PermitRootLogin.*|PermitRootLogin yes|g" "${ETCDIR}/ssh/sshd_config" |
|
23 | 24 | fi |
|
24 | 25 | else |
|
25 | 26 | # Set no root password to disable root login |
|
26 | 27 | chroot_exec usermod -p \'!\' root |
|
27 | 28 | fi |
|
28 | 29 | |
|
29 | 30 | # Enable serial console systemd style |
|
30 | 31 | if [ "$ENABLE_CONSOLE" = true ] ; then |
|
31 | 32 | chroot_exec systemctl enable serial-getty\@ttyAMA0.service |
|
32 | 33 | fi |
@@ -1,513 +1,517 | |||
|
1 | 1 | #!/bin/sh |
|
2 | 2 | |
|
3 | 3 | ######################################################################## |
|
4 | 4 | # rpi2-gen-image.sh ver2a 12/2015 |
|
5 | 5 | # |
|
6 | 6 | # Advanced debian "jessie" bootstrap script for RPi2 |
|
7 | 7 | # |
|
8 | 8 | # This program is free software; you can redistribute it and/or |
|
9 | 9 | # modify it under the terms of the GNU General Public License |
|
10 | 10 | # as published by the Free Software Foundation; either version 2 |
|
11 | 11 | # of the License, or (at your option) any later version. |
|
12 | 12 | # |
|
13 | 13 | # some parts based on rpi2-build-image: |
|
14 | 14 | # Copyright (C) 2015 Ryan Finnie <ryan@finnie.org> |
|
15 | 15 | # Copyright (C) 2015 Luca Falavigna <dktrkranz@debian.org> |
|
16 | 16 | ######################################################################## |
|
17 | 17 | |
|
18 | 18 | # Are we running as root? |
|
19 | 19 | if [ "$(id -u)" -ne "0" ] ; then |
|
20 | 20 | echo "error: this script must be executed with root privileges!" |
|
21 | 21 | exit 1 |
|
22 | 22 | fi |
|
23 | 23 | |
|
24 | 24 | # Check if ./functions.sh script exists |
|
25 | 25 | if [ ! -r "./functions.sh" ] ; then |
|
26 | 26 | echo "error: './functions.sh' required script not found!" |
|
27 | 27 | exit 1 |
|
28 | 28 | fi |
|
29 | 29 | |
|
30 | 30 | # Load utility functions |
|
31 | 31 | . ./functions.sh |
|
32 | 32 | |
|
33 | 33 | # Introduce settings |
|
34 | 34 | set -e |
|
35 | 35 | echo -n -e "\n#\n# RPi2 Bootstrap Settings\n#\n" |
|
36 | 36 | set -x |
|
37 | 37 | |
|
38 | 38 | # Debian release |
|
39 | 39 | RELEASE=${RELEASE:=jessie} |
|
40 | 40 | KERNEL_ARCH=${KERNEL_ARCH:=arm} |
|
41 | 41 | RELEASE_ARCH=${RELEASE_ARCH:=armhf} |
|
42 | 42 | CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-} |
|
43 | 43 | COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2} |
|
44 | 44 | KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig} |
|
45 | 45 | KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img} |
|
46 | 46 | DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb} |
|
47 | 47 | UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig} |
|
48 | 48 | QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static} |
|
49 | 49 | |
|
50 | 50 | # Build directories |
|
51 | 51 | BASEDIR="$(pwd)/images/${RELEASE}" |
|
52 | 52 | BUILDDIR="${BASEDIR}/build" |
|
53 | 53 | |
|
54 | 54 | # Chroot directories |
|
55 | 55 | R="${BUILDDIR}/chroot" |
|
56 | 56 | ETCDIR="${R}/etc" |
|
57 | 57 | BOOTDIR="${R}/boot/firmware" |
|
58 | 58 | KERNELDIR="${R}/usr/src/linux" |
|
59 | 59 | |
|
60 | # Firmware directory: Blank if download from github | |
|
61 | FIRMWAREDIR=${FIRMWAREDIR:=""} | |
|
62 | ||
|
60 | 63 | # General settings |
|
61 | 64 | HOSTNAME=${HOSTNAME:=rpi2-${RELEASE}} |
|
62 | 65 | PASSWORD=${PASSWORD:=raspberry} |
|
63 | 66 | DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"} |
|
64 | 67 | TIMEZONE=${TIMEZONE:="Europe/Berlin"} |
|
65 | 68 | EXPANDROOT=${EXPANDROOT:=true} |
|
66 | 69 | |
|
67 | 70 | # Keyboard settings |
|
68 | 71 | XKB_MODEL=${XKB_MODEL:=""} |
|
69 | 72 | XKB_LAYOUT=${XKB_LAYOUT:=""} |
|
70 | 73 | XKB_VARIANT=${XKB_VARIANT:=""} |
|
71 | 74 | XKB_OPTIONS=${XKB_OPTIONS:=""} |
|
72 | 75 | |
|
73 | 76 | # Network settings (DHCP) |
|
74 | 77 | ENABLE_DHCP=${ENABLE_DHCP:=true} |
|
75 | 78 | |
|
76 | 79 | # Network settings (static) |
|
77 | 80 | NET_ADDRESS=${NET_ADDRESS:=""} |
|
78 | 81 | NET_GATEWAY=${NET_GATEWAY:=""} |
|
79 | 82 | NET_DNS_1=${NET_DNS_1:=""} |
|
80 | 83 | NET_DNS_2=${NET_DNS_2:=""} |
|
81 | 84 | NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""} |
|
82 | 85 | NET_NTP_1=${NET_NTP_1:=""} |
|
83 | 86 | NET_NTP_2=${NET_NTP_2:=""} |
|
84 | 87 | |
|
85 | 88 | # APT settings |
|
86 | 89 | APT_PROXY=${APT_PROXY:=""} |
|
87 | 90 | APT_SERVER=${APT_SERVER:="ftp.debian.org"} |
|
88 | 91 | |
|
89 | 92 | # Feature settings |
|
90 | 93 | ENABLE_CONSOLE=${ENABLE_CONSOLE:=true} |
|
91 | 94 | ENABLE_IPV6=${ENABLE_IPV6:=true} |
|
92 | 95 | ENABLE_SSHD=${ENABLE_SSHD:=true} |
|
93 | 96 | ENABLE_SOUND=${ENABLE_SOUND:=true} |
|
94 | 97 | ENABLE_DBUS=${ENABLE_DBUS:=true} |
|
95 | 98 | ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true} |
|
96 | 99 | ENABLE_MINGPU=${ENABLE_MINGPU:=false} |
|
97 | 100 | ENABLE_XORG=${ENABLE_XORG:=false} |
|
98 | 101 | ENABLE_WM=${ENABLE_WM:=""} |
|
99 | 102 | ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true} |
|
100 | 103 | ENABLE_USER=${ENABLE_USER:=true} |
|
104 | USER_NAME=${USER_NAME:="pi"} | |
|
101 | 105 | ENABLE_ROOT=${ENABLE_ROOT:=false} |
|
102 | 106 | ENABLE_ROOT_SSH=${ENABLE_ROOT_SSH:=false} |
|
103 | 107 | |
|
104 | 108 | # Advanced settings |
|
105 | 109 | ENABLE_MINBASE=${ENABLE_MINBASE:=false} |
|
106 | 110 | ENABLE_REDUCE=${ENABLE_REDUCE:=flase} |
|
107 | 111 | ENABLE_UBOOT=${ENABLE_UBOOT:=false} |
|
108 | 112 | ENABLE_FBTURBO=${ENABLE_FBTURBO:=false} |
|
109 | 113 | ENABLE_HARDNET=${ENABLE_HARDNET:=false} |
|
110 | 114 | ENABLE_IPTABLES=${ENABLE_IPTABLES:=false} |
|
111 | 115 | ENABLE_SPLITFS=${ENABLE_SPLITFS:=false} |
|
112 | 116 | ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false} |
|
113 | 117 | |
|
114 | 118 | # Kernel compilation settings |
|
115 | 119 | BUILD_KERNEL=${BUILD_KERNEL:=false} |
|
116 | 120 | KERNEL_REDUCE=${KERNEL_REDUCE:=false} |
|
117 | 121 | KERNEL_THREADS=${KERNEL_THREADS:=1} |
|
118 | 122 | KERNEL_HEADERS=${KERNEL_HEADERS:=true} |
|
119 | 123 | KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false} |
|
120 | 124 | KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true} |
|
121 | 125 | |
|
122 | 126 | # Kernel compilation from source directory settings |
|
123 | 127 | KERNELSRC_DIR=${KERNELSRC_DIR:=""} |
|
124 | 128 | KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false} |
|
125 | 129 | KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true} |
|
126 | 130 | KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false} |
|
127 | 131 | |
|
128 | 132 | # Reduce disk usage settings |
|
129 | 133 | REDUCE_APT=${REDUCE_APT:=true} |
|
130 | 134 | REDUCE_DOC=${REDUCE_DOC:=true} |
|
131 | 135 | REDUCE_MAN=${REDUCE_MAN:=true} |
|
132 | 136 | REDUCE_VIM=${REDUCE_VIM:=false} |
|
133 | 137 | REDUCE_BASH=${REDUCE_BASH:=false} |
|
134 | 138 | REDUCE_HWDB=${REDUCE_HWDB:=true} |
|
135 | 139 | REDUCE_SSHD=${REDUCE_SSHD:=true} |
|
136 | 140 | REDUCE_LOCALE=${REDUCE_LOCALE:=true} |
|
137 | 141 | |
|
138 | 142 | # Encrypted filesystem settings |
|
139 | 143 | ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false} |
|
140 | 144 | CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""} |
|
141 | 145 | CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"} |
|
142 | 146 | CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"} |
|
143 | 147 | CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512} |
|
144 | 148 | |
|
145 | 149 | # Stop the Crypto Wars |
|
146 | 150 | DISABLE_FBI=${DISABLE_FBI:=false} |
|
147 | 151 | |
|
148 | 152 | # Chroot scripts directory |
|
149 | 153 | CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""} |
|
150 | 154 | |
|
151 | 155 | # Packages required in the chroot build environment |
|
152 | 156 | APT_INCLUDES=${APT_INCLUDES:=""} |
|
153 | 157 | APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo" |
|
154 | 158 | |
|
155 | 159 | # Packages required for bootstrapping |
|
156 | 160 | REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git" |
|
157 | 161 | MISSING_PACKAGES="" |
|
158 | 162 | |
|
159 | 163 | set +x |
|
160 | 164 | |
|
161 | 165 | # Add packages required for kernel cross compilation |
|
162 | 166 | if [ "$BUILD_KERNEL" = true ] ; then |
|
163 | 167 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf" |
|
164 | 168 | fi |
|
165 | 169 | |
|
166 | 170 | # Add libncurses5 to enable kernel menuconfig |
|
167 | 171 | if [ "$KERNEL_MENUCONFIG" = true ] ; then |
|
168 | 172 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev" |
|
169 | 173 | fi |
|
170 | 174 | |
|
171 | 175 | # Stop the Crypto Wars |
|
172 | 176 | if [ "$DISABLE_FBI" = true ] ; then |
|
173 | 177 | ENABLE_CRYPTFS=true |
|
174 | 178 | fi |
|
175 | 179 | |
|
176 | 180 | # Add cryptsetup package to enable filesystem encryption |
|
177 | 181 | if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then |
|
178 | 182 | REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup" |
|
179 | 183 | APT_INCLUDES="${APT_INCLUDES},cryptsetup" |
|
180 | 184 | |
|
181 | 185 | if [ -z "$CRYPTFS_PASSWORD" ] ; then |
|
182 | 186 | echo "error: no password defined (CRYPTFS_PASSWORD)!" |
|
183 | 187 | exit 1 |
|
184 | 188 | fi |
|
185 | 189 | ENABLE_INITRAMFS=true |
|
186 | 190 | fi |
|
187 | 191 | |
|
188 | 192 | # Add initramfs generation tools |
|
189 | 193 | if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then |
|
190 | 194 | APT_INCLUDES="${APT_INCLUDES},initramfs-tools" |
|
191 | 195 | fi |
|
192 | 196 | |
|
193 | 197 | # Check if all required packages are installed on the build system |
|
194 | 198 | for package in $REQUIRED_PACKAGES ; do |
|
195 | 199 | if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then |
|
196 | 200 | MISSING_PACKAGES="${MISSING_PACKAGES} $package" |
|
197 | 201 | fi |
|
198 | 202 | done |
|
199 | 203 | |
|
200 | 204 | # Ask if missing packages should get installed right now |
|
201 | 205 | if [ -n "$MISSING_PACKAGES" ] ; then |
|
202 | 206 | echo "the following packages needed by this script are not installed:" |
|
203 | 207 | echo "$MISSING_PACKAGES" |
|
204 | 208 | |
|
205 | 209 | echo -n "\ndo you want to install the missing packages right now? [y/n] " |
|
206 | 210 | read confirm |
|
207 | 211 | [ "$confirm" != "y" ] && exit 1 |
|
208 | 212 | fi |
|
209 | 213 | |
|
210 | 214 | # Make sure all required packages are installed |
|
211 | 215 | apt-get -qq -y install ${REQUIRED_PACKAGES} |
|
212 | 216 | |
|
213 | 217 | # Check if ./bootstrap.d directory exists |
|
214 | 218 | if [ ! -d "./bootstrap.d/" ] ; then |
|
215 | 219 | echo "error: './bootstrap.d' required directory not found!" |
|
216 | 220 | exit 1 |
|
217 | 221 | fi |
|
218 | 222 | |
|
219 | 223 | # Check if ./files directory exists |
|
220 | 224 | if [ ! -d "./files/" ] ; then |
|
221 | 225 | echo "error: './files' required directory not found!" |
|
222 | 226 | exit 1 |
|
223 | 227 | fi |
|
224 | 228 | |
|
225 | 229 | # Check if specified KERNELSRC_DIR directory exists |
|
226 | 230 | if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then |
|
227 | 231 | echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!" |
|
228 | 232 | exit 1 |
|
229 | 233 | fi |
|
230 | 234 | |
|
231 | 235 | # Check if specified CHROOT_SCRIPTS directory exists |
|
232 | 236 | if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then |
|
233 | 237 | echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!" |
|
234 | 238 | exit 1 |
|
235 | 239 | fi |
|
236 | 240 | |
|
237 | 241 | # Check if specified device mapping already exists (will be used by cryptsetup) |
|
238 | 242 | if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then |
|
239 | 243 | echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding" |
|
240 | 244 | exit 1 |
|
241 | 245 | fi |
|
242 | 246 | |
|
243 | 247 | # Don't clobber an old build |
|
244 | 248 | if [ -e "$BUILDDIR" ] ; then |
|
245 | 249 | echo "error: directory ${BUILDDIR} already exists, not proceeding" |
|
246 | 250 | exit 1 |
|
247 | 251 | fi |
|
248 | 252 | |
|
249 | 253 | # Setup chroot directory |
|
250 | 254 | mkdir -p "${R}" |
|
251 | 255 | |
|
252 | 256 | # Check if build directory has enough of free disk space >512MB |
|
253 | 257 | if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then |
|
254 | 258 | echo "error: ${BUILDDIR} not enough space left to generate the output image!" |
|
255 | 259 | exit 1 |
|
256 | 260 | fi |
|
257 | 261 | |
|
258 | 262 | set -x |
|
259 | 263 | |
|
260 | 264 | # Call "cleanup" function on various signals and errors |
|
261 | 265 | trap cleanup 0 1 2 3 6 |
|
262 | 266 | |
|
263 | 267 | # Add required packages for the minbase installation |
|
264 | 268 | if [ "$ENABLE_MINBASE" = true ] ; then |
|
265 | 269 | APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown" |
|
266 | 270 | else |
|
267 | 271 | APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup" |
|
268 | 272 | fi |
|
269 | 273 | |
|
270 | 274 | # Add parted package, required to get partprobe utility |
|
271 | 275 | if [ "$EXPANDROOT" = true ] ; then |
|
272 | 276 | APT_INCLUDES="${APT_INCLUDES},parted" |
|
273 | 277 | fi |
|
274 | 278 | |
|
275 | 279 | # Add dbus package, recommended if using systemd |
|
276 | 280 | if [ "$ENABLE_DBUS" = true ] ; then |
|
277 | 281 | APT_INCLUDES="${APT_INCLUDES},dbus" |
|
278 | 282 | fi |
|
279 | 283 | |
|
280 | 284 | # Add iptables IPv4/IPv6 package |
|
281 | 285 | if [ "$ENABLE_IPTABLES" = true ] ; then |
|
282 | 286 | APT_INCLUDES="${APT_INCLUDES},iptables" |
|
283 | 287 | fi |
|
284 | 288 | |
|
285 | 289 | # Add openssh server package |
|
286 | 290 | if [ "$ENABLE_SSHD" = true ] ; then |
|
287 | 291 | APT_INCLUDES="${APT_INCLUDES},openssh-server" |
|
288 | 292 | fi |
|
289 | 293 | |
|
290 | 294 | # Add alsa-utils package |
|
291 | 295 | if [ "$ENABLE_SOUND" = true ] ; then |
|
292 | 296 | APT_INCLUDES="${APT_INCLUDES},alsa-utils" |
|
293 | 297 | fi |
|
294 | 298 | |
|
295 | 299 | # Add rng-tools package |
|
296 | 300 | if [ "$ENABLE_HWRANDOM" = true ] ; then |
|
297 | 301 | APT_INCLUDES="${APT_INCLUDES},rng-tools" |
|
298 | 302 | fi |
|
299 | 303 | |
|
300 | 304 | # Add fbturbo video driver |
|
301 | 305 | if [ "$ENABLE_FBTURBO" = true ] ; then |
|
302 | 306 | # Enable xorg package dependencies |
|
303 | 307 | ENABLE_XORG=true |
|
304 | 308 | fi |
|
305 | 309 | |
|
306 | 310 | # Add user defined window manager package |
|
307 | 311 | if [ -n "$ENABLE_WM" ] ; then |
|
308 | 312 | APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}" |
|
309 | 313 | |
|
310 | 314 | # Enable xorg package dependencies |
|
311 | 315 | ENABLE_XORG=true |
|
312 | 316 | fi |
|
313 | 317 | |
|
314 | 318 | # Add xorg package |
|
315 | 319 | if [ "$ENABLE_XORG" = true ] ; then |
|
316 | 320 | APT_INCLUDES="${APT_INCLUDES},xorg" |
|
317 | 321 | fi |
|
318 | 322 | |
|
319 | 323 | # Replace selected packages with smaller clones |
|
320 | 324 | if [ "$ENABLE_REDUCE" = true ] ; then |
|
321 | 325 | # Add levee package instead of vim-tiny |
|
322 | 326 | if [ "$REDUCE_VIM" = true ] ; then |
|
323 | 327 | APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")" |
|
324 | 328 | fi |
|
325 | 329 | |
|
326 | 330 | # Add dropbear package instead of openssh-server |
|
327 | 331 | if [ "$REDUCE_SSHD" = true ] ; then |
|
328 | 332 | APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")" |
|
329 | 333 | fi |
|
330 | 334 | fi |
|
331 | 335 | |
|
332 | 336 | # Configure kernel sources if no KERNELSRC_DIR |
|
333 | 337 | if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then |
|
334 | 338 | KERNELSRC_CONFIG=true |
|
335 | 339 | fi |
|
336 | 340 | |
|
337 | 341 | # Configure reduced kernel |
|
338 | 342 | if [ "$KERNEL_REDUCE" = true ] ; then |
|
339 | 343 | KERNELSRC_CONFIG=false |
|
340 | 344 | fi |
|
341 | 345 | |
|
342 | 346 | # Execute bootstrap scripts |
|
343 | 347 | for SCRIPT in bootstrap.d/*.sh; do |
|
344 | 348 | head -n 3 "$SCRIPT" |
|
345 | 349 | . "$SCRIPT" |
|
346 | 350 | done |
|
347 | 351 | |
|
348 | 352 | ## Execute custom bootstrap scripts |
|
349 | 353 | if [ -d "custom.d" ] ; then |
|
350 | 354 | for SCRIPT in custom.d/*.sh; do |
|
351 | 355 | . "$SCRIPT" |
|
352 | 356 | done |
|
353 | 357 | fi |
|
354 | 358 | |
|
355 | 359 | # Execute custom scripts inside the chroot |
|
356 | 360 | if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then |
|
357 | 361 | cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts" |
|
358 | 362 | chroot_exec /bin/bash -x <<'EOF' |
|
359 | 363 | for SCRIPT in /chroot_scripts/* ; do |
|
360 | 364 | if [ -f $SCRIPT -a -x $SCRIPT ] ; then |
|
361 | 365 | $SCRIPT |
|
362 | 366 | fi |
|
363 | 367 | done |
|
364 | 368 | EOF |
|
365 | 369 | rm -rf "${R}/chroot_scripts" |
|
366 | 370 | fi |
|
367 | 371 | |
|
368 | 372 | # Remove apt-utils |
|
369 | 373 | chroot_exec apt-get purge -qq -y --force-yes apt-utils |
|
370 | 374 | |
|
371 | 375 | # Generate required machine-id |
|
372 | 376 | MACHINE_ID=$(dbus-uuidgen) |
|
373 | 377 | echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id" |
|
374 | 378 | echo -n "${MACHINE_ID}" > "${ETCDIR}/machine-id" |
|
375 | 379 | |
|
376 | 380 | # APT Cleanup |
|
377 | 381 | chroot_exec apt-get -y clean |
|
378 | 382 | chroot_exec apt-get -y autoclean |
|
379 | 383 | chroot_exec apt-get -y autoremove |
|
380 | 384 | |
|
381 | 385 | # Unmount mounted filesystems |
|
382 | 386 | umount -l "${R}/proc" |
|
383 | 387 | umount -l "${R}/sys" |
|
384 | 388 | |
|
385 | 389 | # Clean up directories |
|
386 | 390 | rm -rf "${R}/run/*" |
|
387 | 391 | rm -rf "${R}/tmp/*" |
|
388 | 392 | |
|
389 | 393 | # Clean up files |
|
390 | 394 | rm -f "${ETCDIR}/ssh/ssh_host_*" |
|
391 | 395 | rm -f "${ETCDIR}/dropbear/dropbear_*" |
|
392 | 396 | rm -f "${ETCDIR}/apt/sources.list.save" |
|
393 | 397 | rm -f "${ETCDIR}/resolvconf/resolv.conf.d/original" |
|
394 | 398 | rm -f "${ETCDIR}/*-" |
|
395 | 399 | rm -f "${ETCDIR}/apt/apt.conf.d/10proxy" |
|
396 | 400 | rm -f "${ETCDIR}/resolv.conf" |
|
397 | 401 | rm -f "${R}/root/.bash_history" |
|
398 | 402 | rm -f "${R}/var/lib/urandom/random-seed" |
|
399 | 403 | rm -f "${R}/initrd.img" |
|
400 | 404 | rm -f "${R}/vmlinuz" |
|
401 | 405 | rm -f "${R}${QEMU_BINARY}" |
|
402 | 406 | |
|
403 | 407 | # Calculate size of the chroot directory in KB |
|
404 | 408 | CHROOT_SIZE=$(expr `du -s "${R}" | awk '{ print $1 }'`) |
|
405 | 409 | |
|
406 | 410 | # Calculate the amount of needed 512 Byte sectors |
|
407 | 411 | TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512) |
|
408 | 412 | FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512) |
|
409 | 413 | ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS}) |
|
410 | 414 | |
|
411 | 415 | # The root partition is EXT4 |
|
412 | 416 | # This means more space than the actual used space of the chroot is used. |
|
413 | 417 | # As overhead for journaling and reserved blocks 20% are added. |
|
414 | 418 | ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512) |
|
415 | 419 | |
|
416 | 420 | # Calculate required image size in 512 Byte sectors |
|
417 | 421 | IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS}) |
|
418 | 422 | |
|
419 | 423 | # Prepare date string for image file name |
|
420 | 424 | DATE="$(date +%Y-%m-%d)" |
|
421 | 425 | |
|
422 | 426 | # Prepare image file |
|
423 | 427 | if [ "$ENABLE_SPLITFS" = true ] ; then |
|
424 | 428 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=${TABLE_SECTORS} |
|
425 | 429 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS} |
|
426 | 430 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=${TABLE_SECTORS} |
|
427 | 431 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=0 seek=${ROOT_SECTORS} |
|
428 | 432 | |
|
429 | 433 | # Write firmware/boot partition tables |
|
430 | 434 | sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" 2> /dev/null <<EOM |
|
431 | 435 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* |
|
432 | 436 | EOM |
|
433 | 437 | |
|
434 | 438 | # Write root partition table |
|
435 | 439 | sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}-root.img" 2> /dev/null <<EOM |
|
436 | 440 | ${TABLE_SECTORS},${ROOT_SECTORS},83 |
|
437 | 441 | EOM |
|
438 | 442 | |
|
439 | 443 | # Setup temporary loop devices |
|
440 | 444 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-frmw.img)" |
|
441 | 445 | ROOT_LOOP="$(losetup -o 1M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-root.img)" |
|
442 | 446 | else # ENABLE_SPLITFS=false |
|
443 | 447 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS} |
|
444 | 448 | dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS} |
|
445 | 449 | |
|
446 | 450 | # Write partition table |
|
447 | 451 | sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" 2> /dev/null <<EOM |
|
448 | 452 | ${TABLE_SECTORS},${FRMW_SECTORS},c,* |
|
449 | 453 | ${ROOT_OFFSET},${ROOT_SECTORS},83 |
|
450 | 454 | EOM |
|
451 | 455 | |
|
452 | 456 | # Setup temporary loop devices |
|
453 | 457 | FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)" |
|
454 | 458 | ROOT_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)" |
|
455 | 459 | fi |
|
456 | 460 | |
|
457 | 461 | if [ "$ENABLE_CRYPTFS" = true ] ; then |
|
458 | 462 | # Create dummy ext4 fs |
|
459 | 463 | mkfs.ext4 "$ROOT_LOOP" |
|
460 | 464 | |
|
461 | 465 | # Setup password keyfile |
|
462 | 466 | echo -n ${CRYPTFS_PASSWORD} > .password |
|
463 | 467 | chmod 600 .password |
|
464 | 468 | |
|
465 | 469 | # Initialize encrypted partition |
|
466 | 470 | echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password |
|
467 | 471 | |
|
468 | 472 | # Open encrypted partition and setup mapping |
|
469 | 473 | cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}" |
|
470 | 474 | |
|
471 | 475 | # Secure delete password keyfile |
|
472 | 476 | shred -zu .password |
|
473 | 477 | |
|
474 | 478 | # Update temporary loop device |
|
475 | 479 | ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}" |
|
476 | 480 | |
|
477 | 481 | # Wipe encrypted partition (encryption cipher is used for randomness) |
|
478 | 482 | dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count=$(blockdev --getsz "${ROOT_LOOP}") |
|
479 | 483 | fi |
|
480 | 484 | |
|
481 | 485 | # Build filesystems |
|
482 | 486 | mkfs.vfat "$FRMW_LOOP" |
|
483 | 487 | mkfs.ext4 "$ROOT_LOOP" |
|
484 | 488 | |
|
485 | 489 | # Mount the temporary loop devices |
|
486 | 490 | mkdir -p "$BUILDDIR/mount" |
|
487 | 491 | mount "$ROOT_LOOP" "$BUILDDIR/mount" |
|
488 | 492 | |
|
489 | 493 | mkdir -p "$BUILDDIR/mount/boot/firmware" |
|
490 | 494 | mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware" |
|
491 | 495 | |
|
492 | 496 | # Copy all files from the chroot to the loop device mount point directory |
|
493 | 497 | rsync -a "${R}/" "$BUILDDIR/mount/" |
|
494 | 498 | |
|
495 | 499 | # Unmount all temporary loop devices and mount points |
|
496 | 500 | cleanup |
|
497 | 501 | |
|
498 | 502 | # Create block map file(s) of image(s) |
|
499 | 503 | if [ "$ENABLE_SPLITFS" = true ] ; then |
|
500 | 504 | # Create block map files for "bmaptool" |
|
501 | 505 | bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" |
|
502 | 506 | bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-root.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-root.img" |
|
503 | 507 | |
|
504 | 508 | # Image was successfully created |
|
505 | 509 | echo "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" |
|
506 | 510 | echo "$BASEDIR/${DATE}-debian-${RELEASE}-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" |
|
507 | 511 | else |
|
508 | 512 | # Create block map file for "bmaptool" |
|
509 | 513 | bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}.img" |
|
510 | 514 | |
|
511 | 515 | # Image was successfully created |
|
512 | 516 | echo "$BASEDIR/${DATE}-debian-${RELEASE}.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created" |
|
513 | 517 | fi |
General Comments 0
Vous devez vous connecter pour laisser un commentaire.
Se connecter maintenant