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