##// END OF EJS Templates
Added: KERNEL_REDUCE - less than 128MB used space, Added: REDUCE_ parameters
Jan Wagner -
r76:50170a27d411
parent child
Show More
@@ -0,0 +1,72
1 #
2 # Reduce system disk usage
3 #
4
5 # Load utility functions
6 . ./functions.sh
7
8 # Reduce the image size by various operations
9 if [ "$ENABLE_REDUCE" = true ] ; then
10 if [ "$REDUCE_APT" = true ] ; then
11 # Install dpkg configuration file
12 if [ "$REDUCE_DOC" = true ] || [ "$REDUCE_MAN" = true ] ; then
13 install_readonly files/dpkg/01nodoc "$R/etc/dpkg/dpkg.cfg.d/01nodoc"
14 fi
15
16 # Install APT configuration files
17 install_readonly files/apt/02nocache "$R/etc/apt/apt.conf.d/02nocache"
18 install_readonly files/apt/03compress "$R/etc/apt/apt.conf.d/03compress"
19 install_readonly files/apt/04norecommends "$R/etc/apt/apt.conf.d/04norecommends"
20
21 # Remove APT cache files
22 rm -fr "$R/var/cache/apt/pkgcache.bin"
23 rm -fr "$R/var/cache/apt/srcpkgcache.bin"
24 fi
25
26 # Remove all doc files
27 if [ "$REDUCE_DOC" = true ] ; then
28 find "$R/usr/share/doc" -depth -type f ! -name copyright | xargs rm || true
29 find "$R/usr/share/doc" -empty | xargs rmdir || true
30 fi
31
32 # Remove all man pages and info files
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"
35 fi
36
37 # Remove all locale translation files
38 if [ "$REDUCE_LOCALE" = true ] ; then
39 find "$R/usr/share/locale" -mindepth 1 -maxdepth 1 ! -name 'en' | xargs rm -r
40 fi
41
42 # Remove hwdb PCI device classes (experimental)
43 if [ "$REDUCE_HWDB" = true ] ; then
44 rm -fr "/lib/udev/hwdb.d/20-pci-*"
45 fi
46
47 # Replace bash shell by dash shell (experimental)
48 if [ "$REDUCE_BASH" = true ] ; then
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
51 fi
52
53 # Remove sound utils and libraries
54 if [ "$ENABLE_SOUND" = false ] ; then
55 chroot_exec apt-get -qq -y --force-yes purge alsa-utils libsamplerate0 libasound2 libasound2-data
56 fi
57
58 # Re-install tools for managing kernel moduless
59 chroot_exec apt-get -qq -y --force-yes install module-init-tools
60
61 # Remove GPU kernels
62 if [ "$ENABLE_MINGPU" = true ] ; then
63 rm -f "$R/boot/firmware/start.elf"
64 rm -f "$R/boot/firmware/fixup.dat"
65 rm -f "$R/boot/firmware/start_x.elf"
66 rm -f "$R/boot/firmware/fixup_x.dat"
67 fi
68
69 # Clean APT list of repositories
70 rm -fr "$R/var/lib/apt/lists/*"
71 chroot_exec apt-get -qq -y update
72 fi
@@ -1,243 +1,273
1 # rpi2-gen-image
1 # rpi2-gen-image
2 ## Introduction
2 ## Introduction
3 `rpi2-gen-image.sh` is an advanced Debian Linux bootstrapping shell script for generating Debian OS images for the Raspberry 2 (RPi2) computer. The script at this time only supports the bootstrapping of the current stable Debian 8 "jessie" release.
3 `rpi2-gen-image.sh` is an advanced Debian Linux bootstrapping shell script for generating Debian OS images for the Raspberry 2 (RPi2) computer. The script at this time only supports the bootstrapping of the current stable Debian 8 "jessie" release.
4
4
5 ## Build dependencies
5 ## Build dependencies
6 The following list of Debian packages must be installed on the build system because they are essentially required for the bootstrapping process. The script will check if all required packages are installed and missing packages will be installed automatically if confirmed by the user.
6 The following list of Debian packages must be installed on the build system because they are essentially required for the bootstrapping process. The script will check if all required packages are installed and missing packages will be installed automatically if confirmed by the user.
7
7
8 ```debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git-core```
8 ```debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git-core```
9
9
10 ## Command-line parameters
10 ## Command-line parameters
11 The script accepts certain command-line parameters to enable or disable specific OS features, services and configuration settings. These parameters are passed to the `rpi2-gen-image.sh` script via (simple) shell-variables. Unlike environment shell-variables (simple) shell-variables are defined at the beginning of the command-line call of the `rpi2-gen-image.sh` script.
11 The script accepts certain command-line parameters to enable or disable specific OS features, services and configuration settings. These parameters are passed to the `rpi2-gen-image.sh` script via (simple) shell-variables. Unlike environment shell-variables (simple) shell-variables are defined at the beginning of the command-line call of the `rpi2-gen-image.sh` script.
12
12
13 #####Command-line examples:
13 #####Command-line examples:
14 ```shell
14 ```shell
15 ENABLE_UBOOT=true ./rpi2-gen-image.sh
15 ENABLE_UBOOT=true ./rpi2-gen-image.sh
16 ENABLE_CONSOLE=false ENABLE_IPV6=false ./rpi2-gen-image.sh
16 ENABLE_CONSOLE=false ENABLE_IPV6=false ./rpi2-gen-image.sh
17 ENABLE_WM=xfce4 ENABLE_FBTURBO=true ENABLE_MINBASE=true ./rpi2-gen-image.sh
17 ENABLE_WM=xfce4 ENABLE_FBTURBO=true ENABLE_MINBASE=true ./rpi2-gen-image.sh
18 ENABLE_HARDNET=true ENABLE_IPTABLES=true /rpi2-gen-image.sh
18 ENABLE_HARDNET=true ENABLE_IPTABLES=true /rpi2-gen-image.sh
19 APT_SERVER=ftp.de.debian.org APT_PROXY="http://127.0.0.1:3142/" ./rpi2-gen-image.sh
19 APT_SERVER=ftp.de.debian.org APT_PROXY="http://127.0.0.1:3142/" ./rpi2-gen-image.sh
20 ENABLE_MINBASE=true ./rpi2-gen-image.sh
20 ENABLE_MINBASE=true ./rpi2-gen-image.sh
21 BUILD_KERNEL=true ENABLE_MINBASE=true ENABLE_IPV6=false ./rpi2-gen-image.sh
21 BUILD_KERNEL=true ENABLE_MINBASE=true ENABLE_IPV6=false ./rpi2-gen-image.sh
22 BUILD_KERNEL=true KERNELSRC_DIR=/tmp/linux ./rpi2-gen-image.sh
22 BUILD_KERNEL=true KERNELSRC_DIR=/tmp/linux ./rpi2-gen-image.sh
23 ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi2-gen-image.sh
23 ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi2-gen-image.sh
24 ```
24 ```
25
25
26 #### APT settings:
26 #### APT settings:
27 ##### `APT_SERVER`="ftp.debian.org"
27 ##### `APT_SERVER`="ftp.debian.org"
28 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.
28 Set Debian packages server address. Choose a server from the list of Debian worldwide [mirror sites](https://www.debian.org/mirror/list). Using a nearby server will probably speed-up all required downloads within the bootstrapping process.
29
29
30 ##### `APT_PROXY`=""
30 ##### `APT_PROXY`=""
31 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.
31 Set Proxy server address. Using a local Proxy-Cache like `apt-cacher-ng` will speed-up the bootstrapping process because all required Debian packages will only be downloaded from the Debian mirror site once.
32
32
33 ##### `APT_INCLUDES`=""
33 ##### `APT_INCLUDES`=""
34 A comma seperated list of additional packages to be installed during bootstrapping.
34 A comma seperated list of additional packages to be installed during bootstrapping.
35
35
36 #### General system settings:
36 #### General system settings:
37 ##### `HOSTNAME`="rpi2-jessie"
37 ##### `HOSTNAME`="rpi2-jessie"
38 Set system host name. It's recommended that the host name is unique in the corresponding subnet.
38 Set system host name. It's recommended that the host name is unique in the corresponding subnet.
39
39
40 ##### `PASSWORD`="raspberry"
40 ##### `PASSWORD`="raspberry"
41 Set system `root` password. The same password is used for the created user `pi`. It's **STRONGLY** recommended that you choose a custom password.
41 Set system `root` password. The same password is used for the created user `pi`. It's **STRONGLY** recommended that you choose a custom password.
42
42
43 ##### `DEFLOCAL`="en_US.UTF-8"
43 ##### `DEFLOCAL`="en_US.UTF-8"
44 Set default system locale. This setting can also be changed inside the running OS using the `dpkg-reconfigure locales` command. The script variant `minbase` (ENABLE_MINBASE=true) doesn't install `locales`.
44 Set default system locale. This setting can also be changed inside the running OS using the `dpkg-reconfigure locales` command. The script variant `minbase` (ENABLE_MINBASE=true) doesn't install `locales`.
45
45
46 ##### `TIMEZONE`="Europe/Berlin"
46 ##### `TIMEZONE`="Europe/Berlin"
47 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.
47 Set default system timezone. All available timezones can be found in the `/usr/share/zoneinfo/` directory. This setting can also be changed inside the running OS using the `dpkg-reconfigure tzdata` command.
48
48
49 ##### `EXPANDROOT`=true
49 ##### `EXPANDROOT`=true
50 Expand the root partition and filesystem automatically on first boot.
50 Expand the root partition and filesystem automatically on first boot.
51
51
52 #### Keyboard settings:
52 #### Keyboard settings:
53 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.
53 These options are used to configure keyboard layout in `/etc/default/keyboard` for console and Xorg. These settings can also be changed inside the running OS using the `dpkg-reconfigure keyboard-configuration` command.
54
54
55 ##### `XKB_MODEL`=""
55 ##### `XKB_MODEL`=""
56 Set the name of the model of your keyboard type.
56 Set the name of the model of your keyboard type.
57
57
58 ##### `XKB_LAYOUT`=""
58 ##### `XKB_LAYOUT`=""
59 Set the supported keyboard layout(s).
59 Set the supported keyboard layout(s).
60
60
61 ##### `XKB_VARIANT`=""
61 ##### `XKB_VARIANT`=""
62 Set the supported variant(s) of the keyboard layout(s).
62 Set the supported variant(s) of the keyboard layout(s).
63
63
64 ##### `XKB_OPTIONS`=""
64 ##### `XKB_OPTIONS`=""
65 Set extra xkb configuration options.
65 Set extra xkb configuration options.
66
66
67 #### Networking settings (DHCP):
67 #### Networking settings (DHCP):
68 This setting is used to set up networking auto configuration in `/etc/systemd/network/eth.network`.
68 This setting is used to set up networking auto configuration in `/etc/systemd/network/eth.network`.
69
69
70 #####`ENABLE_DHCP`=true
70 #####`ENABLE_DHCP`=true
71 Set the system to use DHCP. This requires an DHCP server.
71 Set the system to use DHCP. This requires an DHCP server.
72
72
73 #### Networking settings (static):
73 #### Networking settings (static):
74 These settings are used to set up a static networking configuration in /etc/systemd/network/eth.network. The following static networking settings are only supported if `ENABLE_DHCP` was set to `false`.
74 These settings are used to set up a static networking configuration in /etc/systemd/network/eth.network. The following static networking settings are only supported if `ENABLE_DHCP` was set to `false`.
75
75
76 #####`NET_ADDRESS`=""
76 #####`NET_ADDRESS`=""
77 Set a static IPv4 or IPv6 address and its prefix, separated by "/", eg. "192.169.0.3/24".
77 Set a static IPv4 or IPv6 address and its prefix, separated by "/", eg. "192.169.0.3/24".
78
78
79 #####`NET_GATEWAY`=""
79 #####`NET_GATEWAY`=""
80 Set the IP address for the default gateway.
80 Set the IP address for the default gateway.
81
81
82 #####`NET_DNS_1`=""
82 #####`NET_DNS_1`=""
83 Set the IP address for the first DNS server.
83 Set the IP address for the first DNS server.
84
84
85 #####`NET_DNS_2`=""
85 #####`NET_DNS_2`=""
86 Set the IP address for the second DNS server.
86 Set the IP address for the second DNS server.
87
87
88 #####`NET_DNS_DOMAINS`=""
88 #####`NET_DNS_DOMAINS`=""
89 Set the default DNS search domains to use for non fully qualified host names.
89 Set the default DNS search domains to use for non fully qualified host names.
90
90
91 #####`NET_NTP_1`=""
91 #####`NET_NTP_1`=""
92 Set the IP address for the first NTP server.
92 Set the IP address for the first NTP server.
93
93
94 #####`NET_NTP_2`=""
94 #####`NET_NTP_2`=""
95 Set the IP address for the second NTP server.
95 Set the IP address for the second NTP server.
96
96
97 #### Basic system features:
97 #### Basic system features:
98 ##### `ENABLE_CONSOLE`=true
98 ##### `ENABLE_CONSOLE`=true
99 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.
99 Enable serial console interface. Recommended if no monitor or keyboard is connected to the RPi2. In case of problems fe. if the network (auto) configuration failed - the serial console can be used to access the system.
100
100
101 ##### `ENABLE_IPV6`=true
101 ##### `ENABLE_IPV6`=true
102 Enable IPv6 support. The network interface configuration is managed via systemd-networkd.
102 Enable IPv6 support. The network interface configuration is managed via systemd-networkd.
103
103
104 ##### `ENABLE_SSHD`=true
104 ##### `ENABLE_SSHD`=true
105 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.
105 Install and enable OpenSSH service. The default configuration of the service doesn't allow `root` to login. Please use the user `pi` instead and `su -` or `sudo` to execute commands as root.
106
106
107 ##### `ENABLE_RSYSLOG`=true
107 ##### `ENABLE_RSYSLOG`=true
108 If set to false, disable and uninstall rsyslog (so logs will be available only
108 If set to false, disable and uninstall rsyslog (so logs will be available only
109 in journal files)
109 in journal files)
110
110
111 ##### `ENABLE_SOUND`=true
111 ##### `ENABLE_SOUND`=true
112 Enable sound hardware and install Advanced Linux Sound Architecture.
112 Enable sound hardware and install Advanced Linux Sound Architecture.
113
113
114 ##### `ENABLE_HWRANDOM`=true
114 ##### `ENABLE_HWRANDOM`=true
115 Enable Hardware Random Number Generator. Strong random numbers are important for most network based communications that use encryption. It's recommended to be enabled.
115 Enable Hardware Random Number Generator. Strong random numbers are important for most network based communications that use encryption. It's recommended to be enabled.
116
116
117 ##### `ENABLE_MINGPU`=false
117 ##### `ENABLE_MINGPU`=false
118 Minimize the amount of shared memory reserved for the GPU. It doesn't seem to be possible to fully disable the GPU.
118 Minimize the amount of shared memory reserved for the GPU. It doesn't seem to be possible to fully disable the GPU.
119
119
120 ##### `ENABLE_DBUS`=true
120 ##### `ENABLE_DBUS`=true
121 Install and enable D-Bus message bus. Please note that systemd should work without D-bus but it's recommended to be enabled.
121 Install and enable D-Bus message bus. Please note that systemd should work without D-bus but it's recommended to be enabled.
122
122
123 ##### `ENABLE_XORG`=false
123 ##### `ENABLE_XORG`=false
124 Install Xorg open-source X Window System.
124 Install Xorg open-source X Window System.
125
125
126 ##### `ENABLE_WM`=""
126 ##### `ENABLE_WM`=""
127 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`.
127 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`.
128
128
129 #### Advanced system features:
129 #### Advanced system features:
130 ##### `ENABLE_MINBASE`=false
130 ##### `ENABLE_MINBASE`=false
131 Use debootstrap script variant `minbase` which only includes essential packages and apt. This will reduce the disk usage by about 65 MB.
131 Use debootstrap script variant `minbase` which only includes essential packages and apt. This will reduce the disk usage by about 65 MB.
132
132
133 ##### `ENABLE_REDUCE`=false
133 ##### `ENABLE_REDUCE`=false
134 Reduce the disk usage by deleting all man pages and doc files (harsh). APT will be configured to use compressed package repository lists and no package caching files. If `ENABLE_MINGPU`=true unnecessary start.elf and fixup.dat files will also be removed from the boot partition. This will make it possible to generate output OS images with about 160MB of used disk space. It's recommended to use this parameter in combination with `ENABLE_MINBASE`=true.
134 Reduce the disk usage by deleting packages and files. See `REDUCE_*` parameters for detailed information.
135
135
136 ##### `ENABLE_UBOOT`=false
136 ##### `ENABLE_UBOOT`=false
137 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.
137 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.
138
138
139 ##### `ENABLE_FBTURBO`=false
139 ##### `ENABLE_FBTURBO`=false
140 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.
140 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.
141
141
142 ##### `ENABLE_IPTABLES`=false
142 ##### `ENABLE_IPTABLES`=false
143 Enable iptables IPv4/IPv6 firewall. Simplified ruleset: Allow all outgoing connections. Block all incoming connections except to OpenSSH service.
143 Enable iptables IPv4/IPv6 firewall. Simplified ruleset: Allow all outgoing connections. Block all incoming connections except to OpenSSH service.
144
144
145 ##### `ENABLE_USER`=true
145 ##### `ENABLE_USER`=true
146 Create pi user with password raspberry
146 Create pi user with password raspberry
147
147
148 ##### `ENABLE_ROOT`=true
148 ##### `ENABLE_ROOT`=true
149 Set root user password so root login will be enabled
149 Set root user password so root login will be enabled
150
150
151 ##### `ENABLE_ROOT_SSH`=true
151 ##### `ENABLE_ROOT_SSH`=true
152 Enable password root login via SSH. May be a security risk with default
152 Enable password root login via SSH. May be a security risk with default
153 password, use only in trusted environments.
153 password, use only in trusted environments.
154
154
155 ##### `ENABLE_HARDNET`=false
155 ##### `ENABLE_HARDNET`=false
156 Enable IPv4/IPv6 network stack hardening settings.
156 Enable IPv4/IPv6 network stack hardening settings.
157
157
158 ##### `ENABLE_SPLITFS`=false
158 ##### `ENABLE_SPLITFS`=false
159 Enable having root partition on an USB drive by creating two image files: one for the `/boot/firmware` mount point, and another for `/`.
159 Enable having root partition on an USB drive by creating two image files: one for the `/boot/firmware` mount point, and another for `/`.
160
160
161 ##### `CHROOT_SCRIPTS`=""
161 ##### `CHROOT_SCRIPTS`=""
162 Path to a directory with scripts that should be run in the chroot before the image is finally built. Every executable file in this direcory is run in lexicographical order.
162 Path to a directory with scripts that should be run in the chroot before the image is finally built. Every executable file in this direcory is run in lexicographical order.
163
163
164 #### Kernel compilation:
164 #### Kernel compilation:
165 ##### `BUILD_KERNEL`=false
165 ##### `BUILD_KERNEL`=false
166 Build and install the latest RPi2 Linux kernel. Currently only the default RPi2 kernel configuration is used. Detailed configuration parameters for customizing the kernel and minor bug fixes still need to get implemented. feel free to help.
166 Build and install the latest RPi2 Linux kernel. Currently only the default RPi2 kernel configuration is used. Detailed configuration parameters for customizing the kernel and minor bug fixes still need to get implemented. feel free to help.
167
167
168 ##### `KERNEL_REDUCE`=false
169 Reduce the size of the generated kernel by removing unwanted device, network and filesystem drivers (experimental).
170
168 ##### `KERNEL_THREADS`=1
171 ##### `KERNEL_THREADS`=1
169 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.
172 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.
170
173
171 ##### `KERNEL_HEADERS`=true
174 ##### `KERNEL_HEADERS`=true
172 Install kernel headers with built kernel.
175 Install kernel headers with built kernel.
173
176
174 ##### `KERNEL_MENUCONFIG`=false
177 ##### `KERNEL_MENUCONFIG`=false
175 Start `make menuconfig` interactive menu-driven kernel configuration. The script will continue after `make menuconfig` was terminated.
178 Start `make menuconfig` interactive menu-driven kernel configuration. The script will continue after `make menuconfig` was terminated.
176
179
177 ##### `KERNEL_REMOVESRC`=true
180 ##### `KERNEL_REMOVESRC`=true
178 Remove all kernel sources from the generated OS image after it was built and installed.
181 Remove all kernel sources from the generated OS image after it was built and installed.
179
182
180 ##### `KERNELSRC_DIR`=""
183 ##### `KERNELSRC_DIR`=""
181 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.
184 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.
182
185
183 ##### `KERNELSRC_CLEAN`=false
186 ##### `KERNELSRC_CLEAN`=false
184 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 setting will be ignored if no `KERNELSRC_DIR` was specified or if `KERNELSRC_PREBUILT`=true.
187 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 setting will be ignored if no `KERNELSRC_DIR` was specified or if `KERNELSRC_PREBUILT`=true.
185
188
186 ##### `KERNELSRC_CONFIG`=true
189 ##### `KERNELSRC_CONFIG`=true
187 Run `make bcm2709_defconfig` (and optional `make menuconfig`) to configure the kernel sources before building. This setting is automatically set to `true` if no existing kernel sources directory was specified using `KERNELSRC_DIR`. This settings is ignored if `KERNELSRC_PREBUILT`=true.
190 Run `make bcm2709_defconfig` (and optional `make menuconfig`) to configure the kernel sources before building. This setting is automatically set to `true` if no existing kernel sources directory was specified using `KERNELSRC_DIR`. This settings is ignored if `KERNELSRC_PREBUILT`=true.
188
191
189 ##### `KERNELSRC_PREBUILT`=false
192 ##### `KERNELSRC_PREBUILT`=false
190 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.
193 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.
191
194
195 #### Reduce disk usage:
196 The following list of parameters is ignored if `ENABLE_REDUCE`=false.
197
198 ##### `REDUCE_APT`=true
199 Configure APT to use compressed package repository lists and no package caching files.
200
201 ##### `REDUCE_DOC`=true
202 Remove all doc files (harsh). Configure APT to not include doc files on future `apt-get` package installations.
203
204 ##### `REDUCE_MAN`=true
205 Remove all man pages and info files (harsh). Configure APT to not include man pages on future `apt-get` package installations.
206
207 ##### `REDUCE_VIM`=true
208 Replace `vim-tiny` package by `levee` a tiny vim clone.
209
210 ##### `REDUCE_BASH`=false
211 Remove `bash` package and switch to `dash` shell (experimental).
212
213 ##### `REDUCE_HWDB`=true
214 Remove PCI related hwdb files (experimental).
215
216 ##### `REDUCE_SSHD`=true
217 Replace `openssh-server` with dropbear.
218
219 ##### `REDUCE_LOCALE`=true
220 Remove all `locale` translation files.
221
192 ## Understanding the script
222 ## Understanding the script
193 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:
223 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:
194
224
195 | Script | Description |
225 | Script | Description |
196 | --- | --- |
226 | --- | --- |
197 | `10-bootstrap.sh` | Debootstrap basic system |
227 | `10-bootstrap.sh` | Debootstrap basic system |
198 | `11-apt.sh` | Setup APT repositories |
228 | `11-apt.sh` | Setup APT repositories |
199 | `12-locale.sh` | Setup Locales and keyboard settings |
229 | `12-locale.sh` | Setup Locales and keyboard settings |
200 | `13-kernel.sh` | Build and install RPi2 Kernel |
230 | `13-kernel.sh` | Build and install RPi2 Kernel |
201 | `20-networking.sh` | Setup Networking |
231 | `20-networking.sh` | Setup Networking |
202 | `21-firewall.sh` | Setup Firewall |
232 | `21-firewall.sh` | Setup Firewall |
203 | `30-security.sh` | Setup Users and Security settings |
233 | `30-security.sh` | Setup Users and Security settings |
204 | `31-logging.sh` | Setup Logging |
234 | `31-logging.sh` | Setup Logging |
205 | `41-uboot.sh` | Build and Setup U-Boot |
235 | `41-uboot.sh` | Build and Setup U-Boot |
206 | `42-fbturbo.sh` | Build and Setup fbturbo Xorg driver |
236 | `42-fbturbo.sh` | Build and Setup fbturbo Xorg driver |
207 | `50-firstboot.sh` | First boot actions |
237 | `50-firstboot.sh` | First boot actions |
208
238
209 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.
239 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.
210
240
211 | Directory | Description |
241 | Directory | Description |
212 | --- | --- |
242 | --- | --- |
213 | `boot` | Boot and RPi2 configuration files |
243 | `boot` | Boot and RPi2 configuration files |
214 | `dpkg` | Package Manager configuration |
244 | `dpkg` | Package Manager configuration |
215 | `firstboot` | Scripts that get executed on first boot |
245 | `firstboot` | Scripts that get executed on first boot |
216 | `iptables` | Firewall configuration files |
246 | `iptables` | Firewall configuration files |
217 | `locales` | Locales configuration |
247 | `locales` | Locales configuration |
218 | `modules` | Kernel Modules configuration |
248 | `modules` | Kernel Modules configuration |
219 | `mount` | Fstab configuration |
249 | `mount` | Fstab configuration |
220 | `network` | Networking configuration files |
250 | `network` | Networking configuration files |
221 | `sysctl.d` | Swapping and Network Hardening configuration |
251 | `sysctl.d` | Swapping and Network Hardening configuration |
222 | `xorg` | fbturbo Xorg driver configuration |
252 | `xorg` | fbturbo Xorg driver configuration |
223
253
224 ## Logging of the bootstrapping process
254 ## Logging of the bootstrapping process
225 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:
255 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:
226
256
227 ```shell
257 ```shell
228 script -c 'APT_SERVER=ftp.de.debian.org ./rpi2-gen-image.sh' ./build.log
258 script -c 'APT_SERVER=ftp.de.debian.org ./rpi2-gen-image.sh' ./build.log
229 ```
259 ```
230
260
231 ## Flashing the image file
261 ## Flashing the image file
232 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`.
262 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`.
233
263
234 #####Flashing examples:
264 #####Flashing examples:
235 ```shell
265 ```shell
236 bmaptool copy ./images/jessie/2015-12-13-debian-jessie.img /dev/mmcblk0
266 bmaptool copy ./images/jessie/2015-12-13-debian-jessie.img /dev/mmcblk0
237 dd bs=4M if=./images/jessie/2015-12-13-debian-jessie.img of=/dev/mmcblk0
267 dd bs=4M if=./images/jessie/2015-12-13-debian-jessie.img of=/dev/mmcblk0
238 ```
268 ```
239 If you have set `ENABLE_SPLITFS`, copy the `-frmw` image on the microSD card, then the `-root` one on the USB drive:
269 If you have set `ENABLE_SPLITFS`, copy the `-frmw` image on the microSD card, then the `-root` one on the USB drive:
240 ```shell
270 ```shell
241 bmaptool copy ./images/jessie/2015-12-13-debian-jessie-frmw.img /dev/mmcblk0
271 bmaptool copy ./images/jessie/2015-12-13-debian-jessie-frmw.img /dev/mmcblk0
242 bmaptool copy ./images/jessie/2015-12-13-debian-jessie-root.img /dev/sdc
272 bmaptool copy ./images/jessie/2015-12-13-debian-jessie-root.img /dev/sdc
243 ```
273 ```
@@ -1,28 +1,28
1 #
1 #
2 # Debootstrap basic system
2 # Debootstrap basic system
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 # Base debootstrap (unpack only)
8 # Base debootstrap (unpack only)
9 if [ "$ENABLE_MINBASE" = true ] ; then
9 if [ "$ENABLE_MINBASE" = true ] ; then
10 http_proxy=${APT_PROXY} debootstrap --arch="${RELEASE_ARCH}" --variant=minbase --foreign --include="${APT_INCLUDES}" "${RELEASE}" "$R" "http://${APT_SERVER}/debian"
10 http_proxy=${APT_PROXY} debootstrap --arch="${RELEASE_ARCH}" --foreign --variant=minbase --include="${APT_INCLUDES}" "${RELEASE}" "$R" "http://${APT_SERVER}/debian"
11 else
11 else
12 http_proxy=${APT_PROXY} debootstrap --arch="${RELEASE_ARCH}" --foreign --include="${APT_INCLUDES}" "${RELEASE}" "$R" "http://${APT_SERVER}/debian"
12 http_proxy=${APT_PROXY} debootstrap --arch="${RELEASE_ARCH}" --foreign --include="${APT_INCLUDES}" "${RELEASE}" "$R" "http://${APT_SERVER}/debian"
13 fi
13 fi
14
14
15 # Copy qemu emulator binary to chroot
15 # Copy qemu emulator binary to chroot
16 cp "${QEMU_BINARY}" "$R/usr/bin"
16 cp "${QEMU_BINARY}" "$R/usr/bin"
17
17
18 # Copy debian-archive-keyring.pgp
18 # Copy debian-archive-keyring.pgp
19 mkdir -p "$R/usr/share/keyrings"
19 mkdir -p "$R/usr/share/keyrings"
20 cp /usr/share/keyrings/debian-archive-keyring.gpg "$R/usr/share/keyrings/debian-archive-keyring.gpg"
20 cp /usr/share/keyrings/debian-archive-keyring.gpg "$R/usr/share/keyrings/debian-archive-keyring.gpg"
21
21
22 # Complete the bootstrapping process
22 # Complete the bootstrapping process
23 chroot_exec /debootstrap/debootstrap --second-stage
23 chroot_exec /debootstrap/debootstrap --second-stage
24
24
25 # Mount required filesystems
25 # Mount required filesystems
26 mount -t proc none "$R/proc"
26 mount -t proc none "$R/proc"
27 mount -t sysfs none "$R/sys"
27 mount -t sysfs none "$R/sys"
28 mount --bind /dev/pts "$R/dev/pts"
28 mount --bind /dev/pts "$R/dev/pts"
@@ -1,163 +1,200
1 #
1 #
2 # Build and Setup RPi2 Kernel
2 # Build and Setup RPi2 Kernel
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 # Fetch and build latest raspberry kernel
8 # Fetch and build latest raspberry kernel
9 if [ "$BUILD_KERNEL" = true ] ; then
9 if [ "$BUILD_KERNEL" = true ] ; then
10 # Setup source directory
10 # Setup source directory
11 mkdir -p "$R/usr/src"
11 mkdir -p "$R/usr/src"
12
12
13 # Copy existing kernel sources into chroot directory
13 # Copy existing kernel sources into chroot directory
14 if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then
14 if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then
15 # Copy kernel sources
15 # Copy kernel sources
16 cp -r "${KERNELSRC_DIR}" "${R}/usr/src"
16 cp -r "${KERNELSRC_DIR}" "${R}/usr/src"
17
17
18 # Clean the kernel sources
18 # Clean the kernel sources
19 if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then
19 if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then
20 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" mrproper
20 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" mrproper
21 fi
21 fi
22 else # KERNELSRC_DIR=""
22 else # KERNELSRC_DIR=""
23 # Fetch current raspberrypi kernel sources
23 # Fetch current raspberrypi kernel sources
24 git -C "$R/usr/src" clone --depth=1 https://github.com/raspberrypi/linux
24 git -C "$R/usr/src" clone --depth=1 https://github.com/raspberrypi/linux
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 if [ "$KERNELSRC_PREBUILT" = false ] ; then
33 if [ "$KERNELSRC_PREBUILT" = false ] ; then
34 # Remove device, network and filesystem drivers from kernel configuration
35 if [ "$KERNEL_REDUCE" = true ] ; then
36 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
37 sed -i\
38 -e "s/\(^CONFIG_SND.*\=\).*/\1n/"\
39 -e "s/\(^CONFIG_SOUND.*\=\).*/\1n/"\
40 -e "s/\(^CONFIG_AC97.*\=\).*/\1n/"\
41 -e "s/\(^CONFIG_VIDEO_.*\=\).*/\1n/"\
42 -e "s/\(^CONFIG_MEDIA_TUNER.*\=\).*/\1n/"\
43 -e "s/\(^CONFIG_DVB.*\=\)[ym]/\1n/"\
44 -e "s/\(^CONFIG_REISERFS.*\=\).*/\1n/"\
45 -e "s/\(^CONFIG_JFS.*\=\).*/\1n/"\
46 -e "s/\(^CONFIG_XFS.*\=\).*/\1n/"\
47 -e "s/\(^CONFIG_GFS2.*\=\).*/\1n/"\
48 -e "s/\(^CONFIG_OCFS2.*\=\).*/\1n/"\
49 -e "s/\(^CONFIG_BTRFS.*\=\).*/\1n/"\
50 -e "s/\(^CONFIG_HFS.*\=\).*/\1n/"\
51 -e "s/\(^CONFIG_JFFS2.*\=\)[ym]/\1n/"\
52 -e "s/\(^CONFIG_UBIFS.*\=\).*/\1n/"\
53 -e "s/\(^CONFIG_SQUASHFS.*\=\)[ym]/\1n/"\
54 -e "s/\(^CONFIG_W1.*\=\)[ym]/\1n/"\
55 -e "s/\(^CONFIG_HAMRADIO.*\=\).*/\1n/"\
56 -e "s/\(^CONFIG_CAN.*\=\).*/\1n/"\
57 -e "s/\(^CONFIG_IRDA.*\=\).*/\1n/"\
58 -e "s/\(^CONFIG_BT_.*\=\).*/\1n/"\
59 -e "s/\(^CONFIG_WIMAX.*\=\)[ym]/\1n/"\
60 -e "s/\(^CONFIG_6LOWPAN.*\=\).*/\1n/"\
61 -e "s/\(^CONFIG_IEEE802154.*\=\).*/\1n/"\
62 -e "s/\(^CONFIG_NFC.*\=\).*/\1n/"\
63 -e "s/\(^CONFIG_FB_TFT=.*\=\).*/\1n/"\
64 -e "s/\(^CONFIG_TOUCHSCREEN.*\=\).*/\1n/"\
65 -e "s/\(^CONFIG_USB_GSPCA_.*\=\).*/\1n/"\
66 -e "s/\(^CONFIG_DRM.*\=\).*/\1n/"\
67 "$R/usr/src/linux/.config"
68 fi
69
33 if [ "$KERNELSRC_CONFIG" = true ] ; then
70 if [ "$KERNELSRC_CONFIG" = true ] ; then
34 # Load default raspberry kernel configuration
71 # Load default raspberry kernel configuration
35 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
72 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
36
73
37 # Start menu-driven kernel configuration (interactive)
74 # Start menu-driven kernel configuration (interactive)
38 if [ "$KERNEL_MENUCONFIG" = true ] ; then
75 if [ "$KERNEL_MENUCONFIG" = true ] ; then
39 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig
76 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig
40 fi
77 fi
41 fi
78 fi
42
79
43 # Cross compile kernel and modules
80 # Cross compile kernel and modules
44 make -C "$R/usr/src/linux" -j${KERNEL_THREADS} ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" zImage modules dtbs
81 make -C "$R/usr/src/linux" -j${KERNEL_THREADS} ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" zImage modules dtbs
45 fi
82 fi
46
83
47 # Check if kernel compilation was successful
84 # Check if kernel compilation was successful
48 if [ ! -r "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/zImage" ] ; then
85 if [ ! -r "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/zImage" ] ; then
49 echo "error: kernel compilation failed! (zImage not found)"
86 echo "error: kernel compilation failed! (zImage not found)"
50 cleanup
87 cleanup
51 exit 1
88 exit 1
52 fi
89 fi
53
90
54 # Install kernel modules
91 # Install kernel modules
55 if [ "$ENABLE_REDUCE" = true ] ; then
92 if [ "$ENABLE_REDUCE" = true ] ; then
56 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install
93 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install
57 else
94 else
58 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install
95 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install
59
96
60 # Install kernel firmware
97 # Install kernel firmware
61 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install
98 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install
62 fi
99 fi
63
100
64 # Install kernel headers
101 # Install kernel headers
65 if [ "$KERNEL_HEADERS" = true ] ; then
102 if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then
66 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install
103 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install
67 fi
104 fi
68
105
69 # Prepare boot (firmware) directory
106 # Prepare boot (firmware) directory
70 mkdir "$R/boot/firmware/"
107 mkdir "$R/boot/firmware/"
71
108
72 # Get kernel release version
109 # Get kernel release version
73 KERNEL_VERSION=`cat "$R/usr/src/linux/include/config/kernel.release"`
110 KERNEL_VERSION=`cat "$R/usr/src/linux/include/config/kernel.release"`
74
111
75 # Copy kernel configuration file to the boot directory
112 # Copy kernel configuration file to the boot directory
76 cp "$R/usr/src/linux/.config" "$R/boot/config-${KERNEL_VERSION}"
113 cp "$R/usr/src/linux/.config" "$R/boot/config-${KERNEL_VERSION}"
77
114
78 # Copy dts and dtb device tree sources and binaries
115 # Copy dts and dtb device tree sources and binaries
79 mkdir "$R/boot/firmware/overlays/"
116 mkdir "$R/boot/firmware/overlays/"
80 cp "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/dts/"*.dtb "$R/boot/firmware/"
117 cp "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/dts/"*.dtb "$R/boot/firmware/"
81 cp "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb* "$R/boot/firmware/overlays/"
118 cp "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb* "$R/boot/firmware/overlays/"
82 cp "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "$R/boot/firmware/overlays/"
119 cp "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "$R/boot/firmware/overlays/"
83
120
84 # Convert kernel zImage and copy it to the boot directory
121 # Convert kernel zImage and copy it to the boot directory
85 "$R/usr/src/linux/scripts/mkknlimg" "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/zImage" "$R/boot/firmware/kernel7.img"
122 "$R/usr/src/linux/scripts/mkknlimg" "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/zImage" "$R/boot/firmware/kernel7.img"
86
123
87 # Remove kernel sources
124 # Remove kernel sources
88 if [ "$KERNEL_REMOVESRC" = true ] ; then
125 if [ "$KERNEL_REMOVESRC" = true ] ; then
89 rm -fr "$R/usr/src/linux"
126 rm -fr "$R/usr/src/linux"
90 fi
127 fi
91
128
92 # Install raspberry bootloader and flash-kernel packages
129 # Install raspberry bootloader and flash-kernel packages
93 chroot_exec apt-get -qq -y --no-install-recommends install raspberrypi-bootloader-nokernel
130 chroot_exec apt-get -qq -y --no-install-recommends install raspberrypi-bootloader-nokernel
94 else # BUILD_KERNEL=false
131 else # BUILD_KERNEL=false
95 # Kernel installation
132 # Kernel installation
96 chroot_exec apt-get -qq -y --no-install-recommends install linux-image-"${COLLABORA_KERNEL}" raspberrypi-bootloader-nokernel
133 chroot_exec apt-get -qq -y --no-install-recommends install linux-image-"${COLLABORA_KERNEL}" raspberrypi-bootloader-nokernel
97
134
98 # Install flash-kernel last so it doesn't try (and fail) to detect the platform in the chroot
135 # Install flash-kernel last so it doesn't try (and fail) to detect the platform in the chroot
99 chroot_exec apt-get -qq -y install flash-kernel
136 chroot_exec apt-get -qq -y install flash-kernel
100
137
101 VMLINUZ="$(ls -1 $R/boot/vmlinuz-* | sort | tail -n 1)"
138 VMLINUZ="$(ls -1 $R/boot/vmlinuz-* | sort | tail -n 1)"
102 [ -z "$VMLINUZ" ] && exit 1
139 [ -z "$VMLINUZ" ] && exit 1
103 cp "$VMLINUZ" "$R/boot/firmware/kernel7.img"
140 cp "$VMLINUZ" "$R/boot/firmware/kernel7.img"
104 fi
141 fi
105
142
106 # Setup firmware boot cmdline
143 # Setup firmware boot cmdline
107 if [ "$ENABLE_SPLITFS" = true ] ; then
144 if [ "$ENABLE_SPLITFS" = true ] ; then
108 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait net.ifnames=1 console=tty1 ${CMDLINE}"
145 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/sda1 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait net.ifnames=1 console=tty1 ${CMDLINE}"
109 else
146 else
110 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait net.ifnames=1 console=tty1 ${CMDLINE}"
147 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait net.ifnames=1 console=tty1 ${CMDLINE}"
111 fi
148 fi
112
149
113 # Add serial console support
150 # Add serial console support
114 if [ "$ENABLE_CONSOLE" = true ] ; then
151 if [ "$ENABLE_CONSOLE" = true ] ; then
115 CMDLINE="${CMDLINE} console=ttyAMA0,115200 kgdboc=ttyAMA0,115200"
152 CMDLINE="${CMDLINE} console=ttyAMA0,115200 kgdboc=ttyAMA0,115200"
116 fi
153 fi
117
154
118 # Remove IPv6 networking support
155 # Remove IPv6 networking support
119 if [ "$ENABLE_IPV6" = false ] ; then
156 if [ "$ENABLE_IPV6" = false ] ; then
120 CMDLINE="${CMDLINE} ipv6.disable=1"
157 CMDLINE="${CMDLINE} ipv6.disable=1"
121 fi
158 fi
122
159
123 # Install firmware boot cmdline
160 # Install firmware boot cmdline
124 echo "${CMDLINE}" > "$R/boot/firmware/cmdline.txt"
161 echo "${CMDLINE}" > "$R/boot/firmware/cmdline.txt"
125
162
126 # Install firmware config
163 # Install firmware config
127 install_readonly files/boot/config.txt "$R/boot/firmware/config.txt"
164 install_readonly files/boot/config.txt "$R/boot/firmware/config.txt"
128
165
129 # Setup minimal GPU memory allocation size: 16MB (no X)
166 # Setup minimal GPU memory allocation size: 16MB (no X)
130 if [ "$ENABLE_MINGPU" = true ] ; then
167 if [ "$ENABLE_MINGPU" = true ] ; then
131 echo "gpu_mem=16" >> "$R/boot/firmware/config.txt"
168 echo "gpu_mem=16" >> "$R/boot/firmware/config.txt"
132 fi
169 fi
133
170
134 # Create firmware configuration and cmdline symlinks
171 # Create firmware configuration and cmdline symlinks
135 ln -sf firmware/config.txt "$R/boot/config.txt"
172 ln -sf firmware/config.txt "$R/boot/config.txt"
136 ln -sf firmware/cmdline.txt "$R/boot/cmdline.txt"
173 ln -sf firmware/cmdline.txt "$R/boot/cmdline.txt"
137
174
138 # Install and setup kernel modules to load at boot
175 # Install and setup kernel modules to load at boot
139 mkdir -p "$R/lib/modules-load.d/"
176 mkdir -p "$R/lib/modules-load.d/"
140 install_readonly files/modules/rpi2.conf "$R/lib/modules-load.d/rpi2.conf"
177 install_readonly files/modules/rpi2.conf "$R/lib/modules-load.d/rpi2.conf"
141
178
142 # Load hardware random module at boot
179 # Load hardware random module at boot
143 if [ "$ENABLE_HWRANDOM" = true ] ; then
180 if [ "$ENABLE_HWRANDOM" = true ] ; then
144 sed -i "s/^# bcm2708_rng/bcm2708_rng/" "$R/lib/modules-load.d/rpi2.conf"
181 sed -i "s/^# bcm2708_rng/bcm2708_rng/" "$R/lib/modules-load.d/rpi2.conf"
145 fi
182 fi
146
183
147 # Load sound module at boot
184 # Load sound module at boot
148 if [ "$ENABLE_SOUND" = true ] ; then
185 if [ "$ENABLE_SOUND" = true ] ; then
149 sed -i "s/^# snd_bcm2835/snd_bcm2835/" "$R/lib/modules-load.d/rpi2.conf"
186 sed -i "s/^# snd_bcm2835/snd_bcm2835/" "$R/lib/modules-load.d/rpi2.conf"
150 fi
187 fi
151
188
152 # Install kernel modules blacklist
189 # Install kernel modules blacklist
153 mkdir -p "$R/etc/modprobe.d/"
190 mkdir -p "$R/etc/modprobe.d/"
154 install_readonly files/modules/raspi-blacklist.conf "$R/etc/modprobe.d/raspi-blacklist.conf"
191 install_readonly files/modules/raspi-blacklist.conf "$R/etc/modprobe.d/raspi-blacklist.conf"
155
192
156 # Install and setup fstab
193 # Install and setup fstab
157 install_readonly files/mount/fstab "$R/etc/fstab"
194 install_readonly files/mount/fstab "$R/etc/fstab"
158 if [ "$ENABLE_SPLITFS" = true ] ; then
195 if [ "$ENABLE_SPLITFS" = true ] ; then
159 sed -i 's/mmcblk0p2/sda1/' "$R/etc/fstab"
196 sed -i 's/mmcblk0p2/sda1/' "$R/etc/fstab"
160 fi
197 fi
161
198
162 # Install sysctl.d configuration files
199 # Install sysctl.d configuration files
163 install_readonly files/sysctl.d/81-rpi-vm.conf "$R/etc/sysctl.d/81-rpi-vm.conf"
200 install_readonly files/sysctl.d/81-rpi-vm.conf "$R/etc/sysctl.d/81-rpi-vm.conf"
@@ -1,35 +1,35
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 > "$R/etc/rc.firstboot"
9 cat files/firstboot/10-begin.sh > "$R/etc/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 ] && [ "$ENABLE_REDUCE" = false ]; then
13 cat files/firstboot/21-generate-ssh-keys.sh >> "$R/etc/rc.firstboot"
13 cat files/firstboot/21-generate-ssh-keys.sh >> "$R/etc/rc.firstboot"
14 rm -f "$R/etc/ssh/ssh_host_*"
14 rm -f "$R/etc/ssh/ssh_host_*"
15 fi
15 fi
16
16
17 # Prepare filesystem auto expand
17 # Prepare filesystem auto expand
18 if [ "$EXPANDROOT" = true ] ; then
18 if [ "$EXPANDROOT" = true ] ; then
19 cat files/firstboot/22-expandroot.sh >> "$R/etc/rc.firstboot"
19 cat files/firstboot/22-expandroot.sh >> "$R/etc/rc.firstboot"
20 fi
20 fi
21
21
22 # Ensure that dbus machine-id exists
22 # Ensure that dbus machine-id exists
23 cat files/firstboot/23-generate-machineid.sh >> "$R/etc/rc.firstboot"
23 cat files/firstboot/23-generate-machineid.sh >> "$R/etc/rc.firstboot"
24
24
25 # Create /etc/resolv.conf symlink
25 # Create /etc/resolv.conf symlink
26 cat files/firstboot/24-create-resolv-symlink.sh >> "$R/etc/rc.firstboot"
26 cat files/firstboot/24-create-resolv-symlink.sh >> "$R/etc/rc.firstboot"
27
27
28 # Finalize rc.firstboot script
28 # Finalize rc.firstboot script
29 cat files/firstboot/99-finish.sh >> "$R/etc/rc.firstboot"
29 cat files/firstboot/99-finish.sh >> "$R/etc/rc.firstboot"
30 chmod +x "$R/etc/rc.firstboot"
30 chmod +x "$R/etc/rc.firstboot"
31
31
32 # Add rc.firstboot script to rc.local
32 # Add rc.firstboot script to rc.local
33 sed -i '/exit 0/d' "$R/etc/rc.local"
33 sed -i '/exit 0/d' "$R/etc/rc.local"
34 echo /etc/rc.firstboot >> "$R/etc/rc.local"
34 echo /etc/rc.firstboot >> "$R/etc/rc.local"
35 echo exit 0 >> "$R/etc/rc.local"
35 echo exit 0 >> "$R/etc/rc.local"
@@ -1,4 +1,13
1 logger -t "rc.firstboot" "Creating /etc/resolv.conf symlink"
1 logger -t "rc.firstboot" "Creating /etc/resolv.conf symlink"
2 if [ -f "/run/systemd/resolve/resolv.conf" ] ; then
2
3
4 # Check if systemd resolve directory exists
5 if [ -d "/run/systemd/resolve" ] ; then
6 # Create resolv.conf file if it does not exists
7 if [ ! -f "/run/systemd/resolve/resolv.conf" ] ; then
8 touch /run/systemd/resolve/resolv.conf
9 fi
10
11 # Create symlink to /etc/reolv.conf
3 ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
12 ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
4 fi
13 fi
@@ -1,461 +1,443
1 #!/bin/sh
1 #!/bin/sh
2
2
3 ########################################################################
3 ########################################################################
4 # rpi2-gen-image.sh ver2a 12/2015
4 # rpi2-gen-image.sh ver2a 12/2015
5 #
5 #
6 # Advanced debian "jessie" bootstrap script for RPi2
6 # Advanced debian "jessie" bootstrap script for RPi2
7 #
7 #
8 # This program is free software; you can redistribute it and/or
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
11 # of the License, or (at your option) any later version.
12 #
12 #
13 # some parts based on rpi2-build-image:
13 # some parts based on rpi2-build-image:
14 # Copyright (C) 2015 Ryan Finnie <ryan@finnie.org>
14 # Copyright (C) 2015 Ryan Finnie <ryan@finnie.org>
15 # Copyright (C) 2015 Luca Falavigna <dktrkranz@debian.org>
15 # Copyright (C) 2015 Luca Falavigna <dktrkranz@debian.org>
16 ########################################################################
16 ########################################################################
17
17
18 # Are we running as root?
19 if [ "$(id -u)" -ne "0" ] ; then
20 echo "error: this script must be executed with root privileges!"
21 exit 1
22 fi
23
18 # Check if ./functions.sh script exists
24 # Check if ./functions.sh script exists
19 if [ ! -r "./functions.sh" ] ; then
25 if [ ! -r "./functions.sh" ] ; then
20 echo "error: './functions.sh' required script not found. please reinstall the latest script version!"
26 echo "error: './functions.sh' required script not found. please reinstall the latest script version!"
21 exit 1
27 exit 1
22 fi
28 fi
23
29
24 # Load utility functions
30 # Load utility functions
25 . ./functions.sh
31 . ./functions.sh
26
32
27 # Introduce settings
33 # Introduce settings
28 set -e
34 set -e
29 echo -n -e "\n#\n# RPi2 Bootstrap Settings\n#\n"
35 echo -n -e "\n#\n# RPi2 Bootstrap Settings\n#\n"
30 set -x
36 set -x
31
37
32 # Debian release
38 # Debian release
33 RELEASE=${RELEASE:=jessie}
39 RELEASE=${RELEASE:=jessie}
34 KERNEL_ARCH=${KERNEL_ARCH:=arm}
40 KERNEL_ARCH=${KERNEL_ARCH:=arm}
35 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
41 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
36 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
42 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
37 COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2}
43 COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2}
38 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
44 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
39 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
45 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
40
46
41 # Build settings
47 # Build directories
42 BASEDIR=$(pwd)/images/${RELEASE}
48 BASEDIR=$(pwd)/images/${RELEASE}
43 BUILDDIR=${BASEDIR}/build
49 BUILDDIR=${BASEDIR}/build
50 R=${BUILDDIR}/chroot
44
51
45 # General settings
52 # General settings
46 HOSTNAME=${HOSTNAME:=rpi2-${RELEASE}}
53 HOSTNAME=${HOSTNAME:=rpi2-${RELEASE}}
47 PASSWORD=${PASSWORD:=raspberry}
54 PASSWORD=${PASSWORD:=raspberry}
48 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
55 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
49 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
56 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
50 EXPANDROOT=${EXPANDROOT:=true}
57 EXPANDROOT=${EXPANDROOT:=true}
51
58
52 # Keyboard settings
59 # Keyboard settings
53 XKB_MODEL=${XKB_MODEL:=""}
60 XKB_MODEL=${XKB_MODEL:=""}
54 XKB_LAYOUT=${XKB_LAYOUT:=""}
61 XKB_LAYOUT=${XKB_LAYOUT:=""}
55 XKB_VARIANT=${XKB_VARIANT:=""}
62 XKB_VARIANT=${XKB_VARIANT:=""}
56 XKB_OPTIONS=${XKB_OPTIONS:=""}
63 XKB_OPTIONS=${XKB_OPTIONS:=""}
57
64
58 # Network settings (DHCP)
65 # Network settings (DHCP)
59 ENABLE_DHCP=${ENABLE_DHCP:=true}
66 ENABLE_DHCP=${ENABLE_DHCP:=true}
60
67
61 # Network settings (static)
68 # Network settings (static)
62 # only used on ENABLE_DHCP=false
63 NET_ADDRESS=${NET_ADDRESS:=""}
69 NET_ADDRESS=${NET_ADDRESS:=""}
64 NET_GATEWAY=${NET_GATEWAY:=""}
70 NET_GATEWAY=${NET_GATEWAY:=""}
65 NET_DNS_1=${NET_DNS_1:=""}
71 NET_DNS_1=${NET_DNS_1:=""}
66 NET_DNS_2=${NET_DNS_2:=""}
72 NET_DNS_2=${NET_DNS_2:=""}
67 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
73 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
68 NET_NTP_1=${NET_NTP_1:=""}
74 NET_NTP_1=${NET_NTP_1:=""}
69 NET_NTP_2=${NET_NTP_2:=""}
75 NET_NTP_2=${NET_NTP_2:=""}
70
76
71 # APT settings
77 # APT settings
72 APT_PROXY=${APT_PROXY:=""}
78 APT_PROXY=${APT_PROXY:=""}
73 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
79 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
74
80
75 # Feature settings
81 # Feature settings
76 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
82 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
77 ENABLE_IPV6=${ENABLE_IPV6:=true}
83 ENABLE_IPV6=${ENABLE_IPV6:=true}
78 ENABLE_SSHD=${ENABLE_SSHD:=true}
84 ENABLE_SSHD=${ENABLE_SSHD:=true}
79 ENABLE_SOUND=${ENABLE_SOUND:=true}
85 ENABLE_SOUND=${ENABLE_SOUND:=true}
80 ENABLE_DBUS=${ENABLE_DBUS:=true}
86 ENABLE_DBUS=${ENABLE_DBUS:=true}
81 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
87 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
82 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
88 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
83 ENABLE_XORG=${ENABLE_XORG:=false}
89 ENABLE_XORG=${ENABLE_XORG:=false}
84 ENABLE_WM=${ENABLE_WM:=""}
90 ENABLE_WM=${ENABLE_WM:=""}
85 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
91 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
86 ENABLE_USER=${ENABLE_USER:=true}
92 ENABLE_USER=${ENABLE_USER:=true}
87 ENABLE_ROOT=${ENABLE_ROOT:=false}
93 ENABLE_ROOT=${ENABLE_ROOT:=false}
88 ENABLE_ROOT_SSH=${ENABLE_ROOT_SSH:=false}
94 ENABLE_ROOT_SSH=${ENABLE_ROOT_SSH:=false}
89
95
90 # Advanced settings
96 # Advanced settings
91 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
97 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
92 ENABLE_REDUCE=${ENABLE_REDUCE:=flase}
98 ENABLE_REDUCE=${ENABLE_REDUCE:=flase}
93 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
99 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
94 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
100 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
95 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
101 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
96 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
102 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
97 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
103 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
98
104
99 # Kernel compilation settings
105 # Kernel compilation settings
100 BUILD_KERNEL=${BUILD_KERNEL:=false}
106 BUILD_KERNEL=${BUILD_KERNEL:=false}
107 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
101 KERNEL_THREADS=${KERNEL_THREADS:=1}
108 KERNEL_THREADS=${KERNEL_THREADS:=1}
102 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
109 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
103 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
110 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
104 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
111 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
105
112
106 # Kernel compilation from source directory settings
113 # Kernel compilation from source directory settings
107 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
114 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
108 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
115 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
109 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
116 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
110 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
117 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
111
118
112 # Image chroot path
119 # Reduce disk usage settings
113 R=${BUILDDIR}/chroot
120 REDUCE_APT=${REDUCE_APT:=true}
121 REDUCE_DOC=${REDUCE_DOC:=true}
122 REDUCE_MAN=${REDUCE_MAN:=true}
123 REDUCE_VIM=${REDUCE_VIM:=true}
124 REDUCE_BASH=${REDUCE_BASH:=false}
125 REDUCE_HWDB=${REDUCE_HWDB:=true}
126 REDUCE_SSHD=${REDUCE_SSHD:=true}
127 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
128
129 # Chroot scripts directory
114 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
130 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
115
131
116 # Packages required for bootstrapping
117 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git-core"
118
119 # Missing packages that need to be installed
120 MISSING_PACKAGES=""
121
122 # Packages required in the chroot build environment
132 # Packages required in the chroot build environment
123 APT_INCLUDES=${APT_INCLUDES:=""}
133 APT_INCLUDES=${APT_INCLUDES:=""}
124 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo"
134 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo"
125
135
126 set +x
136 # Packages required for bootstrapping
127
137 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git-core"
128 # Are we running as root?
138 MISSING_PACKAGES=""
129 if [ "$(id -u)" -ne "0" ] ; then
130 echo "error: this script must be executed with root privileges!"
131 exit 1
132 fi
133
134 # Check if ./bootstrap.d directory exists
135 if [ ! -d "./bootstrap.d/" ] ; then
136 echo "error: './bootstrap.d' required directory not found. please reinstall the latest script version!"
137 exit 1
138 fi
139
140 # Check if ./files directory exists
141 if [ ! -d "./files/" ] ; then
142 echo "error: './files' required directory not found. please reinstall the latest script version!"
143 exit 1
144 fi
145
146 # Check if specified KERNELSRC_DIR directory exists
147 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
148 echo "error: ${KERNELSRC_DIR} (KERNELSRC_DIR) specified directory not found!"
149 exit 1
150 fi
151
139
152 # Check if specified CHROOT_SCRIPTS directory exists
140 set +x
153 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
154 echo "error: ${CHROOT_SCRIPTS} (CHROOT_SCRIPTS) specified directory not found!"
155 exit 1
156 fi
157
141
158 # Add packages required for kernel cross compilation
142 # Add packages required for kernel cross compilation
159 if [ "$BUILD_KERNEL" = true ] ; then
143 if [ "$BUILD_KERNEL" = true ] ; then
160 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
144 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
145 fi
161
146
162 if [ "$KERNEL_MENUCONFIG" = true ] ; then
147 # Add libncurses5 to enable kernel menuconfig
163 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ncurses-dev"
148 if [ "$KERNEL_MENUCONFIG" = true ] ; then
164 fi
149 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
165 fi
150 fi
166
151
167 # Check if all required packages are installed
152 # Check if all required packages are installed on the build system
168 for package in $REQUIRED_PACKAGES ; do
153 for package in $REQUIRED_PACKAGES ; do
169 if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then
154 if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then
170 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
155 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
171 fi
156 fi
172 done
157 done
173
158
174 # Ask if missing packages should get installed right now
159 # Ask if missing packages should get installed right now
175 if [ -n "$MISSING_PACKAGES" ] ; then
160 if [ -n "$MISSING_PACKAGES" ] ; then
176 echo "the following packages needed by this script are not installed:"
161 echo "the following packages needed by this script are not installed:"
177 echo "$MISSING_PACKAGES"
162 echo "$MISSING_PACKAGES"
178
163
179 echo -n "\ndo you want to install the missing packages right now? [y/n] "
164 echo -n "\ndo you want to install the missing packages right now? [y/n] "
180 read confirm
165 read confirm
181 if [ "$confirm" != "y" ] ; then
166 [ "$confirm" != "y" ] && exit 1
182 exit 1
183 fi
184 fi
167 fi
185
168
186 # Make sure all required packages are installed
169 # Make sure all required packages are installed
187 apt-get -qq -y install ${REQUIRED_PACKAGES}
170 apt-get -qq -y install ${REQUIRED_PACKAGES}
188
171
172 # Check if ./bootstrap.d directory exists
173 if [ ! -d "./bootstrap.d/" ] ; then
174 echo "error: './bootstrap.d' required directory not found!"
175 exit 1
176 fi
177
178 # Check if ./files directory exists
179 if [ ! -d "./files/" ] ; then
180 echo "error: './files' required directory not found!"
181 exit 1
182 fi
183
184 # Check if specified KERNELSRC_DIR directory exists
185 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
186 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
187 exit 1
188 fi
189
190 # Check if specified CHROOT_SCRIPTS directory exists
191 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
192 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
193 exit 1
194 fi
195
189 # Don't clobber an old build
196 # Don't clobber an old build
190 if [ -e "$BUILDDIR" ] ; then
197 if [ -e "$BUILDDIR" ] ; then
191 echo "error: directory ${BUILDDIR} already exists, not proceeding"
198 echo "error: directory ${BUILDDIR} already exists, not proceeding"
192 exit 1
199 exit 1
193 fi
200 fi
194
201
195 # Setup chroot directory
202 # Setup chroot directory
196 mkdir -p "$R"
203 mkdir -p "$R"
197
204
198 # Check if build directory has enough of free disk space >512MB
205 # Check if build directory has enough of free disk space >512MB
199 if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then
206 if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then
200 echo "error: ${BUILDDIR} not enough space left on this partition to generate the output image!"
207 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
201 exit 1
208 exit 1
202 fi
209 fi
203
210
204 # Warn if build directory has low free disk space <1024MB
205 if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "1048576" ] ; then
206 echo `df -h --output=avail ${BUILDDIR} | sed "1 s|.*Avail|warning: $partition is low on free space:|"`
207 fi
208
209 set -x
211 set -x
210
212
211 # Call "cleanup" function on various signals and errors
213 # Call "cleanup" function on various signals and errors
212 trap cleanup 0 1 2 3 6
214 trap cleanup 0 1 2 3 6
213
215
214 # Add required packages for the minbase installation
216 # Add required packages for the minbase installation
215 if [ "$ENABLE_MINBASE" = true ] ; then
217 if [ "$ENABLE_MINBASE" = true ] ; then
216 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools"
218 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools"
217 else
219 else
218 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
220 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
219 fi
221 fi
220
222
221 # Add parted package, required to get partprobe utility
223 # Add parted package, required to get partprobe utility
222 if [ "$EXPANDROOT" = true ] ; then
224 if [ "$EXPANDROOT" = true ] ; then
223 APT_INCLUDES="${APT_INCLUDES},parted"
225 APT_INCLUDES="${APT_INCLUDES},parted"
224 fi
226 fi
225
227
226 # Add dbus package, recommended if using systemd
228 # Add dbus package, recommended if using systemd
227 if [ "$ENABLE_DBUS" = true ] ; then
229 if [ "$ENABLE_DBUS" = true ] ; then
228 APT_INCLUDES="${APT_INCLUDES},dbus"
230 APT_INCLUDES="${APT_INCLUDES},dbus"
229 fi
231 fi
230
232
231 # Add iptables IPv4/IPv6 package
233 # Add iptables IPv4/IPv6 package
232 if [ "$ENABLE_IPTABLES" = true ] ; then
234 if [ "$ENABLE_IPTABLES" = true ] ; then
233 APT_INCLUDES="${APT_INCLUDES},iptables"
235 APT_INCLUDES="${APT_INCLUDES},iptables"
234 fi
236 fi
235
237
236 # Add openssh server package
238 # Add openssh server package
237 if [ "$ENABLE_SSHD" = true ] ; then
239 if [ "$ENABLE_SSHD" = true ] ; then
238 APT_INCLUDES="${APT_INCLUDES},openssh-server"
240 APT_INCLUDES="${APT_INCLUDES},openssh-server"
239 fi
241 fi
240
242
241 # Add alsa-utils package
243 # Add alsa-utils package
242 if [ "$ENABLE_SOUND" = true ] ; then
244 if [ "$ENABLE_SOUND" = true ] ; then
243 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
245 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
244 fi
246 fi
245
247
246 # Add rng-tools package
248 # Add rng-tools package
247 if [ "$ENABLE_HWRANDOM" = true ] ; then
249 if [ "$ENABLE_HWRANDOM" = true ] ; then
248 APT_INCLUDES="${APT_INCLUDES},rng-tools"
250 APT_INCLUDES="${APT_INCLUDES},rng-tools"
249 fi
251 fi
250
252
251 # Add fbturbo video driver
253 # Add fbturbo video driver
252 if [ "$ENABLE_FBTURBO" = true ] ; then
254 if [ "$ENABLE_FBTURBO" = true ] ; then
253 # Enable xorg package dependencies
255 # Enable xorg package dependencies
254 ENABLE_XORG=true
256 ENABLE_XORG=true
255 fi
257 fi
256
258
257 # Add user defined window manager package
259 # Add user defined window manager package
258 if [ -n "$ENABLE_WM" ] ; then
260 if [ -n "$ENABLE_WM" ] ; then
259 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
261 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
260
262
261 # Enable xorg package dependencies
263 # Enable xorg package dependencies
262 ENABLE_XORG=true
264 ENABLE_XORG=true
263 fi
265 fi
264
266
265 # Add xorg package
267 # Add xorg package
266 if [ "$ENABLE_XORG" = true ] ; then
268 if [ "$ENABLE_XORG" = true ] ; then
267 APT_INCLUDES="${APT_INCLUDES},xorg"
269 APT_INCLUDES="${APT_INCLUDES},xorg"
268 fi
270 fi
269
271
270 # Set KERNELSRC_CONFIG=true
272 # Replace selected packages with smaller clones
273 if [ "$ENABLE_REDUCE" = true ] ; then
274 # Add levee package instead of vim-tiny
275 if [ "$REDUCE_VIM" = true ] ; then
276 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
277 fi
278
279 # Add dropbear package instead of openssh-server
280 if [ "$REDUCE_SSHD" = true ] ; then
281 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")"
282 fi
283 fi
284
285 # Configure kernel sources if no KERNELSRC_DIR
271 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
286 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
272 KERNELSRC_CONFIG=true
287 KERNELSRC_CONFIG=true
273 fi
288 fi
274
289
275 ## MAIN bootstrap
290 # Configure reduced kernel
291 if [ "$KERNEL_REDUCE" = true ] ; then
292 KERNELSRC_CONFIG=false
293 fi
294
295 # Execute bootstrap scripts
276 for SCRIPT in bootstrap.d/*.sh; do
296 for SCRIPT in bootstrap.d/*.sh; do
277 # Execute bootstrap scripts (lexicographical order)
278 head -n 3 "$SCRIPT"
297 head -n 3 "$SCRIPT"
279 . "$SCRIPT"
298 . "$SCRIPT"
280 done
299 done
281
300
282 ## Custom bootstrap scripts
301 ## Execute custom bootstrap scripts
283 if [ -d "custom.d" ] ; then
302 if [ -d "custom.d" ] ; then
284 # Execute custom bootstrap scripts (lexicographical order)
285 for SCRIPT in custom.d/*.sh; do
303 for SCRIPT in custom.d/*.sh; do
286 . "$SCRIPT"
304 . "$SCRIPT"
287 done
305 done
288 fi
306 fi
289
307
290 # Invoke custom scripts
308 # Execute custom scripts inside the chroot
291 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
309 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
292 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
310 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
293 # Execute scripts inside the chroot (lexicographical order)
294 chroot_exec /bin/bash -x <<'EOF'
311 chroot_exec /bin/bash -x <<'EOF'
295 for SCRIPT in /chroot_scripts/* ; do
312 for SCRIPT in /chroot_scripts/* ; do
296 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
313 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
297 $SCRIPT
314 $SCRIPT
298 fi
315 fi
299 done
316 done
300 EOF
317 EOF
301 rm -rf "$R/chroot_scripts"
318 rm -rf "$R/chroot_scripts"
302 fi
319 fi
303
320
304 # Remove apt-utils
321 # Remove apt-utils
305 chroot_exec apt-get purge -qq -y --force-yes apt-utils
322 chroot_exec apt-get purge -qq -y --force-yes apt-utils
306
323
307 # Reduce the image size by removing and compressing
308 if [ "$ENABLE_REDUCE" = true ] ; then
309 # Install dpkg configuration fragment file
310 install_readonly files/dpkg/01nodoc "$R/etc/dpkg/dpkg.cfg.d/01nodoc"
311
312 # Install APT configuration fragment files
313 install_readonly files/apt/02nocache "$R/etc/apt/apt.conf.d/02nocache"
314 install_readonly files/apt/03compress "$R/etc/apt/apt.conf.d/03compress"
315 install_readonly files/apt/04norecommends "$R/etc/apt/apt.conf.d/04norecommends"
316
317 # Remove APT cache files
318 rm -fr "$R/var/cache/apt/pkgcache.bin"
319 rm -fr "$R/var/cache/apt/srcpkgcache.bin"
320
321 # Remove all doc and man files
322 find "$R/usr/share/doc" -depth -type f ! -name copyright | xargs rm || true
323 find "$R/usr/share/doc" -empty | xargs rmdir || true
324 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"
325
326 # Remove all translation files
327 find "$R/usr/share/locale" -mindepth 1 -maxdepth 1 ! -name 'en' | xargs rm -r
328
329 # Clean APT list of repositories
330 rm -fr "$R/var/lib/apt/lists/*"
331 chroot_exec apt-get -qq -y update
332
333 # Remove GPU kernels
334 if [ "$ENABLE_MINGPU" = true ] ; then
335 rm -f "$R/boot/firmware/start.elf"
336 rm -f "$R/boot/firmware/fixup.dat"
337 rm -f "$R/boot/firmware/start_x.elf"
338 rm -f "$R/boot/firmware/fixup_x.dat"
339 fi
340 fi
341
342 # APT Cleanup
324 # APT Cleanup
343 chroot_exec apt-get -y clean
325 chroot_exec apt-get -y clean
344 chroot_exec apt-get -y autoclean
326 chroot_exec apt-get -y autoclean
345 chroot_exec apt-get -y autoremove
327 chroot_exec apt-get -y autoremove
346
328
347 # Unmount mounted filesystems
329 # Unmount mounted filesystems
348 umount -l "$R/proc"
330 umount -l "$R/proc"
349 umount -l "$R/sys"
331 umount -l "$R/sys"
350
332
351 # Clean up directories
333 # Clean up directories
352 rm -rf "$R/run"
334 rm -rf "$R/run"
353 rm -rf "$R/tmp/*"
335 rm -rf "$R/tmp/*"
354
336
355 # Clean up files
337 # Clean up files
356 rm -f "$R/etc/apt/sources.list.save"
338 rm -f "$R/etc/apt/sources.list.save"
357 rm -f "$R/etc/resolvconf/resolv.conf.d/original"
339 rm -f "$R/etc/resolvconf/resolv.conf.d/original"
358 rm -f "$R/etc/*-"
340 rm -f "$R/etc/*-"
359 rm -f "$R/root/.bash_history"
341 rm -f "$R/root/.bash_history"
360 rm -f "$R/var/lib/urandom/random-seed"
342 rm -f "$R/var/lib/urandom/random-seed"
361 rm -f "$R/var/lib/dbus/machine-id"
343 rm -f "$R/var/lib/dbus/machine-id"
362 rm -f "$R/etc/machine-id"
344 rm -f "$R/etc/machine-id"
363 rm -f "$R/etc/apt/apt.conf.d/10proxy"
345 rm -f "$R/etc/apt/apt.conf.d/10proxy"
364 rm -f "$R/etc/resolv.conf"
346 rm -f "$R/etc/resolv.conf"
365 rm -f "${R}${QEMU_BINARY}"
347 rm -f "${R}${QEMU_BINARY}"
366
348
367 # Calculate size of the chroot directory in KB
349 # Calculate size of the chroot directory in KB
368 CHROOT_SIZE=$(expr `du -s "$R" | awk '{ print $1 }'`)
350 CHROOT_SIZE=$(expr `du -s "$R" | awk '{ print $1 }'`)
369
351
370 # Calculate the amount of needed 512 Byte sectors
352 # Calculate the amount of needed 512 Byte sectors
371 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
353 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
372 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
354 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
373 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS})
355 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS})
374
356
375 # The root partition is EXT4
357 # The root partition is EXT4
376 # This means more space than the actual used space of the chroot is used.
358 # This means more space than the actual used space of the chroot is used.
377 # As overhead for journaling and reserved blocks 20% are added.
359 # As overhead for journaling and reserved blocks 20% are added.
378 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512)
360 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512)
379
361
380 # Calculate required image size in 512 Byte sectors
362 # Calculate required image size in 512 Byte sectors
381 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS})
363 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS})
382
364
383 # Prepare date string for image file name
365 # Prepare date string for image file name
384 DATE="$(date +%Y-%m-%d)"
366 DATE="$(date +%Y-%m-%d)"
385
367
386 # Prepare image file
368 # Prepare image file
387 if [ "$ENABLE_SPLITFS" = true ] ; then
369 if [ "$ENABLE_SPLITFS" = true ] ; then
388 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=${TABLE_SECTORS}
370 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=${TABLE_SECTORS}
389 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS}
371 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS}
390 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=${TABLE_SECTORS}
372 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=${TABLE_SECTORS}
391 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=0 seek=${ROOT_SECTORS}
373 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=0 seek=${ROOT_SECTORS}
392 # Write partition tables
374 # Write partition tables
393 sfdisk -q -L -f "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" <<EOM
375 sfdisk -q -L -f "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" <<EOM
394 unit: sectors
376 unit: sectors
395
377
396 1 : start= ${TABLE_SECTORS}, size= ${FRMW_SECTORS}, Id= c, bootable
378 1 : start= ${TABLE_SECTORS}, size= ${FRMW_SECTORS}, Id= c, bootable
397 2 : start= 0, size= 0, Id= 0
379 2 : start= 0, size= 0, Id= 0
398 3 : start= 0, size= 0, Id= 0
380 3 : start= 0, size= 0, Id= 0
399 4 : start= 0, size= 0, Id= 0
381 4 : start= 0, size= 0, Id= 0
400 EOM
382 EOM
401 sfdisk -q -L -f "$BASEDIR/${DATE}-debian-${RELEASE}-root.img" <<EOM
383 sfdisk -q -L -f "$BASEDIR/${DATE}-debian-${RELEASE}-root.img" <<EOM
402 unit: sectors
384 unit: sectors
403
385
404 1 : start= ${TABLE_SECTORS}, size= ${ROOT_SECTORS}, Id=83
386 1 : start= ${TABLE_SECTORS}, size= ${ROOT_SECTORS}, Id=83
405 2 : start= 0, size= 0, Id= 0
387 2 : start= 0, size= 0, Id= 0
406 3 : start= 0, size= 0, Id= 0
388 3 : start= 0, size= 0, Id= 0
407 4 : start= 0, size= 0, Id= 0
389 4 : start= 0, size= 0, Id= 0
408 EOM
390 EOM
409 # Setup temporary loop devices
391 # Setup temporary loop devices
410 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-frmw.img)"
392 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-frmw.img)"
411 ROOT_LOOP="$(losetup -o 1M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-root.img)"
393 ROOT_LOOP="$(losetup -o 1M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-root.img)"
412 else
394 else
413 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS}
395 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS}
414 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS}
396 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS}
415 # Write partition table
397 # Write partition table
416 sfdisk -q -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" <<EOM
398 sfdisk -q -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" <<EOM
417 unit: sectors
399 unit: sectors
418
400
419 1 : start= ${TABLE_SECTORS}, size= ${FRMW_SECTORS}, Id= c, bootable
401 1 : start= ${TABLE_SECTORS}, size= ${FRMW_SECTORS}, Id= c, bootable
420 2 : start= ${ROOT_OFFSET}, size= ${ROOT_SECTORS}, Id=83
402 2 : start= ${ROOT_OFFSET}, size= ${ROOT_SECTORS}, Id=83
421 3 : start= 0, size= 0, Id= 0
403 3 : start= 0, size= 0, Id= 0
422 4 : start= 0, size= 0, Id= 0
404 4 : start= 0, size= 0, Id= 0
423 EOM
405 EOM
424 # Setup temporary loop devices
406 # Setup temporary loop devices
425 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
407 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
426 ROOT_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
408 ROOT_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
427 fi
409 fi
428
410
429 # Build filesystems
411 # Build filesystems
430 mkfs.vfat "$FRMW_LOOP"
412 mkfs.vfat "$FRMW_LOOP"
431 mkfs.ext4 "$ROOT_LOOP"
413 mkfs.ext4 "$ROOT_LOOP"
432
414
433 # Mount the temporary loop devices
415 # Mount the temporary loop devices
434 mkdir -p "$BUILDDIR/mount"
416 mkdir -p "$BUILDDIR/mount"
435 mount "$ROOT_LOOP" "$BUILDDIR/mount"
417 mount "$ROOT_LOOP" "$BUILDDIR/mount"
436
418
437 mkdir -p "$BUILDDIR/mount/boot/firmware"
419 mkdir -p "$BUILDDIR/mount/boot/firmware"
438 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
420 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
439
421
440 # Copy all files from the chroot to the loop device mount point directory
422 # Copy all files from the chroot to the loop device mount point directory
441 rsync -a "$R/" "$BUILDDIR/mount/"
423 rsync -a "$R/" "$BUILDDIR/mount/"
442
424
443 # Unmount all temporary loop devices and mount points
425 # Unmount all temporary loop devices and mount points
444 cleanup
426 cleanup
445
427
446 # Create block map file(s) of image(s)
428 # Create block map file(s) of image(s)
447 if [ "$ENABLE_SPLITFS" = true ] ; then
429 if [ "$ENABLE_SPLITFS" = true ] ; then
448 # Create block map files for "bmaptool"
430 # Create block map files for "bmaptool"
449 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img"
431 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img"
450 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-root.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-root.img"
432 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-root.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-root.img"
451
433
452 # Image was successfully created
434 # Image was successfully created
453 echo "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
435 echo "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
454 echo "$BASEDIR/${DATE}-debian-${RELEASE}-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
436 echo "$BASEDIR/${DATE}-debian-${RELEASE}-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
455 else
437 else
456 # Create block map file for "bmaptool"
438 # Create block map file for "bmaptool"
457 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}.img"
439 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}.img"
458
440
459 # Image was successfully created
441 # Image was successfully created
460 echo "$BASEDIR/${DATE}-debian-${RELEASE}.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
442 echo "$BASEDIR/${DATE}-debian-${RELEASE}.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
461 fi
443 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant