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