##// END OF EJS Templates
Added: QEMU initramfs output
drtyhlpr -
r260:bd495e424ce6
parent child
Show More
@@ -1,741 +1,746
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 #bcm2708-rpi-0-w.dtb (Used for Pi 0 and PI 0W)
46 46 RPI0_DTB_FILE=${RPI0_DTB_FILE:=bcm2708-rpi-0-w.dtb}
47 47 RPI0_UBOOT_CONFIG=${RPI0_UBOOT_CONFIG:=rpi_defconfig}
48 48 #bcm2708-rpi-b.dtb (Used for Pi 1 model A and B)
49 49 RPI1_DTB_FILE=${RPI1_DTB_FILE:=bcm2708-rpi-b.dtb}
50 50 RPI1_UBOOT_CONFIG=${RPI1_UBOOT_CONFIG:=rpi_defconfig}
51 51 #bcm2708-rpi-b-plus.dtb (Used for Pi 1 model B+ and A+)
52 52 RPI1P_DTB_FILE=${RPI1P_DTB_FILE:=bcm2708-rpi-b-plus.dtb}
53 53 RPI1P_UBOOT_CONFIG=${RPI1P_UBOOT_CONFIG:=rpi_defconfig}
54 54 #bcm2709-rpi-2-b.dtb (Used for Pi 2 model B)
55 55 RPI2_DTB_FILE=${RPI2_DTB_FILE:=bcm2709-rpi-2-b.dtb}
56 56 RPI2_UBOOT_CONFIG=${RPI2_UBOOT_CONFIG:=rpi_2_defconfig}
57 57 #bcm2710-rpi-3-b.dtb (Used for Pi 3 model B)
58 58 RPI3_DTB_FILE=${RPI3_DTB_FILE:=bcm2710-rpi-3-b.dtb}
59 59 RPI3_UBOOT_CONFIG=${RPI3_UBOOT_CONFIG:=rpi_3_32b_defconfig}
60 60 #bcm2710-rpi-3-b-plus.dtb (Used for Pi 3 model B+)
61 61 RPI3P_DTB_FILE=${RPI3P_DTB_FILE:=bcm2710-rpi-3-b-plus.dtb}
62 62 RPI3P_UBOOT_CONFIG=${RPI3P_UBOOT_CONFIG:=rpi_3_32b_defconfig}
63 63
64 64 # Debian release
65 65 RELEASE=${RELEASE:=jessie}
66 66 KERNEL_ARCH=${KERNEL_ARCH:=arm}
67 67 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
68 68 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
69 69 COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2}
70 70 if [ "$KERNEL_ARCH" = "arm64" ] ; then
71 71 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi3_defconfig}
72 72 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel8.img}
73 73 fi
74 74
75 75 if [ "$RPI_MODEL" = 0 || "$RPI_MODEL" = 1 || "$RPI_MODEL" = 1P ] ; then
76 76 #RASPBERRY PI 1, PI ZERO, PI ZERO W, AND COMPUTE MODULE DEFAULT Kernel BUILD CONFIGURATION
77 77 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcmrpi_defconfig}
78 78 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
79 79 else
80 80 #RASPBERRY PI 2, PI 3, PI 3+, AND COMPUTE MODULE 3 DEFAULT Kernel BUILD CONFIGURATION
81 81 #https://www.raspberrypi.org/documentation/linux/kernel/building.md
82 82 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
83 83 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
84 84 fi
85 85
86 86 if [ "$RELEASE_ARCH" = "arm64" ] ; then
87 87 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-aarch64-static}
88 88 else
89 89 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
90 90 fi
91 91 KERNEL_BRANCH=${KERNEL_BRANCH:=""}
92 92
93 93 # URLs
94 94 KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux}
95 95 FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot}
96 96 WLAN_FIRMWARE_URL=${WLAN_FIRMWARE_URL:=https://github.com/RPi-Distro/firmware-nonfree/raw/master/brcm}
97 97 COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian}
98 98 FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git}
99 99 UBOOT_URL=${UBOOT_URL:=https://git.denx.de/u-boot.git}
100 100
101 101 # Build directories
102 102 BASEDIR=${BASEDIR:=$(pwd)/images/${RELEASE}}
103 103 BUILDDIR="${BASEDIR}/build"
104 104
105 105 # Prepare date string for default image file name
106 106 DATE="$(date +%Y-%m-%d)"
107 107 if [ -z "$KERNEL_BRANCH" ] ; then
108 108 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
109 109 else
110 110 IMAGE_NAME=${IMAGE_NAME:=${BASEDIR}/${DATE}-${KERNEL_ARCH}-${KERNEL_BRANCH}-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
111 111 fi
112 112
113 113 # Chroot directories
114 114 R="${BUILDDIR}/chroot"
115 115 ETC_DIR="${R}/etc"
116 116 LIB_DIR="${R}/lib"
117 117 BOOT_DIR="${R}/boot/firmware"
118 118 KERNEL_DIR="${R}/usr/src/linux"
119 119 WLAN_FIRMWARE_DIR="${R}/lib/firmware/brcm"
120 120
121 121 # Firmware directory: Blank if download from github
122 122 RPI_FIRMWARE_DIR=${RPI_FIRMWARE_DIR:=""}
123 123
124 124 # General settings
125 125 HOSTNAME=${HOSTNAME:=rpi${RPI_MODEL}-${RELEASE}}
126 126 PASSWORD=${PASSWORD:=raspberry}
127 127 USER_PASSWORD=${USER_PASSWORD:=raspberry}
128 128 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
129 129 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
130 130 EXPANDROOT=${EXPANDROOT:=true}
131 131
132 132 # Keyboard settings
133 133 XKB_MODEL=${XKB_MODEL:=""}
134 134 XKB_LAYOUT=${XKB_LAYOUT:=""}
135 135 XKB_VARIANT=${XKB_VARIANT:=""}
136 136 XKB_OPTIONS=${XKB_OPTIONS:=""}
137 137
138 138 # Network settings (DHCP)
139 139 ENABLE_DHCP=${ENABLE_DHCP:=true}
140 140
141 141 # Network settings (static)
142 142 NET_ADDRESS=${NET_ADDRESS:=""}
143 143 NET_GATEWAY=${NET_GATEWAY:=""}
144 144 NET_DNS_1=${NET_DNS_1:=""}
145 145 NET_DNS_2=${NET_DNS_2:=""}
146 146 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
147 147 NET_NTP_1=${NET_NTP_1:=""}
148 148 NET_NTP_2=${NET_NTP_2:=""}
149 149
150 150 # APT settings
151 151 APT_PROXY=${APT_PROXY:=""}
152 152 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
153 153
154 154 # Feature settings
155 155 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
156 156 ENABLE_I2C=${ENABLE_I2C:=false}
157 157 ENABLE_SPI=${ENABLE_SPI:=false}
158 158 ENABLE_IPV6=${ENABLE_IPV6:=true}
159 159 ENABLE_SSHD=${ENABLE_SSHD:=true}
160 160 ENABLE_NONFREE=${ENABLE_NONFREE:=false}
161 161 ENABLE_WIRELESS=${ENABLE_WIRELESS:=false}
162 162 ENABLE_SOUND=${ENABLE_SOUND:=true}
163 163 ENABLE_DBUS=${ENABLE_DBUS:=true}
164 164 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
165 165 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
166 166 ENABLE_XORG=${ENABLE_XORG:=false}
167 167 ENABLE_WM=${ENABLE_WM:=""}
168 168 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
169 169 ENABLE_USER=${ENABLE_USER:=true}
170 170 USER_NAME=${USER_NAME:="pi"}
171 171 ENABLE_ROOT=${ENABLE_ROOT:=false}
172 172 ENABLE_QEMU=${ENABLE_QEMU:=false}
173 173
174 174 # SSH settings
175 175 SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false}
176 176 SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false}
177 177 SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false}
178 178 SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""}
179 179 SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""}
180 180
181 181 # Advanced settings
182 182 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
183 183 ENABLE_REDUCE=${ENABLE_REDUCE:=false}
184 184 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
185 185 UBOOTSRC_DIR=${UBOOTSRC_DIR:=""}
186 186 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
187 187 FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""}
188 188 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
189 189 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
190 190 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
191 191 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
192 192 ENABLE_IFNAMES=${ENABLE_IFNAMES:=true}
193 193 DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=}
194 194
195 195 # Kernel compilation settings
196 196 BUILD_KERNEL=${BUILD_KERNEL:=false}
197 197 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
198 198 KERNEL_THREADS=${KERNEL_THREADS:=1}
199 199 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
200 200 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
201 201 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
202 202 KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false}
203 203 KERNEL_CCACHE=${KERNEL_CCACHE:=false}
204 204
205 205 if [ "$KERNEL_ARCH" = "arm64" ] ; then
206 206 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"}
207 207 else
208 208 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"}
209 209 fi
210 210
211 211 # Kernel compilation from source directory settings
212 212 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
213 213 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
214 214 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
215 215 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
216 216
217 217 # Reduce disk usage settings
218 218 REDUCE_APT=${REDUCE_APT:=true}
219 219 REDUCE_DOC=${REDUCE_DOC:=true}
220 220 REDUCE_MAN=${REDUCE_MAN:=true}
221 221 REDUCE_VIM=${REDUCE_VIM:=false}
222 222 REDUCE_BASH=${REDUCE_BASH:=false}
223 223 REDUCE_HWDB=${REDUCE_HWDB:=true}
224 224 REDUCE_SSHD=${REDUCE_SSHD:=true}
225 225 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
226 226
227 227 # Encrypted filesystem settings
228 228 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
229 229 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
230 230 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
231 231 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
232 232 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
233 233
234 234 # Chroot scripts directory
235 235 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
236 236
237 237 # Packages required in the chroot build environment
238 238 APT_INCLUDES=${APT_INCLUDES:=""}
239 239 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils"
240 240
241 241 # Packages required for bootstrapping
242 242 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo"
243 243 MISSING_PACKAGES=""
244 244
245 245 # Packages installed for c/c++ build environment in chroot (keep empty)
246 246 COMPILER_PACKAGES=""
247 247
248 248 set +x
249 249
250 250 # Set Raspberry Pi model specific configuration
251 251 if [ "$RPI_MODEL" = 0 ] ; then
252 252 DTB_FILE=${RPI2_DTB_FILE}
253 253 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
254 254 elif [ "$RPI_MODEL" = 1 ] ; then
255 255 DTB_FILE=${RPI2_DTB_FILE}
256 256 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
257 257 elif [ "$RPI_MODEL" = 1P ] ; then
258 258 DTB_FILE=${RPI2_DTB_FILE}
259 259 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
260 260 elif [ "$RPI_MODEL" = 2 ] ; then
261 261 DTB_FILE=${RPI2_DTB_FILE}
262 262 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
263 263 elif [ "$RPI_MODEL" = 3 ] ; then
264 264 DTB_FILE=${RPI3_DTB_FILE}
265 265 UBOOT_CONFIG=${RPI3_UBOOT_CONFIG}
266 266 BUILD_KERNEL=true
267 267 elif [ "$RPI_MODEL" = 3P ] ; then
268 268 DTB_FILE=${RPI3P_DTB_FILE}
269 269 UBOOT_CONFIG=${RPI3P_UBOOT_CONFIG}
270 270 BUILD_KERNEL=true
271 271 else
272 272 echo "error: Raspberry Pi model ${RPI_MODEL} is not supported!"
273 273 exit 1
274 274 fi
275 275
276 276 # Check if the internal wireless interface is supported by the RPi model
277 277 if [ "$ENABLE_WIRELESS" = true ] && [ "$RPI_MODEL" = 2 ]; then
278 278 echo "error: The selected Raspberry Pi model has no internal wireless interface"
279 279 exit 1
280 280 fi
281 281
282 282 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
283 283 if [ ! -z "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
284 284 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
285 285 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
286 286 exit 1
287 287 fi
288 288 fi
289 289
290 290 # Build RPi2/3 Linux kernel if required by Debian release
291 291 if [ "$RELEASE" = "stretch" ] || [ "$RELEASE" = "buster" ] ; then
292 292 BUILD_KERNEL=true
293 293 fi
294 294
295 295 # Add packages required for kernel cross compilation
296 296 if [ "$BUILD_KERNEL" = true ] ; then
297 297 if [ "$KERNEL_ARCH" = "arm" ] ; then
298 298 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
299 299 else
300 300 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64"
301 301 fi
302 302 fi
303 303
304 304 # Add libncurses5 to enable kernel menuconfig
305 305 if [ "$KERNEL_MENUCONFIG" = true ] ; then
306 306 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
307 307 fi
308 308
309 309 # Add ccache compiler cache for (faster) kernel cross (re)compilation
310 310 if [ "$KERNEL_CCACHE" = true ] ; then
311 311 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache"
312 312 fi
313 313
314 314 # Add cryptsetup package to enable filesystem encryption
315 315 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
316 316 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
317 317 APT_INCLUDES="${APT_INCLUDES},cryptsetup,busybox,console-setup"
318 318
319 319 if [ -z "$CRYPTFS_PASSWORD" ] ; then
320 320 echo "error: no password defined (CRYPTFS_PASSWORD)!"
321 321 exit 1
322 322 fi
323 323 ENABLE_INITRAMFS=true
324 324 fi
325 325
326 326 # Add initramfs generation tools
327 327 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
328 328 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
329 329 fi
330 330
331 331 # Add device-tree-compiler required for building the U-Boot bootloader
332 332 if [ "$ENABLE_UBOOT" = true ] ; then
333 333 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler"
334 334 fi
335 335
336 336 # Check if root SSH (v2) public key file exists
337 337 if [ ! -z "$SSH_ROOT_PUB_KEY" ] ; then
338 338 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
339 339 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
340 340 exit 1
341 341 fi
342 342 fi
343 343
344 344 # Check if $USER_NAME SSH (v2) public key file exists
345 345 if [ ! -z "$SSH_USER_PUB_KEY" ] ; then
346 346 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
347 347 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
348 348 exit 1
349 349 fi
350 350 fi
351 351
352 352 # Check if all required packages are installed on the build system
353 353 for package in $REQUIRED_PACKAGES ; do
354 354 if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then
355 355 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
356 356 fi
357 357 done
358 358
359 359 # If there are missing packages ask confirmation for install, or exit
360 360 if [ -n "$MISSING_PACKAGES" ] ; then
361 361 echo "the following packages needed by this script are not installed:"
362 362 echo "$MISSING_PACKAGES"
363 363
364 364 echo -n "\ndo you want to install the missing packages right now? [y/n] "
365 365 read confirm
366 366 [ "$confirm" != "y" ] && exit 1
367 367
368 368 # Make sure all missing required packages are installed
369 369 apt-get -qq -y install ${MISSING_PACKAGES}
370 370 fi
371 371
372 372 # Check if ./bootstrap.d directory exists
373 373 if [ ! -d "./bootstrap.d/" ] ; then
374 374 echo "error: './bootstrap.d' required directory not found!"
375 375 exit 1
376 376 fi
377 377
378 378 # Check if ./files directory exists
379 379 if [ ! -d "./files/" ] ; then
380 380 echo "error: './files' required directory not found!"
381 381 exit 1
382 382 fi
383 383
384 384 # Check if specified KERNELSRC_DIR directory exists
385 385 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
386 386 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
387 387 exit 1
388 388 fi
389 389
390 390 # Check if specified UBOOTSRC_DIR directory exists
391 391 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
392 392 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
393 393 exit 1
394 394 fi
395 395
396 396 # Check if specified FBTURBOSRC_DIR directory exists
397 397 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
398 398 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
399 399 exit 1
400 400 fi
401 401
402 402 # Check if specified CHROOT_SCRIPTS directory exists
403 403 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
404 404 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
405 405 exit 1
406 406 fi
407 407
408 408 # Check if specified device mapping already exists (will be used by cryptsetup)
409 409 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
410 410 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
411 411 exit 1
412 412 fi
413 413
414 414 # Don't clobber an old build
415 415 if [ -e "$BUILDDIR" ] ; then
416 416 echo "error: directory ${BUILDDIR} already exists, not proceeding"
417 417 exit 1
418 418 fi
419 419
420 420 # Setup chroot directory
421 421 mkdir -p "${R}"
422 422
423 423 # Check if build directory has enough of free disk space >512MB
424 424 if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then
425 425 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
426 426 exit 1
427 427 fi
428 428
429 429 set -x
430 430
431 431 # Call "cleanup" function on various signals and errors
432 432 trap cleanup 0 1 2 3 6
433 433
434 434 # Add required packages for the minbase installation
435 435 if [ "$ENABLE_MINBASE" = true ] ; then
436 436 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
437 437 fi
438 438
439 439 # Add required locales packages
440 440 if [ "$DEFLOCAL" != "en_US.UTF-8" ] ; then
441 441 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
442 442 fi
443 443
444 444 # Add parted package, required to get partprobe utility
445 445 if [ "$EXPANDROOT" = true ] ; then
446 446 APT_INCLUDES="${APT_INCLUDES},parted"
447 447 fi
448 448
449 449 # Add dbus package, recommended if using systemd
450 450 if [ "$ENABLE_DBUS" = true ] ; then
451 451 APT_INCLUDES="${APT_INCLUDES},dbus"
452 452 fi
453 453
454 454 # Add iptables IPv4/IPv6 package
455 455 if [ "$ENABLE_IPTABLES" = true ] ; then
456 456 APT_INCLUDES="${APT_INCLUDES},iptables"
457 457 fi
458 458
459 459 # Add openssh server package
460 460 if [ "$ENABLE_SSHD" = true ] ; then
461 461 APT_INCLUDES="${APT_INCLUDES},openssh-server"
462 462 fi
463 463
464 464 # Add alsa-utils package
465 465 if [ "$ENABLE_SOUND" = true ] ; then
466 466 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
467 467 fi
468 468
469 469 # Add rng-tools package
470 470 if [ "$ENABLE_HWRANDOM" = true ] ; then
471 471 APT_INCLUDES="${APT_INCLUDES},rng-tools"
472 472 fi
473 473
474 474 # Add fbturbo video driver
475 475 if [ "$ENABLE_FBTURBO" = true ] ; then
476 476 # Enable xorg package dependencies
477 477 ENABLE_XORG=true
478 478 fi
479 479
480 480 # Add user defined window manager package
481 481 if [ -n "$ENABLE_WM" ] ; then
482 482 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
483 483
484 484 # Enable xorg package dependencies
485 485 ENABLE_XORG=true
486 486 fi
487 487
488 488 # Add xorg package
489 489 if [ "$ENABLE_XORG" = true ] ; then
490 490 APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11"
491 491 fi
492 492
493 493 # Replace selected packages with smaller clones
494 494 if [ "$ENABLE_REDUCE" = true ] ; then
495 495 # Add levee package instead of vim-tiny
496 496 if [ "$REDUCE_VIM" = true ] ; then
497 497 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
498 498 fi
499 499
500 500 # Add dropbear package instead of openssh-server
501 501 if [ "$REDUCE_SSHD" = true ] ; then
502 502 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")"
503 503 fi
504 504 fi
505 505
506 506 if [ "$RELEASE" != "jessie" ] ; then
507 507 APT_INCLUDES="${APT_INCLUDES},libnss-systemd"
508 508 fi
509 509
510 510 # Configure kernel sources if no KERNELSRC_DIR
511 511 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
512 512 KERNELSRC_CONFIG=true
513 513 fi
514 514
515 515 # Configure reduced kernel
516 516 if [ "$KERNEL_REDUCE" = true ] ; then
517 517 KERNELSRC_CONFIG=false
518 518 fi
519 519
520 520 # Configure qemu compatible kernel
521 521 if [ "$ENABLE_QEMU" = true ] ; then
522 522 KERNEL_DEFCONFIG="vexpress_defconfig"
523 523 KERNEL_OLDDEFCONFIG=true
524 524 fi
525 525
526 526 # Execute bootstrap scripts
527 527 for SCRIPT in bootstrap.d/*.sh; do
528 528 head -n 3 "$SCRIPT"
529 529 . "$SCRIPT"
530 530 done
531 531
532 532 ## Execute custom bootstrap scripts
533 533 if [ -d "custom.d" ] ; then
534 534 for SCRIPT in custom.d/*.sh; do
535 535 . "$SCRIPT"
536 536 done
537 537 fi
538 538
539 539 # Execute custom scripts inside the chroot
540 540 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
541 541 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
542 542 chroot_exec /bin/bash -x <<'EOF'
543 543 for SCRIPT in /chroot_scripts/* ; do
544 544 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
545 545 $SCRIPT
546 546 fi
547 547 done
548 548 EOF
549 549 rm -rf "${R}/chroot_scripts"
550 550 fi
551 551
552 552 # Remove c/c++ build environment from the chroot
553 553 chroot_remove_cc
554 554
555 555 # Remove apt-utils
556 556 if [ "$RELEASE" = "jessie" ] ; then
557 557 chroot_exec apt-get purge -qq -y --force-yes apt-utils
558 558 fi
559 559
560 560 # Generate required machine-id
561 561 MACHINE_ID=$(dbus-uuidgen)
562 562 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
563 563 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
564 564
565 565 # APT Cleanup
566 566 chroot_exec apt-get -y clean
567 567 chroot_exec apt-get -y autoclean
568 568 chroot_exec apt-get -y autoremove
569 569
570 570 # Unmount mounted filesystems
571 571 umount -l "${R}/proc"
572 572 umount -l "${R}/sys"
573 573
574 574 # Clean up directories
575 575 rm -rf "${R}/run/*"
576 576 rm -rf "${R}/tmp/*"
577 577
578 578 # Clean up files
579 579 rm -f "${ETC_DIR}/ssh/ssh_host_*"
580 580 rm -f "${ETC_DIR}/dropbear/dropbear_*"
581 581 rm -f "${ETC_DIR}/apt/sources.list.save"
582 582 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
583 583 rm -f "${ETC_DIR}/*-"
584 584 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
585 585 rm -f "${ETC_DIR}/resolv.conf"
586 586 rm -f "${R}/root/.bash_history"
587 587 rm -f "${R}/var/lib/urandom/random-seed"
588 588 rm -f "${R}/initrd.img"
589 589 rm -f "${R}/vmlinuz"
590 590 rm -f "${R}${QEMU_BINARY}"
591 591
592 592 if [ "$ENABLE_QEMU" = true ] ; then
593 593 # Setup QEMU directory
594 594 mkdir "${BASEDIR}/qemu"
595 595
596 596 # Copy kernel image to QEMU directory
597 597 install_readonly "${BOOT_DIR}/${KERNEL_IMAGE}" "${BASEDIR}/qemu/${KERNEL_IMAGE}"
598 598
599 599 # Copy kernel config to QEMU directory
600 600 install_readonly "${R}/boot/config-${KERNEL_VERSION}" "${BASEDIR}/qemu/config-${KERNEL_VERSION}"
601 601
602 602 # Copy kernel dtbs to QEMU directory
603 603 for dtb in "${BOOT_DIR}/"*.dtb ; do
604 604 if [ -f "${dtb}" ] ; then
605 605 install_readonly "${dtb}" "${BASEDIR}/qemu/"
606 606 fi
607 607 done
608 608
609 609 # Copy kernel overlays to QEMU directory
610 610 if [ -d "${BOOT_DIR}/overlays" ] ; then
611 611 # Setup overlays dtbs directory
612 612 mkdir "${BASEDIR}/qemu/overlays"
613 613
614 614 for dtb in "${BOOT_DIR}/overlays/"*.dtb ; do
615 615 if [ -f "${dtb}" ] ; then
616 616 install_readonly "${dtb}" "${BASEDIR}/qemu/overlays/"
617 617 fi
618 618 done
619 619 fi
620
621 # Copy initramfs to QEMU directory
622 if [ -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" ] ; then
623 install_readonly "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" "${BASEDIR}/qemu/initramfs-${KERNEL_VERSION}"
624 fi
620 625 fi
621 626
622 627 # Calculate size of the chroot directory in KB
623 628 CHROOT_SIZE=$(expr `du -s "${R}" | awk '{ print $1 }'`)
624 629
625 630 # Calculate the amount of needed 512 Byte sectors
626 631 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
627 632 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
628 633 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS})
629 634
630 635 # The root partition is EXT4
631 636 # This means more space than the actual used space of the chroot is used.
632 637 # As overhead for journaling and reserved blocks 35% are added.
633 638 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 35) \* 1024 \/ 512)
634 639
635 640 # Calculate required image size in 512 Byte sectors
636 641 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS})
637 642
638 643 # Prepare image file
639 644 if [ "$ENABLE_SPLITFS" = true ] ; then
640 645 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=${TABLE_SECTORS}
641 646 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS}
642 647 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=${TABLE_SECTORS}
643 648 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek=${ROOT_SECTORS}
644 649
645 650 # Write firmware/boot partition tables
646 651 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
647 652 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
648 653 EOM
649 654
650 655 # Write root partition table
651 656 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
652 657 ${TABLE_SECTORS},${ROOT_SECTORS},83
653 658 EOM
654 659
655 660 # Setup temporary loop devices
656 661 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $IMAGE_NAME-frmw.img)"
657 662 ROOT_LOOP="$(losetup -o 1M -f --show $IMAGE_NAME-root.img)"
658 663 else # ENABLE_SPLITFS=false
659 664 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=${TABLE_SECTORS}
660 665 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek=${IMAGE_SECTORS}
661 666
662 667 # Write partition table
663 668 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
664 669 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
665 670 ${ROOT_OFFSET},${ROOT_SECTORS},83
666 671 EOM
667 672
668 673 # Setup temporary loop devices
669 674 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $IMAGE_NAME.img)"
670 675 ROOT_LOOP="$(losetup -o 65M -f --show $IMAGE_NAME.img)"
671 676 fi
672 677
673 678 if [ "$ENABLE_CRYPTFS" = true ] ; then
674 679 # Create dummy ext4 fs
675 680 mkfs.ext4 "$ROOT_LOOP"
676 681
677 682 # Setup password keyfile
678 683 touch .password
679 684 chmod 600 .password
680 685 echo -n ${CRYPTFS_PASSWORD} > .password
681 686
682 687 # Initialize encrypted partition
683 688 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
684 689
685 690 # Open encrypted partition and setup mapping
686 691 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
687 692
688 693 # Secure delete password keyfile
689 694 shred -zu .password
690 695
691 696 # Update temporary loop device
692 697 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
693 698
694 699 # Wipe encrypted partition (encryption cipher is used for randomness)
695 700 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count=$(blockdev --getsz "${ROOT_LOOP}")
696 701 fi
697 702
698 703 # Build filesystems
699 704 mkfs.vfat "$FRMW_LOOP"
700 705 mkfs.ext4 "$ROOT_LOOP"
701 706
702 707 # Mount the temporary loop devices
703 708 mkdir -p "$BUILDDIR/mount"
704 709 mount "$ROOT_LOOP" "$BUILDDIR/mount"
705 710
706 711 mkdir -p "$BUILDDIR/mount/boot/firmware"
707 712 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
708 713
709 714 # Copy all files from the chroot to the loop device mount point directory
710 715 rsync -a "${R}/" "$BUILDDIR/mount/"
711 716
712 717 # Unmount all temporary loop devices and mount points
713 718 cleanup
714 719
715 720 # Create block map file(s) of image(s)
716 721 if [ "$ENABLE_SPLITFS" = true ] ; then
717 722 # Create block map files for "bmaptool"
718 723 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
719 724 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
720 725
721 726 # Image was successfully created
722 727 echo "$IMAGE_NAME-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
723 728 echo "$IMAGE_NAME-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
724 729 else
725 730 # Create block map file for "bmaptool"
726 731 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
727 732
728 733 # Image was successfully created
729 734 echo "$IMAGE_NAME.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
730 735
731 736 # Create qemu qcow2 image
732 737 if [ "$ENABLE_QEMU" = true ] ; then
733 738 QEMU_IMAGE=${QEMU_IMAGE:=${BASEDIR}/qemu/${DATE}-${KERNEL_ARCH}-CURRENT-rpi${RPI_MODEL}-${RELEASE}-${RELEASE_ARCH}}
734 739 QEMU_SIZE=16G
735 740
736 741 qemu-img convert -f raw -O qcow2 $IMAGE_NAME.img $QEMU_IMAGE.qcow2
737 742 qemu-img resize $QEMU_IMAGE.qcow2 $QEMU_SIZE
738 743
739 744 echo "$QEMU_IMAGE.qcow2 ($QEMU_SIZE)" ": successfully created"
740 745 fi
741 746 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant