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