##// END OF EJS Templates
Added Debian stretch release support
drtyhlpr -
r92:09d30ea4bc55
parent child
Show More
@@ -0,0 +1,14
1 #!/bin/sh -e
2 #
3 # rc.local
4 #
5 # This script is executed at the end of each multiuser runlevel.
6 # Make sure that the script will "exit 0" on success or any other
7 # value on error.
8 #
9 # In order to enable or disable this script just change the execution
10 # bits.
11 #
12 # By default this script does nothing.
13
14 exit 0
@@ -0,0 +1,13
1 logger -t "rc.firstboot" "Configuring network interface name"
2
3 INTERFACE_NAME=$(dmesg | grep "renamed from eth0" | awk -F ":| " '{ print $9 }')
4
5 if [ ! -z INTERFACE_NAME ] ; then
6 if [ -r "/etc/systemd/network/eth.network" ] ; then
7 sed -i "s/eth0/${INTERFACE_NAME}/" /etc/systemd/network/eth.network
8 fi
9
10 if [ -r "/lib/systemd/network/10-eth.network" ] ; then
11 sed -i "s/eth0/${INTERFACE_NAME}/" /lib/systemd/network/10-eth.network
12 fi
13 fi
@@ -1,310 +1,317
1 1 # rpi2-gen-image
2 2 ## Introduction
3 `rpi2-gen-image.sh` is an advanced Debian Linux bootstrapping shell script for generating Debian OS images for the Raspberry 2 (RPi2) computer. The script at this time only supports the bootstrapping of the current stable Debian 8 "jessie" release.
3 `rpi2-gen-image.sh` is an advanced Debian Linux bootstrapping shell script for generating Debian OS images for the Raspberry 2 (RPi2) computer. The script at this time supports the bootstrapping of the Debian releases "jessie" and "stretch".
4 4
5 5 ## Build dependencies
6 6 The following list of Debian packages must be installed on the build system because they are essentially required for the bootstrapping process. The script will check if all required packages are installed and missing packages will be installed automatically if confirmed by the user.
7 7
8 8 ```debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git```
9 9
10 10 ## Command-line parameters
11 11 The script accepts certain command-line parameters to enable or disable specific OS features, services and configuration settings. These parameters are passed to the `rpi2-gen-image.sh` script via (simple) shell-variables. Unlike environment shell-variables (simple) shell-variables are defined at the beginning of the command-line call of the `rpi2-gen-image.sh` script.
12 12
13 13 #####Command-line examples:
14 14 ```shell
15 15 ENABLE_UBOOT=true ./rpi2-gen-image.sh
16 16 ENABLE_CONSOLE=false ENABLE_IPV6=false ./rpi2-gen-image.sh
17 17 ENABLE_WM=xfce4 ENABLE_FBTURBO=true ENABLE_MINBASE=true ./rpi2-gen-image.sh
18 18 ENABLE_HARDNET=true ENABLE_IPTABLES=true /rpi2-gen-image.sh
19 19 APT_SERVER=ftp.de.debian.org APT_PROXY="http://127.0.0.1:3142/" ./rpi2-gen-image.sh
20 20 ENABLE_MINBASE=true ./rpi2-gen-image.sh
21 21 BUILD_KERNEL=true ENABLE_MINBASE=true ENABLE_IPV6=false ./rpi2-gen-image.sh
22 22 BUILD_KERNEL=true KERNELSRC_DIR=/tmp/linux ./rpi2-gen-image.sh
23 23 ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi2-gen-image.sh
24 24 ENABLE_CRYPTFS=true CRYPTFS_PASSWORD=changeme EXPANDROOT=false ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi2-gen-image.sh
25 RELEASE=stretch BUILD_KERNEL=true ./rpi2-gen-image.sh
25 26 ```
26 27
27 28 #### APT settings:
28 29 ##### `APT_SERVER`="ftp.debian.org"
29 30 Set Debian packages server address. Choose a server from the list of Debian worldwide [mirror sites](https://www.debian.org/mirror/list). Using a nearby server will probably speed-up all required downloads within the bootstrapping process.
30 31
31 32 ##### `APT_PROXY`=""
32 33 Set Proxy server address. Using a local Proxy-Cache like `apt-cacher-ng` will speed-up the bootstrapping process because all required Debian packages will only be downloaded from the Debian mirror site once.
33 34
34 35 ##### `APT_INCLUDES`=""
35 36 A comma separated list of additional packages to be installed during bootstrapping.
36 37
37 38 #### General system settings:
39 ##### `RELEASE`="jessie"
40 Set the desired Debian release name. The script at this time supports the bootstrapping of the Debian releases "jessie" and "stretch". `BUILD_KERNEL`=true will automatically be set if the Debian release `stretch` is used.
41
38 42 ##### `HOSTNAME`="rpi2-jessie"
39 43 Set system host name. It's recommended that the host name is unique in the corresponding subnet.
40 44
41 45 ##### `PASSWORD`="raspberry"
42 46 Set system `root` password. The same password is used for the created user `pi`. It's **STRONGLY** recommended that you choose a custom password.
43 47
44 48 ##### `DEFLOCAL`="en_US.UTF-8"
45 49 Set default system locale. This setting can also be changed inside the running OS using the `dpkg-reconfigure locales` command. Please note that on using this parameter the script will automatically install the required packages `locales`, `keyboard-configuration` and `console-setup`.
46 50
47 51 ##### `TIMEZONE`="Europe/Berlin"
48 52 Set default system timezone. All available timezones can be found in the `/usr/share/zoneinfo/` directory. This setting can also be changed inside the running OS using the `dpkg-reconfigure tzdata` command.
49 53
50 54 ##### `EXPANDROOT`=true
51 55 Expand the root partition and filesystem automatically on first boot.
52 56
53 57 #### Keyboard settings:
54 58 These options are used to configure keyboard layout in `/etc/default/keyboard` for console and Xorg. These settings can also be changed inside the running OS using the `dpkg-reconfigure keyboard-configuration` command.
55 59
56 60 ##### `XKB_MODEL`=""
57 61 Set the name of the model of your keyboard type.
58 62
59 63 ##### `XKB_LAYOUT`=""
60 64 Set the supported keyboard layout(s).
61 65
62 66 ##### `XKB_VARIANT`=""
63 67 Set the supported variant(s) of the keyboard layout(s).
64 68
65 69 ##### `XKB_OPTIONS`=""
66 70 Set extra xkb configuration options.
67 71
68 72 #### Networking settings (DHCP):
69 73 This parameter is used to set up networking auto configuration in `/etc/systemd/network/eth.network`.
70 74
71 75 #####`ENABLE_DHCP`=true
72 76 Set the system to use DHCP. This requires an DHCP server.
73 77
74 78 #### Networking settings (static):
75 79 These parameters are used to set up a static networking configuration in /etc/systemd/network/eth.network. The following static networking parameters are only supported if `ENABLE_DHCP` was set to `false`.
76 80
77 81 #####`NET_ADDRESS`=""
78 82 Set a static IPv4 or IPv6 address and its prefix, separated by "/", eg. "192.169.0.3/24".
79 83
80 84 #####`NET_GATEWAY`=""
81 85 Set the IP address for the default gateway.
82 86
83 87 #####`NET_DNS_1`=""
84 88 Set the IP address for the first DNS server.
85 89
86 90 #####`NET_DNS_2`=""
87 91 Set the IP address for the second DNS server.
88 92
89 93 #####`NET_DNS_DOMAINS`=""
90 94 Set the default DNS search domains to use for non fully qualified host names.
91 95
92 96 #####`NET_NTP_1`=""
93 97 Set the IP address for the first NTP server.
94 98
95 99 #####`NET_NTP_2`=""
96 100 Set the IP address for the second NTP server.
97 101
98 102 #### Basic system features:
99 103 ##### `ENABLE_CONSOLE`=true
100 104 Enable serial console interface. Recommended if no monitor or keyboard is connected to the RPi2. In case of problems fe. if the network (auto) configuration failed - the serial console can be used to access the system.
101 105
102 106 ##### `ENABLE_IPV6`=true
103 107 Enable IPv6 support. The network interface configuration is managed via systemd-networkd.
104 108
105 109 ##### `ENABLE_SSHD`=true
106 110 Install and enable OpenSSH service. The default configuration of the service doesn't allow `root` to login. Please use the user `pi` instead and `su -` or `sudo` to execute commands as root.
107 111
108 112 ##### `ENABLE_NONFREE`=false
109 113 Allow the installation of non-free Debian packages that do not comply with the DFSG. This is required to install closed-source firmware binary blobs.
110 114
111 115 ##### `ENABLE_RSYSLOG`=true
112 116 If set to false, disable and uninstall rsyslog (so logs will be available only
113 117 in journal files)
114 118
115 119 ##### `ENABLE_SOUND`=true
116 120 Enable sound hardware and install Advanced Linux Sound Architecture.
117 121
118 122 ##### `ENABLE_HWRANDOM`=true
119 123 Enable Hardware Random Number Generator. Strong random numbers are important for most network based communications that use encryption. It's recommended to be enabled.
120 124
121 125 ##### `ENABLE_MINGPU`=false
122 126 Minimize the amount of shared memory reserved for the GPU. It doesn't seem to be possible to fully disable the GPU.
123 127
124 128 ##### `ENABLE_DBUS`=true
125 129 Install and enable D-Bus message bus. Please note that systemd should work without D-bus but it's recommended to be enabled.
126 130
127 131 ##### `ENABLE_XORG`=false
128 132 Install Xorg open-source X Window System.
129 133
130 134 ##### `ENABLE_WM`=""
131 135 Install a user defined window manager for the X Window System. To make sure all X related package dependencies are getting installed `ENABLE_XORG` will automatically get enabled if `ENABLE_WM` is used. The `rpi2-gen-image.sh` script has been tested with the following list of window managers: `blackbox`, `openbox`, `fluxbox`, `jwm`, `dwm`, `xfce4`, `awesome`.
132 136
133 137 #### Advanced system features:
134 138 ##### `ENABLE_MINBASE`=false
135 139 Use debootstrap script variant `minbase` which only includes essential packages and apt. This will reduce the disk usage by about 65 MB.
136 140
137 141 ##### `ENABLE_REDUCE`=false
138 142 Reduce the disk space usage by deleting packages and files. See `REDUCE_*` parameters for detailed information.
139 143
140 144 ##### `ENABLE_UBOOT`=false
141 145 Replace default RPi2 second stage bootloader (bootcode.bin) with U-Boot bootloader. U-Boot can boot images via the network using the BOOTP/TFTP protocol.
142 146
143 147 ##### `ENABLE_FBTURBO`=false
144 148 Install and enable the hardware accelerated Xorg video driver `fbturbo`. Please note that this driver is currently limited to hardware accelerated window moving and scrolling.
145 149
146 150 ##### `ENABLE_IPTABLES`=false
147 151 Enable iptables IPv4/IPv6 firewall. Simplified ruleset: Allow all outgoing connections. Block all incoming connections except to OpenSSH service.
148 152
149 153 ##### `ENABLE_USER`=true
150 154 Create non-root user with password raspberry. Unless overridden with `USER_NAME`=user, username will be `pi`.
151 155
152 156 ##### `USER_NAME`=pi
153 157 Non-root user to create. Ignored if `ENABLE_USER`=false
154 158
155 159 ##### `ENABLE_ROOT`=true
156 160 Set root user password so root login will be enabled
157 161
158 162 ##### `ENABLE_ROOT_SSH`=true
159 163 Enable password root login via SSH. May be a security risk with default
160 164 password, use only in trusted environments.
161 165
162 166 ##### `ENABLE_HARDNET`=false
163 167 Enable IPv4/IPv6 network stack hardening settings.
164 168
165 169 ##### `ENABLE_SPLITFS`=false
166 170 Enable having root partition on an USB drive by creating two image files: one for the `/boot/firmware` mount point, and another for `/`.
167 171
168 172 ##### `CHROOT_SCRIPTS`=""
169 173 Path to a directory with scripts that should be run in the chroot before the image is finally built. Every executable file in this directory is run in lexicographical order.
170 174
171 175 ##### `ENABLE_INITRAMFS`=false
172 176 Create an initramfs that that will be loaded during the Linux startup process. `ENABLE_INITRAMFS` will automatically get enabled if `ENABLE_CRYPTFS`=true. This parameter will be ignored if `BUILD_KERNEL`=false.
173 177
178 ##### `ENABLE_IFNAMES`=true
179 Enable automatic assignment of predictable, stable network interface names for all local Ethernet, WLAN interfaces. This might create complex and long interface names. This parameter is only supported if the Debian release `stretch` is used.
180
174 181 #### Kernel compilation:
175 182 ##### `BUILD_KERNEL`=false
176 183 Build and install the latest RPi2 Linux kernel. Currently only the default RPi2 kernel configuration is used.
177 184
178 185 ##### `KERNEL_REDUCE`=false
179 186 Reduce the size of the generated kernel by removing unwanted device, network and filesystem drivers (experimental).
180 187
181 188 ##### `KERNEL_THREADS`=1
182 189 Number of parallel kernel building threads. If the parameter is left untouched the script will automatically determine the number of CPU cores to set the number of parallel threads to speed the kernel compilation.
183 190
184 191 ##### `KERNEL_HEADERS`=true
185 192 Install kernel headers with built kernel.
186 193
187 194 ##### `KERNEL_MENUCONFIG`=false
188 195 Start `make menuconfig` interactive menu-driven kernel configuration. The script will continue after `make menuconfig` was terminated.
189 196
190 197 ##### `KERNEL_REMOVESRC`=true
191 198 Remove all kernel sources from the generated OS image after it was built and installed.
192 199
193 200 ##### `KERNELSRC_DIR`=""
194 201 Path to a directory of [RaspberryPi Linux kernel sources](https://github.com/raspberrypi/linux) that will be copied, configured, build and installed inside the chroot.
195 202
196 203 ##### `KERNELSRC_CLEAN`=false
197 204 Clean the existing kernel sources directory `KERNELSRC_DIR` (using `make mrproper`) after it was copied to the chroot and before the compilation of the kernel has started. This parameter will be ignored if no `KERNELSRC_DIR` was specified or if `KERNELSRC_PREBUILT`=true.
198 205
199 206 ##### `KERNELSRC_CONFIG`=true
200 207 Run `make bcm2709_defconfig` (and optional `make menuconfig`) to configure the kernel sources before building. This parameter is automatically set to `true` if no existing kernel sources directory was specified using `KERNELSRC_DIR`. This parameter is ignored if `KERNELSRC_PREBUILT`=true.
201 208
202 209 ##### `KERNELSRC_PREBUILT`=false
203 210 With this parameter set to true the script expects the existing kernel sources directory to be already successfully cross-compiled. The parameters `KERNELSRC_CLEAN`, `KERNELSRC_CONFIG` and `KERNEL_MENUCONFIG` are ignored and no kernel compilation tasks are performed.
204 211
205 212 ##### `FIRMWAREDIR`=""
206 213 The directory containing a local copy of the firmware from the [RaspberryPi firmware project](https://github.com/raspberrypi/firmware). Default is to download the latest firmware directly from the project.
207 214
208 215 #### Reduce disk usage:
209 216 The following list of parameters is ignored if `ENABLE_REDUCE`=false.
210 217
211 218 ##### `REDUCE_APT`=true
212 219 Configure APT to use compressed package repository lists and no package caching files.
213 220
214 221 ##### `REDUCE_DOC`=true
215 222 Remove all doc files (harsh). Configure APT to not include doc files on future `apt-get` package installations.
216 223
217 224 ##### `REDUCE_MAN`=true
218 225 Remove all man pages and info files (harsh). Configure APT to not include man pages on future `apt-get` package installations.
219 226
220 227 ##### `REDUCE_VIM`=false
221 228 Replace `vim-tiny` package by `levee` a tiny vim clone.
222 229
223 230 ##### `REDUCE_BASH`=false
224 231 Remove `bash` package and switch to `dash` shell (experimental).
225 232
226 233 ##### `REDUCE_HWDB`=true
227 234 Remove PCI related hwdb files (experimental).
228 235
229 236 ##### `REDUCE_SSHD`=true
230 237 Replace `openssh-server` with `dropbear`.
231 238
232 239 ##### `REDUCE_LOCALE`=true
233 240 Remove all `locale` translation files.
234 241
235 242 #### Encrypted root partition:
236 243
237 244 ##### `ENABLE_CRYPTFS`=false
238 245 Enable full system encryption with dm-crypt. Setup a fully LUKS encrypted root partition (aes-xts-plain64:sha512) and generate required initramfs. The /boot directory will not be encrypted. This parameter will be ignored if `BUILD_KERNEL`=false. `ENABLE_CRYPTFS` is experimental. SSH-to-initramfs is currently not supported but will be soon - feel free to help.
239 246
240 247 ##### `CRYPTFS_PASSWORD`=""
241 248 Set password of the encrypted root partition. This parameter is mandatory if `ENABLE_CRYPTFS`=true.
242 249
243 250 ##### `CRYPTFS_MAPPING`="secure"
244 251 Set name of dm-crypt managed device-mapper mapping.
245 252
246 253 ##### `CRYPTFS_CIPHER`="aes-xts-plain64:sha512"
247 254 Set cipher specification string. `aes-xts*` ciphers are strongly recommended.
248 255
249 256 ##### `CRYPTFS_XTSKEYSIZE`=512
250 257 Sets key size in bits. The argument has to be a multiple of 8.
251 258
252 259 ## Understanding the script
253 260 The functions of this script that are required for the different stages of the bootstrapping are split up into single files located inside the `bootstrap.d` directory. During the bootstrapping every script in this directory gets executed in lexicographical order:
254 261
255 262 | Script | Description |
256 263 | --- | --- |
257 264 | `10-bootstrap.sh` | Debootstrap basic system |
258 265 | `11-apt.sh` | Setup APT repositories |
259 266 | `12-locale.sh` | Setup Locales and keyboard settings |
260 267 | `13-kernel.sh` | Build and install RPi2 Kernel |
261 268 | `20-networking.sh` | Setup Networking |
262 269 | `21-firewall.sh` | Setup Firewall |
263 270 | `30-security.sh` | Setup Users and Security settings |
264 271 | `31-logging.sh` | Setup Logging |
265 272 | `41-uboot.sh` | Build and Setup U-Boot |
266 273 | `42-fbturbo.sh` | Build and Setup fbturbo Xorg driver |
267 274 | `50-firstboot.sh` | First boot actions |
268 275 | `99-reduce.sh` | Reduce the disk space usage |
269 276
270 277 All the required configuration files that will be copied to the generated OS image are located inside the `files` directory. It is not recommended to modify these configuration files manually.
271 278
272 279 | Directory | Description |
273 280 | --- | --- |
274 281 | `apt` | APT management configuration files |
275 282 | `boot` | Boot and RPi2 configuration files |
276 283 | `dpkg` | Package Manager configuration |
277 284 | `firstboot` | Scripts that get executed on first boot |
278 285 | `initramfs` | Initramfs scripts |
279 286 | `iptables` | Firewall configuration files |
280 287 | `locales` | Locales configuration |
281 288 | `modules` | Kernel Modules configuration |
282 289 | `mount` | Fstab configuration |
283 290 | `network` | Networking configuration files |
284 291 | `sysctl.d` | Swapping and Network Hardening configuration |
285 292 | `xorg` | fbturbo Xorg driver configuration |
286 293
287 294 Debian custom packages, i.e. those not in the debian repositories, can be installed by placing them in the `packages` directory. They are installed immediately after packages from the repositories are installed. Any dependencies listed in the custom packages will be downloaded automatically from the repositories. Do not list these custom packages in `APT_INCLUDES`.
288 295
289 296 Scripts in the custom.d directory will be executed after all other installation is complete but before the image is created.
290 297
291 298 ## Logging of the bootstrapping process
292 299 All information related to the bootstrapping process and the commands executed by the `rpi2-gen-image.sh` script can easily be saved into a logfile. The common shell command `script` can be used for this purpose:
293 300
294 301 ```shell
295 302 script -c 'APT_SERVER=ftp.de.debian.org ./rpi2-gen-image.sh' ./build.log
296 303 ```
297 304
298 305 ## Flashing the image file
299 306 After the image file was successfully created by the `rpi2-gen-image.sh` script it can be copied to the microSD card that will be used by the RPi2 computer. This can be performed by using the tools `bmaptool` or `dd`. Using `bmaptool` will probably speed-up the copy process because `bmaptool` copies more wisely than `dd`.
300 307
301 308 #####Flashing examples:
302 309 ```shell
303 310 bmaptool copy ./images/jessie/2015-12-13-debian-jessie.img /dev/mmcblk0
304 311 dd bs=4M if=./images/jessie/2015-12-13-debian-jessie.img of=/dev/mmcblk0
305 312 ```
306 313 If you have set `ENABLE_SPLITFS`, copy the `-frmw` image on the microSD card, then the `-root` one on the USB drive:
307 314 ```shell
308 315 bmaptool copy ./images/jessie/2015-12-13-debian-jessie-frmw.img /dev/mmcblk0
309 316 bmaptool copy ./images/jessie/2015-12-13-debian-jessie-root.img /dev/sdc
310 317 ```
@@ -1,37 +1,47
1 1 #
2 2 # Debootstrap basic system
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 VARIANT=""
9 9 COMPONENTS="main"
10 EXCLUDES=""
10 11
11 12 # Use non-free Debian packages if needed
12 13 if [ "$ENABLE_NONFREE" = true ] ; then
13 14 COMPONENTS="main,non-free"
14 15 fi
15 16
16 17 # Use minbase bootstrap variant which only includes essential packages
17 18 if [ "$ENABLE_MINBASE" = true ] ; then
18 19 VARIANT="--variant=minbase"
19 20 fi
20 21
22 # Exclude packages if required by Debian release
23 if [ "$RELEASE" = "stretch" ] ; then
24 EXCLUDES="--exclude=init,systemd-sysv"
25 fi
26
21 27 # Base debootstrap (unpack only)
22 http_proxy=${APT_PROXY} debootstrap --arch="${RELEASE_ARCH}" --foreign ${VARIANT} --components="${COMPONENTS}" --include="${APT_INCLUDES}" "${RELEASE}" "${R}" "http://${APT_SERVER}/debian"
28 http_proxy=${APT_PROXY} debootstrap ${EXCLUDES} --arch="${RELEASE_ARCH}" --foreign ${VARIANT} --components="${COMPONENTS}" --include="${APT_INCLUDES}" "${RELEASE}" "${R}" "http://${APT_SERVER}/debian"
23 29
24 30 # Copy qemu emulator binary to chroot
25 31 install_exec "${QEMU_BINARY}" "${R}${QEMU_BINARY}"
26 32
27 33 # Copy debian-archive-keyring.pgp
28 34 mkdir -p "${R}/usr/share/keyrings"
29 35 install_readonly /usr/share/keyrings/debian-archive-keyring.gpg "${R}/usr/share/keyrings/debian-archive-keyring.gpg"
30 36
31 37 # Complete the bootstrapping process
32 38 chroot_exec /debootstrap/debootstrap --second-stage
33 39
34 40 # Mount required filesystems
35 41 mount -t proc none "${R}/proc"
36 42 mount -t sysfs none "${R}/sys"
37 mount --bind /dev/pts "${R}/dev/pts"
43
44 # Mount pseudo terminal slave if supported by Debian release
45 if [ -d "${R}/dev/pts" ] ; then
46 mount --bind /dev/pts "${R}/dev/pts"
47 fi
@@ -1,287 +1,299
1 1 #
2 2 # Build and Setup RPi2 Kernel
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 # Fetch and build latest raspberry kernel
9 9 if [ "$BUILD_KERNEL" = true ] ; then
10 10 # Setup source directory
11 11 mkdir -p "${R}/usr/src"
12 12
13 13 # Copy existing kernel sources into chroot directory
14 14 if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then
15 15 # Copy kernel sources
16 16 cp -r "${KERNELSRC_DIR}" "${R}/usr/src"
17 17
18 18 # Clean the kernel sources
19 19 if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then
20 20 make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" mrproper
21 21 fi
22 22 else # KERNELSRC_DIR=""
23 23 # Fetch current raspberrypi kernel sources
24 24 git -C "${R}/usr/src" clone --depth=1 "${KERNEL_URL}"
25 25 fi
26 26
27 27 # Calculate optimal number of kernel building threads
28 28 if [ "$KERNEL_THREADS" = "1" ] && [ -r /proc/cpuinfo ] ; then
29 29 KERNEL_THREADS=$(grep -c processor /proc/cpuinfo)
30 30 fi
31 31
32 32 # Configure and build kernel
33 33 if [ "$KERNELSRC_PREBUILT" = false ] ; then
34 34 # Remove device, network and filesystem drivers from kernel configuration
35 35 if [ "$KERNEL_REDUCE" = true ] ; then
36 36 make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
37 37 sed -i\
38 38 -e "s/\(^CONFIG_SND.*\=\).*/\1n/"\
39 39 -e "s/\(^CONFIG_SOUND.*\=\).*/\1n/"\
40 40 -e "s/\(^CONFIG_AC97.*\=\).*/\1n/"\
41 41 -e "s/\(^CONFIG_VIDEO_.*\=\).*/\1n/"\
42 42 -e "s/\(^CONFIG_MEDIA_TUNER.*\=\).*/\1n/"\
43 43 -e "s/\(^CONFIG_DVB.*\=\)[ym]/\1n/"\
44 44 -e "s/\(^CONFIG_REISERFS.*\=\).*/\1n/"\
45 45 -e "s/\(^CONFIG_JFS.*\=\).*/\1n/"\
46 46 -e "s/\(^CONFIG_XFS.*\=\).*/\1n/"\
47 47 -e "s/\(^CONFIG_GFS2.*\=\).*/\1n/"\
48 48 -e "s/\(^CONFIG_OCFS2.*\=\).*/\1n/"\
49 49 -e "s/\(^CONFIG_BTRFS.*\=\).*/\1n/"\
50 50 -e "s/\(^CONFIG_HFS.*\=\).*/\1n/"\
51 51 -e "s/\(^CONFIG_JFFS2.*\=\)[ym]/\1n/"\
52 52 -e "s/\(^CONFIG_UBIFS.*\=\).*/\1n/"\
53 53 -e "s/\(^CONFIG_SQUASHFS.*\=\)[ym]/\1n/"\
54 54 -e "s/\(^CONFIG_W1.*\=\)[ym]/\1n/"\
55 55 -e "s/\(^CONFIG_HAMRADIO.*\=\).*/\1n/"\
56 56 -e "s/\(^CONFIG_CAN.*\=\).*/\1n/"\
57 57 -e "s/\(^CONFIG_IRDA.*\=\).*/\1n/"\
58 58 -e "s/\(^CONFIG_BT_.*\=\).*/\1n/"\
59 59 -e "s/\(^CONFIG_WIMAX.*\=\)[ym]/\1n/"\
60 60 -e "s/\(^CONFIG_6LOWPAN.*\=\).*/\1n/"\
61 61 -e "s/\(^CONFIG_IEEE802154.*\=\).*/\1n/"\
62 62 -e "s/\(^CONFIG_NFC.*\=\).*/\1n/"\
63 63 -e "s/\(^CONFIG_FB_TFT=.*\=\).*/\1n/"\
64 64 -e "s/\(^CONFIG_TOUCHSCREEN.*\=\).*/\1n/"\
65 65 -e "s/\(^CONFIG_USB_GSPCA_.*\=\).*/\1n/"\
66 66 -e "s/\(^CONFIG_DRM.*\=\).*/\1n/"\
67 67 "${KERNELDIR}/.config"
68 68 fi
69 69
70 70 if [ "$KERNELSRC_CONFIG" = true ] ; then
71 71 # Load default raspberry kernel configuration
72 72 make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
73 73
74 74 # Start menu-driven kernel configuration (interactive)
75 75 if [ "$KERNEL_MENUCONFIG" = true ] ; then
76 76 make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig
77 77 fi
78 78 fi
79 79
80 80 # Cross compile kernel and modules
81 81 make -C "${KERNELDIR}" -j${KERNEL_THREADS} ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" zImage modules dtbs
82 82 fi
83 83
84 84 # Check if kernel compilation was successful
85 85 if [ ! -r "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/zImage" ] ; then
86 86 echo "error: kernel compilation failed! (zImage not found)"
87 87 cleanup
88 88 exit 1
89 89 fi
90 90
91 91 # Install kernel modules
92 92 if [ "$ENABLE_REDUCE" = true ] ; then
93 93 make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install
94 94 else
95 95 make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install
96 96
97 97 # Install kernel firmware
98 98 make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install
99 99 fi
100 100
101 101 # Install kernel headers
102 102 if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then
103 103 make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install
104 104 fi
105 105
106 106 # Prepare boot (firmware) directory
107 107 mkdir "${BOOTDIR}"
108 108
109 109 # Get kernel release version
110 110 KERNEL_VERSION=`cat "${KERNELDIR}/include/config/kernel.release"`
111 111
112 112 # Copy kernel configuration file to the boot directory
113 113 install_readonly "${KERNELDIR}/.config" "${R}/boot/config-${KERNEL_VERSION}"
114 114
115 115 # Copy dts and dtb device tree sources and binaries
116 116 mkdir "${BOOTDIR}/overlays"
117 117 install_readonly "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb "${BOOTDIR}/"
118 118 install_readonly "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb* "${BOOTDIR}/overlays/"
119 119 install_readonly "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOTDIR}/overlays/README"
120 120
121 121 if [ "$ENABLE_UBOOT" = false ] ; then
122 122 # Convert and copy zImage kernel to the boot directory
123 123 "${KERNELDIR}/scripts/mkknlimg" "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/zImage" "${BOOTDIR}/${KERNEL_IMAGE}"
124 124 else
125 125 # Copy zImage kernel to the boot directory
126 126 install_readonly "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/zImage" "${BOOTDIR}/${KERNEL_IMAGE}"
127 127 fi
128 128
129 129 # Remove kernel sources
130 130 if [ "$KERNEL_REMOVESRC" = true ] ; then
131 131 rm -fr "${KERNELDIR}"
132 132 fi
133 133
134 134 if [ -n "$FIRMWAREDIR" ] && [ -d "$FIRMWAREDIR" ] ; then
135 135 # Install boot binaries from local directory
136 136 cp ${FIRMWAREDIR}/boot/bootcode.bin ${BOOTDIR}/bootcode.bin
137 137 cp ${FIRMWAREDIR}/boot/fixup.dat ${BOOTDIR}/fixup.dat
138 138 cp ${FIRMWAREDIR}/boot/fixup_cd.dat ${BOOTDIR}/fixup_cd.dat
139 139 cp ${FIRMWAREDIR}/boot/fixup_x.dat ${BOOTDIR}/fixup_x.dat
140 140 cp ${FIRMWAREDIR}/boot/start.elf ${BOOTDIR}/start.elf
141 141 cp ${FIRMWAREDIR}/boot/start_cd.elf ${BOOTDIR}/start_cd.elf
142 142 cp ${FIRMWAREDIR}/boot/start_x.elf ${BOOTDIR}/start_x.elf
143 143 else
144 144 # Install latest boot binaries from raspberry/firmware github
145 145 wget -q -O "${BOOTDIR}/bootcode.bin" "${FIRMWARE_URL}/bootcode.bin"
146 146 wget -q -O "${BOOTDIR}/fixup.dat" "${FIRMWARE_URL}/fixup.dat"
147 147 wget -q -O "${BOOTDIR}/fixup_cd.dat" "${FIRMWARE_URL}/fixup_cd.dat"
148 148 wget -q -O "${BOOTDIR}/fixup_x.dat" "${FIRMWARE_URL}/fixup_x.dat"
149 149 wget -q -O "${BOOTDIR}/start.elf" "${FIRMWARE_URL}/start.elf"
150 150 wget -q -O "${BOOTDIR}/start_cd.elf" "${FIRMWARE_URL}/start_cd.elf"
151 151 wget -q -O "${BOOTDIR}/start_x.elf" "${FIRMWARE_URL}/start_x.elf"
152 152 fi
153 153
154 154 else # BUILD_KERNEL=false
155 155 # Kernel installation
156 156 chroot_exec apt-get -qq -y --no-install-recommends install linux-image-"${COLLABORA_KERNEL}" raspberrypi-bootloader-nokernel
157 157
158 158 # Install flash-kernel last so it doesn't try (and fail) to detect the platform in the chroot
159 159 chroot_exec apt-get -qq -y install flash-kernel
160 160
161 161 # Check if kernel installation was successful
162 162 VMLINUZ="$(ls -1 ${R}/boot/vmlinuz-* | sort | tail -n 1)"
163 163 if [ -z "$VMLINUZ" ] ; then
164 164 echo "error: kernel installation failed! (/boot/vmlinuz-* not found)"
165 165 cleanup
166 166 exit 1
167 167 fi
168 168 # Copy vmlinuz kernel to the boot directory
169 169 install_readonly "${VMLINUZ}" "${BOOTDIR}/${KERNEL_IMAGE}"
170 170 fi
171 171
172 172 # Setup firmware boot cmdline
173 173 if [ "$ENABLE_SPLITFS" = true ] ; then
174 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait net.ifnames=1 console=tty1 ${CMDLINE}"
174 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1"
175 175 else
176 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait net.ifnames=1 console=tty1 ${CMDLINE}"
176 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait console=tty1"
177 177 fi
178 178
179 179 # Add encrypted root partition to cmdline.txt
180 180 if [ "$ENABLE_CRYPTFS" = true ] ; then
181 181 if [ "$ENABLE_SPLITFS" = true ] ; then
182 182 CMDLINE=$(echo ${CMDLINE} | sed "s/sda1/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda1:${CRYPTFS_MAPPING}/")
183 183 else
184 184 CMDLINE=$(echo ${CMDLINE} | sed "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/mmcblk0p2:${CRYPTFS_MAPPING}/")
185 185 fi
186 186 fi
187 187
188 188 # Add serial console support
189 189 if [ "$ENABLE_CONSOLE" = true ] ; then
190 190 CMDLINE="${CMDLINE} console=ttyAMA0,115200 kgdboc=ttyAMA0,115200"
191 191 fi
192 192
193 193 # Remove IPv6 networking support
194 194 if [ "$ENABLE_IPV6" = false ] ; then
195 195 CMDLINE="${CMDLINE} ipv6.disable=1"
196 196 fi
197 197
198 # Automatically assign predictable network interface names
199 if [ "$ENABLE_IFNAMES" = false ] ; then
200 CMDLINE="${CMDLINE} net.ifnames=0"
201 else
202 CMDLINE="${CMDLINE} net.ifnames=1"
203 fi
204
205 # Set init to systemd if required by Debian release
206 if [ "$RELEASE" = "stretch" ] ; then
207 CMDLINE="${CMDLINE} init=/bin/systemd"
208 fi
209
198 210 # Install firmware boot cmdline
199 211 echo "${CMDLINE}" > "${BOOTDIR}/cmdline.txt"
200 212
201 213 # Install firmware config
202 214 install_readonly files/boot/config.txt "${BOOTDIR}/config.txt"
203 215
204 216 # Setup minimal GPU memory allocation size: 16MB (no X)
205 217 if [ "$ENABLE_MINGPU" = true ] ; then
206 218 echo "gpu_mem=16" >> "${BOOTDIR}/config.txt"
207 219 fi
208 220
209 221 # Setup boot with initramfs
210 222 if [ "$ENABLE_INITRAMFS" = true ] ; then
211 223 echo "initramfs initramfs-${KERNEL_VERSION} followkernel" >> "${BOOTDIR}/config.txt"
212 224 fi
213 225
214 226 # Create firmware configuration and cmdline symlinks
215 227 ln -sf firmware/config.txt "${R}/boot/config.txt"
216 228 ln -sf firmware/cmdline.txt "${R}/boot/cmdline.txt"
217 229
218 230 # Install and setup kernel modules to load at boot
219 231 mkdir -p "${R}/lib/modules-load.d/"
220 232 install_readonly files/modules/rpi2.conf "${R}/lib/modules-load.d/rpi2.conf"
221 233
222 234 # Load hardware random module at boot
223 235 if [ "$ENABLE_HWRANDOM" = true ] && [ "$BUILD_KERNEL" = false ] ; then
224 236 sed -i "s/^# bcm2708_rng/bcm2708_rng/" "${R}/lib/modules-load.d/rpi2.conf"
225 237 fi
226 238
227 239 # Load sound module at boot
228 240 if [ "$ENABLE_SOUND" = true ] ; then
229 241 sed -i "s/^# snd_bcm2835/snd_bcm2835/" "${R}/lib/modules-load.d/rpi2.conf"
230 242 fi
231 243
232 244 # Install kernel modules blacklist
233 245 mkdir -p "${ETCDIR}/modprobe.d/"
234 246 install_readonly files/modules/raspi-blacklist.conf "${ETCDIR}/modprobe.d/raspi-blacklist.conf"
235 247
236 248 # Install and setup fstab
237 249 install_readonly files/mount/fstab "${ETCDIR}/fstab"
238 250
239 251 # Add usb/sda disk root partition to fstab
240 252 if [ "$ENABLE_SPLITFS" = true ] && [ "$ENABLE_CRYPTFS" = false ] ; then
241 253 sed -i "s/mmcblk0p2/sda1/" "${ETCDIR}/fstab"
242 254 fi
243 255
244 256 # Add encrypted root partition to fstab and crypttab
245 257 if [ "$ENABLE_CRYPTFS" = true ] ; then
246 258 # Replace fstab root partition with encrypted partition mapping
247 259 sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING}/" "${ETCDIR}/fstab"
248 260
249 261 # Add encrypted partition to crypttab and fstab
250 262 install_readonly files/mount/crypttab "${ETCDIR}/crypttab"
251 263 echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks" >> "${ETCDIR}/crypttab"
252 264
253 265 if [ "$ENABLE_SPLITFS" = true ] ; then
254 266 # Add usb/sda disk to crypttab
255 267 sed -i "s/mmcblk0p2/sda1/" "${ETCDIR}/crypttab"
256 268 fi
257 269 fi
258 270
259 271 # Generate initramfs file
260 272 if [ "$ENABLE_INITRAMFS" = true ] ; then
261 273 if [ "$ENABLE_CRYPTFS" = true ] ; then
262 274 # Include initramfs scripts to auto expand encrypted root partition
263 275 if [ "$EXPANDROOT" = true ] ; then
264 276 install_exec files/initramfs/expand_encrypted_rootfs "${ETCDIR}/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs"
265 277 install_exec files/initramfs/expand-premount "${ETCDIR}/initramfs-tools/scripts/local-premount/expand-premount"
266 278 install_exec files/initramfs/expand-tools "${ETCDIR}/initramfs-tools/hooks/expand-tools"
267 279 fi
268 280
269 281 # Disable SSHD inside initramfs
270 282 printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=n\n" >> "${ETCDIR}/initramfs-tools/initramfs.conf"
271 283
272 284 # Dummy mapping required by mkinitramfs
273 285 echo "0 1 crypt $(echo ${CRYPTFS_CIPHER} | cut -d ':' -f 1) ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0 7:0 4096" | chroot_exec dmsetup create "${CRYPTFS_MAPPING}"
274 286
275 287 # Generate initramfs with encrypted root partition support
276 288 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
277 289
278 290 # Remove dummy mapping
279 291 chroot_exec cryptsetup close "${CRYPTFS_MAPPING}"
280 292 else
281 293 # Generate initramfs without encrypted root partition support
282 294 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
283 295 fi
284 296 fi
285 297
286 298 # Install sysctl.d configuration files
287 299 install_readonly files/sysctl.d/81-rpi-vm.conf "${ETCDIR}/sysctl.d/81-rpi-vm.conf"
@@ -1,77 +1,83
1 1 #
2 2 # Setup Networking
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 # Install and setup hostname
9 9 install_readonly files/network/hostname "${ETCDIR}/hostname"
10 10 sed -i "s/^rpi2-jessie/${HOSTNAME}/" "${ETCDIR}/hostname"
11 11
12 12 # Install and setup hosts
13 13 install_readonly files/network/hosts "${ETCDIR}/hosts"
14 14 sed -i "s/rpi2-jessie/${HOSTNAME}/" "${ETCDIR}/hosts"
15 15
16 16 # Setup hostname entry with static IP
17 17 if [ "$NET_ADDRESS" != "" ] ; then
18 18 NET_IP=$(echo "${NET_ADDRESS}" | cut -f 1 -d'/')
19 19 sed -i "s/^127.0.1.1/${NET_IP}/" "${ETCDIR}/hosts"
20 20 fi
21 21
22 22 # Remove IPv6 hosts
23 23 if [ "$ENABLE_IPV6" = false ] ; then
24 24 sed -i -e "/::[1-9]/d" -e "/^$/d" "${ETCDIR}/hosts"
25 25 fi
26 26
27 27 # Install hint about network configuration
28 28 install_readonly files/network/interfaces "${ETCDIR}/network/interfaces"
29 29
30 30 # Install configuration for interface eth0
31 31 install_readonly files/network/eth.network "${ETCDIR}/systemd/network/eth.network"
32 32
33 33 if [ "$ENABLE_DHCP" = true ] ; then
34 34 # Enable DHCP configuration for interface eth0
35 35 sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" "${ETCDIR}/systemd/network/eth.network"
36 36
37 37 # Set DHCP configuration to IPv4 only
38 38 if [ "$ENABLE_IPV6" = false ] ; then
39 39 sed -i "s/DHCP=.*/DHCP=v4/" "${ETCDIR}/systemd/network/eth.network"
40 40 fi
41 41
42 42 else # ENABLE_DHCP=false
43 43 # Set static network configuration for interface eth0
44 44 sed -i\
45 45 -e "s|DHCP=.*|DHCP=no|"\
46 46 -e "s|Address=\$|Address=${NET_ADDRESS}|"\
47 47 -e "s|Gateway=\$|Gateway=${NET_GATEWAY}|"\
48 48 -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_DNS_1}|"\
49 49 -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_DNS_2}|"\
50 50 -e "s|Domains=\$|Domains=${NET_DNS_DOMAINS}|"\
51 51 -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_NTP_1}|"\
52 52 -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_NTP_2}|"\
53 53 "${ETCDIR}/systemd/network/eth.network"
54 54 fi
55 55
56 56 # Remove empty settings from network configuration
57 57 sed -i "/.*=\$/d" "${ETCDIR}/systemd/network/eth.network"
58 58
59 # Move systemd network configuration if required by Debian release
60 if [ "$RELEASE" = "stretch" ] ; then
61 mv -v "${ETCDIR}/systemd/network/eth.network" "${LIBDIR}/systemd/network/10-eth.network"
62 rm -fr "${ETCDIR}/systemd/network"
63 fi
64
59 65 # Enable systemd-networkd service
60 66 chroot_exec systemctl enable systemd-networkd
61 67
62 68 # Install host.conf resolver configuration
63 69 install_readonly files/network/host.conf "${ETCDIR}/host.conf"
64 70
65 71 # Enable network stack hardening
66 72 if [ "$ENABLE_HARDNET" = true ] ; then
67 73 # Install sysctl.d configuration files
68 74 install_readonly files/sysctl.d/82-rpi-net-hardening.conf "${ETCDIR}/sysctl.d/82-rpi-net-hardening.conf"
69 75
70 76 # Setup resolver warnings about spoofed addresses
71 77 sed -i "s/^# spoof warn/spoof warn/" "${ETCDIR}/host.conf"
72 78 fi
73 79
74 80 # Enable time sync
75 81 if [ "NET_NTP_1" != "" ] ; then
76 82 chroot_exec systemctl enable systemd-timesyncd.service
77 83 fi
@@ -1,39 +1,49
1 1 #
2 2 # First boot actions
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 # Prepare rc.firstboot script
9 9 cat files/firstboot/10-begin.sh > "${ETCDIR}/rc.firstboot"
10 10
11 11 # Ensure openssh server host keys are regenerated on first boot
12 12 if [ "$ENABLE_SSHD" = true ] ; then
13 13 cat files/firstboot/21-generate-ssh-keys.sh >> "${ETCDIR}/rc.firstboot"
14 14 fi
15 15
16 16 # Prepare filesystem auto expand
17 17 if [ "$EXPANDROOT" = true ] ; then
18 18 if [ "$ENABLE_CRYPTFS" = false ] ; then
19 19 cat files/firstboot/22-expandroot.sh >> "${ETCDIR}/rc.firstboot"
20 20 else
21 21 # Regenerate initramfs to remove encrypted root partition auto expand
22 22 cat files/firstboot/23-regenerate-initramfs.sh >> "${ETCDIR}/rc.firstboot"
23 23 fi
24 24 fi
25 25
26 26 # Ensure that dbus machine-id exists
27 27 cat files/firstboot/24-generate-machineid.sh >> "${ETCDIR}/rc.firstboot"
28 28
29 29 # Create /etc/resolv.conf symlink
30 30 cat files/firstboot/25-create-resolv-symlink.sh >> "${ETCDIR}/rc.firstboot"
31 31
32 # Configure automatic network interface names
33 if [ "$ENABLE_IFNAMES" = true ] ; then
34 cat files/firstboot/26-config-ifnames.sh >> "${ETCDIR}/rc.firstboot"
35 fi
36
32 37 # Finalize rc.firstboot script
33 38 cat files/firstboot/99-finish.sh >> "${ETCDIR}/rc.firstboot"
34 39 chmod +x "${ETCDIR}/rc.firstboot"
35 40
41 # Install default rc.local if it does not exist
42 if [ ! -f "${ETCDIR}/rc.local" ] ; then
43 install_exec files/etc/rc.local "${ETCDIR}/rc.local"
44 fi
45
36 46 # Add rc.firstboot script to rc.local
37 47 sed -i '/exit 0/d' "${ETCDIR}/rc.local"
38 48 echo /etc/rc.firstboot >> "${ETCDIR}/rc.local"
39 49 echo exit 0 >> "${ETCDIR}/rc.local"
@@ -1,3 +1,7
1 logger -t "rc.firstboot" "Reload systemd manager configuration"
2 systemctl daemon-reload
3 systemctl restart networking.service
4 systemctl restart systemd-networkd.service
1 5 logger -t "rc.firstboot" "First boot actions finished"
2 6 rm -f /etc/rc.firstboot
3 7 sed -i '/.*rc.firstboot/d' /etc/rc.local
@@ -1,528 +1,535
1 1 #!/bin/sh
2 2
3 3 ########################################################################
4 4 # rpi2-gen-image.sh 2015-2016
5 5 #
6 # Advanced debian "jessie" bootstrap script for RPi2
6 # Advanced Debian "jessie" and "stretch" bootstrap script for RPi2
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 10+ 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 # Introduce settings
34 34 set -e
35 35 echo -n -e "\n#\n# RPi2 Bootstrap Settings\n#\n"
36 36 set -x
37 37
38 38 # Debian release
39 39 RELEASE=${RELEASE:=jessie}
40 40 KERNEL_ARCH=${KERNEL_ARCH:=arm}
41 41 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
42 42 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
43 43 COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2}
44 44 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
45 45 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
46 46 DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
47 47 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
48 48 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
49 49
50 50 # URLs
51 51 KERNEL_URL=${KERNEL_URL:=https://github.com/raspberrypi/linux}
52 52 FIRMWARE_URL=${FIRMWARE_URL:=https://github.com/raspberrypi/firmware/raw/master/boot}
53 53 COLLABORA_URL=${COLLABORA_URL:=https://repositories.collabora.co.uk/debian}
54 54 FBTURBO_URL=${FBTURBO_URL:=https://github.com/ssvb/xf86-video-fbturbo.git}
55 55 UBOOT_URL=${UBOOT_URL:=git://git.denx.de/u-boot.git}
56 56
57 57 # Build directories
58 58 BASEDIR="$(pwd)/images/${RELEASE}"
59 59 BUILDDIR="${BASEDIR}/build"
60 60
61 61 # Chroot directories
62 62 R="${BUILDDIR}/chroot"
63 63 ETCDIR="${R}/etc"
64 LIBDIR="${R}/lib"
64 65 BOOTDIR="${R}/boot/firmware"
65 66 KERNELDIR="${R}/usr/src/linux"
66 67
67 68 # Firmware directory: Blank if download from github
68 69 FIRMWAREDIR=${FIRMWAREDIR:=""}
69 70
70 71 # General settings
71 72 HOSTNAME=${HOSTNAME:=rpi2-${RELEASE}}
72 73 PASSWORD=${PASSWORD:=raspberry}
73 74 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
74 75 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
75 76 EXPANDROOT=${EXPANDROOT:=true}
76 77
77 78 # Keyboard settings
78 79 XKB_MODEL=${XKB_MODEL:=""}
79 80 XKB_LAYOUT=${XKB_LAYOUT:=""}
80 81 XKB_VARIANT=${XKB_VARIANT:=""}
81 82 XKB_OPTIONS=${XKB_OPTIONS:=""}
82 83
83 84 # Network settings (DHCP)
84 85 ENABLE_DHCP=${ENABLE_DHCP:=true}
85 86
86 87 # Network settings (static)
87 88 NET_ADDRESS=${NET_ADDRESS:=""}
88 89 NET_GATEWAY=${NET_GATEWAY:=""}
89 90 NET_DNS_1=${NET_DNS_1:=""}
90 91 NET_DNS_2=${NET_DNS_2:=""}
91 92 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
92 93 NET_NTP_1=${NET_NTP_1:=""}
93 94 NET_NTP_2=${NET_NTP_2:=""}
94 95
95 96 # APT settings
96 97 APT_PROXY=${APT_PROXY:=""}
97 98 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
98 99
99 100 # Feature settings
100 101 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
101 102 ENABLE_IPV6=${ENABLE_IPV6:=true}
102 103 ENABLE_SSHD=${ENABLE_SSHD:=true}
103 104 ENABLE_NONFREE=${ENABLE_NONFREE:=false}
104 105 ENABLE_SOUND=${ENABLE_SOUND:=true}
105 106 ENABLE_DBUS=${ENABLE_DBUS:=true}
106 107 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
107 108 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
108 109 ENABLE_XORG=${ENABLE_XORG:=false}
109 110 ENABLE_WM=${ENABLE_WM:=""}
110 111 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
111 112 ENABLE_USER=${ENABLE_USER:=true}
112 113 USER_NAME=${USER_NAME:="pi"}
113 114 ENABLE_ROOT=${ENABLE_ROOT:=false}
114 115 ENABLE_ROOT_SSH=${ENABLE_ROOT_SSH:=false}
115 116
116 117 # Advanced settings
117 118 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
118 119 ENABLE_REDUCE=${ENABLE_REDUCE:=false}
119 120 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
120 121 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
121 122 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
122 123 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
123 124 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
124 125 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
126 ENABLE_IFNAMES=${ENABLE_IFNAMES:=true}
125 127
126 128 # Kernel compilation settings
127 129 BUILD_KERNEL=${BUILD_KERNEL:=false}
128 130 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
129 131 KERNEL_THREADS=${KERNEL_THREADS:=1}
130 132 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
131 133 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
132 134 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
133 135
134 136 # Kernel compilation from source directory settings
135 137 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
136 138 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
137 139 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
138 140 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
139 141
140 142 # Reduce disk usage settings
141 143 REDUCE_APT=${REDUCE_APT:=true}
142 144 REDUCE_DOC=${REDUCE_DOC:=true}
143 145 REDUCE_MAN=${REDUCE_MAN:=true}
144 146 REDUCE_VIM=${REDUCE_VIM:=false}
145 147 REDUCE_BASH=${REDUCE_BASH:=false}
146 148 REDUCE_HWDB=${REDUCE_HWDB:=true}
147 149 REDUCE_SSHD=${REDUCE_SSHD:=true}
148 150 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
149 151
150 152 # Encrypted filesystem settings
151 153 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
152 154 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
153 155 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
154 156 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
155 157 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
156 158
157 159 # Stop the Crypto Wars
158 160 DISABLE_FBI=${DISABLE_FBI:=false}
159 161
160 162 # Chroot scripts directory
161 163 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
162 164
163 165 # Packages required in the chroot build environment
164 166 APT_INCLUDES=${APT_INCLUDES:=""}
165 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo"
167 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo,systemd,sysvinit-utils"
166 168
167 169 # Packages required for bootstrapping
168 170 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git"
169 171 MISSING_PACKAGES=""
170 172
171 173 set +x
172 174
175 # Build latest RPi2 Linux kernel if required by Debian release
176 if [ "$RELEASE" = "stretch" ] ; then
177 BUILD_KERNEL=true
178 fi
179
173 180 # Add packages required for kernel cross compilation
174 181 if [ "$BUILD_KERNEL" = true ] ; then
175 182 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
176 183 fi
177 184
178 185 # Add libncurses5 to enable kernel menuconfig
179 186 if [ "$KERNEL_MENUCONFIG" = true ] ; then
180 187 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
181 188 fi
182 189
183 190 # Stop the Crypto Wars
184 191 if [ "$DISABLE_FBI" = true ] ; then
185 192 ENABLE_CRYPTFS=true
186 193 fi
187 194
188 195 # Add cryptsetup package to enable filesystem encryption
189 196 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
190 197 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
191 198 APT_INCLUDES="${APT_INCLUDES},cryptsetup"
192 199
193 200 if [ -z "$CRYPTFS_PASSWORD" ] ; then
194 201 echo "error: no password defined (CRYPTFS_PASSWORD)!"
195 202 exit 1
196 203 fi
197 204 ENABLE_INITRAMFS=true
198 205 fi
199 206
200 207 # Add initramfs generation tools
201 208 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
202 209 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
203 210 fi
204 211
205 212 # Check if all required packages are installed on the build system
206 213 for package in $REQUIRED_PACKAGES ; do
207 214 if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then
208 215 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
209 216 fi
210 217 done
211 218
212 219 # Ask if missing packages should get installed right now
213 220 if [ -n "$MISSING_PACKAGES" ] ; then
214 221 echo "the following packages needed by this script are not installed:"
215 222 echo "$MISSING_PACKAGES"
216 223
217 224 echo -n "\ndo you want to install the missing packages right now? [y/n] "
218 225 read confirm
219 226 [ "$confirm" != "y" ] && exit 1
220 227 fi
221 228
222 229 # Make sure all required packages are installed
223 230 apt-get -qq -y install ${REQUIRED_PACKAGES}
224 231
225 232 # Check if ./bootstrap.d directory exists
226 233 if [ ! -d "./bootstrap.d/" ] ; then
227 234 echo "error: './bootstrap.d' required directory not found!"
228 235 exit 1
229 236 fi
230 237
231 238 # Check if ./files directory exists
232 239 if [ ! -d "./files/" ] ; then
233 240 echo "error: './files' required directory not found!"
234 241 exit 1
235 242 fi
236 243
237 244 # Check if specified KERNELSRC_DIR directory exists
238 245 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
239 246 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
240 247 exit 1
241 248 fi
242 249
243 250 # Check if specified CHROOT_SCRIPTS directory exists
244 251 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
245 252 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
246 253 exit 1
247 254 fi
248 255
249 256 # Check if specified device mapping already exists (will be used by cryptsetup)
250 257 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
251 258 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
252 259 exit 1
253 260 fi
254 261
255 262 # Don't clobber an old build
256 263 if [ -e "$BUILDDIR" ] ; then
257 264 echo "error: directory ${BUILDDIR} already exists, not proceeding"
258 265 exit 1
259 266 fi
260 267
261 268 # Setup chroot directory
262 269 mkdir -p "${R}"
263 270
264 271 # Check if build directory has enough of free disk space >512MB
265 272 if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then
266 273 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
267 274 exit 1
268 275 fi
269 276
270 277 set -x
271 278
272 279 # Call "cleanup" function on various signals and errors
273 280 trap cleanup 0 1 2 3 6
274 281
275 282 # Add required packages for the minbase installation
276 283 if [ "$ENABLE_MINBASE" = true ] ; then
277 284 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
278 285 fi
279 286
280 287 # Add required locales packages
281 288 if [ "$DEFLOCAL" != "en_US.UTF-8" ] ; then
282 289 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
283 290 fi
284 291
285 292 # Add parted package, required to get partprobe utility
286 293 if [ "$EXPANDROOT" = true ] ; then
287 294 APT_INCLUDES="${APT_INCLUDES},parted"
288 295 fi
289 296
290 297 # Add dbus package, recommended if using systemd
291 298 if [ "$ENABLE_DBUS" = true ] ; then
292 299 APT_INCLUDES="${APT_INCLUDES},dbus"
293 300 fi
294 301
295 302 # Add iptables IPv4/IPv6 package
296 303 if [ "$ENABLE_IPTABLES" = true ] ; then
297 304 APT_INCLUDES="${APT_INCLUDES},iptables"
298 305 fi
299 306
300 307 # Add openssh server package
301 308 if [ "$ENABLE_SSHD" = true ] ; then
302 309 APT_INCLUDES="${APT_INCLUDES},openssh-server"
303 310 fi
304 311
305 312 # Add alsa-utils package
306 313 if [ "$ENABLE_SOUND" = true ] ; then
307 314 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
308 315 fi
309 316
310 317 # Add rng-tools package
311 318 if [ "$ENABLE_HWRANDOM" = true ] ; then
312 319 APT_INCLUDES="${APT_INCLUDES},rng-tools"
313 320 fi
314 321
315 322 # Add fbturbo video driver
316 323 if [ "$ENABLE_FBTURBO" = true ] ; then
317 324 # Enable xorg package dependencies
318 325 ENABLE_XORG=true
319 326 fi
320 327
321 328 # Add user defined window manager package
322 329 if [ -n "$ENABLE_WM" ] ; then
323 330 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
324 331
325 332 # Enable xorg package dependencies
326 333 ENABLE_XORG=true
327 334 fi
328 335
329 336 # Add xorg package
330 337 if [ "$ENABLE_XORG" = true ] ; then
331 338 APT_INCLUDES="${APT_INCLUDES},xorg"
332 339 fi
333 340
334 341 # Replace selected packages with smaller clones
335 342 if [ "$ENABLE_REDUCE" = true ] ; then
336 343 # Add levee package instead of vim-tiny
337 344 if [ "$REDUCE_VIM" = true ] ; then
338 345 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
339 346 fi
340 347
341 348 # Add dropbear package instead of openssh-server
342 349 if [ "$REDUCE_SSHD" = true ] ; then
343 350 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")"
344 351 fi
345 352 fi
346 353
347 354 # Configure kernel sources if no KERNELSRC_DIR
348 355 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
349 356 KERNELSRC_CONFIG=true
350 357 fi
351 358
352 359 # Configure reduced kernel
353 360 if [ "$KERNEL_REDUCE" = true ] ; then
354 361 KERNELSRC_CONFIG=false
355 362 fi
356 363
357 364 # Execute bootstrap scripts
358 365 for SCRIPT in bootstrap.d/*.sh; do
359 366 head -n 3 "$SCRIPT"
360 367 . "$SCRIPT"
361 368 done
362 369
363 370 ## Execute custom bootstrap scripts
364 371 if [ -d "custom.d" ] ; then
365 372 for SCRIPT in custom.d/*.sh; do
366 373 . "$SCRIPT"
367 374 done
368 375 fi
369 376
370 377 # Execute custom scripts inside the chroot
371 378 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
372 379 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
373 380 chroot_exec /bin/bash -x <<'EOF'
374 381 for SCRIPT in /chroot_scripts/* ; do
375 382 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
376 383 $SCRIPT
377 384 fi
378 385 done
379 386 EOF
380 387 rm -rf "${R}/chroot_scripts"
381 388 fi
382 389
383 390 # Remove apt-utils
384 391 chroot_exec apt-get purge -qq -y --force-yes apt-utils
385 392
386 393 # Generate required machine-id
387 394 MACHINE_ID=$(dbus-uuidgen)
388 395 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
389 396 echo -n "${MACHINE_ID}" > "${ETCDIR}/machine-id"
390 397
391 398 # APT Cleanup
392 399 chroot_exec apt-get -y clean
393 400 chroot_exec apt-get -y autoclean
394 401 chroot_exec apt-get -y autoremove
395 402
396 403 # Unmount mounted filesystems
397 404 umount -l "${R}/proc"
398 405 umount -l "${R}/sys"
399 406
400 407 # Clean up directories
401 408 rm -rf "${R}/run/*"
402 409 rm -rf "${R}/tmp/*"
403 410
404 411 # Clean up files
405 412 rm -f "${ETCDIR}/ssh/ssh_host_*"
406 413 rm -f "${ETCDIR}/dropbear/dropbear_*"
407 414 rm -f "${ETCDIR}/apt/sources.list.save"
408 415 rm -f "${ETCDIR}/resolvconf/resolv.conf.d/original"
409 416 rm -f "${ETCDIR}/*-"
410 417 rm -f "${ETCDIR}/apt/apt.conf.d/10proxy"
411 418 rm -f "${ETCDIR}/resolv.conf"
412 419 rm -f "${R}/root/.bash_history"
413 420 rm -f "${R}/var/lib/urandom/random-seed"
414 421 rm -f "${R}/initrd.img"
415 422 rm -f "${R}/vmlinuz"
416 423 rm -f "${R}${QEMU_BINARY}"
417 424
418 425 # Calculate size of the chroot directory in KB
419 426 CHROOT_SIZE=$(expr `du -s "${R}" | awk '{ print $1 }'`)
420 427
421 428 # Calculate the amount of needed 512 Byte sectors
422 429 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
423 430 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
424 431 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS})
425 432
426 433 # The root partition is EXT4
427 434 # This means more space than the actual used space of the chroot is used.
428 435 # As overhead for journaling and reserved blocks 20% are added.
429 436 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512)
430 437
431 438 # Calculate required image size in 512 Byte sectors
432 439 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS})
433 440
434 441 # Prepare date string for image file name
435 442 DATE="$(date +%Y-%m-%d)"
436 443
437 444 # Prepare image file
438 445 if [ "$ENABLE_SPLITFS" = true ] ; then
439 446 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=${TABLE_SECTORS}
440 447 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS}
441 448 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=${TABLE_SECTORS}
442 449 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=0 seek=${ROOT_SECTORS}
443 450
444 451 # Write firmware/boot partition tables
445 452 sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" 2> /dev/null <<EOM
446 453 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
447 454 EOM
448 455
449 456 # Write root partition table
450 457 sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}-root.img" 2> /dev/null <<EOM
451 458 ${TABLE_SECTORS},${ROOT_SECTORS},83
452 459 EOM
453 460
454 461 # Setup temporary loop devices
455 462 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-frmw.img)"
456 463 ROOT_LOOP="$(losetup -o 1M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-root.img)"
457 464 else # ENABLE_SPLITFS=false
458 465 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS}
459 466 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS}
460 467
461 468 # Write partition table
462 469 sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" 2> /dev/null <<EOM
463 470 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
464 471 ${ROOT_OFFSET},${ROOT_SECTORS},83
465 472 EOM
466 473
467 474 # Setup temporary loop devices
468 475 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
469 476 ROOT_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
470 477 fi
471 478
472 479 if [ "$ENABLE_CRYPTFS" = true ] ; then
473 480 # Create dummy ext4 fs
474 481 mkfs.ext4 "$ROOT_LOOP"
475 482
476 483 # Setup password keyfile
477 484 echo -n ${CRYPTFS_PASSWORD} > .password
478 485 chmod 600 .password
479 486
480 487 # Initialize encrypted partition
481 488 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
482 489
483 490 # Open encrypted partition and setup mapping
484 491 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
485 492
486 493 # Secure delete password keyfile
487 494 shred -zu .password
488 495
489 496 # Update temporary loop device
490 497 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
491 498
492 499 # Wipe encrypted partition (encryption cipher is used for randomness)
493 500 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count=$(blockdev --getsz "${ROOT_LOOP}")
494 501 fi
495 502
496 503 # Build filesystems
497 504 mkfs.vfat "$FRMW_LOOP"
498 505 mkfs.ext4 "$ROOT_LOOP"
499 506
500 507 # Mount the temporary loop devices
501 508 mkdir -p "$BUILDDIR/mount"
502 509 mount "$ROOT_LOOP" "$BUILDDIR/mount"
503 510
504 511 mkdir -p "$BUILDDIR/mount/boot/firmware"
505 512 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
506 513
507 514 # Copy all files from the chroot to the loop device mount point directory
508 515 rsync -a "${R}/" "$BUILDDIR/mount/"
509 516
510 517 # Unmount all temporary loop devices and mount points
511 518 cleanup
512 519
513 520 # Create block map file(s) of image(s)
514 521 if [ "$ENABLE_SPLITFS" = true ] ; then
515 522 # Create block map files for "bmaptool"
516 523 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img"
517 524 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-root.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-root.img"
518 525
519 526 # Image was successfully created
520 527 echo "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
521 528 echo "$BASEDIR/${DATE}-debian-${RELEASE}-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
522 529 else
523 530 # Create block map file for "bmaptool"
524 531 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}.img"
525 532
526 533 # Image was successfully created
527 534 echo "$BASEDIR/${DATE}-debian-${RELEASE}.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
528 535 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant