##// END OF EJS Templates
Added: KERNELSRC_PREBUILT, KERNELSRC_ rename, fix-quotes
Jan Wagner -
r75:24bd7e97cf9d
parent child
Show More
@@ -1,3 +1,4
1 1 images
2 2 custom.d
3 3 *.swp
4 *.log
@@ -1,240 +1,243
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 BUILD_KERNEL=true KERNEL_SRCDIR=/tmp/linux ./rpi2-gen-image.sh
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 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.
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_SRCDIR`=""
169 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.
170
171 168 ##### `KERNEL_THREADS`=1
172 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.
173 170
174 171 ##### `KERNEL_HEADERS`=true
175 172 Install kernel headers with built kernel.
176 173
177 174 ##### `KERNEL_MENUCONFIG`=false
178 175 Start `make menuconfig` interactive menu-driven kernel configuration. The script will continue after `make menuconfig` was terminated.
179 176
180 ##### `KERNEL_CONFIGSRC`=true
181 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 `KERNEL_SRCDIR`.
177 ##### `KERNEL_REMOVESRC`=true
178 Remove all kernel sources from the generated OS image after it was built and installed.
182 179
183 ##### `KERNEL_CLEANSRC`=false
184 Clean the existing kernel sources directory `KERNEL_SRCDIR` (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 `KERNEL_SRCDIR` was specified.
180 ##### `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.
185 182
186 ##### `KERNEL_RMSRC`=true
187 Remove all kernel sources from the generated OS image after it was built and installed.
183 ##### `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.
185
186 ##### `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.
188
189 ##### `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.
188 191
189 192 ## Understanding the script
190 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:
191 194
192 195 | Script | Description |
193 196 | --- | --- |
194 197 | `10-bootstrap.sh` | Debootstrap basic system |
195 198 | `11-apt.sh` | Setup APT repositories |
196 199 | `12-locale.sh` | Setup Locales and keyboard settings |
197 200 | `13-kernel.sh` | Build and install RPi2 Kernel |
198 201 | `20-networking.sh` | Setup Networking |
199 202 | `21-firewall.sh` | Setup Firewall |
200 203 | `30-security.sh` | Setup Users and Security settings |
201 204 | `31-logging.sh` | Setup Logging |
202 205 | `41-uboot.sh` | Build and Setup U-Boot |
203 206 | `42-fbturbo.sh` | Build and Setup fbturbo Xorg driver |
204 207 | `50-firstboot.sh` | First boot actions |
205 208
206 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.
207 210
208 211 | Directory | Description |
209 212 | --- | --- |
210 213 | `boot` | Boot and RPi2 configuration files |
211 214 | `dpkg` | Package Manager configuration |
212 215 | `firstboot` | Scripts that get executed on first boot |
213 216 | `iptables` | Firewall configuration files |
214 217 | `locales` | Locales configuration |
215 218 | `modules` | Kernel Modules configuration |
216 219 | `mount` | Fstab configuration |
217 220 | `network` | Networking configuration files |
218 221 | `sysctl.d` | Swapping and Network Hardening configuration |
219 222 | `xorg` | fbturbo Xorg driver configuration |
220 223
221 224 ## Logging of the bootstrapping process
222 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:
223 226
224 227 ```shell
225 228 script -c 'APT_SERVER=ftp.de.debian.org ./rpi2-gen-image.sh' ./build.log
226 229 ```
227 230
228 231 ## Flashing the image file
229 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`.
230 233
231 234 #####Flashing examples:
232 235 ```shell
233 236 bmaptool copy ./images/jessie/2015-12-13-debian-jessie.img /dev/mmcblk0
234 237 dd bs=4M if=./images/jessie/2015-12-13-debian-jessie.img of=/dev/mmcblk0
235 238 ```
236 239 If you have set `ENABLE_SPLITFS`, copy the `-frmw` image on the microSD card, then the `-root` one on the USB drive:
237 240 ```shell
238 241 bmaptool copy ./images/jessie/2015-12-13-debian-jessie-frmw.img /dev/mmcblk0
239 242 bmaptool copy ./images/jessie/2015-12-13-debian-jessie-root.img /dev/sdc
240 243 ```
@@ -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}" --variant=minbase --foreign --include="${APT_INCLUDES}" "${RELEASE}" "$R" "http://${APT_SERVER}/debian"
11 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 13 fi
14 14
15 15 # Copy qemu emulator binary to chroot
16 cp ${QEMU_BINARY} $R/usr/bin
16 cp "${QEMU_BINARY}" "$R/usr/bin"
17 17
18 18 # Copy debian-archive-keyring.pgp
19 mkdir -p $R/usr/share/keyrings
20 cp /usr/share/keyrings/debian-archive-keyring.gpg $R/usr/share/keyrings/debian-archive-keyring.gpg
19 mkdir -p "$R/usr/share/keyrings"
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 mount -t proc none $R/proc
27 mount -t sysfs none $R/sys
28 mount --bind /dev/pts $R/dev/pts
26 mount -t proc none "$R/proc"
27 mount -t sysfs none "$R/sys"
28 mount --bind /dev/pts "$R/dev/pts"
@@ -1,30 +1,30
1 1 #
2 2 # Setup APT repositories
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 # Install and setup APT proxy configuration
9 9 if [ -z "$APT_PROXY" ] ; then
10 install_readonly files/apt/10proxy $R/etc/apt/apt.conf.d/10proxy
11 sed -i "s/\"\"/\"${APT_PROXY}\"/" $R/etc/apt/apt.conf.d/10proxy
10 install_readonly files/apt/10proxy "$R/etc/apt/apt.conf.d/10proxy"
11 sed -i "s/\"\"/\"${APT_PROXY}\"/" "$R/etc/apt/apt.conf.d/10proxy"
12 12 fi
13 13
14 14 # Install APT pinning configuration for flash-kernel package
15 install_readonly files/apt/flash-kernel $R/etc/apt/preferences.d/flash-kernel
15 install_readonly files/apt/flash-kernel "$R/etc/apt/preferences.d/flash-kernel"
16 16
17 17 # Upgrade collabora package index and install collabora keyring
18 echo "deb https://repositories.collabora.co.uk/debian ${RELEASE} rpi2" >$R/etc/apt/sources.list
18 echo "deb https://repositories.collabora.co.uk/debian ${RELEASE} rpi2" > "$R/etc/apt/sources.list"
19 19 chroot_exec apt-get -qq -y update
20 20 chroot_exec apt-get -qq -y --force-yes install collabora-obs-archive-keyring
21 21
22 22 # Install APT sources.list
23 install_readonly files/apt/sources.list $R/etc/apt/sources.list
24 sed -i "s/\/ftp.debian.org\//\/${APT_SERVER}\//" $R/etc/apt/sources.list
25 sed -i "s/ jessie/ ${RELEASE}/" $R/etc/apt/sources.list
23 install_readonly files/apt/sources.list "$R/etc/apt/sources.list"
24 sed -i "s/\/ftp.debian.org\//\/${APT_SERVER}\//" "$R/etc/apt/sources.list"
25 sed -i "s/ jessie/ ${RELEASE}/" "$R/etc/apt/sources.list"
26 26
27 27 # Upgrade package index and update all installed packages and changed dependencies
28 28 chroot_exec apt-get -qq -y update
29 29 chroot_exec apt-get -qq -y -u dist-upgrade
30 30 chroot_exec apt-get -qq -y check
@@ -1,58 +1,58
1 1 #
2 2 # Setup Locales and keyboard settings
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 # Install and setup timezone
9 echo ${TIMEZONE} >$R/etc/timezone
9 echo ${TIMEZONE} > "$R/etc/timezone"
10 10 chroot_exec dpkg-reconfigure -f noninteractive tzdata
11 11
12 12 # Install and setup default locale and keyboard configuration
13 13 if [ "$ENABLE_MINBASE" = false ] ; then
14 14 # Set locale choice in debconf db, even though dpkg-reconfigure ignores and overwrites them due to some bug
15 15 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=684134 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=685957
16 16 # ... so we have to set locales manually
17 17 if [ "$DEFLOCAL" = "en_US.UTF-8" ] ; then
18 18 chroot_exec echo "locales locales/locales_to_be_generated multiselect ${DEFLOCAL} UTF-8" | debconf-set-selections
19 19 else
20 20 # en_US.UTF-8 should be available anyway : https://www.debian.org/doc/manuals/debian-reference/ch08.en.html#_the_reconfiguration_of_the_locale
21 21 chroot_exec echo "locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8, ${DEFLOCAL} UTF-8" | debconf-set-selections
22 sed -i "/en_US.UTF-8/s/^#//" $R/etc/locale.gen
22 sed -i "/en_US.UTF-8/s/^#//" "$R/etc/locale.gen"
23 23 fi
24 24
25 sed -i "/${DEFLOCAL}/s/^#//" $R/etc/locale.gen
25 sed -i "/${DEFLOCAL}/s/^#//" "$R/etc/locale.gen"
26 26 chroot_exec echo "locales locales/default_environment_locale select ${DEFLOCAL}" | debconf-set-selections
27 27 chroot_exec locale-gen
28 chroot_exec update-locale LANG=${DEFLOCAL}
28 chroot_exec update-locale LANG="${DEFLOCAL}"
29 29
30 30 # Install and setup default keyboard configuration
31 31 if [ "$XKB_MODEL" != "" ] ; then
32 sed -i "s/^XKBMODEL.*/XKBMODEL=\"${XKB_MODEL}\"/" $R/etc/default/keyboard
32 sed -i "s/^XKBMODEL.*/XKBMODEL=\"${XKB_MODEL}\"/" "$R/etc/default/keyboard"
33 33 fi
34 34 if [ "$XKB_LAYOUT" != "" ] ; then
35 sed -i "s/^XKBLAYOUT.*/XKBLAYOUT=\"${XKB_LAYOUT}\"/" $R/etc/default/keyboard
35 sed -i "s/^XKBLAYOUT.*/XKBLAYOUT=\"${XKB_LAYOUT}\"/" "$R/etc/default/keyboard"
36 36 fi
37 37 if [ "$XKB_VARIANT" != "" ] ; then
38 sed -i "s/^XKBVARIANT.*/XKBVARIANT=\"${XKB_VARIANT}\"/" $R/etc/default/keyboard
38 sed -i "s/^XKBVARIANT.*/XKBVARIANT=\"${XKB_VARIANT}\"/" "$R/etc/default/keyboard"
39 39 fi
40 40 if [ "$XKB_OPTIONS" != "" ] ; then
41 sed -i "s/^XKBOPTIONS.*/XKBOPTIONS=\"${XKB_OPTIONS}\"/" $R/etc/default/keyboard
41 sed -i "s/^XKBOPTIONS.*/XKBOPTIONS=\"${XKB_OPTIONS}\"/" "$R/etc/default/keyboard"
42 42 fi
43 43 chroot_exec dpkg-reconfigure -f noninteractive keyboard-configuration
44 44
45 45 # Install and setup font console
46 46 case "${DEFLOCAL}" in
47 47 *UTF-8)
48 sed -i 's/^CHARMAP.*/CHARMAP="UTF-8"/' $R/etc/default/console-setup
48 sed -i 's/^CHARMAP.*/CHARMAP="UTF-8"/' "$R/etc/default/console-setup"
49 49 ;;
50 50 *)
51 sed -i 's/^CHARMAP.*/CHARMAP="guess"/' $R/etc/default/console-setup
51 sed -i 's/^CHARMAP.*/CHARMAP="guess"/' "$R/etc/default/console-setup"
52 52 ;;
53 53 esac
54 54 chroot_exec dpkg-reconfigure -f noninteractive console-setup
55 55 else # ENABLE_MINBASE=true
56 56 # Install POSIX default locale
57 install_readonly files/locales/locale $R/etc/default/locale
57 install_readonly files/locales/locale "$R/etc/default/locale"
58 58 fi
@@ -1,152 +1,163
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 mkdir -p $R/usr/src
11 mkdir -p "$R/usr/src"
12 12
13 13 # Copy existing kernel sources into chroot directory
14 if [ -n "$KERNEL_SRCDIR" ] && [ -d "$KERNEL_SRCDIR" ] ; then
14 if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then
15 15 # Copy kernel sources
16 cp -r "${KERNEL_SRCDIR}" "${R}/usr/src"
16 cp -r "${KERNELSRC_DIR}" "${R}/usr/src"
17 17
18 18 # Clean the kernel sources
19 if [ "$KERNEL_CLEANSRC" = true ] ; then
20 make -C $R/usr/src/linux ARCH=${KERNEL_ARCH} CROSS_COMPILE=${CROSS_COMPILE} mrproper
19 if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then
20 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" mrproper
21 21 fi
22 else # KERNEL_SRCDIR=""
22 else # KERNELSRC_DIR=""
23 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 25 fi
26 26
27 27 # Calculate optimal number of kernel building threads
28 if [ "$KERNEL_THREADS" = "1" ] ; then
29 if [ -r /proc/cpuinfo ] ; then
28 if [ "$KERNEL_THREADS" = "1" ] && [ -r /proc/cpuinfo ] ; then
30 29 KERNEL_THREADS=$(grep -c processor /proc/cpuinfo)
31 30 fi
32 fi
33 31
34 if [ "$KERNEL_CONFIGSRC" = true ] ; then
32 if [ "$KERNELSRC_PREBUILT" = false ] ; then
33 if [ "$KERNELSRC_CONFIG" = true ] ; then
35 34 # Load default raspberry kernel configuration
36 make -C $R/usr/src/linux ARCH=${KERNEL_ARCH} CROSS_COMPILE=${CROSS_COMPILE} ${KERNEL_DEFCONFIG}
35 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
37 36
38 37 # Start menu-driven kernel configuration (interactive)
39 38 if [ "$KERNEL_MENUCONFIG" = true ] ; then
40 make -C $R/usr/src/linux ARCH=${KERNEL_ARCH} CROSS_COMPILE=${CROSS_COMPILE} menuconfig
39 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig
41 40 fi
42 41 fi
43 42
44 43 # Cross compile kernel and modules
45 make -C $R/usr/src/linux -j${KERNEL_THREADS} ARCH=${KERNEL_ARCH} CROSS_COMPILE=${CROSS_COMPILE} zImage modules dtbs
44 make -C "$R/usr/src/linux" -j${KERNEL_THREADS} ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" zImage modules dtbs
45 fi
46 46
47 47 # Check if kernel compilation was successful
48 if [ ! -r $R/usr/src/linux/arch/${KERNEL_ARCH}/boot/zImage ] ; then
49 echo "error: kernel compilation failed!"
48 if [ ! -r "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/zImage" ] ; then
49 echo "error: kernel compilation failed! (zImage not found)"
50 50 cleanup
51 51 exit 1
52 52 fi
53 53
54 54 # Install kernel modules
55 55 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
56 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install
57 57 else
58 make -C $R/usr/src/linux ARCH=${KERNEL_ARCH} CROSS_COMPILE=${CROSS_COMPILE} INSTALL_MOD_PATH=../../.. modules_install
58 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install
59
60 # Install kernel firmware
61 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install
59 62 fi
60 63
61 64 # Install kernel headers
62 65 if [ "$KERNEL_HEADERS" = true ] ; then
63 make -C $R/usr/src/linux ARCH=${KERNEL_ARCH} CROSS_COMPILE=${CROSS_COMPILE} INSTALL_HDR_PATH=../.. headers_install
66 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install
64 67 fi
65 68
66 # Copy and rename compiled kernel to boot directory
67 mkdir $R/boot/firmware/
68 $R/usr/src/linux/scripts/mkknlimg $R/usr/src/linux/arch/${KERNEL_ARCH}/boot/zImage $R/boot/firmware/kernel7.img
69 # Prepare boot (firmware) directory
70 mkdir "$R/boot/firmware/"
71
72 # Get kernel release version
73 KERNEL_VERSION=`cat "$R/usr/src/linux/include/config/kernel.release"`
74
75 # Copy kernel configuration file to the boot directory
76 cp "$R/usr/src/linux/.config" "$R/boot/config-${KERNEL_VERSION}"
77
78 # Copy dts and dtb device tree sources and binaries
79 mkdir "$R/boot/firmware/overlays/"
80 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/"
82 cp "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "$R/boot/firmware/overlays/"
69 83
70 # Copy dts and dtb device definitions
71 mkdir $R/boot/firmware/overlays/
72 cp $R/usr/src/linux/arch/${KERNEL_ARCH}/boot/dts/*.dtb $R/boot/firmware/
73 cp $R/usr/src/linux/arch/${KERNEL_ARCH}/boot/dts/overlays/*.dtb* $R/boot/firmware/overlays/
74 cp $R/usr/src/linux/arch/${KERNEL_ARCH}/boot/dts/overlays/README $R/boot/firmware/overlays/
84 # 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"
75 86
76 87 # Remove kernel sources
77 if [ "$KERNEL_RMSRC" = true ] ; then
78 rm -fr $R/usr/src/linux
88 if [ "$KERNEL_REMOVESRC" = true ] ; then
89 rm -fr "$R/usr/src/linux"
79 90 fi
80 91
81 92 # Install raspberry bootloader and flash-kernel packages
82 93 chroot_exec apt-get -qq -y --no-install-recommends install raspberrypi-bootloader-nokernel
83 94 else # BUILD_KERNEL=false
84 95 # Kernel installation
85 chroot_exec apt-get -qq -y --no-install-recommends install linux-image-${COLLABORA_KERNEL} raspberrypi-bootloader-nokernel
96 chroot_exec apt-get -qq -y --no-install-recommends install linux-image-"${COLLABORA_KERNEL}" raspberrypi-bootloader-nokernel
86 97
87 98 # Install flash-kernel last so it doesn't try (and fail) to detect the platform in the chroot
88 99 chroot_exec apt-get -qq -y install flash-kernel
89 100
90 101 VMLINUZ="$(ls -1 $R/boot/vmlinuz-* | sort | tail -n 1)"
91 102 [ -z "$VMLINUZ" ] && exit 1
92 cp $VMLINUZ $R/boot/firmware/kernel7.img
103 cp "$VMLINUZ" "$R/boot/firmware/kernel7.img"
93 104 fi
94 105
95 106 # Setup firmware boot cmdline
96 107 if [ "$ENABLE_SPLITFS" = true ] ; then
97 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}"
98 109 else
99 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}"
100 111 fi
101 112
102 113 # Add serial console support
103 114 if [ "$ENABLE_CONSOLE" = true ] ; then
104 115 CMDLINE="${CMDLINE} console=ttyAMA0,115200 kgdboc=ttyAMA0,115200"
105 116 fi
106 117
107 118 # Remove IPv6 networking support
108 119 if [ "$ENABLE_IPV6" = false ] ; then
109 120 CMDLINE="${CMDLINE} ipv6.disable=1"
110 121 fi
111 122
112 123 # Install firmware boot cmdline
113 echo "${CMDLINE}" >$R/boot/firmware/cmdline.txt
124 echo "${CMDLINE}" > "$R/boot/firmware/cmdline.txt"
114 125
115 126 # Install firmware config
116 install_readonly files/boot/config.txt $R/boot/firmware/config.txt
127 install_readonly files/boot/config.txt "$R/boot/firmware/config.txt"
117 128
118 129 # Setup minimal GPU memory allocation size: 16MB (no X)
119 130 if [ "$ENABLE_MINGPU" = true ] ; then
120 echo "gpu_mem=16" >>$R/boot/firmware/config.txt
131 echo "gpu_mem=16" >> "$R/boot/firmware/config.txt"
121 132 fi
122 133
123 134 # Create firmware configuration and cmdline symlinks
124 ln -sf firmware/config.txt $R/boot/config.txt
125 ln -sf firmware/cmdline.txt $R/boot/cmdline.txt
135 ln -sf firmware/config.txt "$R/boot/config.txt"
136 ln -sf firmware/cmdline.txt "$R/boot/cmdline.txt"
126 137
127 138 # Install and setup kernel modules to load at boot
128 mkdir -p $R/lib/modules-load.d/
129 install_readonly files/modules/rpi2.conf $R/lib/modules-load.d/rpi2.conf
139 mkdir -p "$R/lib/modules-load.d/"
140 install_readonly files/modules/rpi2.conf "$R/lib/modules-load.d/rpi2.conf"
130 141
131 142 # Load hardware random module at boot
132 143 if [ "$ENABLE_HWRANDOM" = true ] ; then
133 sed -i "s/^# bcm2708_rng/bcm2708_rng/" $R/lib/modules-load.d/rpi2.conf
144 sed -i "s/^# bcm2708_rng/bcm2708_rng/" "$R/lib/modules-load.d/rpi2.conf"
134 145 fi
135 146
136 147 # Load sound module at boot
137 148 if [ "$ENABLE_SOUND" = true ] ; then
138 sed -i "s/^# snd_bcm2835/snd_bcm2835/" $R/lib/modules-load.d/rpi2.conf
149 sed -i "s/^# snd_bcm2835/snd_bcm2835/" "$R/lib/modules-load.d/rpi2.conf"
139 150 fi
140 151
141 152 # Install kernel modules blacklist
142 mkdir -p $R/etc/modprobe.d/
143 install_readonly files/modules/raspi-blacklist.conf $R/etc/modprobe.d/raspi-blacklist.conf
153 mkdir -p "$R/etc/modprobe.d/"
154 install_readonly files/modules/raspi-blacklist.conf "$R/etc/modprobe.d/raspi-blacklist.conf"
144 155
145 156 # Install and setup fstab
146 install_readonly files/mount/fstab $R/etc/fstab
157 install_readonly files/mount/fstab "$R/etc/fstab"
147 158 if [ "$ENABLE_SPLITFS" = true ] ; then
148 sed -i 's/mmcblk0p2/sda1/' $R/etc/fstab
159 sed -i 's/mmcblk0p2/sda1/' "$R/etc/fstab"
149 160 fi
150 161
151 162 # Install sysctl.d configuration files
152 install_readonly files/sysctl.d/81-rpi-vm.conf $R/etc/sysctl.d/81-rpi-vm.conf
163 install_readonly files/sysctl.d/81-rpi-vm.conf "$R/etc/sysctl.d/81-rpi-vm.conf"
@@ -1,72 +1,72
1 1 #
2 2 # Setup Networking
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 # Install and setup hostname
9 install_readonly files/network/hostname $R/etc/hostname
10 sed -i "s/^rpi2-jessie/${HOSTNAME}/" $R/etc/hostname
9 install_readonly files/network/hostname "$R/etc/hostname"
10 sed -i "s/^rpi2-jessie/${HOSTNAME}/" "$R/etc/hostname"
11 11
12 12 # Install and setup hosts
13 install_readonly files/network/hosts $R/etc/hosts
14 sed -i "s/rpi2-jessie/${HOSTNAME}/" $R/etc/hosts
13 install_readonly files/network/hosts "$R/etc/hosts"
14 sed -i "s/rpi2-jessie/${HOSTNAME}/" "$R/etc/hosts"
15 15
16 16 # Setup hostname entry with static IP
17 17 if [ "$NET_ADDRESS" != "" ] ; then
18 NET_IP=$(echo ${NET_ADDRESS} | cut -f 1 -d'/')
19 sed -i "s/^127.0.1.1/${NET_IP}/" $R/etc/hosts
18 NET_IP=$(echo "${NET_ADDRESS}" | cut -f 1 -d'/')
19 sed -i "s/^127.0.1.1/${NET_IP}/" "$R/etc/hosts"
20 20 fi
21 21
22 22 # Remove IPv6 hosts
23 23 if [ "$ENABLE_IPV6" = false ] ; then
24 sed -i -e "/::[1-9]/d" -e "/^$/d" $R/etc/hosts
24 sed -i -e "/::[1-9]/d" -e "/^$/d" "$R/etc/hosts"
25 25 fi
26 26
27 27 # Install hint about network configuration
28 install_readonly files/network/interfaces $R/etc/network/interfaces
28 install_readonly files/network/interfaces "$R/etc/network/interfaces"
29 29
30 30 # Install configuration for interface eth0
31 install_readonly files/network/eth.network $R/etc/systemd/network/eth.network
31 install_readonly files/network/eth.network "$R/etc/systemd/network/eth.network"
32 32
33 33 if [ "$ENABLE_DHCP" = true ] ; then
34 34 # Enable DHCP configuration for interface eth0
35 sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" $R/etc/systemd/network/eth.network
35 sed -i -e "s/DHCP=.*/DHCP=yes/" -e "/DHCP/q" "$R/etc/systemd/network/eth.network"
36 36
37 37 # Set DHCP configuration to IPv4 only
38 38 if [ "$ENABLE_IPV6" = false ] ; then
39 sed -i "s/DHCP=.*/DHCP=v4/" $R/etc/systemd/network/eth.network
39 sed -i "s/DHCP=.*/DHCP=v4/" "$R/etc/systemd/network/eth.network"
40 40 fi
41 41
42 42 else # ENABLE_DHCP=false
43 43 # Set static network configuration for interface eth0
44 44 sed -i\
45 45 -e "s|DHCP=.*|DHCP=no|"\
46 46 -e "s|Address=\$|Address=${NET_ADDRESS}|"\
47 47 -e "s|Gateway=\$|Gateway=${NET_GATEWAY}|"\
48 48 -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_DNS_1}|"\
49 49 -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_DNS_2}|"\
50 50 -e "s|Domains=\$|Domains=${NET_DNS_DOMAINS}|"\
51 51 -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_NTP_1}|"\
52 52 -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_NTP_2}|"\
53 $R/etc/systemd/network/eth.network
53 "$R/etc/systemd/network/eth.network"
54 54 fi
55 55
56 56 # Remove empty settings from network configuration
57 sed -i "/.*=\$/d" $R/etc/systemd/network/eth.network
57 sed -i "/.*=\$/d" "$R/etc/systemd/network/eth.network"
58 58
59 59 # Enable systemd-networkd service
60 60 chroot_exec systemctl enable systemd-networkd
61 61
62 62 # Install host.conf resolver configuration
63 install_readonly files/network/host.conf $R/etc/host.conf
63 install_readonly files/network/host.conf "$R/etc/host.conf"
64 64
65 65 # Enable network stack hardening
66 66 if [ "$ENABLE_HARDNET" = true ] ; then
67 67 # Install sysctl.d configuration files
68 install_readonly files/sysctl.d/82-rpi-net-hardening.conf $R/etc/sysctl.d/82-rpi-net-hardening.conf
68 install_readonly files/sysctl.d/82-rpi-net-hardening.conf "$R/etc/sysctl.d/82-rpi-net-hardening.conf"
69 69
70 70 # Setup resolver warnings about spoofed addresses
71 sed -i "s/^# spoof warn/spoof warn/" $R/etc/host.conf
71 sed -i "s/^# spoof warn/spoof warn/" "$R/etc/host.conf"
72 72 fi
@@ -1,44 +1,44
1 1 #
2 2 # Setup Firewall
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 if [ "$ENABLE_IPTABLES" = true ] ; then
9 9 # Create iptables configuration directory
10 10 mkdir -p "$R/etc/iptables"
11 11
12 12 # Install iptables systemd service
13 install_readonly files/iptables/iptables.service $R/etc/systemd/system/iptables.service
13 install_readonly files/iptables/iptables.service "$R/etc/systemd/system/iptables.service"
14 14
15 15 # Install flush-table script called by iptables service
16 install_exec files/iptables/flush-iptables.sh $R/etc/iptables/flush-iptables.sh
16 install_exec files/iptables/flush-iptables.sh "$R/etc/iptables/flush-iptables.sh"
17 17
18 18 # Install iptables rule file
19 install_readonly files/iptables/iptables.rules $R/etc/iptables/iptables.rules
19 install_readonly files/iptables/iptables.rules "$R/etc/iptables/iptables.rules"
20 20
21 21 # Reload systemd configuration and enable iptables service
22 22 chroot_exec systemctl daemon-reload
23 23 chroot_exec systemctl enable iptables.service
24 24
25 25 if [ "$ENABLE_IPV6" = true ] ; then
26 26 # Install ip6tables systemd service
27 install_readonly files/iptables/ip6tables.service $R/etc/systemd/system/ip6tables.service
27 install_readonly files/iptables/ip6tables.service "$R/etc/systemd/system/ip6tables.service"
28 28
29 29 # Install ip6tables file
30 install_exec files/iptables/flush-ip6tables.sh $R/etc/iptables/flush-ip6tables.sh
30 install_exec files/iptables/flush-ip6tables.sh "$R/etc/iptables/flush-ip6tables.sh"
31 31
32 install_readonly files/iptables/ip6tables.rules $R/etc/iptables/ip6tables.rules
32 install_readonly files/iptables/ip6tables.rules "$R/etc/iptables/ip6tables.rules"
33 33
34 34 # Reload systemd configuration and enable iptables service
35 35 chroot_exec systemctl daemon-reload
36 36 chroot_exec systemctl enable ip6tables.service
37 37 fi
38 38 fi
39 39
40 40 if [ "$ENABLE_SSHD" = false ] ; then
41 41 # Remove SSHD related iptables rules
42 sed -i "/^#/! {/SSH/ s/^/# /}" $R/etc/iptables/iptables.rules 2> /dev/null
43 sed -i "/^#/! {/SSH/ s/^/# /}" $R/etc/iptables/ip6tables.rules 2> /dev/null
42 sed -i "/^#/! {/SSH/ s/^/# /}" "$R/etc/iptables/iptables.rules" 2> /dev/null
43 sed -i "/^#/! {/SSH/ s/^/# /}" "$R/etc/iptables/ip6tables.rules" 2> /dev/null
44 44 fi
@@ -1,32 +1,32
1 1 #
2 2 # Setup users and security settings
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 # Generate crypt(3) password string
9 ENCRYPTED_PASSWORD=`mkpasswd -m sha-512 ${PASSWORD}`
9 ENCRYPTED_PASSWORD=`mkpasswd -m sha-512 "${PASSWORD}"`
10 10
11 11 # Setup default user
12 12 if [ "$ENABLE_USER" = true ] ; then
13 13 chroot_exec adduser --gecos pi --add_extra_groups --disabled-password pi
14 14 chroot_exec usermod -a -G sudo -p "${ENCRYPTED_PASSWORD}" pi
15 15 fi
16 16
17 17 # Setup root password or not
18 18 if [ "$ENABLE_ROOT" = true ] ; then
19 19 chroot_exec usermod -p "${ENCRYPTED_PASSWORD}" root
20 20
21 21 if [ "$ENABLE_ROOT_SSH" = true ] ; then
22 sed -i "s|[#]*PermitRootLogin.*|PermitRootLogin yes|g" $R/etc/ssh/sshd_config
22 sed -i "s|[#]*PermitRootLogin.*|PermitRootLogin yes|g" "$R/etc/ssh/sshd_config"
23 23 fi
24 24 else
25 25 # Set no root password to disable root login
26 26 chroot_exec usermod -p \'!\' root
27 27 fi
28 28
29 29 # Enable serial console systemd style
30 30 if [ "$ENABLE_CONSOLE" = true ] ; then
31 31 chroot_exec systemctl enable serial-getty\@ttyAMA0.service
32 32 fi
@@ -1,13 +1,13
1 1 #
2 2 # Setup Logging
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 # Disable rsyslog
9 9 if [ "$ENABLE_RSYSLOG" = false ] ; then
10 sed -i "s|[#]*ForwardToSyslog=yes|ForwardToSyslog=no|g" $R/etc/systemd/journald.conf
10 sed -i "s|[#]*ForwardToSyslog=yes|ForwardToSyslog=no|g" "$R/etc/systemd/journald.conf"
11 11 chroot_exec systemctl disable rsyslog
12 12 chroot_exec apt-get -qq -y --force-yes purge rsyslog
13 13 fi
@@ -1,31 +1,31
1 1 #
2 2 # Build and Setup U-Boot
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 # Install gcc/c++ build environment inside the chroot
9 9 if [ "$ENABLE_UBOOT" = true ] || [ "$ENABLE_FBTURBO" = true ] ; then
10 10 chroot_exec apt-get -q -y --force-yes --no-install-recommends install linux-compiler-gcc-4.9-arm g++ make bc
11 11 fi
12 12
13 13 # Fetch and build U-Boot bootloader
14 14 if [ "$ENABLE_UBOOT" = true ] ; then
15 15 # Fetch U-Boot bootloader sources
16 git -C $R/tmp clone git://git.denx.de/u-boot.git
16 git -C "$R/tmp" clone git://git.denx.de/u-boot.git
17 17
18 18 # Build and install U-Boot inside chroot
19 19 chroot_exec make -C /tmp/u-boot/ rpi_2_defconfig all
20 20
21 21 # Copy compiled bootloader binary and set config.txt to load it
22 cp $R/tmp/u-boot/u-boot.bin $R/boot/firmware/
23 printf "\n# boot u-boot kernel\nkernel=u-boot.bin\n" >> $R/boot/firmware/config.txt
22 cp "$R/tmp/u-boot/u-boot.bin" "$R/boot/firmware/"
23 printf "\n# boot u-boot kernel\nkernel=u-boot.bin\n" >> "$R/boot/firmware/config.txt"
24 24
25 25 # Install and setup U-Boot command file
26 install_readonly files/boot/uboot.mkimage $R/boot/firmware/uboot.mkimage
27 printf "# Set the kernel boot command line\nsetenv bootargs \"earlyprintk ${CMDLINE}\"\n\n$(cat $R/boot/firmware/uboot.mkimage)" > $R/boot/firmware/uboot.mkimage
26 install_readonly files/boot/uboot.mkimage "$R/boot/firmware/uboot.mkimage"
27 printf "# Set the kernel boot command line\nsetenv bootargs \"earlyprintk ${CMDLINE}\"\n\n$(cat $R/boot/firmware/uboot.mkimage)" > "$R/boot/firmware/uboot.mkimage"
28 28
29 29 # Generate U-Boot bootloader image
30 chroot_exec /tmp/u-boot/tools/mkimage -A ${KERNEL_ARCH} -O linux -T script -C none -a 0x00000000 -e 0x00000000 -n RPi2 -d /boot/firmware/uboot.mkimage /boot/firmware/boot.scr
30 chroot_exec /tmp/u-boot/tools/mkimage -A "${KERNEL_ARCH}" -O linux -T script -C none -a 0x00000000 -e 0x00000000 -n RPi2 -d /boot/firmware/uboot.mkimage /boot/firmware/boot.scr
31 31 fi
@@ -1,34 +1,34
1 1 #
2 2 # Build and Setup fbturbo Xorg driver
3 3 #
4 4
5 5 # Load utility functions
6 6 . ./functions.sh
7 7
8 8 if [ "$ENABLE_FBTURBO" = true ] ; then
9 9 # Fetch fbturbo driver sources
10 git -C $R/tmp clone https://github.com/ssvb/xf86-video-fbturbo.git
10 git -C "$R/tmp" clone https://github.com/ssvb/xf86-video-fbturbo.git
11 11
12 12 # Install Xorg build dependencies
13 13 chroot_exec apt-get -q -y --no-install-recommends install xorg-dev xutils-dev x11proto-dri2-dev libltdl-dev libtool automake libdrm-dev
14 14
15 15 # Build and install fbturbo driver inside chroot
16 16 chroot_exec /bin/bash -x <<'EOF'
17 17 cd /tmp/xf86-video-fbturbo
18 18 autoreconf -vi
19 19 ./configure --prefix=/usr
20 20 make
21 21 make install
22 22 EOF
23 23
24 24 # Install fbturbo driver Xorg configuration
25 install_readonly files/xorg/99-fbturbo.conf $R/usr/share/X11/xorg.conf.d/99-fbturbo.conf
25 install_readonly files/xorg/99-fbturbo.conf "$R/usr/share/X11/xorg.conf.d/99-fbturbo.conf"
26 26
27 27 # Remove Xorg build dependencies
28 28 chroot_exec apt-get -qq -y --auto-remove purge xorg-dev xutils-dev x11proto-dri2-dev libltdl-dev libtool automake libdrm-dev
29 29 fi
30 30
31 31 # Remove gcc/c++ build environment from the chroot
32 32 if [ "$ENABLE_UBOOT" = true ] || [ "$ENABLE_FBTURBO" = true ] ; then
33 33 chroot_exec apt-get -qq -y --auto-remove purge bc binutils cpp cpp-4.9 g++ g++-4.9 gcc gcc-4.9 libasan1 libatomic1 libc-dev-bin libc6-dev libcloog-isl4 libgcc-4.9-dev libgomp1 libisl10 libmpc3 libmpfr4 libstdc++-4.9-dev libubsan0 linux-compiler-gcc-4.9-arm linux-libc-dev make
34 34 fi
@@ -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 cat files/firstboot/10-begin.sh > $R/etc/rc.firstboot
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 12 if [ "$ENABLE_SSHD" = true ] ; then
13 cat files/firstboot/21-generate-ssh-keys.sh >> $R/etc/rc.firstboot
14 rm -f $R/etc/ssh/ssh_host_*
13 cat files/firstboot/21-generate-ssh-keys.sh >> "$R/etc/rc.firstboot"
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 cat files/firstboot/22-expandroot.sh >> $R/etc/rc.firstboot
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 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 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 28 # Finalize rc.firstboot script
29 cat files/firstboot/99-finish.sh >> $R/etc/rc.firstboot
30 chmod +x $R/etc/rc.firstboot
29 cat files/firstboot/99-finish.sh >> "$R/etc/rc.firstboot"
30 chmod +x "$R/etc/rc.firstboot"
31 31
32 32 # Add rc.firstboot script to rc.local
33 sed -i '/exit 0/d' $R/etc/rc.local
34 echo /etc/rc.firstboot >> $R/etc/rc.local
35 echo exit 0 >> $R/etc/rc.local
33 sed -i '/exit 0/d' "$R/etc/rc.local"
34 echo /etc/rc.firstboot >> "$R/etc/rc.local"
35 echo exit 0 >> "$R/etc/rc.local"
@@ -1,456 +1,461
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 18 # Check if ./functions.sh script exists
19 19 if [ ! -r "./functions.sh" ] ; then
20 20 echo "error: './functions.sh' required script not found. please reinstall the latest script version!"
21 21 exit 1
22 22 fi
23 23
24 24 # Load utility functions
25 25 . ./functions.sh
26 26
27 27 # Introduce settings
28 28 set -e
29 29 echo -n -e "\n#\n# RPi2 Bootstrap Settings\n#\n"
30 30 set -x
31 31
32 32 # Debian release
33 33 RELEASE=${RELEASE:=jessie}
34 34 KERNEL_ARCH=${KERNEL_ARCH:=arm}
35 35 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
36 36 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
37 37 COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2}
38 38 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
39 39 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
40 40
41 41 # Build settings
42 42 BASEDIR=$(pwd)/images/${RELEASE}
43 43 BUILDDIR=${BASEDIR}/build
44 44
45 45 # General settings
46 46 HOSTNAME=${HOSTNAME:=rpi2-${RELEASE}}
47 47 PASSWORD=${PASSWORD:=raspberry}
48 48 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
49 49 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
50 50 EXPANDROOT=${EXPANDROOT:=true}
51 51
52 52 # Keyboard settings
53 53 XKB_MODEL=${XKB_MODEL:=""}
54 54 XKB_LAYOUT=${XKB_LAYOUT:=""}
55 55 XKB_VARIANT=${XKB_VARIANT:=""}
56 56 XKB_OPTIONS=${XKB_OPTIONS:=""}
57 57
58 58 # Network settings (DHCP)
59 59 ENABLE_DHCP=${ENABLE_DHCP:=true}
60 60
61 61 # Network settings (static)
62 62 # only used on ENABLE_DHCP=false
63 63 NET_ADDRESS=${NET_ADDRESS:=""}
64 64 NET_GATEWAY=${NET_GATEWAY:=""}
65 65 NET_DNS_1=${NET_DNS_1:=""}
66 66 NET_DNS_2=${NET_DNS_2:=""}
67 67 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
68 68 NET_NTP_1=${NET_NTP_1:=""}
69 69 NET_NTP_2=${NET_NTP_2:=""}
70 70
71 71 # APT settings
72 72 APT_PROXY=${APT_PROXY:=""}
73 73 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
74 74
75 75 # Feature settings
76 76 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
77 77 ENABLE_IPV6=${ENABLE_IPV6:=true}
78 78 ENABLE_SSHD=${ENABLE_SSHD:=true}
79 79 ENABLE_SOUND=${ENABLE_SOUND:=true}
80 80 ENABLE_DBUS=${ENABLE_DBUS:=true}
81 81 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
82 82 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
83 83 ENABLE_XORG=${ENABLE_XORG:=false}
84 84 ENABLE_WM=${ENABLE_WM:=""}
85 85 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
86 86 ENABLE_USER=${ENABLE_USER:=true}
87 87 ENABLE_ROOT=${ENABLE_ROOT:=false}
88 88 ENABLE_ROOT_SSH=${ENABLE_ROOT_SSH:=false}
89 89
90 90 # Advanced settings
91 91 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
92 92 ENABLE_REDUCE=${ENABLE_REDUCE:=flase}
93 93 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
94 94 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
95 95 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
96 96 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
97 97 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
98 98
99 99 # Kernel compilation settings
100 100 BUILD_KERNEL=${BUILD_KERNEL:=false}
101 KERNEL_SRCDIR=${KERNEL_SRCDIR:=""}
102 101 KERNEL_THREADS=${KERNEL_THREADS:=1}
103 102 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
104 103 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
105 KERNEL_CLEANSRC=${KERNEL_CLEANSRC:=false}
106 KERNEL_CONFIGSRC=${KERNEL_CONFIGSRC:=true}
107 KERNEL_RMSRC=${KERNEL_RMSRC:=true}
104 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
105
106 # Kernel compilation from source directory settings
107 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
108 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
109 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
110 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
108 111
109 112 # Image chroot path
110 113 R=${BUILDDIR}/chroot
111 114 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
112 115
113 116 # Packages required for bootstrapping
114 117 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git-core"
115 118
116 119 # Missing packages that need to be installed
117 120 MISSING_PACKAGES=""
118 121
119 122 # Packages required in the chroot build environment
120 123 APT_INCLUDES=${APT_INCLUDES:=""}
121 124 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo"
122 125
123 126 set +x
124 127
125 128 # Are we running as root?
126 129 if [ "$(id -u)" -ne "0" ] ; then
127 130 echo "error: this script must be executed with root privileges!"
128 131 exit 1
129 132 fi
130 133
131 134 # Check if ./bootstrap.d directory exists
132 135 if [ ! -d "./bootstrap.d/" ] ; then
133 136 echo "error: './bootstrap.d' required directory not found. please reinstall the latest script version!"
134 137 exit 1
135 138 fi
136 139
137 140 # Check if ./files directory exists
138 141 if [ ! -d "./files/" ] ; then
139 142 echo "error: './files' required directory not found. please reinstall the latest script version!"
140 143 exit 1
141 144 fi
142 145
143 # Check if specified KERNEL_SRCDIR directory exists
144 if [ -n "$KERNEL_SRCDIR" ] && [ ! -d "$KERNEL_SRCDIR" ] ; then
145 echo "error: ${KERNEL_SRCDIR} (KERNEL_SRCDIR) specified directory not found!"
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!"
146 149 exit 1
147 150 fi
148 151
149 152 # Check if specified CHROOT_SCRIPTS directory exists
150 153 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
151 154 echo "error: ${CHROOT_SCRIPTS} (CHROOT_SCRIPTS) specified directory not found!"
152 155 exit 1
153 156 fi
154 157
155 158 # Add packages required for kernel cross compilation
156 159 if [ "$BUILD_KERNEL" = true ] ; then
157 160 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
161
158 162 if [ "$KERNEL_MENUCONFIG" = true ] ; then
159 163 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} ncurses-dev"
160 164 fi
161 165 fi
162 166
163 167 # Check if all required packages are installed
164 168 for package in $REQUIRED_PACKAGES ; do
165 169 if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then
166 MISSING_PACKAGES="$MISSING_PACKAGES $package"
170 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
167 171 fi
168 172 done
169 173
170 174 # Ask if missing packages should get installed right now
171 175 if [ -n "$MISSING_PACKAGES" ] ; then
172 176 echo "the following packages needed by this script are not installed:"
173 177 echo "$MISSING_PACKAGES"
174 178
175 179 echo -n "\ndo you want to install the missing packages right now? [y/n] "
176 180 read confirm
177 181 if [ "$confirm" != "y" ] ; then
178 182 exit 1
179 183 fi
180 184 fi
181 185
182 186 # Make sure all required packages are installed
183 187 apt-get -qq -y install ${REQUIRED_PACKAGES}
184 188
185 189 # Don't clobber an old build
186 190 if [ -e "$BUILDDIR" ] ; then
187 191 echo "error: directory ${BUILDDIR} already exists, not proceeding"
188 192 exit 1
189 193 fi
190 194
195 # Setup chroot directory
196 mkdir -p "$R"
197
191 198 # Check if build directory has enough of free disk space >512MB
192 199 if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then
193 200 echo "error: ${BUILDDIR} not enough space left on this partition to generate the output image!"
194 201 exit 1
195 202 fi
196 203
197 204 # Warn if build directory has low free disk space <1024MB
198 205 if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "1048576" ] ; then
199 206 echo `df -h --output=avail ${BUILDDIR} | sed "1 s|.*Avail|warning: $partition is low on free space:|"`
200 207 fi
201 208
202 209 set -x
203 210
204 211 # Call "cleanup" function on various signals and errors
205 212 trap cleanup 0 1 2 3 6
206 213
207 # Setup chroot directory
208 mkdir -p $R
209
210 214 # Add required packages for the minbase installation
211 215 if [ "$ENABLE_MINBASE" = true ] ; then
212 216 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools"
213 217 else
214 218 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
215 219 fi
216 220
217 221 # Add parted package, required to get partprobe utility
218 222 if [ "$EXPANDROOT" = true ] ; then
219 223 APT_INCLUDES="${APT_INCLUDES},parted"
220 224 fi
221 225
222 226 # Add dbus package, recommended if using systemd
223 227 if [ "$ENABLE_DBUS" = true ] ; then
224 228 APT_INCLUDES="${APT_INCLUDES},dbus"
225 229 fi
226 230
227 231 # Add iptables IPv4/IPv6 package
228 232 if [ "$ENABLE_IPTABLES" = true ] ; then
229 233 APT_INCLUDES="${APT_INCLUDES},iptables"
230 234 fi
231 235
232 236 # Add openssh server package
233 237 if [ "$ENABLE_SSHD" = true ] ; then
234 238 APT_INCLUDES="${APT_INCLUDES},openssh-server"
235 239 fi
236 240
237 241 # Add alsa-utils package
238 242 if [ "$ENABLE_SOUND" = true ] ; then
239 243 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
240 244 fi
241 245
242 246 # Add rng-tools package
243 247 if [ "$ENABLE_HWRANDOM" = true ] ; then
244 248 APT_INCLUDES="${APT_INCLUDES},rng-tools"
245 249 fi
246 250
247 251 # Add fbturbo video driver
248 252 if [ "$ENABLE_FBTURBO" = true ] ; then
249 253 # Enable xorg package dependencies
250 254 ENABLE_XORG=true
251 255 fi
252 256
253 257 # Add user defined window manager package
254 258 if [ -n "$ENABLE_WM" ] ; then
255 259 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
256 260
257 261 # Enable xorg package dependencies
258 262 ENABLE_XORG=true
259 263 fi
260 264
261 265 # Add xorg package
262 266 if [ "$ENABLE_XORG" = true ] ; then
263 267 APT_INCLUDES="${APT_INCLUDES},xorg"
264 268 fi
265 269
266 # Set KERNEL_CONFIGSRC=true
267 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNEL_SRCDIR" ] ; then
268 KERNEL_CONFIGSRC=true
270 # Set KERNELSRC_CONFIG=true
271 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
272 KERNELSRC_CONFIG=true
269 273 fi
270 274
271 275 ## MAIN bootstrap
272 276 for SCRIPT in bootstrap.d/*.sh; do
273 277 # Execute bootstrap scripts (lexicographical order)
274 head -n 3 $SCRIPT
275 . $SCRIPT
278 head -n 3 "$SCRIPT"
279 . "$SCRIPT"
276 280 done
277 281
278 282 ## Custom bootstrap scripts
279 283 if [ -d "custom.d" ] ; then
280 284 # Execute custom bootstrap scripts (lexicographical order)
281 285 for SCRIPT in custom.d/*.sh; do
282 . $SCRIPT
286 . "$SCRIPT"
283 287 done
284 288 fi
285 289
286 290 # Invoke custom scripts
287 291 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
288 292 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
289 293 # Execute scripts inside the chroot (lexicographical order)
290 294 chroot_exec /bin/bash -x <<'EOF'
291 295 for SCRIPT in /chroot_scripts/* ; do
292 296 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
293 297 $SCRIPT
294 298 fi
295 299 done
296 300 EOF
297 rm -rf "${R}/chroot_scripts"
301 rm -rf "$R/chroot_scripts"
298 302 fi
299 303
300 304 # Remove apt-utils
301 305 chroot_exec apt-get purge -qq -y --force-yes apt-utils
302 306
303 307 # Reduce the image size by removing and compressing
304 308 if [ "$ENABLE_REDUCE" = true ] ; then
305 309 # Install dpkg configuration fragment file
306 install_readonly files/dpkg/01nodoc $R/etc/dpkg/dpkg.cfg.d/01nodoc
310 install_readonly files/dpkg/01nodoc "$R/etc/dpkg/dpkg.cfg.d/01nodoc"
307 311
308 312 # Install APT configuration fragment files
309 install_readonly files/apt/02nocache $R/etc/apt/apt.conf.d/02nocache
310 install_readonly files/apt/03compress $R/etc/apt/apt.conf.d/03compress
311 install_readonly files/apt/04norecommends $R/etc/apt/apt.conf.d/04norecommends
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"
312 316
313 317 # Remove APT cache files
314 rm -fr $R/var/cache/apt/pkgcache.bin
315 rm -fr $R/var/cache/apt/srcpkgcache.bin
318 rm -fr "$R/var/cache/apt/pkgcache.bin"
319 rm -fr "$R/var/cache/apt/srcpkgcache.bin"
316 320
317 321 # Remove all doc and man files
318 find $R/usr/share/doc -depth -type f ! -name copyright | xargs rm || true
319 find $R/usr/share/doc -empty | xargs rmdir || true
320 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
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"
321 325
322 326 # Remove all translation files
323 find $R/usr/share/locale -mindepth 1 -maxdepth 1 ! -name 'en' | xargs rm -r
327 find "$R/usr/share/locale" -mindepth 1 -maxdepth 1 ! -name 'en' | xargs rm -r
324 328
325 329 # Clean APT list of repositories
326 rm -fr $R/var/lib/apt/lists/*
330 rm -fr "$R/var/lib/apt/lists/*"
327 331 chroot_exec apt-get -qq -y update
328 332
333 # Remove GPU kernels
329 334 if [ "$ENABLE_MINGPU" = true ] ; then
330 rm -f $R/boot/firmware/start.elf
331 rm -f $R/boot/firmware/fixup.dat
332 rm -f $R/boot/firmware/start_x.elf
333 rm -f $R/boot/firmware/fixup_x.dat
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"
334 339 fi
335 340 fi
336 341
337 342 # APT Cleanup
338 343 chroot_exec apt-get -y clean
339 344 chroot_exec apt-get -y autoclean
340 345 chroot_exec apt-get -y autoremove
341 346
342 347 # Unmount mounted filesystems
343 umount -l $R/proc
344 umount -l $R/sys
348 umount -l "$R/proc"
349 umount -l "$R/sys"
345 350
346 351 # Clean up directories
347 rm -rf $R/run
348 rm -rf $R/tmp/*
352 rm -rf "$R/run"
353 rm -rf "$R/tmp/*"
349 354
350 355 # Clean up files
351 rm -f $R/etc/apt/sources.list.save
352 rm -f $R/etc/resolvconf/resolv.conf.d/original
353 rm -f $R/etc/*-
354 rm -f $R/root/.bash_history
355 rm -f $R/var/lib/urandom/random-seed
356 rm -f $R/var/lib/dbus/machine-id
357 rm -f $R/etc/machine-id
358 rm -f $R/etc/apt/apt.conf.d/10proxy
359 rm -f $R/etc/resolv.conf
356 rm -f "$R/etc/apt/sources.list.save"
357 rm -f "$R/etc/resolvconf/resolv.conf.d/original"
358 rm -f "$R/etc/*-"
359 rm -f "$R/root/.bash_history"
360 rm -f "$R/var/lib/urandom/random-seed"
361 rm -f "$R/var/lib/dbus/machine-id"
362 rm -f "$R/etc/machine-id"
363 rm -f "$R/etc/apt/apt.conf.d/10proxy"
364 rm -f "$R/etc/resolv.conf"
360 365 rm -f "${R}${QEMU_BINARY}"
361 366
362 367 # Calculate size of the chroot directory in KB
363 CHROOT_SIZE=$(expr `du -s $R | awk '{ print $1 }'`)
368 CHROOT_SIZE=$(expr `du -s "$R" | awk '{ print $1 }'`)
364 369
365 370 # Calculate the amount of needed 512 Byte sectors
366 371 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
367 372 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
368 373 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS})
369 374
370 375 # The root partition is EXT4
371 376 # This means more space than the actual used space of the chroot is used.
372 377 # As overhead for journaling and reserved blocks 20% are added.
373 378 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512)
374 379
375 380 # Calculate required image size in 512 Byte sectors
376 381 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS})
377 382
378 383 # Prepare date string for image file name
379 384 DATE="$(date +%Y-%m-%d)"
380 385
381 386 # Prepare image file
382 387 if [ "$ENABLE_SPLITFS" = true ] ; then
383 388 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=${TABLE_SECTORS}
384 389 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS}
385 390 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=${TABLE_SECTORS}
386 391 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=0 seek=${ROOT_SECTORS}
387 392 # Write partition tables
388 393 sfdisk -q -L -f "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" <<EOM
389 394 unit: sectors
390 395
391 396 1 : start= ${TABLE_SECTORS}, size= ${FRMW_SECTORS}, Id= c, bootable
392 397 2 : start= 0, size= 0, Id= 0
393 398 3 : start= 0, size= 0, Id= 0
394 399 4 : start= 0, size= 0, Id= 0
395 400 EOM
396 401 sfdisk -q -L -f "$BASEDIR/${DATE}-debian-${RELEASE}-root.img" <<EOM
397 402 unit: sectors
398 403
399 404 1 : start= ${TABLE_SECTORS}, size= ${ROOT_SECTORS}, Id=83
400 405 2 : start= 0, size= 0, Id= 0
401 406 3 : start= 0, size= 0, Id= 0
402 407 4 : start= 0, size= 0, Id= 0
403 408 EOM
404 409 # Setup temporary loop devices
405 410 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-frmw.img)"
406 411 ROOT_LOOP="$(losetup -o 1M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-root.img)"
407 412 else
408 413 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS}
409 414 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS}
410 415 # Write partition table
411 416 sfdisk -q -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" <<EOM
412 417 unit: sectors
413 418
414 419 1 : start= ${TABLE_SECTORS}, size= ${FRMW_SECTORS}, Id= c, bootable
415 420 2 : start= ${ROOT_OFFSET}, size= ${ROOT_SECTORS}, Id=83
416 421 3 : start= 0, size= 0, Id= 0
417 422 4 : start= 0, size= 0, Id= 0
418 423 EOM
419 424 # Setup temporary loop devices
420 425 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
421 426 ROOT_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
422 427 fi
423 428
424 429 # Build filesystems
425 430 mkfs.vfat "$FRMW_LOOP"
426 431 mkfs.ext4 "$ROOT_LOOP"
427 432
428 433 # Mount the temporary loop devices
429 434 mkdir -p "$BUILDDIR/mount"
430 435 mount "$ROOT_LOOP" "$BUILDDIR/mount"
431 436
432 437 mkdir -p "$BUILDDIR/mount/boot/firmware"
433 438 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
434 439
435 440 # Copy all files from the chroot to the loop device mount point directory
436 441 rsync -a "$R/" "$BUILDDIR/mount/"
437 442
438 443 # Unmount all temporary loop devices and mount points
439 444 cleanup
440 445
441 446 # Create block map file(s) of image(s)
442 447 if [ "$ENABLE_SPLITFS" = true ] ; then
443 448 # Create block map files for "bmaptool"
444 449 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img"
445 450 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-root.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-root.img"
446 451
447 452 # Image was successfully created
448 453 echo "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
449 454 echo "$BASEDIR/${DATE}-debian-${RELEASE}-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
450 455 else
451 456 # Create block map file for "bmaptool"
452 457 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}.img"
453 458
454 459 # Image was successfully created
455 460 echo "$BASEDIR/${DATE}-debian-${RELEASE}.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
456 461 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant