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