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