##// END OF EJS Templates
autoselect local apt-cacher-ng instance...
burnbabyburn -
r343:b08ad2f7992a
parent child
Show More
@@ -1,487 +1,487
1 1 # rpi23-gen-image
2 2 ## Introduction
3 3 `rpi23-gen-image.sh` is an advanced Debian Linux bootstrapping shell script for generating Debian OS images for Raspberry Pi 2 (RPi2) and Raspberry Pi 3 (RPi3) computers. The script at this time supports the bootstrapping of the Debian (armhf) releases `stretch` and `buster`. Raspberry Pi 3 images are generated for 32-bit mode only. Raspberry Pi 3 64-bit images can be generated using custom configuration parameters (```templates/rpi3-stretch-arm64-4.11.y```).
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 bc psmisc dbus sudo```
9 9
10 10 It is recommended to configure the `rpi23-gen-image.sh` script to build and install the latest Raspberry Pi Linux kernel. For the RPi3 this is mandatory. Kernel compilation and linking will be performed on the build system using an ARM (armhf) cross-compiler toolchain.
11 11
12 12 The script has been tested using the default `crossbuild-essential-armhf` toolchain meta package on Debian Linux and `stretch` build systems. Please check the [Debian CrossToolchains Wiki](https://wiki.debian.org/CrossToolchains) for further information.
13 13
14 14 ## Command-line parameters
15 15 The script accepts certain command-line parameters to enable or disable specific OS features, services and configuration settings. These parameters are passed to the `rpi23-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 `rpi23-gen-image.sh` script.
16 16
17 17 ##### Command-line examples:
18 18 ```shell
19 19 ENABLE_UBOOT=true ./rpi23-gen-image.sh
20 20 ENABLE_CONSOLE=false ENABLE_IPV6=false ./rpi23-gen-image.sh
21 21 ENABLE_WM=xfce4 ENABLE_FBTURBO=true ENABLE_MINBASE=true ./rpi23-gen-image.sh
22 22 ENABLE_HARDNET=true ENABLE_IPTABLES=true /rpi23-gen-image.sh
23 23 APT_SERVER=ftp.de.debian.org APT_PROXY="http://127.0.0.1:3142/" ./rpi23-gen-image.sh
24 24 ENABLE_MINBASE=true ./rpi23-gen-image.sh
25 25 BUILD_KERNEL=true ENABLE_MINBASE=true ENABLE_IPV6=false ./rpi23-gen-image.sh
26 26 BUILD_KERNEL=true KERNELSRC_DIR=/tmp/linux ./rpi23-gen-image.sh
27 27 ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi23-gen-image.sh
28 28 ENABLE_CRYPTFS=true CRYPTFS_PASSWORD=changeme EXPANDROOT=false ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi23-gen-image.sh
29 29 RELEASE=stretch BUILD_KERNEL=true ./rpi23-gen-image.sh
30 30 RPI_MODEL=3 ENABLE_WIRELESS=true ENABLE_MINBASE=true BUILD_KERNEL=true ./rpi23-gen-image.sh
31 31 RELEASE=stretch RPI_MODEL=3 ENABLE_WIRELESS=true ENABLE_MINBASE=true BUILD_KERNEL=true ./rpi23-gen-image.sh
32 32 ```
33 33
34 34 ## Configuration template files
35 35 To avoid long lists of command-line parameters and to help to store the favourite parameter configurations the `rpi23-gen-image.sh` script supports so called configuration template files (`CONFIG_TEMPLATE`=template). These are simple text files located in the `./templates` directory that contain the list of configuration parameters that will be used. New configuration template files can be added to the `./templates` directory.
36 36
37 37 ##### Command-line examples:
38 38 ```shell
39 39 CONFIG_TEMPLATE=rpi3stretch ./rpi23-gen-image.sh
40 40 CONFIG_TEMPLATE=rpi2stretch ./rpi23-gen-image.sh
41 41 ```
42 42
43 43 ## Supported parameters and settings
44 44 #### APT settings:
45 45 ##### `APT_SERVER`="ftp.debian.org/debian"
46 46 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.
47 47
48 48 ##### `APT_PROXY`=""
49 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.
49 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. If `apt-cacher-ng` is running on default `http://127.0.0.1:3142` it is autodetected and you don't need to set this.
50 50
51 51 ##### `APT_INCLUDES`=""
52 52 A comma separated list of additional packages to be installed by debootstrap during bootstrapping.
53 53
54 54 ##### `APT_INCLUDES_LATE`=""
55 55 A comma separated list of additional packages to be installed by apt after bootstrapping and after APT sources are set up. This is useful for packages with pre-depends, which debootstrap do not handle well.
56 56
57 57 ---
58 58
59 59 #### General system settings:
60 60 ##### `RPI_MODEL`=2
61 61 Specifiy the target Raspberry Pi hardware model. The script at this time supports the following Raspberry Pi models:
62 62 `0` = Used for Raspberry Pi 0 and Raspberry Pi 0 W
63 63 `1` = Used for Pi 1 model A and B
64 64 `1P` = Used for Pi 1 model B+ and A+
65 65 `2` = Used for Pi 2 model B
66 66 `3` = Used for Pi 3 model B
67 67 `3P` = Used for Pi 3 model B+
68 68 `BUILD_KERNEL`=true will automatically be set if the Raspberry Pi model `3` or `3P` is used.
69 69
70 70 ##### `RELEASE`="buster"
71 71 Set the desired Debian release name. The script at this time supports the bootstrapping of the Debian releases "stretch" and "buster". `BUILD_KERNEL`=true will automatically be set if the Debian releases `stretch` or `buster` are used.
72 72
73 73 ##### `RELEASE_ARCH`="armhf"
74 74 Set the desired Debian release architecture.
75 75
76 76 ##### `HOSTNAME`="rpi$RPI_MODEL-$RELEASE"
77 77 Set system host name. It's recommended that the host name is unique in the corresponding subnet.
78 78
79 79 ##### `PASSWORD`="raspberry"
80 80 Set system `root` password. It's **STRONGLY** recommended that you choose a custom password.
81 81
82 82 ##### `USER_PASSWORD`="raspberry"
83 83 Set password for the created non-root user `USER_NAME`=pi. Ignored if `ENABLE_USER`=false. It's **STRONGLY** recommended that you choose a custom password.
84 84
85 85 ##### `DEFLOCAL`="en_US.UTF-8"
86 86 Set default system locale. This setting can also be changed inside the running OS using the `dpkg-reconfigure locales` command. Please note that on using this parameter the script will automatically install the required packages `locales`, `keyboard-configuration` and `console-setup`.
87 87
88 88 ##### `TIMEZONE`="Europe/Berlin"
89 89 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.
90 90
91 91 ##### `EXPANDROOT`=true
92 92 Expand the root partition and filesystem automatically on first boot.
93 93
94 94 ##### `ENABLE_QEMU`=false
95 95 Generate kernel (`vexpress_defconfig`), file system image (`qcow2`) and DTB files that can be used for QEMU full system emulation (`vexpress-A15`). The output files are stored in the `$(pwd)/images/qemu` directory. You can find more information about running the generated image in the QEMU section of this readme file.
96 96
97 97 ---
98 98
99 99 #### Keyboard settings:
100 100 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.
101 101
102 102 ##### `XKB_MODEL`=""
103 103 Set the name of the model of your keyboard type.
104 104
105 105 ##### `XKB_LAYOUT`=""
106 106 Set the supported keyboard layout(s).
107 107
108 108 ##### `XKB_VARIANT`=""
109 109 Set the supported variant(s) of the keyboard layout(s).
110 110
111 111 ##### `XKB_OPTIONS`=""
112 112 Set extra xkb configuration options.
113 113
114 114 ---
115 115
116 116 #### Networking settings (DHCP):
117 117 This parameter is used to set up networking auto configuration in `/etc/systemd/network/eth.network`. The default location of network configuration files in the Debian `stretch` release was changed to `/lib/systemd/network`.`
118 118
119 119 ##### `ENABLE_DHCP`=true
120 120 Set the system to use DHCP. This requires an DHCP server.
121 121
122 122 ---
123 123
124 124 #### Networking settings (static):
125 125 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`. The default location of network configuration files in the Debian `stretch` release was changed to `/lib/systemd/network`.
126 126
127 127 ##### `NET_ADDRESS`=""
128 128 Set a static IPv4 or IPv6 address and its prefix, separated by "/", eg. "192.169.0.3/24".
129 129
130 130 ##### `NET_GATEWAY`=""
131 131 Set the IP address for the default gateway.
132 132
133 133 ##### `NET_DNS_1`=""
134 134 Set the IP address for the first DNS server.
135 135
136 136 ##### `NET_DNS_2`=""
137 137 Set the IP address for the second DNS server.
138 138
139 139 ##### `NET_DNS_DOMAINS`=""
140 140 Set the default DNS search domains to use for non fully qualified host names.
141 141
142 142 ##### `NET_NTP_1`=""
143 143 Set the IP address for the first NTP server.
144 144
145 145 ##### `NET_NTP_2`=""
146 146 Set the IP address for the second NTP server.
147 147
148 148 ---
149 149
150 150 #### Basic system features:
151 151 ##### `ENABLE_CONSOLE`=true
152 152 Enable serial console interface. Recommended if no monitor or keyboard is connected to the RPi2/3. In case of problems fe. if the network (auto) configuration failed - the serial console can be used to access the system.
153 153
154 154 ##### `ENABLE_I2C`=false
155 155 Enable I2C interface on the RPi2/3. Please check the [RPi2/3 pinout diagrams](https://elinux.org/RPi_Low-level_peripherals) to connect the right GPIO pins.
156 156
157 157 ##### `ENABLE_SPI`=false
158 158 Enable SPI interface on the RPi2/3. Please check the [RPi2/3 pinout diagrams](https://elinux.org/RPi_Low-level_peripherals) to connect the right GPIO pins.
159 159
160 160 ##### `ENABLE_IPV6`=true
161 161 Enable IPv6 support. The network interface configuration is managed via systemd-networkd.
162 162
163 163 ##### `ENABLE_SSHD`=true
164 164 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.
165 165
166 166 ##### `ENABLE_NONFREE`=false
167 167 Allow the installation of non-free Debian packages that do not comply with the DFSG. This is required to install closed-source firmware binary blobs.
168 168
169 169 ##### `ENABLE_WIRELESS`=false
170 170 Download and install the [closed-source firmware binary blob](https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm) that is required to run the internal wireless interface of the Raspberry Pi model `3`. This parameter is ignored if the specified `RPI_MODEL` is not `3`.
171 171
172 172 ##### `ENABLE_RSYSLOG`=true
173 173 If set to false, disable and uninstall rsyslog (so logs will be available only
174 174 in journal files)
175 175
176 176 ##### `ENABLE_SOUND`=true
177 177 Enable sound hardware and install Advanced Linux Sound Architecture.
178 178
179 179 ##### `ENABLE_HWRANDOM`=true
180 180 Enable Hardware Random Number Generator. Strong random numbers are important for most network based communications that use encryption. It's recommended to be enabled.
181 181
182 182 ##### `ENABLE_MINGPU`=false
183 183 Minimize the amount of shared memory reserved for the GPU. It doesn't seem to be possible to fully disable the GPU.
184 184
185 185 ##### `ENABLE_DBUS`=true
186 186 Install and enable D-Bus message bus. Please note that systemd should work without D-bus but it's recommended to be enabled.
187 187
188 188 ##### `ENABLE_XORG`=false
189 189 Install Xorg open-source X Window System.
190 190
191 191 ##### `ENABLE_WM`=""
192 192 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 `rpi23-gen-image.sh` script has been tested with the following list of window managers: `blackbox`, `openbox`, `fluxbox`, `jwm`, `dwm`, `xfce4`, `awesome`.
193 193
194 194 ---
195 195
196 196 #### Advanced system features:
197 197 ##### `ENABLE_MINBASE`=false
198 198 Use debootstrap script variant `minbase` which only includes essential packages and apt. This will reduce the disk usage by about 65 MB.
199 199
200 200 ##### `ENABLE_REDUCE`=false
201 201 Reduce the disk space usage by deleting packages and files. See `REDUCE_*` parameters for detailed information.
202 202
203 203 ##### `ENABLE_UBOOT`=false
204 204 Replace the default RPi2/3 second stage bootloader (bootcode.bin) with [U-Boot bootloader](https://git.denx.de/?p=u-boot.git;a=summary). U-Boot can boot images via the network using the BOOTP/TFTP protocol.
205 205
206 206 ##### `UBOOTSRC_DIR`=""
207 207 Path to a directory (`u-boot`) of [U-Boot bootloader sources](https://git.denx.de/?p=u-boot.git;a=summary) that will be copied, configured, build and installed inside the chroot.
208 208
209 209 ##### `ENABLE_FBTURBO`=false
210 210 Install and enable the [hardware accelerated Xorg video driver](https://github.com/ssvb/xf86-video-fbturbo) `fbturbo`. Please note that this driver is currently limited to hardware accelerated window moving and scrolling.
211 211
212 212 ##### `FBTURBOSRC_DIR`=""
213 213 Path to a directory (`xf86-video-fbturbo`) of [hardware accelerated Xorg video driver sources](https://github.com/ssvb/xf86-video-fbturbo) that will be copied, configured, build and installed inside the chroot.
214 214
215 215 ##### `ENABLE_VIDEOCORE`=false
216 216 Install and enable the [Source code for ARM side libraries for interfacing to Raspberry Pi GPU](https://github.com/raspberrypi/userland) `vcgencmd`. Please note that this driver is currently limited to hardware accelerated window moving and scrolling.
217 217
218 218 ##### `VIDEOCORESRC_DIR`=""
219 219 Path to a directory (`userland`) of [Source code for ARM side libraries for interfacing to Raspberry Pi GPU](https://github.com/raspberrypi/userland) that will be copied, configured, build and installed inside the chroot.
220 220
221 221 ##### `ENABLE_IPTABLES`=false
222 222 Enable iptables IPv4/IPv6 firewall. Simplified ruleset: Allow all outgoing connections. Block all incoming connections except to OpenSSH service.
223 223
224 224 ##### `ENABLE_USER`=true
225 225 Create non-root user with password `USER_PASSWORD`=raspberry. Unless overridden with `USER_NAME`=user, username will be `pi`.
226 226
227 227 ##### `USER_NAME`=pi
228 228 Non-root user to create. Ignored if `ENABLE_USER`=false
229 229
230 230 ##### `ENABLE_ROOT`=false
231 231 Set root user password so root login will be enabled
232 232
233 233 ##### `ENABLE_HARDNET`=false
234 234 Enable IPv4/IPv6 network stack hardening settings.
235 235
236 236 ##### `ENABLE_SPLITFS`=false
237 237 Enable having root partition on an USB drive by creating two image files: one for the `/boot/firmware` mount point, and another for `/`.
238 238
239 239 ##### `CHROOT_SCRIPTS`=""
240 240 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.
241 241
242 242 ##### `ENABLE_INITRAMFS`=false
243 243 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.
244 244
245 245 ##### `ENABLE_IFNAMES`=true
246 246 Enable automatic assignment of predictable, stable network interface names for all local Ethernet, WLAN interfaces. This might create complex and long interface names. This parameter is only supported if the Debian releases `stretch` or `buster` are used.
247 247
248 248 ##### `DISABLE_UNDERVOLT_WARNINGS`=
249 249 Disable RPi2/3 under-voltage warnings and overlays. Setting the parameter to `1` will disable the warning overlay. Setting it to `2` will additionally allow RPi2/3 turbo mode when low-voltage is present.
250 250
251 251 ---
252 252
253 253 #### SSH settings:
254 254 ##### `SSH_ENABLE_ROOT`=false
255 255 Enable password root login via SSH. This may be a security risk with default password, use only in trusted environments. `ENABLE_ROOT` must be set to `true`.
256 256
257 257 ##### `SSH_DISABLE_PASSWORD_AUTH`=false
258 258 Disable password based SSH authentication. Only public key based SSH (v2) authentication will be supported.
259 259
260 260 ##### `SSH_LIMIT_USERS`=false
261 261 Limit the users that are allowed to login via SSH. Only allow user `USER_NAME`=pi and root if `SSH_ENABLE_ROOT`=true to login. This parameter will be ignored if `dropbear` SSH is used (`REDUCE_SSHD`=true).
262 262
263 263 ##### `SSH_ROOT_PUB_KEY`=""
264 264 Add SSH (v2) public key(s) from specified file to `authorized_keys` file to enable public key based SSH (v2) authentication of user `root`. The specified file can also contain multiple SSH (v2) public keys. SSH protocol version 1 is not supported. `ENABLE_ROOT` **and** `SSH_ENABLE_ROOT` must be set to `true`.
265 265
266 266 ##### `SSH_USER_PUB_KEY`=""
267 267 Add SSH (v2) public key(s) from specified file to `authorized_keys` file to enable public key based SSH (v2) authentication of user `USER_NAME`=pi. The specified file can also contain multiple SSH (v2) public keys. SSH protocol version 1 is not supported.
268 268
269 269 ---
270 270
271 271 #### Kernel compilation:
272 272 ##### `BUILD_KERNEL`=false
273 273 Build and install the latest RPi2/3 Linux kernel. Currently only the default RPi2/3 kernel configuration is used. `BUILD_KERNEL`=true will automatically be set if the Raspberry Pi model `3` is used.
274 274
275 275 ##### `CROSS_COMPILE`="arm-linux-gnueabihf-"
276 276 This sets the cross compile enviornment for the compiler.
277 277
278 278 ##### `KERNEL_ARCH`="arm"
279 279 This sets the kernel architecture for the compiler.
280 280
281 281 ##### `KERNEL_IMAGE`="kernel7.img"
282 282 Name of the image file in the boot partition. If not set, `KERNEL_IMAGE` will be set to "kernel8.img" automatically if building for arm64.
283 283
284 284 ##### `KERNEL_BRANCH`=""
285 285 Name of the requested branch from the GIT location for the RPi Kernel. Default is using the current default branch from the GIT site.
286 286
287 287 ##### `QEMU_BINARY`="/usr/bin/qemu-arm-static"
288 288 Sets the QEMU enviornment for the Debian archive. If not set, `QEMU_BINARY` will be set to "/usr/bin/qemu-aarch64-static" automatically if building for arm64.
289 289
290 290 ##### `KERNEL_DEFCONFIG`="bcm2709_defconfig"
291 291 Sets the default config for kernel compiling. If not set, `KERNEL_DEFCONFIG` will be set to "bcmrpi3\_defconfig" automatically if building for arm64.
292 292
293 293 ##### `KERNEL_REDUCE`=false
294 294 Reduce the size of the generated kernel by removing unwanted device, network and filesystem drivers (experimental).
295 295
296 296 ##### `KERNEL_THREADS`=1
297 297 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.
298 298
299 299 ##### `KERNEL_HEADERS`=true
300 300 Install kernel headers with built kernel.
301 301
302 302 ##### `KERNEL_MENUCONFIG`=false
303 303 Start `make menuconfig` interactive menu-driven kernel configuration. The script will continue after `make menuconfig` was terminated.
304 304
305 305 ##### `KERNEL_OLDDEFCONFIG`=false
306 306 Run `make olddefconfig` to automatically set all new kernel configuration options to their recommended default values.
307 307
308 308 ##### `KERNEL_CCACHE`=false
309 309 Compile the kernel using ccache. This speeds up kernel recompilation by caching previous compilations and detecting when the same compilation is being done again.
310 310
311 311 ##### `KERNEL_REMOVESRC`=true
312 312 Remove all kernel sources from the generated OS image after it was built and installed.
313 313
314 314 ##### `KERNELSRC_DIR`=""
315 315 Path to a directory (`linux`) of [RaspberryPi Linux kernel sources](https://github.com/raspberrypi/linux) that will be copied, configured, build and installed inside the chroot.
316 316
317 317 ##### `KERNELSRC_CLEAN`=false
318 318 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.
319 319
320 320 ##### `KERNELSRC_CONFIG`=true
321 321 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.
322 322
323 323 ##### `KERNELSRC_USRCONFIG`=""
324 324 Copy own config file to kernel `.config`. If `KERNEL_MENUCONFIG`=true then running after copy.
325 325
326 326 ##### `KERNELSRC_PREBUILT`=false
327 327 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`, `KERNELSRC_USRCONFIG` and `KERNEL_MENUCONFIG` are ignored and no kernel compilation tasks are performed.
328 328
329 329 ##### `RPI_FIRMWARE_DIR`=""
330 330 The directory (`firmware`) 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.
331 331
332 332 ---
333 333
334 334 #### Reduce disk usage:
335 335 The following list of parameters is ignored if `ENABLE_REDUCE`=false.
336 336
337 337 ##### `REDUCE_APT`=true
338 338 Configure APT to use compressed package repository lists and no package caching files.
339 339
340 340 ##### `REDUCE_DOC`=true
341 341 Remove all doc files (harsh). Configure APT to not include doc files on future `apt-get` package installations.
342 342
343 343 ##### `REDUCE_MAN`=true
344 344 Remove all man pages and info files (harsh). Configure APT to not include man pages on future `apt-get` package installations.
345 345
346 346 ##### `REDUCE_VIM`=false
347 347 Replace `vim-tiny` package by `levee` a tiny vim clone.
348 348
349 349 ##### `REDUCE_BASH`=false
350 350 Remove `bash` package and switch to `dash` shell (experimental).
351 351
352 352 ##### `REDUCE_HWDB`=true
353 353 Remove PCI related hwdb files (experimental).
354 354
355 355 ##### `REDUCE_SSHD`=true
356 356 Replace `openssh-server` with `dropbear`.
357 357
358 358 ##### `REDUCE_LOCALE`=true
359 359 Remove all `locale` translation files.
360 360
361 361 ---
362 362
363 363 #### Encrypted root partition:
364 364 ##### `ENABLE_CRYPTFS`=false
365 365 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.
366 366
367 367 ##### `CRYPTFS_PASSWORD`=""
368 368 Set password of the encrypted root partition. This parameter is mandatory if `ENABLE_CRYPTFS`=true.
369 369
370 370 ##### `CRYPTFS_MAPPING`="secure"
371 371 Set name of dm-crypt managed device-mapper mapping.
372 372
373 373 ##### `CRYPTFS_CIPHER`="aes-xts-plain64:sha512"
374 374 Set cipher specification string. `aes-xts*` ciphers are strongly recommended.
375 375
376 376 ##### `CRYPTFS_XTSKEYSIZE`=512
377 377 Sets key size in bits. The argument has to be a multiple of 8.
378 378
379 379 ---
380 380
381 381 #### Build settings:
382 382 ##### `BASEDIR`=$(pwd)/images/${RELEASE}
383 383 Set a path to a working directory used by the script to generate an image.
384 384
385 385 ##### `IMAGE_NAME`=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}
386 386 Set a filename for the output file(s). Note: the script will create $IMAGE_NAME.img if `ENABLE_SPLITFS`=false or $IMAGE_NAME-frmw.img and $IMAGE_NAME-root.img if `ENABLE_SPLITFS`=true. Note 2: If the KERNEL_BRANCH is not set, the word "CURRENT" is used.
387 387
388 388 ## Understanding the script
389 389 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:
390 390
391 391 | Script | Description |
392 392 | --- | --- |
393 393 | `10-bootstrap.sh` | Debootstrap basic system |
394 394 | `11-apt.sh` | Setup APT repositories |
395 395 | `12-locale.sh` | Setup Locales and keyboard settings |
396 396 | `13-kernel.sh` | Build and install RPi2/3 Kernel |
397 397 | `14-fstab.sh` | Setup fstab and initramfs |
398 398 | `15-rpi-config.sh` | Setup RPi2/3 config and cmdline |
399 399 | `20-networking.sh` | Setup Networking |
400 400 | `21-firewall.sh` | Setup Firewall |
401 401 | `30-security.sh` | Setup Users and Security settings |
402 402 | `31-logging.sh` | Setup Logging |
403 403 | `32-sshd.sh` | Setup SSH and public keys |
404 404 | `41-uboot.sh` | Build and Setup U-Boot |
405 405 | `42-fbturbo.sh` | Build and Setup fbturbo Xorg driver |
406 406 | `50-firstboot.sh` | First boot actions |
407 407 | `99-reduce.sh` | Reduce the disk space usage |
408 408
409 409 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.
410 410
411 411 | Directory | Description |
412 412 | --- | --- |
413 413 | `apt` | APT management configuration files |
414 414 | `boot` | Boot and RPi2/3 configuration files |
415 415 | `dpkg` | Package Manager configuration |
416 416 | `etc` | Configuration files and rc scripts |
417 417 | `firstboot` | Scripts that get executed on first boot |
418 418 | `initramfs` | Initramfs scripts |
419 419 | `iptables` | Firewall configuration files |
420 420 | `locales` | Locales configuration |
421 421 | `modules` | Kernel Modules configuration |
422 422 | `mount` | Fstab configuration |
423 423 | `network` | Networking configuration files |
424 424 | `sysctl.d` | Swapping and Network Hardening configuration |
425 425 | `xorg` | fbturbo Xorg driver configuration |
426 426
427 427 ## Custom packages and scripts
428 428 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`.
429 429
430 430 Scripts in the custom.d directory will be executed after all other installation is complete but before the image is created.
431 431
432 432 ## Logging of the bootstrapping process
433 433 All information related to the bootstrapping process and the commands executed by the `rpi23-gen-image.sh` script can easily be saved into a logfile. The common shell command `script` can be used for this purpose:
434 434
435 435 ```shell
436 436 script -c 'APT_SERVER=ftp.de.debian.org ./rpi23-gen-image.sh' ./build.log
437 437 ```
438 438
439 439 ## Flashing the image file
440 440 After the image file was successfully created by the `rpi23-gen-image.sh` script it can be copied to the microSD card that will be used by the RPi2/3 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`.
441 441
442 442 ##### Flashing examples:
443 443 ```shell
444 444 bmaptool copy ./images/jessie/2017-01-23-rpi3-jessie.img /dev/mmcblk0
445 445 dd bs=4M if=./images/jessie/2017-01-23-rpi3-jessie.img of=/dev/mmcblk0
446 446 ```
447 447 If you have set `ENABLE_SPLITFS`, copy the `-frmw` image on the microSD card, then the `-root` one on the USB drive:
448 448 ```shell
449 449 bmaptool copy ./images/jessie/2017-01-23-rpi3-jessie-frmw.img /dev/mmcblk0
450 450 bmaptool copy ./images/jessie/2017-01-23-rpi3-jessie-root.img /dev/sdc
451 451 ```
452 452
453 453 ## QEMU emulation
454 454 Start QEMU full system emulation:
455 455 ```shell
456 456 qemu-system-arm -m 2048M -M vexpress-a15 -cpu cortex-a15 -kernel kernel7.img -no-reboot -dtb vexpress-v2p-ca15_a7.dtb -sd ${IMAGE_NAME}.qcow2 -append "root=/dev/mmcblk0p2 rw rootfstype=ext4 console=tty1"
457 457 ```
458 458
459 459 Start QEMU full system emulation and output to console:
460 460 ```shell
461 461 qemu-system-arm -m 2048M -M vexpress-a15 -cpu cortex-a15 -kernel kernel7.img -no-reboot -dtb vexpress-v2p-ca15_a7.dtb -sd ${IMAGE_NAME}.qcow2 -append "root=/dev/mmcblk0p2 rw rootfstype=ext4 console=ttyAMA0,115200 init=/bin/systemd" -serial stdio
462 462 ```
463 463
464 464 Start QEMU full system emulation with SMP and output to console:
465 465 ```shell
466 466 qemu-system-arm -m 2048M -M vexpress-a15 -cpu cortex-a15 -smp cpus=2,maxcpus=2 -kernel kernel7.img -no-reboot -dtb vexpress-v2p-ca15_a7.dtb -sd ${IMAGE_NAME}.qcow2 -append "root=/dev/mmcblk0p2 rw rootfstype=ext4 console=ttyAMA0,115200 init=/bin/systemd" -serial stdio
467 467 ```
468 468
469 469 Start QEMU full system emulation with cryptfs, initramfs and output to console:
470 470 ```shell
471 471 qemu-system-arm -m 2048M -M vexpress-a15 -cpu cortex-a15 -kernel kernel7.img -no-reboot -dtb vexpress-v2p-ca15_a7.dtb -sd ${IMAGE_NAME}.qcow2 -initrd "initramfs-${KERNEL_VERSION}" -append "root=/dev/mapper/secure cryptdevice=/dev/mmcblk0p2:secure rw rootfstype=ext4 console=ttyAMA0,115200 init=/bin/systemd" -serial stdio
472 472 ```
473 473
474 474 ## Weekly image builds
475 475 The image files are provided by JRWR'S I/O PORT and are built once a Sunday at midnight UTC!
476 476 * [Debian Stretch Raspberry Pi2/3 Weekly Image Builds](https://jrwr.io/doku.php?id=projects:debianpi)
477 477
478 478 ## External links and references
479 479 * [Debian worldwide mirror sites](https://www.debian.org/mirror/list)
480 480 * [Debian Raspberry Pi 2 Wiki](https://wiki.debian.org/RaspberryPi2)
481 481 * [Debian CrossToolchains Wiki](https://wiki.debian.org/CrossToolchains)
482 482 * [Official Raspberry Pi Firmware on github](https://github.com/raspberrypi/firmware)
483 483 * [Official Raspberry Pi Kernel on github](https://github.com/raspberrypi/linux)
484 484 * [U-BOOT git repository](https://git.denx.de/?p=u-boot.git;a=summary)
485 485 * [Xorg DDX driver fbturbo](https://github.com/ssvb/xf86-video-fbturbo)
486 486 * [RPi3 Wireless interface firmware](https://github.com/RPi-Distro/firmware-nonfree/tree/master/brcm80211/brcm)
487 487 * [Collabora RPi2 Kernel precompiled](https://repositories.collabora.co.uk/debian/)
@@ -1,41 +1,41
1 1 #
2 2 # Debootstrap basic system
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 VARIANT=""
9 9 COMPONENTS="main"
10 10
11 11 # Use non-free Debian packages if needed
12 12 if [ "$ENABLE_NONFREE" = true ] ; then
13 13 COMPONENTS="main,non-free,contrib"
14 14 fi
15 15
16 16 # Use minbase bootstrap variant which only includes essential packages
17 17 if [ "$ENABLE_MINBASE" = true ] ; then
18 18 VARIANT="--variant=minbase"
19 19 fi
20 20
21 21 # Base debootstrap (unpack only)
22 http_proxy=${APT_PROXY} debootstrap "${APT_EXCLUDES}" --arch="${RELEASE_ARCH}" --foreign ${VARIANT} --components="${COMPONENTS}" --include="${APT_INCLUDES}" "${RELEASE}" "${R}" "http://${APT_SERVER}"
22 http_proxy=${APT_PROXY} debootstrap ${APT_EXCLUDES} --arch="${RELEASE_ARCH}" --foreign ${VARIANT} --components="${COMPONENTS}" --include="${APT_INCLUDES}" "${RELEASE}" "${R}" "http://${APT_SERVER}"
23 23
24 24 # Copy qemu emulator binary to chroot
25 25 install -m 755 -o root -g root "${QEMU_BINARY}" "${R}${QEMU_BINARY}"
26 26
27 27 # Copy debian-archive-keyring.pgp
28 28 mkdir -p "${R}/usr/share/keyrings"
29 29 install_readonly /usr/share/keyrings/debian-archive-keyring.gpg "${R}/usr/share/keyrings/debian-archive-keyring.gpg"
30 30
31 31 # Complete the bootstrapping process
32 32 chroot_exec /debootstrap/debootstrap --second-stage
33 33
34 34 # Mount required filesystems
35 35 mount -t proc none "${R}/proc"
36 36 mount -t sysfs none "${R}/sys"
37 37
38 38 # Mount pseudo terminal slave if supported by Debian release
39 39 if [ -d "${R}/dev/pts" ] ; then
40 40 mount --bind /dev/pts "${R}/dev/pts"
41 41 fi
@@ -1,33 +1,46
1 1 #
2 2 # Setup videocore - Raspberry Userland
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 if [ "$ENABLE_VIDEOCORE" = true ] ; then
9 9 # Copy existing videocore sources into chroot directory
10 10 if [ -n "$VIDEOCORESRC_DIR" ] && [ -d "$VIDEOCORESRC_DIR" ] ; then
11 11 # Copy local U-Boot sources
12 12 cp -r "${VIDEOCORESRC_DIR}" "${R}/tmp"
13 13 else
14 14 # Create temporary directory for U-Boot sources
15 15 temp_dir=$(as_nobody mktemp -d)
16 16
17 17 # Fetch U-Boot sources
18 18 as_nobody git -C "${temp_dir}" clone "${VIDEOCORE_URL}"
19 19
20 20 # Copy downloaded U-Boot sources
21 21 mv "${temp_dir}/userland" "${R}/tmp/"
22 22
23 23 # Set permissions of the U-Boot sources
24 24 chown -R root:root "${R}/tmp/userland"
25 25
26 26 # Remove temporary directory for U-Boot sources
27 27 rm -fr "${temp_dir}"
28 28 fi
29 29
30 cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_BUILD_TYPE=release -DARM64=ON -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_ASM_COMPILER=aarch64-linux-gnu-gcc -DVIDEOCORE_BUILD_DIR="${R}"/opt/vc
31 make -j $(nproc)
32 chroot_exec PATH=${PATH}:/opt/vc/bin
30 if [ "$RELEASE_ARCH" = "arm64" ] ; then
31 cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_BUILD_TYPE=release -DARM64=ON -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_ASM_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} -U_FORTIFY_SOURCE" -DCMAKE_ASM_FLAGS="${CMAKE_ASM_FLAGS} -c" -DVIDEOCORE_BUILD_DIR="${R}"/opt/vc "${R}/tmp/userland"
32 fi
33
34 if [ "$RELEASE_ARCH" = "armel" ] ; then
35 cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_BUILD_TYPE=release -DCMAKE_C_COMPILER=arm-linux-gnueabi-gcc -DCMAKE_CXX_COMPILER=arm-linux-gnueabi-g++ -DCMAKE_ASM_COMPILER=arm-linux-gnueabi-gcc -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} -U_FORTIFY_SOURCE" -DCMAKE_ASM_FLAGS="${CMAKE_ASM_FLAGS} -c" -DCMAKE_SYSTEM_PROCESSOR="arm" -DVIDEOCORE_BUILD_DIR="${R}"/opt/vc "${R}/tmp/userland"
36 fi
37
38 if [ "$RELEASE_ARCH" = "armhf" ] ; then
39 cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_BUILD_TYPE=release -DCMAKE_TOOLCHAIN_FILE="${R}"/tmp/userland/makefiles/cmake/toolchains/arm-linux-gnueabihf.cmake -DVIDEOCORE_BUILD_DIR="${R}"/opt/vc "${R}/tmp/userland"
40 fi
41
42 #build userland
43 make -j "$(nproc)"
44 #include default_installdir in path
45 chroot_exec PATH="${PATH}":/opt/vc/bin
33 46 fi
@@ -1,806 +1,819
1 1 #!/bin/bash
2 2 ########################################################################
3 3 # rpi23-gen-image.sh 2015-2017
4 4 #
5 5 # Advanced Debian "stretch" and "buster" bootstrap script for RPi2/3
6 6 #
7 7 # This program is free software; you can redistribute it and/or
8 8 # modify it under the terms of the GNU General Public License
9 9 # as published by the Free Software Foundation; either version 2
10 10 # of the License, or (at your option) any later version.
11 11 #
12 12 # Copyright (C) 2015 Jan Wagner <mail@jwagner.eu>
13 13 #
14 14 # Big thanks for patches and enhancements by 20+ github contributors!
15 15 ########################################################################
16 16
17 17 # Are we running as root?
18 18 if [ "$(id -u)" -ne "0" ] ; then
19 19 echo "error: this script must be executed with root privileges!"
20 20 exit 1
21 21 fi
22 22
23 23 # Check if ./functions.sh script exists
24 24 if [ ! -r "./functions.sh" ] ; then
25 25 echo "error: './functions.sh' required script not found!"
26 26 exit 1
27 27 fi
28 28
29 29 # Load utility functions
30 30 . ./functions.sh
31 31
32 32 # Load parameters from configuration template file
33 33 if [ -n "$CONFIG_TEMPLATE" ] ; then
34 34 use_template
35 35 fi
36 36
37 37 # Introduce settings
38 38 set -e
39 39 echo -n -e "\n#\n# RPi2/3 Bootstrap Settings\n#\n"
40 40 set -x
41 41
42 42 # Raspberry Pi model configuration
43 43 export RPI_MODEL=${RPI_MODEL:=2}
44 44
45 45 # Debian release
46 46 export RELEASE=${RELEASE:=buster}
47 47
48 48 #Kernel Branch
49 49 export KERNEL_BRANCH=${KERNEL_BRANCH:=""}
50 50
51 51 # URLs
52 52 KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux}
53 53 FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot}
54 54 WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm}
55 55 COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian}
56 56 FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git}
57 57 UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git}
58 58 VIDEOCORE_URL=${VIDEOCORE_URL=https://github.com/raspberrypi/userland}
59 59
60 60 # Build directories
61 61 BASEDIR=${BASEDIR:=$(pwd)/images/${RELEASE}}
62 62 BUILDDIR="${BASEDIR}/build"
63 63
64 64 # Prepare date string for default image file name
65 65 DATE="$(date +%Y-%m-%d)"
66 66 if [ -z "$KERNEL_BRANCH" ] ; then
67 67 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
68 68 else
69 69 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
70 70 fi
71 71
72 72 # Chroot directories
73 73 R="${BUILDDIR}/chroot"
74 74 ETC_DIR="${R}/etc"
75 75 LIB_DIR="${R}/lib"
76 76 BOOT_DIR="${R}/boot/firmware"
77 77 KERNEL_DIR="${R}/usr/src/linux"
78 78 WLAN_FIRMWARE_DIR="${R}/lib/firmware/brcm"
79 79
80 80 # Firmware directory: Blank if download from github
81 81 RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""}
82 82 # General settings
83 83 SET_ARCH=${SET_ARCH:=32}
84 84 HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}}
85 85 PASSWORD=${PASSWORD:=raspberry}
86 86 USER_PASSWORD=${USER_PASSWORD:=raspberry}
87 87 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
88 88 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
89 89 EXPANDROOT=${EXPANDROOT:=true}
90 90
91 91 # Keyboard settings
92 92 XKB_MODEL=${XKB_MODEL:=""}
93 93 XKB_LAYOUT=${XKB_LAYOUT:=""}
94 94 XKB_VARIANT=${XKB_VARIANT:=""}
95 95 XKB_OPTIONS=${XKB_OPTIONS:=""}
96 96
97 97 # Network settings (DHCP)
98 98 ENABLE_DHCP=${ENABLE_DHCP:=true}
99 99
100 100 # Network settings (static)
101 101 NET_ADDRESS=${NET_ADDRESS:=""}
102 102 NET_GATEWAY=${NET_GATEWAY:=""}
103 103 NET_DNS_1=${NET_DNS_1:=""}
104 104 NET_DNS_2=${NET_DNS_2:=""}
105 105 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
106 106 NET_NTP_1=${NET_NTP_1:=""}
107 107 NET_NTP_2=${NET_NTP_2:=""}
108 108
109 109 # APT settings
110 110 APT_PROXY=${APT_PROXY:=""}
111 111 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
112 112
113 113 # Feature settings
114 114 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
115 115 ENABLE_I2C=${ENABLE_I2C:=false}
116 116 ENABLE_SPI=${ENABLE_SPI:=false}
117 117 ENABLE_IPV6=${ENABLE_IPV6:=true}
118 118 ENABLE_SSHD=${ENABLE_SSHD:=true}
119 119 ENABLE_NONFREE=${ENABLE_NONFREE:=false}
120 120 ENABLE_WIRELESS=${ENABLE_WIRELESS:=false}
121 121 ENABLE_SOUND=${ENABLE_SOUND:=true}
122 122 ENABLE_DBUS=${ENABLE_DBUS:=true}
123 123 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
124 124 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
125 125 ENABLE_XORG=${ENABLE_XORG:=false}
126 126 ENABLE_WM=${ENABLE_WM:=""}
127 127 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
128 128 ENABLE_USER=${ENABLE_USER:=true}
129 129 USER_NAME=${USER_NAME:="pi"}
130 130 ENABLE_ROOT=${ENABLE_ROOT:=false}
131 131 ENABLE_QEMU=${ENABLE_QEMU:=false}
132 132 ENABLE_SYSVINIT=${ENABLE_SYSVINIT:=false}
133 133
134 134 # SSH settings
135 135 SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false}
136 136 SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false}
137 137 SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false}
138 138 SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""}
139 139 SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""}
140 140
141 141 # Advanced settings
142 142 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
143 143 ENABLE_REDUCE=${ENABLE_REDUCE:=false}
144 144 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
145 145 UBOOTSRC_DIR=${UBOOTSRC_DIR:=""}
146 146 ENABLE_UBOOTUSB=${ENABLE_UBOOTUSB=false}
147 147 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
148 148 ENABLE_VIDEOCORE=${ENABLE_VIDEOCORE:=true}
149 149 VIDEOCORESRC_DIR=${VIDEOCORESRC_DIR:=""}
150 150 FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""}
151 151 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
152 152 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
153 153 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
154 154 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
155 155 ENABLE_IFNAMES=${ENABLE_IFNAMES:=true}
156 156 DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=}
157 157
158 158 # Kernel compilation settings
159 159 BUILD_KERNEL=${BUILD_KERNEL:=true}
160 160 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
161 161 KERNEL_THREADS=${KERNEL_THREADS:=1}
162 162 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
163 163 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
164 164 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
165 165 KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false}
166 166 KERNEL_CCACHE=${KERNEL_CCACHE:=false}
167 167
168 168 # Kernel compilation from source directory settings
169 169 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
170 170 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
171 171 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
172 172 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
173 173
174 174 # Reduce disk usage settings
175 175 REDUCE_APT=${REDUCE_APT:=true}
176 176 REDUCE_DOC=${REDUCE_DOC:=true}
177 177 REDUCE_MAN=${REDUCE_MAN:=true}
178 178 REDUCE_VIM=${REDUCE_VIM:=false}
179 179 REDUCE_BASH=${REDUCE_BASH:=false}
180 180 REDUCE_HWDB=${REDUCE_HWDB:=true}
181 181 REDUCE_SSHD=${REDUCE_SSHD:=true}
182 182 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
183 183
184 184 # Encrypted filesystem settings
185 185 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
186 186 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
187 187 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
188 188 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
189 189 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
190 190
191 191 # Chroot scripts directory
192 192 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
193 193
194 194 # Packages required in the chroot build environment
195 195 APT_INCLUDES=${APT_INCLUDES:=""}
196 196 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils,locales,keyboard-configuration,console-setup"
197 197
198 #Packages to exclude from chroot build environment
199 APT_EXCLUDES=${APT_EXCLUDES:=""}
200
198 201 # Packages required for bootstrapping
199 202 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo netselect-apt"
200 203 MISSING_PACKAGES=""
201 204
202 205 # Packages installed for c/c++ build environment in chroot (keep empty)
203 206 COMPILER_PACKAGES=""
204 207
208 #If init and systemd-sysv are wanted e.g. halt/reboot/shutdown scripts
209 if [ "$ENABLE_SYSVINIT" = false ] ; then
210 APT_EXCLUDES="--exclude=${APT_EXCLUDES},init,systemd-sysv"
211 fi
212
213 #Check if apt-cacher-ng has its default port open on and set APT_PROXY
214 if [ -n "$(lsof -i :3142)" ] ; then
215 HTTP_PROXY=http://127.0.0.1:3142/
216 fi
217
205 218 #ipinfo=$(curl ipinfo.io | grep country )
206 219 #grep -o '\"[^"]*\"' $ipinfo | tr -d '"'
207 220 #grep -Po '"country":.*?[^\\]",' $(curl ipinfo.io | grep country )
208 221 #sed -i "s,http:,https:,g" "${ETC_DIR}/apt/sources.list"
209 222 #autconfigure best apt server to not spam ftp.debian.org
210 223 #rm files/apt/sources.list
211 224 #netselect-apt does not know buster yet
212 225 if [ "$RELEASE" = "buster" ] ; then
213 226 RLS=testing
214 227 else
215 228 RLS="$RELEASE"
216 229 fi
217 230
218 231 if [ -f "$(pwd)/files/apt/sources.list" ] ; then
219 232 rm "$(pwd)/files/apt/sources.list"
220 233 fi
221 234
222 235 if [ "$ENABLE_NONFREE" = true ] ; then
223 236 netselect-apt --arch "$RELEASE_ARCH" --tests 10 --sources --nonfree --outfile "$(pwd)/files/apt/sources.list" -d "$RLS"
224 237 else
225 238 netselect-apt --arch "$RELEASE_ARCH" --tests 10 --sources --outfile "$(pwd)/files/apt/sources.list" -d "$RLS"
226 239 fi
227 240
228 241 #sed and cut the result string so we can use it as APT_SERVER
229 242 APT_SERVER=$(grep -m 1 http files/apt/sources.list | sed "s|http://| |g" | cut -d ' ' -f 3)
230 243 APT_SERVER=${APT_SERVER::-1}
231 244
232 245 #make script easier and more stable to use with convenient setup switch. Just setup SET_ARCH and RPI_MODEL and your good to go!
233 246 if [ -n "$SET_ARCH" ] ; then
234 247 echo "Setting Architecture specific settings"
235 248 ##################################
236 249 # 64 bit config
237 250 ##################################
238 251 if [ "$SET_ARCH" = 64 ] ; then
239 252 echo "64 bit mode selected - Setting up enviroment"
240 253 # 64 bit depended settings
241 254 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static}
242 255 KERNEL_ARCH=${KERNEL_ARCH:=arm64}
243 256 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"}
244 257
245 258 if [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
246 259 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64"
247 260 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig}
248 261 RELEASE_ARCH=${RELEASE_ARCH:=arm64}
249 262 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img}
250 263 CROSS_COMPILE=${CROSS_COMPILE:=aarch64-linux-gnu-}
251 264 else
252 echo "error: At the moment Raspberry PI 3 and 3B+ are the only Models which support 64bit"
265 echo "error: Only Raspberry PI 3 and 3B+ support 64bit"
253 266 exit 1
254 267 fi
255 268 fi
256 269
257 270 ##################################
258 271 # 32 bit config
259 272 ##################################
260 273 if [ "$SET_ARCH" = 32 ] ; then
261 274 echo "32 bit mode selected - Setting up enviroment"
262 275 #General 32bit configuration
263 276 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
264 277 KERNEL_ARCH=${KERNEL_ARCH:=arm}
265 278 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"}
266 279
267 280 #Raspberry setting grouped by board compability
268 281 if [ "$RPI_MODEL" = 0 ] || [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] ; then
269 282 echo "Setting settings for bcm2835 Raspberry PI boards"
270 283 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armel"
271 284 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig}
272 285 RELEASE_ARCH=${RELEASE_ARCH:=armel}
273 286 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel.img}
274 287 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabi-}
275 288 fi
276 289 if [ "$RPI_MODEL" = 2 ] || [ "$RPI_MODEL" = 3 ] || [ "$RPI_MODEL" = 3P ] ; then
277 290 echo "Setting settings for bcm2837 Raspberry PI boards"
278 291 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
279 292 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
280 293 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
281 294 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
282 295 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
283 296 fi
284 297 fi
285 298 #SET_ARCH not set
286 299 else
287 300 echo "error: Please set '32' or '64' as value for SET_ARCH"
288 301 exit 1
289 302 fi
290 303
291 304 #Device specific configuration
292 305 echo "Select DTB-File"
293 306 case "$RPI_MODEL" in
294 307 0)
295 308 DTB_FILE=${DTB_FILE:=bcm2708-rpi-0-w.dtb}
296 309 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
297 310 ;;
298 311 1)
299 312 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b.dtb}
300 313 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
301 314 ;;
302 315 1P)
303 316 DTB_FILE=${DTB_FILE:=bcm2708-rpi-b-plus.dtb}
304 317 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_defconfig}
305 318 ;;
306 319 2)
307 320 DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
308 321 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
309 322 ;;
310 323 3)
311 324 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
312 325 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
313 326 ;;
314 327 3P)
315 328 DTB_FILE=${DTB_FILE:=bcm2710-rpi-3-b.dtb}
316 329 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_3_defconfig}
317 330 ;;
318 331 *)
319 332 echo "error: Raspberry Pi model $RPI_MODEL is not supported!"
320 333 exit 1
321 334 ;;
322 335 esac
323 336 echo "$DTB_FILE selected"
324 337
325 338 #DEBUG off
326 339 set +x
327 340
328 341 # Check if the internal wireless interface is supported by the RPi model
329 342 if [ "$ENABLE_WIRELESS" = true ] ; then
330 343 if [ "$RPI_MODEL" = 1 ] || [ "$RPI_MODEL" = 1P ] || [ "$RPI_MODEL" = 2 ] ; then
331 344 echo "error: The selected Raspberry Pi model has no internal wireless interface"
332 345 exit 1
333 346 else
334 347 echo "Raspberry Pi $RPI_MODEL has WIFI support"
335 348 fi
336 349 fi
337 350
338 351 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
339 352 if [ -n "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
340 353 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
341 354 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
342 355 exit 1
343 356 fi
344 357 fi
345 358
346 359 if [ "$ENABLE_VIDEOCORE" = true ] ; then
347 360 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cmake"
348 361 fi
349 362
350 363 # Add libncurses5 to enable kernel menuconfig
351 364 if [ "$KERNEL_MENUCONFIG" = true ] ; then
352 365 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses-dev"
353 366 fi
354 367
355 368 # Add ccache compiler cache for (faster) kernel cross (re)compilation
356 369 if [ "$KERNEL_CCACHE" = true ] ; then
357 370 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache"
358 371 fi
359 372
360 373 # Add cryptsetup package to enable filesystem encryption
361 374 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
362 375 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
363 376 APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup"
364 377
365 378 if [ -z "$CRYPTFS_PASSWORD" ] ; then
366 379 echo "error: no password defined (CRYPTFS_PASSWORD)!"
367 380 exit 1
368 381 fi
369 382 ENABLE_INITRAMFS=true
370 383 fi
371 384
372 385 # Add initramfs generation tools
373 386 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
374 387 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
375 388 fi
376 389
377 390 # Add device-tree-compiler required for building the U-Boot bootloader
378 391 if [ "$ENABLE_UBOOT" = true ] ; then
379 392 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler,bison,flex,bc"
380 393 else
381 394 if [ "$ENABLE_UBOOTUSB" = true ] ; then
382 395 echo "error: Enabling UBOOTUSB requires u-boot to be enabled"
383 396 exit 1
384 397 fi
385 398 fi
386 399
387 400 # Check if root SSH (v2) public key file exists
388 401 if [ -n "$SSH_ROOT_PUB_KEY" ] ; then
389 402 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
390 403 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
391 404 exit 1
392 405 fi
393 406 fi
394 407
395 408 # Check if $USER_NAME SSH (v2) public key file exists
396 409 if [ -n "$SSH_USER_PUB_KEY" ] ; then
397 410 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
398 411 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
399 412 exit 1
400 413 fi
401 414 fi
402 415
403 416 # Check if all required packages are installed on the build system
404 417 for package in $REQUIRED_PACKAGES ; do
405 418 if [ "$(dpkg-query -W -f='${Status}' $package)" != "install ok installed" ] ; then
406 419 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
407 420 fi
408 421 done
409 422
410 423 # If there are missing packages ask confirmation for install, or exit
411 424 if [ -n "$MISSING_PACKAGES" ] ; then
412 425 echo "the following packages needed by this script are not installed:"
413 426 echo "$MISSING_PACKAGES"
414 427
415 428 printf "\ndo you want to install the missing packages right now? [y/n] "
416 429 read -r confirm
417 430 [ "$confirm" != "y" ] && exit 1
418 431
419 432 # Make sure all missing required packages are installed
420 433 apt-get -qq -y install "${MISSING_PACKAGES}"
421 434 fi
422 435
423 436 # Check if ./bootstrap.d directory exists
424 437 if [ ! -d "./bootstrap.d/" ] ; then
425 438 echo "error: './bootstrap.d' required directory not found!"
426 439 exit 1
427 440 fi
428 441
429 442 # Check if ./files directory exists
430 443 if [ ! -d "./files/" ] ; then
431 444 echo "error: './files' required directory not found!"
432 445 exit 1
433 446 fi
434 447
435 448 # Check if specified KERNELSRC_DIR directory exists
436 449 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
437 450 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
438 451 exit 1
439 452 fi
440 453
441 454 # Check if specified UBOOTSRC_DIR directory exists
442 455 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
443 456 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
444 457 exit 1
445 458 fi
446 459
447 460 # Check if specified VIDEOCORESRC_DIR directory exists
448 461 if [ -n "$VIDEOCORESRC_DIR" ] && [ ! -d "$VIDEOCORESRC_DIR" ] ; then
449 462 echo "error: '${VIDEOCORESRC_DIR}' specified directory not found (VIDEOCORESRC_DIR)!"
450 463 exit 1
451 464 fi
452 465
453 466 # Check if specified FBTURBOSRC_DIR directory exists
454 467 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
455 468 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
456 469 exit 1
457 470 fi
458 471
459 472 # Check if specified CHROOT_SCRIPTS directory exists
460 473 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
461 474 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
462 475 exit 1
463 476 fi
464 477
465 478 # Check if specified device mapping already exists (will be used by cryptsetup)
466 479 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
467 480 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
468 481 exit 1
469 482 fi
470 483
471 484 # Don't clobber an old build
472 485 if [ -e "$BUILDDIR" ] ; then
473 486 echo "error: directory ${BUILDDIR} already exists, not proceeding"
474 487 exit 1
475 488 fi
476 489
477 490 # Setup chroot directory
478 491 mkdir -p "${R}"
479 492
480 493 # Check if build directory has enough of free disk space >512MB
481 494 if [ "$(df --output=avail "${BUILDDIR}" | sed "1d")" -le "524288" ] ; then
482 495 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
483 496 exit 1
484 497 fi
485 498
486 499 set -x
487 500
488 501 # Call "cleanup" function on various signals and errors
489 502 trap cleanup 0 1 2 3 6
490 503
491 504 # Add required packages for the minbase installation
492 505 if [ "$ENABLE_MINBASE" = true ] ; then
493 506 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
494 507 fi
495 508
496 509 # Add parted package, required to get partprobe utility
497 510 if [ "$EXPANDROOT" = true ] ; then
498 511 APT_INCLUDES="${APT_INCLUDES},parted"
499 512 fi
500 513
501 514 # Add dbus package, recommended if using systemd
502 515 if [ "$ENABLE_DBUS" = true ] ; then
503 516 APT_INCLUDES="${APT_INCLUDES},dbus"
504 517 fi
505 518
506 519 # Add iptables IPv4/IPv6 package
507 520 if [ "$ENABLE_IPTABLES" = true ] ; then
508 521 APT_INCLUDES="${APT_INCLUDES},iptables,iptables-persistent"
509 522 fi
510 523
511 524 # Add openssh server package
512 525 if [ "$ENABLE_SSHD" = true ] ; then
513 526 APT_INCLUDES="${APT_INCLUDES},openssh-server"
514 527 fi
515 528
516 529 # Add alsa-utils package
517 530 if [ "$ENABLE_SOUND" = true ] ; then
518 531 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
519 532 fi
520 533
521 534 # Add rng-tools package
522 535 if [ "$ENABLE_HWRANDOM" = true ] ; then
523 536 APT_INCLUDES="${APT_INCLUDES},rng-tools"
524 537 fi
525 538
526 539 # Add fbturbo video driver
527 540 if [ "$ENABLE_FBTURBO" = true ] ; then
528 541 # Enable xorg package dependencies
529 542 ENABLE_XORG=true
530 543 fi
531 544
532 545 # Add user defined window manager package
533 546 if [ -n "$ENABLE_WM" ] ; then
534 547 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
535 548
536 549 # Enable xorg package dependencies
537 550 ENABLE_XORG=true
538 551 fi
539 552
540 553 # Add xorg package
541 554 if [ "$ENABLE_XORG" = true ] ; then
542 555 APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11"
543 556 fi
544 557
545 558 # Replace selected packages with smaller clones
546 559 if [ "$ENABLE_REDUCE" = true ] ; then
547 560 # Add levee package instead of vim-tiny
548 561 if [ "$REDUCE_VIM" = true ] ; then
549 562 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
550 563 fi
551 564
552 565 # Add dropbear package instead of openssh-server
553 566 if [ "$REDUCE_SSHD" = true ] ; then
554 567 APT_INCLUDES="$(echo "${APT_INCLUDES}" | sed "s/openssh-server/dropbear/")"
555 568 fi
556 569 fi
557 570
558 571 # Configure kernel sources if no KERNELSRC_DIR
559 572 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
560 573 KERNELSRC_CONFIG=true
561 574 fi
562 575
563 576 # Configure reduced kernel
564 577 if [ "$KERNEL_REDUCE" = true ] ; then
565 578 KERNELSRC_CONFIG=false
566 579 fi
567 580
568 581 # Configure qemu compatible kernel
569 582 if [ "$ENABLE_QEMU" = true ] ; then
570 583 DTB_FILE=vexpress-v2p-ca15_a7.dtb
571 584 UBOOT_CONFIG=vexpress_ca15_tc2_defconfig
572 585 KERNEL_DEFCONFIG="vexpress_defconfig"
573 586 if [ "$KERNEL_MENUCONFIG" = false ] ; then
574 587 KERNEL_OLDDEFCONFIG=true
575 588 fi
576 589 fi
577 590
578 591 # Execute bootstrap scripts
579 592 for SCRIPT in bootstrap.d/*.sh; do
580 593 head -n 3 "$SCRIPT"
581 594 . "$SCRIPT"
582 595 done
583 596
584 597 ## Execute custom bootstrap scripts
585 598 if [ -d "custom.d" ] ; then
586 599 for SCRIPT in custom.d/*.sh; do
587 600 . "$SCRIPT"
588 601 done
589 602 fi
590 603
591 604 # Execute custom scripts inside the chroot
592 605 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
593 606 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
594 607 chroot_exec /bin/bash -x <<'EOF'
595 608 for SCRIPT in /chroot_scripts/* ; do
596 609 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
597 610 $SCRIPT
598 611 fi
599 612 done
600 613 EOF
601 614 rm -rf "${R}/chroot_scripts"
602 615 fi
603 616
604 617 # Remove c/c++ build environment from the chroot
605 618 chroot_remove_cc
606 619
607 620 # Generate required machine-id
608 621 MACHINE_ID=$(dbus-uuidgen)
609 622 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
610 623 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
611 624
612 625 # APT Cleanup
613 626 chroot_exec apt-get -y clean
614 627 chroot_exec apt-get -y autoclean
615 628 chroot_exec apt-get -y autoremove
616 629
617 630 # Unmount mounted filesystems
618 631 umount -l "${R}/proc"
619 632 umount -l "${R}/sys"
620 633
621 634 # Clean up directories
622 635 rm -rf "${R}/run/*"
623 636 rm -rf "${R}/tmp/*"
624 637
625 638 # Clean up files
626 639 rm -f "${ETC_DIR}/ssh/ssh_host_*"
627 640 rm -f "${ETC_DIR}/dropbear/dropbear_*"
628 641 rm -f "${ETC_DIR}/apt/sources.list.save"
629 642 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
630 643 rm -f "${ETC_DIR}/*-"
631 644 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
632 645 rm -f "${ETC_DIR}/resolv.conf"
633 646 rm -f "${R}/root/.bash_history"
634 647 rm -f "${R}/var/lib/urandom/random-seed"
635 648 rm -f "${R}/initrd.img"
636 649 rm -f "${R}/vmlinuz"
637 650 rm -f "${R}${QEMU_BINARY}"
638 651
639 652 if [ "$ENABLE_QEMU" = true ] ; then
640 653 # Setup QEMU directory
641 654 mkdir "${BASEDIR}/qemu"
642 655
643 656 # Copy kernel image to QEMU directory
644 657 install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}"
645 658
646 659 # Copy kernel config to QEMU directory
647 660 install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}"
648 661
649 662 # Copy kernel dtbs to QEMU directory
650 663 for dtb in "${BOOT_DIR}/"*.dtb ; do
651 664 if [ -f "${dtb}" ] ; then
652 665 install_readonly "${dtb}" "${BASEDIR}/qemu/"
653 666 fi
654 667 done
655 668
656 669 # Copy kernel overlays to QEMU directory
657 670 if [ -d "${BOOT_DIR}/overlays" ] ; then
658 671 # Setup overlays dtbs directory
659 672 mkdir "${BASEDIR}/qemu/overlays"
660 673
661 674 for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do
662 675 if [ -f "${dtb}" ] ; then
663 676 install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/"
664 677 fi
665 678 done
666 679 fi
667 680
668 681 # Copy u-boot files to QEMU directory
669 682 if [ "$ENABLE_UBOOT" = true ] ; then
670 683 if [ -f "${BOOT_DIR}/u-boot.bin" ] ; then
671 684 install_readonly "${BOOT_DIR}/u-boot.bin" "${BASEDIR}/qemu/u-boot.bin"
672 685 fi
673 686 if [ -f "${BOOT_DIR}/uboot.mkimage" ] ; then
674 687 install_readonly "${BOOT_DIR}/uboot.mkimage" "${BASEDIR}/qemu/uboot.mkimage"
675 688 fi
676 689 if [ -f "${BOOT_DIR}/boot.scr" ] ; then
677 690 install_readonly "${BOOT_DIR}/boot.scr" "${BASEDIR}/qemu/boot.scr"
678 691 fi
679 692 fi
680 693
681 694 # Copy initramfs to QEMU directory
682 695 if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then
683 696 install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}"
684 697 fi
685 698 fi
686 699
687 700 # Calculate size of the chroot directory in KB
688 701 CHROOT_SIZE=$(expr "$(du -s "${R}" | awk '{ print $1 }')")
689 702
690 703 # Calculate the amount of needed 512 Byte sectors
691 704 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
692 705 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
693 706 ROOT_OFFSET=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}")
694 707
695 708 # The root partition is EXT4
696 709 # This means more space than the actual used space of the chroot is used.
697 710 # As overhead for journaling and reserved blocks 35% are added.
698 711 ROOT_SECTORS=$(expr "$(expr "${CHROOT_SIZE}" + "${CHROOT_SIZE}" \/ 100 \* 35)" \* 1024 \/ 512)
699 712
700 713 # Calculate required image size in 512 Byte sectors
701 714 IMAGE_SECTORS=$(expr "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}")
702 715
703 716 # Prepare image file
704 717 if [ "$ENABLE_SPLITFS" = true ] ; then
705 718 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count="${TABLE_SECTORS}"
706 719 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek="${FRMW_SECTORS}"
707 720 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count="${TABLE_SECTORS}"
708 721 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek="${ROOT_SECTORS}"
709 722
710 723 # Write firmware/boot partition tables
711 724 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
712 725 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
713 726 EOM
714 727
715 728 # Write root partition table
716 729 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
717 730 ${TABLE_SECTORS},${ROOT_SECTORS},83
718 731 EOM
719 732
720 733 # Setup temporary loop devices
721 734 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME"-frmw.img)"
722 735 ROOT_LOOP="$(losetup -o 1M -f --show "$IMAGE_NAME"-root.img)"
723 736 else # ENABLE_SPLITFS=false
724 737 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count="${TABLE_SECTORS}"
725 738 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek="${IMAGE_SECTORS}"
726 739
727 740 # Write partition table
728 741 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
729 742 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
730 743 ${ROOT_OFFSET},${ROOT_SECTORS},83
731 744 EOM
732 745
733 746 # Setup temporary loop devices
734 747 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show "$IMAGE_NAME".img)"
735 748 ROOT_LOOP="$(losetup -o 65M -f --show "$IMAGE_NAME".img)"
736 749 fi
737 750
738 751 if [ "$ENABLE_CRYPTFS" = true ] ; then
739 752 # Create dummy ext4 fs
740 753 mkfs.ext4 "$ROOT_LOOP"
741 754
742 755 # Setup password keyfile
743 756 touch .password
744 757 chmod 600 .password
745 758 echo -n ${CRYPTFS_PASSWORD} > .password
746 759
747 760 # Initialize encrypted partition
748 761 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
749 762
750 763 # Open encrypted partition and setup mapping
751 764 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
752 765
753 766 # Secure delete password keyfile
754 767 shred -zu .password
755 768
756 769 # Update temporary loop device
757 770 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
758 771
759 772 # Wipe encrypted partition (encryption cipher is used for randomness)
760 773 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count="$(blockdev --getsz "${ROOT_LOOP}")"
761 774 fi
762 775
763 776 # Build filesystems
764 777 mkfs.vfat "$FRMW_LOOP"
765 778 mkfs.ext4 "$ROOT_LOOP"
766 779
767 780 # Mount the temporary loop devices
768 781 mkdir -p "$BUILDDIR/mount"
769 782 mount "$ROOT_LOOP" "$BUILDDIR/mount"
770 783
771 784 mkdir -p "$BUILDDIR/mount/boot/firmware"
772 785 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
773 786
774 787 # Copy all files from the chroot to the loop device mount point directory
775 788 rsync -a "${R}/" "$BUILDDIR/mount/"
776 789
777 790 # Unmount all temporary loop devices and mount points
778 791 cleanup
779 792
780 793 # Create block map file(s) of image(s)
781 794 if [ "$ENABLE_SPLITFS" = true ] ; then
782 795 # Create block map files for "bmaptool"
783 796 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
784 797 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
785 798
786 799 # Image was successfully created
787 800 echo "$IMAGE_NAME-frmw.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
788 801 echo "$IMAGE_NAME-root.img ($(expr \( "${TABLE_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
789 802 else
790 803 # Create block map file for "bmaptool"
791 804 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
792 805
793 806 # Image was successfully created
794 807 echo "$IMAGE_NAME.img ($(expr \( "${TABLE_SECTORS}" + "${FRMW_SECTORS}" + "${ROOT_SECTORS}" \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
795 808
796 809 # Create qemu qcow2 image
797 810 if [ "$ENABLE_QEMU" = true ] ; then
798 811 QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
799 812 QEMU_SIZE=16G
800 813
801 814 qemu-img convert -f raw -O qcow2 "$IMAGE_NAME".img "$QEMU_IMAGE".qcow2
802 815 qemu-img resize "$QEMU_IMAGE".qcow2 $QEMU_SIZE
803 816
804 817 echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created"
805 818 fi
806 819 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant