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