##// END OF EJS Templates
Fix: DTB for all
drtyhlpr -
r258:85dd0b37705f
parent child
Show More
@@ -1,56 +1,56
1 1 #
2 2 # Setup fstab and initramfs
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 # Install and setup fstab
9 9 install_readonly files/mount/fstab "${ETC_DIR}/fstab"
10 10
11 11 # Add usb/sda disk root partition to fstab
12 12 if [ "$ENABLE_SPLITFS" = true ] && [ "$ENABLE_CRYPTFS" = false ] ; then
13 13 sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/fstab"
14 14 fi
15 15
16 16 # Add encrypted root partition to fstab and crypttab
17 17 if [ "$ENABLE_CRYPTFS" = true ] ; then
18 18 # Replace fstab root partition with encrypted partition mapping
19 19 sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING}/" "${ETC_DIR}/fstab"
20 20
21 21 # Add encrypted partition to crypttab and fstab
22 22 install_readonly files/mount/crypttab "${ETC_DIR}/crypttab"
23 echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks" >> "${ETC_DIR}/crypttab"
23 echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks,initramfs" >> "${ETC_DIR}/crypttab"
24 24
25 25 if [ "$ENABLE_SPLITFS" = true ] ; then
26 26 # Add usb/sda disk to crypttab
27 27 sed -i "s/mmcblk0p2/sda1/" "${ETC_DIR}/crypttab"
28 28 fi
29 29 fi
30 30
31 31 # Generate initramfs file
32 32 if [ "$BUILD_KERNEL" = true ] && [ "$ENABLE_INITRAMFS" = true ] ; then
33 33 if [ "$ENABLE_CRYPTFS" = true ] ; then
34 34 # Include initramfs scripts to auto expand encrypted root partition
35 35 if [ "$EXPANDROOT" = true ] ; then
36 36 install_exec files/initramfs/expand_encrypted_rootfs "${ETC_DIR}/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs"
37 37 install_exec files/initramfs/expand-premount "${ETC_DIR}/initramfs-tools/scripts/local-premount/expand-premount"
38 38 install_exec files/initramfs/expand-tools "${ETC_DIR}/initramfs-tools/hooks/expand-tools"
39 39 fi
40 40
41 41 # Disable SSHD inside initramfs
42 42 printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=n\n" >> "${ETC_DIR}/initramfs-tools/initramfs.conf"
43 43
44 44 # Dummy mapping required by mkinitramfs
45 45 echo "0 1 crypt $(echo ${CRYPTFS_CIPHER} | cut -d ':' -f 1) ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0 7:0 4096" | chroot_exec dmsetup create "${CRYPTFS_MAPPING}"
46 46
47 47 # Generate initramfs with encrypted root partition support
48 48 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
49 49
50 50 # Remove dummy mapping
51 51 chroot_exec cryptsetup close "${CRYPTFS_MAPPING}"
52 52 else
53 53 # Generate initramfs without encrypted root partition support
54 54 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
55 55 fi
56 56 fi
@@ -1,693 +1,693
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 if [RPI_MODEL] = 0 || [RPI_MODEL = 1] || [RPI_MODEL = 1P]
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
173 173 # SSH settings
174 174 SSH_ENABLE_ROOT=${SSH_ENABLE_ROOT:=false}
175 175 SSH_DISABLE_PASSWORD_AUTH=${SSH_DISABLE_PASSWORD_AUTH:=false}
176 176 SSH_LIMIT_USERS=${SSH_LIMIT_USERS:=false}
177 177 SSH_ROOT_PUB_KEY=${SSH_ROOT_PUB_KEY:=""}
178 178 SSH_USER_PUB_KEY=${SSH_USER_PUB_KEY:=""}
179 179
180 180 # Advanced settings
181 181 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
182 182 ENABLE_REDUCE=${ENABLE_REDUCE:=false}
183 183 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
184 184 UBOOTSRC_DIR=${UBOOTSRC_DIR:=""}
185 185 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
186 186 FBTURBOSRC_DIR=${FBTURBOSRC_DIR:=""}
187 187 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
188 188 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
189 189 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
190 190 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
191 191 ENABLE_IFNAMES=${ENABLE_IFNAMES:=true}
192 192 DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS:=}
193 193
194 194 # Kernel compilation settings
195 195 BUILD_KERNEL=${BUILD_KERNEL:=false}
196 196 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
197 197 KERNEL_THREADS=${KERNEL_THREADS:=1}
198 198 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
199 199 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
200 200 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
201 201 KERNEL_OLDDEFCONFIG=${KERNEL_OLDDEFCONFIG:=false}
202 202 KERNEL_CCACHE=${KERNEL_CCACHE:=false}
203 203
204 204 if [ "$KERNEL_ARCH" = "arm64" ] ; then
205 205 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="Image"}
206 206 else
207 207 KERNEL_BIN_IMAGE=${KERNEL_BIN_IMAGE:="zImage"}
208 208 fi
209 209
210 210 # Kernel compilation from source directory settings
211 211 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
212 212 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
213 213 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
214 214 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
215 215
216 216 # Reduce disk usage settings
217 217 REDUCE_APT=${REDUCE_APT:=true}
218 218 REDUCE_DOC=${REDUCE_DOC:=true}
219 219 REDUCE_MAN=${REDUCE_MAN:=true}
220 220 REDUCE_VIM=${REDUCE_VIM:=false}
221 221 REDUCE_BASH=${REDUCE_BASH:=false}
222 222 REDUCE_HWDB=${REDUCE_HWDB:=true}
223 223 REDUCE_SSHD=${REDUCE_SSHD:=true}
224 224 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
225 225
226 226 # Encrypted filesystem settings
227 227 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
228 228 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
229 229 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
230 230 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
231 231 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
232 232
233 233 # Chroot scripts directory
234 234 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
235 235
236 236 # Packages required in the chroot build environment
237 237 APT_INCLUDES=${APT_INCLUDES:=""}
238 238 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils"
239 239
240 240 # Packages required for bootstrapping
241 241 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc dbus sudo"
242 242 MISSING_PACKAGES=""
243 243
244 244 # Packages installed for c/c++ build environment in chroot (keep empty)
245 245 COMPILER_PACKAGES=""
246 246
247 247 set +x
248 248
249 249 # Set Raspberry Pi model specific configuration
250 elif [ "$RPI_MODEL" = 0 ] ; then
250 if [ "$RPI_MODEL" = 0 ] ; then
251 251 DTB_FILE=${RPI2_DTB_FILE}
252 252 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
253 253 elif [ "$RPI_MODEL" = 1 ] ; then
254 254 DTB_FILE=${RPI2_DTB_FILE}
255 255 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
256 256 elif [ "$RPI_MODEL" = 1P ] ; then
257 257 DTB_FILE=${RPI2_DTB_FILE}
258 258 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
259 259 elif [ "$RPI_MODEL" = 2 ] ; then
260 260 DTB_FILE=${RPI2_DTB_FILE}
261 261 UBOOT_CONFIG=${RPI2_UBOOT_CONFIG}
262 262 elif [ "$RPI_MODEL" = 3 ] ; then
263 263 DTB_FILE=${RPI3_DTB_FILE}
264 264 UBOOT_CONFIG=${RPI3_UBOOT_CONFIG}
265 265 BUILD_KERNEL=true
266 266 elif [ "$RPI_MODEL" = 3P ] ; then
267 267 DTB_FILE=${RPI3P_DTB_FILE}
268 268 UBOOT_CONFIG=${RPI3P_UBOOT_CONFIG}
269 269 BUILD_KERNEL=true
270 270 else
271 271 echo "error: Raspberry Pi model ${RPI_MODEL} is not supported!"
272 272 exit 1
273 273 fi
274 274
275 275 # Check if the internal wireless interface is supported by the RPi model
276 276 if [ "$ENABLE_WIRELESS" = true ] && [ "$RPI_MODEL" = 2 ]; then
277 277 echo "error: The selected Raspberry Pi model has no internal wireless interface"
278 278 exit 1
279 279 fi
280 280
281 281 # Check if DISABLE_UNDERVOLT_WARNINGS parameter value is supported
282 282 if [ ! -z "$DISABLE_UNDERVOLT_WARNINGS" ] ; then
283 283 if [ "$DISABLE_UNDERVOLT_WARNINGS" != 1 ] && [ "$DISABLE_UNDERVOLT_WARNINGS" != 2 ] ; then
284 284 echo "error: DISABLE_UNDERVOLT_WARNINGS=${DISABLE_UNDERVOLT_WARNINGS} is not supported"
285 285 exit 1
286 286 fi
287 287 fi
288 288
289 289 # Build RPi2/3 Linux kernel if required by Debian release
290 290 if [ "$RELEASE" = "stretch" ] || [ "$RELEASE" = "buster" ] ; then
291 291 BUILD_KERNEL=true
292 292 fi
293 293
294 294 # Add packages required for kernel cross compilation
295 295 if [ "$BUILD_KERNEL" = true ] ; then
296 296 if [ "$KERNEL_ARCH" = "arm" ] ; then
297 297 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
298 298 else
299 299 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-arm64"
300 300 fi
301 301 fi
302 302
303 303 # Add libncurses5 to enable kernel menuconfig
304 304 if [ "$KERNEL_MENUCONFIG" = true ] ; then
305 305 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
306 306 fi
307 307
308 308 # Add ccache compiler cache for (faster) kernel cross (re)compilation
309 309 if [ "$KERNEL_CCACHE" = true ] ; then
310 310 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ccache"
311 311 fi
312 312
313 313 # Add cryptsetup package to enable filesystem encryption
314 314 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
315 315 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
316 316 APT_INCLUDES="${APT_INCLUDES},cryptsetup,console-setup"
317 317
318 318 if [ -z "$CRYPTFS_PASSWORD" ] ; then
319 319 echo "error: no password defined (CRYPTFS_PASSWORD)!"
320 320 exit 1
321 321 fi
322 322 ENABLE_INITRAMFS=true
323 323 fi
324 324
325 325 # Add initramfs generation tools
326 326 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
327 327 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
328 328 fi
329 329
330 330 # Add device-tree-compiler required for building the U-Boot bootloader
331 331 if [ "$ENABLE_UBOOT" = true ] ; then
332 332 APT_INCLUDES="${APT_INCLUDES},device-tree-compiler"
333 333 fi
334 334
335 335 # Check if root SSH (v2) public key file exists
336 336 if [ ! -z "$SSH_ROOT_PUB_KEY" ] ; then
337 337 if [ ! -f "$SSH_ROOT_PUB_KEY" ] ; then
338 338 echo "error: '$SSH_ROOT_PUB_KEY' specified SSH public key file not found (SSH_ROOT_PUB_KEY)!"
339 339 exit 1
340 340 fi
341 341 fi
342 342
343 343 # Check if $USER_NAME SSH (v2) public key file exists
344 344 if [ ! -z "$SSH_USER_PUB_KEY" ] ; then
345 345 if [ ! -f "$SSH_USER_PUB_KEY" ] ; then
346 346 echo "error: '$SSH_USER_PUB_KEY' specified SSH public key file not found (SSH_USER_PUB_KEY)!"
347 347 exit 1
348 348 fi
349 349 fi
350 350
351 351 # Check if all required packages are installed on the build system
352 352 for package in $REQUIRED_PACKAGES ; do
353 353 if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then
354 354 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
355 355 fi
356 356 done
357 357
358 358 # If there are missing packages ask confirmation for install, or exit
359 359 if [ -n "$MISSING_PACKAGES" ] ; then
360 360 echo "the following packages needed by this script are not installed:"
361 361 echo "$MISSING_PACKAGES"
362 362
363 363 echo -n "\ndo you want to install the missing packages right now? [y/n] "
364 364 read confirm
365 365 [ "$confirm" != "y" ] && exit 1
366 366
367 367 # Make sure all missing required packages are installed
368 368 apt-get -qq -y install ${MISSING_PACKAGES}
369 369 fi
370 370
371 371 # Check if ./bootstrap.d directory exists
372 372 if [ ! -d "./bootstrap.d/" ] ; then
373 373 echo "error: './bootstrap.d' required directory not found!"
374 374 exit 1
375 375 fi
376 376
377 377 # Check if ./files directory exists
378 378 if [ ! -d "./files/" ] ; then
379 379 echo "error: './files' required directory not found!"
380 380 exit 1
381 381 fi
382 382
383 383 # Check if specified KERNELSRC_DIR directory exists
384 384 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
385 385 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
386 386 exit 1
387 387 fi
388 388
389 389 # Check if specified UBOOTSRC_DIR directory exists
390 390 if [ -n "$UBOOTSRC_DIR" ] && [ ! -d "$UBOOTSRC_DIR" ] ; then
391 391 echo "error: '${UBOOTSRC_DIR}' specified directory not found (UBOOTSRC_DIR)!"
392 392 exit 1
393 393 fi
394 394
395 395 # Check if specified FBTURBOSRC_DIR directory exists
396 396 if [ -n "$FBTURBOSRC_DIR" ] && [ ! -d "$FBTURBOSRC_DIR" ] ; then
397 397 echo "error: '${FBTURBOSRC_DIR}' specified directory not found (FBTURBOSRC_DIR)!"
398 398 exit 1
399 399 fi
400 400
401 401 # Check if specified CHROOT_SCRIPTS directory exists
402 402 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
403 403 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
404 404 exit 1
405 405 fi
406 406
407 407 # Check if specified device mapping already exists (will be used by cryptsetup)
408 408 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
409 409 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
410 410 exit 1
411 411 fi
412 412
413 413 # Don't clobber an old build
414 414 if [ -e "$BUILDDIR" ] ; then
415 415 echo "error: directory ${BUILDDIR} already exists, not proceeding"
416 416 exit 1
417 417 fi
418 418
419 419 # Setup chroot directory
420 420 mkdir -p "${R}"
421 421
422 422 # Check if build directory has enough of free disk space >512MB
423 423 if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then
424 424 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
425 425 exit 1
426 426 fi
427 427
428 428 set -x
429 429
430 430 # Call "cleanup" function on various signals and errors
431 431 trap cleanup 0 1 2 3 6
432 432
433 433 # Add required packages for the minbase installation
434 434 if [ "$ENABLE_MINBASE" = true ] ; then
435 435 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
436 436 fi
437 437
438 438 # Add required locales packages
439 439 if [ "$DEFLOCAL" != "en_US.UTF-8" ] ; then
440 440 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
441 441 fi
442 442
443 443 # Add parted package, required to get partprobe utility
444 444 if [ "$EXPANDROOT" = true ] ; then
445 445 APT_INCLUDES="${APT_INCLUDES},parted"
446 446 fi
447 447
448 448 # Add dbus package, recommended if using systemd
449 449 if [ "$ENABLE_DBUS" = true ] ; then
450 450 APT_INCLUDES="${APT_INCLUDES},dbus"
451 451 fi
452 452
453 453 # Add iptables IPv4/IPv6 package
454 454 if [ "$ENABLE_IPTABLES" = true ] ; then
455 455 APT_INCLUDES="${APT_INCLUDES},iptables"
456 456 fi
457 457
458 458 # Add openssh server package
459 459 if [ "$ENABLE_SSHD" = true ] ; then
460 460 APT_INCLUDES="${APT_INCLUDES},openssh-server"
461 461 fi
462 462
463 463 # Add alsa-utils package
464 464 if [ "$ENABLE_SOUND" = true ] ; then
465 465 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
466 466 fi
467 467
468 468 # Add rng-tools package
469 469 if [ "$ENABLE_HWRANDOM" = true ] ; then
470 470 APT_INCLUDES="${APT_INCLUDES},rng-tools"
471 471 fi
472 472
473 473 # Add fbturbo video driver
474 474 if [ "$ENABLE_FBTURBO" = true ] ; then
475 475 # Enable xorg package dependencies
476 476 ENABLE_XORG=true
477 477 fi
478 478
479 479 # Add user defined window manager package
480 480 if [ -n "$ENABLE_WM" ] ; then
481 481 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
482 482
483 483 # Enable xorg package dependencies
484 484 ENABLE_XORG=true
485 485 fi
486 486
487 487 # Add xorg package
488 488 if [ "$ENABLE_XORG" = true ] ; then
489 489 APT_INCLUDES="${APT_INCLUDES},xorg,dbus-x11"
490 490 fi
491 491
492 492 # Replace selected packages with smaller clones
493 493 if [ "$ENABLE_REDUCE" = true ] ; then
494 494 # Add levee package instead of vim-tiny
495 495 if [ "$REDUCE_VIM" = true ] ; then
496 496 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
497 497 fi
498 498
499 499 # Add dropbear package instead of openssh-server
500 500 if [ "$REDUCE_SSHD" = true ] ; then
501 501 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")"
502 502 fi
503 503 fi
504 504
505 505 if [ "$RELEASE" != "jessie" ] ; then
506 506 APT_INCLUDES="${APT_INCLUDES},libnss-systemd"
507 507 fi
508 508
509 509 # Configure kernel sources if no KERNELSRC_DIR
510 510 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
511 511 KERNELSRC_CONFIG=true
512 512 fi
513 513
514 514 # Configure reduced kernel
515 515 if [ "$KERNEL_REDUCE" = true ] ; then
516 516 KERNELSRC_CONFIG=false
517 517 fi
518 518
519 519 # Execute bootstrap scripts
520 520 for SCRIPT in bootstrap.d/*.sh; do
521 521 head -n 3 "$SCRIPT"
522 522 . "$SCRIPT"
523 523 done
524 524
525 525 ## Execute custom bootstrap scripts
526 526 if [ -d "custom.d" ] ; then
527 527 for SCRIPT in custom.d/*.sh; do
528 528 . "$SCRIPT"
529 529 done
530 530 fi
531 531
532 532 # Execute custom scripts inside the chroot
533 533 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
534 534 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
535 535 chroot_exec /bin/bash -x <<'EOF'
536 536 for SCRIPT in /chroot_scripts/* ; do
537 537 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
538 538 $SCRIPT
539 539 fi
540 540 done
541 541 EOF
542 542 rm -rf "${R}/chroot_scripts"
543 543 fi
544 544
545 545 # Remove c/c++ build environment from the chroot
546 546 chroot_remove_cc
547 547
548 548 # Remove apt-utils
549 549 if [ "$RELEASE" = "jessie" ] ; then
550 550 chroot_exec apt-get purge -qq -y --force-yes apt-utils
551 551 fi
552 552
553 553 # Generate required machine-id
554 554 MACHINE_ID=$(dbus-uuidgen)
555 555 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
556 556 echo -n "${MACHINE_ID}" > "${ETC_DIR}/machine-id"
557 557
558 558 # APT Cleanup
559 559 chroot_exec apt-get -y clean
560 560 chroot_exec apt-get -y autoclean
561 561 chroot_exec apt-get -y autoremove
562 562
563 563 # Unmount mounted filesystems
564 564 umount -l "${R}/proc"
565 565 umount -l "${R}/sys"
566 566
567 567 # Clean up directories
568 568 rm -rf "${R}/run/*"
569 569 rm -rf "${R}/tmp/*"
570 570
571 571 # Clean up files
572 572 rm -f "${ETC_DIR}/ssh/ssh_host_*"
573 573 rm -f "${ETC_DIR}/dropbear/dropbear_*"
574 574 rm -f "${ETC_DIR}/apt/sources.list.save"
575 575 rm -f "${ETC_DIR}/resolvconf/resolv.conf.d/original"
576 576 rm -f "${ETC_DIR}/*-"
577 577 rm -f "${ETC_DIR}/apt/apt.conf.d/10proxy"
578 578 rm -f "${ETC_DIR}/resolv.conf"
579 579 rm -f "${R}/root/.bash_history"
580 580 rm -f "${R}/var/lib/urandom/random-seed"
581 581 rm -f "${R}/initrd.img"
582 582 rm -f "${R}/vmlinuz"
583 583 rm -f "${R}${QEMU_BINARY}"
584 584
585 585 # Calculate size of the chroot directory in KB
586 586 CHROOT_SIZE=$(expr `du -s "${R}" | awk '{ print $1 }'`)
587 587
588 588 # Calculate the amount of needed 512 Byte sectors
589 589 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
590 590 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
591 591 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS})
592 592
593 593 # The root partition is EXT4
594 594 # This means more space than the actual used space of the chroot is used.
595 595 # As overhead for journaling and reserved blocks 35% are added.
596 596 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 35) \* 1024 \/ 512)
597 597
598 598 # Calculate required image size in 512 Byte sectors
599 599 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS})
600 600
601 601 # Prepare image file
602 602 if [ "$ENABLE_SPLITFS" = true ] ; then
603 603 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=${TABLE_SECTORS}
604 604 dd if=/dev/zero of="$IMAGE_NAME-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS}
605 605 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=${TABLE_SECTORS}
606 606 dd if=/dev/zero of="$IMAGE_NAME-root.img" bs=512 count=0 seek=${ROOT_SECTORS}
607 607
608 608 # Write firmware/boot partition tables
609 609 sfdisk -q -L -uS -f "$IMAGE_NAME-frmw.img" 2> /dev/null <<EOM
610 610 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
611 611 EOM
612 612
613 613 # Write root partition table
614 614 sfdisk -q -L -uS -f "$IMAGE_NAME-root.img" 2> /dev/null <<EOM
615 615 ${TABLE_SECTORS},${ROOT_SECTORS},83
616 616 EOM
617 617
618 618 # Setup temporary loop devices
619 619 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $IMAGE_NAME-frmw.img)"
620 620 ROOT_LOOP="$(losetup -o 1M -f --show $IMAGE_NAME-root.img)"
621 621 else # ENABLE_SPLITFS=false
622 622 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=${TABLE_SECTORS}
623 623 dd if=/dev/zero of="$IMAGE_NAME.img" bs=512 count=0 seek=${IMAGE_SECTORS}
624 624
625 625 # Write partition table
626 626 sfdisk -q -L -uS -f "$IMAGE_NAME.img" 2> /dev/null <<EOM
627 627 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
628 628 ${ROOT_OFFSET},${ROOT_SECTORS},83
629 629 EOM
630 630
631 631 # Setup temporary loop devices
632 632 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $IMAGE_NAME.img)"
633 633 ROOT_LOOP="$(losetup -o 65M -f --show $IMAGE_NAME.img)"
634 634 fi
635 635
636 636 if [ "$ENABLE_CRYPTFS" = true ] ; then
637 637 # Create dummy ext4 fs
638 638 mkfs.ext4 "$ROOT_LOOP"
639 639
640 640 # Setup password keyfile
641 641 touch .password
642 642 chmod 600 .password
643 643 echo -n ${CRYPTFS_PASSWORD} > .password
644 644
645 645 # Initialize encrypted partition
646 646 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
647 647
648 648 # Open encrypted partition and setup mapping
649 649 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
650 650
651 651 # Secure delete password keyfile
652 652 shred -zu .password
653 653
654 654 # Update temporary loop device
655 655 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
656 656
657 657 # Wipe encrypted partition (encryption cipher is used for randomness)
658 658 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count=$(blockdev --getsz "${ROOT_LOOP}")
659 659 fi
660 660
661 661 # Build filesystems
662 662 mkfs.vfat "$FRMW_LOOP"
663 663 mkfs.ext4 "$ROOT_LOOP"
664 664
665 665 # Mount the temporary loop devices
666 666 mkdir -p "$BUILDDIR/mount"
667 667 mount "$ROOT_LOOP" "$BUILDDIR/mount"
668 668
669 669 mkdir -p "$BUILDDIR/mount/boot/firmware"
670 670 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
671 671
672 672 # Copy all files from the chroot to the loop device mount point directory
673 673 rsync -a "${R}/" "$BUILDDIR/mount/"
674 674
675 675 # Unmount all temporary loop devices and mount points
676 676 cleanup
677 677
678 678 # Create block map file(s) of image(s)
679 679 if [ "$ENABLE_SPLITFS" = true ] ; then
680 680 # Create block map files for "bmaptool"
681 681 bmaptool create -o "$IMAGE_NAME-frmw.bmap" "$IMAGE_NAME-frmw.img"
682 682 bmaptool create -o "$IMAGE_NAME-root.bmap" "$IMAGE_NAME-root.img"
683 683
684 684 # Image was successfully created
685 685 echo "$IMAGE_NAME-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
686 686 echo "$IMAGE_NAME-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
687 687 else
688 688 # Create block map file for "bmaptool"
689 689 bmaptool create -o "$IMAGE_NAME.bmap" "$IMAGE_NAME.img"
690 690
691 691 # Image was successfully created
692 692 echo "$IMAGE_NAME.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
693 693 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant