##// END OF EJS Templates
Enhance kernel build by headers install, parallelism and cleanup
Filip Pytloun -
r60:dce1256be471
parent child
Show More
@@ -1,173 +1,176
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 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 ```
22 22
23 23 #### APT settings:
24 24 ##### `APT_SERVER`="ftp.debian.org"
25 25 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.
26 26
27 27 ##### `APT_PROXY`=""
28 28 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.
29 29
30 30 ##### `APT_INCLUDES`=""
31 31 A comma seperated list of additional packages to be installed during bootstrapping.
32 32
33 33 #### General system settings:
34 34 ##### `HOSTNAME`="rpi2-jessie"
35 35 Set system host name. It's recommended that the host name is unique in the corresponding subnet.
36 36
37 37 ##### `PASSWORD`="raspberry"
38 38 Set system `root` password. The same password is used for the created user `pi`. It's **STRONGLY** recommended that you choose a custom password.
39 39
40 40 ##### `DEFLOCAL`="en_US.UTF-8"
41 41 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`.
42 42
43 43 ##### `TIMEZONE`="Europe/Berlin"
44 44 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.
45 45
46 46 ##### `EXPANDROOT`=true
47 47 Expand the root partition and filesystem automatically on first boot.
48 48
49 49 #### Keyboard settings:
50 50 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.
51 51
52 52 ##### `XKBMODEL`=""
53 53 Set the name of the model of your keyboard type.
54 54
55 55 ##### `XKBLAYOUT`=""
56 56 Set the supported keyboard layout(s).
57 57
58 58 ##### `XKBVARIANT`=""
59 59 Set the supported variant(s) of the keyboard layout(s).
60 60
61 61 ##### `XKBOPTIONS`=""
62 62 Set extra xkb configuration options.
63 63
64 64 #### Networking settings (DHCP)
65 65 This setting is used to set up networking auto configuration in `/etc/systemd/network/eth.network`.
66 66
67 67 #####`ENABLE_DHCP`=true
68 68 Set the system to use DHCP. This requires an DHCP server.
69 69
70 70 #### Networking settings (static)
71 71 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`.
72 72
73 73 #####`NET_ADDRESS`=""
74 74 Set a static IPv4 or IPv6 address and its prefix, separated by "/", eg. "192.169.0.3/24".
75 75
76 76 #####`NET_GATEWAY`=""
77 77 Set the IP address for the default gateway.
78 78
79 79 #####`NET_DNS_1`=""
80 80 Set the IP address for the first DNS server.
81 81
82 82 #####`NET_DNS_2`=""
83 83 Set the IP address for the second DNS server.
84 84
85 85 #####`NET_DNS_DOMAINS`=""
86 86 Set the default DNS search domains to use for non fully qualified host names.
87 87
88 88 #####`NET_NTP_1`=""
89 89 Set the IP address for the first NTP server.
90 90
91 91 #####`NET_NTP_2`=""
92 92 Set the IP address for the second NTP server.
93 93
94 94 #### Basic system features:
95 95 ##### `ENABLE_CONSOLE`=true
96 96 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.
97 97
98 98 ##### `ENABLE_IPV6`=true
99 99 Enable IPv6 support. The network interface configuration is managed via systemd-networkd.
100 100
101 101 ##### `ENABLE_SSHD`=true
102 102 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.
103 103
104 104 ##### `ENABLE_RSYSLOG`=true
105 105 If set to false, disable and uninstall rsyslog (so logs will be available only
106 106 in journal files)
107 107
108 108 ##### `ENABLE_SOUND`=true
109 109 Enable sound hardware and install Advanced Linux Sound Architecture.
110 110
111 111 ##### `ENABLE_HWRANDOM`=true
112 112 Enable Hardware Random Number Generator. Strong random numbers are important for most network based communications that use encryption. It's recommended to be enabled.
113 113
114 114 ##### `ENABLE_MINGPU`=false
115 115 Minimize the amount of shared memory reserved for the GPU. It doesn't seem to be possible to fully disable the GPU.
116 116
117 117 ##### `ENABLE_DBUS`=true
118 118 Install and enable D-Bus message bus. Please note that systemd should work without D-bus but it's recommended to be enabled.
119 119
120 120 ##### `ENABLE_XORG`=false
121 121 Install Xorg open-source X Window System.
122 122
123 123 ##### `ENABLE_WM`=""
124 124 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`.
125 125
126 126 #### Advanced sytem features:
127 127 ##### `ENABLE_MINBASE`=false
128 128 Use debootstrap script variant `minbase` which only includes essential packages and apt. This will reduce the disk usage by about 65 MB.
129 129
130 130 ##### `ENABLE_UBOOT`=false
131 131 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.
132 132
133 133 ##### `ENABLE_FBTURBO`=false
134 134 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.
135 135
136 136 ##### `ENABLE_IPTABLES`=false
137 137 Enable iptables IPv4/IPv6 firewall. Simplified ruleset: Allow all outgoing connections. Block all incoming connections except to OpenSSH service.
138 138
139 139 ##### `ENABLE_USER`=true
140 140 Create pi user with password raspberry
141 141
142 142 ##### `ENABLE_ROOT`=true
143 143 Set root user password so root login will be enabled
144 144
145 145 ##### `ENABLE_ROOT_SSH`=true
146 146 Enable password root login via SSH. May be a security risk with default
147 147 password, use only in trusted environments.
148 148
149 149 ##### `ENABLE_HARDNET`=false
150 150 Enable IPv4/IPv6 network stack hardening settings.
151 151
152 152 ##### `CHROOT_SCRIPTS`=""
153 153 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.
154 154
155 155 #### Kernel compilation:
156 156 ##### `BUILD_KERNEL`=false
157 157 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.
158 158
159 ##### `KERNEL_HEADERS`=true
160 If true, also install kernel headers with built kernel.
161
159 162 ## Logging of the bootstrapping process
160 163 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:
161 164
162 165 ```shell
163 166 script -c 'APT_SERVER=ftp.de.debian.org ./rpi2-gen-image.sh' ./build.log
164 167 ```
165 168
166 169 ## Flashing the image file
167 170 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`.
168 171
169 172 #####Flashing examples:
170 173 ```shell
171 174 bmaptool copy ./images/jessie/2015-12-13-debian-jessie.img /dev/mmcblk0
172 175 dd bs=4M if=./images/jessie/2015-12-13-debian-jessie.img of=/dev/mmcblk0
173 176 ```
@@ -1,97 +1,102
1 1 #
2 2 # Kernel installation
3 3 #
4 4
5 5 . ./functions.sh
6 6
7 7 # Fetch and build latest raspberry kernel
8 8 if [ "$BUILD_KERNEL" = true ] ; then
9 9 # Fetch current raspberrypi kernel sources
10 git -C $R/tmp clone --depth=1 https://github.com/raspberrypi/linux
10 git -C $R/usr/local/src clone --depth=1 https://github.com/raspberrypi/linux
11 11
12 12 # Load default raspberry kernel configuration
13 make -C $R/tmp/linux ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig
13 make -C $R/usr/local/src/linux ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig
14 14
15 15 # Cross compile kernel and modules
16 make -C $R/tmp/linux -j 8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs
16 make -C $R/usr/local/src/linux -j$(grep -c processor /proc/cpuinfo) ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs
17 17
18 18 # Install kernel modules
19 make -C $R/tmp/linux ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=../.. modules_install
19 make -C $R/usr/local/src/linux ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=../.. modules_install
20
21 # Install kernel headers
22 if [ "$KERNEL_HEADERS" = true ]; then
23 make -C $R/usr/local/src/linux ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_HDR_PATH=../../usr headers_install
24 fi
20 25
21 26 # Copy and rename compiled kernel to boot directory
22 27 mkdir $R/boot/firmware/
23 $R/tmp/linux/scripts/mkknlimg $R/tmp/linux/arch/arm/boot/zImage $R/boot/firmware/kernel7.img
28 $R/usr/local/src/linux/scripts/mkknlimg $R/usr/local/src/linux/arch/arm/boot/zImage $R/boot/firmware/kernel7.img
24 29
25 30 # Copy dts and dtb device definitions
26 31 mkdir $R/boot/firmware/overlays/
27 cp $R/tmp/linux/arch/arm/boot/dts/*.dtb $R/boot/firmware/
28 cp $R/tmp/linux/arch/arm/boot/dts/overlays/*.dtb* $R/boot/firmware/overlays/
29 cp $R/tmp/linux/arch/arm/boot/dts/overlays/README $R/boot/firmware/overlays/
32 cp $R/usr/local/src/linux/arch/arm/boot/dts/*.dtb $R/boot/firmware/
33 cp $R/usr/local/src/linux/arch/arm/boot/dts/overlays/*.dtb* $R/boot/firmware/overlays/
34 cp $R/usr/local/src/linux/arch/arm/boot/dts/overlays/README $R/boot/firmware/overlays/
30 35
31 36 # Install raspberry bootloader and flash-kernel
32 37 chroot_exec apt-get -qq -y --no-install-recommends install raspberrypi-bootloader-nokernel
33 38 else
34 39 # Kernel installation
35 40 chroot_exec apt-get -qq -y --no-install-recommends install linux-image-${KERNEL} raspberrypi-bootloader-nokernel
36 41
37 42 # Install flash-kernel last so it doesn't try (and fail) to detect the platform in the chroot
38 43 chroot_exec apt-get -qq -y install flash-kernel
39 44
40 45 VMLINUZ="$(ls -1 $R/boot/vmlinuz-* | sort | tail -n 1)"
41 46 [ -z "$VMLINUZ" ] && exit 1
42 47 cp $VMLINUZ $R/boot/firmware/kernel7.img
43 48 fi
44 49
45 50 # Set up firmware boot cmdline
46 51 CMDLINE="dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 rootflags=commit=100,data=writeback elevator=deadline rootwait net.ifnames=1 console=tty1"
47 52
48 53 # Set up serial console support (if requested)
49 54 if [ "$ENABLE_CONSOLE" = true ] ; then
50 55 CMDLINE="${CMDLINE} console=ttyAMA0,115200 kgdboc=ttyAMA0,115200"
51 56 fi
52 57
53 58 # Set up IPv6 networking support
54 59 if [ "$ENABLE_IPV6" = false ] ; then
55 60 CMDLINE="${CMDLINE} ipv6.disable=1"
56 61 fi
57 62
58 63 echo "${CMDLINE}" >$R/boot/firmware/cmdline.txt
59 64
60 65 # Set up firmware config
61 66 install -o root -g root -m 644 files/config.txt $R/boot/firmware/config.txt
62 67
63 68 # Load snd_bcm2835 kernel module at boot time
64 69 if [ "$ENABLE_SOUND" = true ] ; then
65 70 echo "snd_bcm2835" >>$R/etc/modules
66 71 fi
67 72
68 73 # Set smallest possible GPU memory allocation size: 16MB (no X)
69 74 if [ "$ENABLE_MINGPU" = true ] ; then
70 75 echo "gpu_mem=16" >>$R/boot/firmware/config.txt
71 76 fi
72 77
73 78 # Create symlinks
74 79 ln -sf firmware/config.txt $R/boot/config.txt
75 80 ln -sf firmware/cmdline.txt $R/boot/cmdline.txt
76 81
77 82 # Prepare modules-load.d directory
78 83 mkdir -p $R/lib/modules-load.d/
79 84
80 85 # Load random module on boot
81 86 if [ "$ENABLE_HWRANDOM" = true ] ; then
82 87 cat <<EOM >$R/lib/modules-load.d/rpi2.conf
83 88 bcm2708_rng
84 89 EOM
85 90 fi
86 91
87 92 # Prepare modprobe.d directory
88 93 mkdir -p $R/etc/modprobe.d/
89 94
90 95 # Blacklist sound modules
91 96 install -o root -g root -m 644 files/modprobe.d/raspi-blacklist.conf $R/etc/modprobe.d/raspi-blacklist.conf
92 97
93 98 # Create default fstab
94 99 install -o root -g root -m 644 files/fstab $R/etc/fstab
95 100
96 101 # Avoid swapping and increase cache sizes
97 102 install -o root -g root -m 644 files/sysctl.d/81-rpi-vm.conf $R/etc/sysctl.d/81-rpi-vm.conf
@@ -1,301 +1,302
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 source ./functions.sh
19 19
20 20 set -e
21 21 set -x
22 22
23 23 # Debian release
24 24 RELEASE=${RELEASE:=jessie}
25 25 KERNEL=${KERNEL:=3.18.0-trunk-rpi2}
26 26
27 27 # Build settings
28 28 BASEDIR=$(pwd)/images/${RELEASE}
29 29 BUILDDIR=${BASEDIR}/build
30 30
31 31 # General settings
32 32 HOSTNAME=${HOSTNAME:=rpi2-${RELEASE}}
33 33 PASSWORD=${PASSWORD:=raspberry}
34 34 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
35 35 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
36 36 XKBMODEL=${XKBMODEL:=""}
37 37 XKBLAYOUT=${XKBLAYOUT:=""}
38 38 XKBVARIANT=${XKBVARIANT:=""}
39 39 XKBOPTIONS=${XKBOPTIONS:=""}
40 40 EXPANDROOT=${EXPANDROOT:=true}
41 41
42 42 # Network settings
43 43 ENABLE_DHCP=${ENABLE_DHCP:=true}
44 44 # NET_* settings are ignored when ENABLE_DHCP=true
45 45 # NET_ADDRESS is an IPv4 or IPv6 address and its prefix, separated by "/"
46 46 NET_ADDRESS=${NET_ADDRESS:=""}
47 47 NET_GATEWAY=${NET_GATEWAY:=""}
48 48 NET_DNS_1=${NET_DNS_1:=""}
49 49 NET_DNS_2=${NET_DNS_2:=""}
50 50 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
51 51 NET_NTP_1=${NET_NTP_1:=""}
52 52 NET_NTP_2=${NET_NTP_2:=""}
53 53
54 54 # APT settings
55 55 APT_PROXY=${APT_PROXY:=""}
56 56 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
57 57
58 58 # Feature settings
59 59 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
60 60 ENABLE_IPV6=${ENABLE_IPV6:=true}
61 61 ENABLE_SSHD=${ENABLE_SSHD:=true}
62 62 ENABLE_SOUND=${ENABLE_SOUND:=true}
63 63 ENABLE_DBUS=${ENABLE_DBUS:=true}
64 64 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
65 65 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
66 66 ENABLE_XORG=${ENABLE_XORG:=false}
67 67 ENABLE_WM=${ENABLE_WM:=""}
68 68 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
69 69 ENABLE_USER=${ENABLE_USER:=true}
70 70 ENABLE_ROOT=${ENABLE_ROOT:=false}
71 71 ENABLE_ROOT_SSH=${ENABLE_ROOT_SSH:=false}
72 72
73 73 # Advanced settings
74 74 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
75 75 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
76 76 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
77 77 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
78 78 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
79 79
80 80 # Kernel compilation settings
81 81 BUILD_KERNEL=${BUILD_KERNEL:=false}
82 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
82 83
83 84 # Image chroot path
84 85 R=${BUILDDIR}/chroot
85 86 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
86 87
87 88 # Packages required for bootstrapping
88 89 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git-core"
89 90
90 91 # Missing packages that need to be installed
91 92 MISSING_PACKAGES=""
92 93
93 94 # Packages required in the chroot build environment
94 95 APT_INCLUDES=${APT_INCLUDES:=""}
95 96 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,ca-certificates,debian-archive-keyring,dialog,sudo"
96 97
97 98 set +x
98 99
99 100 # Are we running as root?
100 101 if [ "$(id -u)" -ne "0" ] ; then
101 102 echo "this script must be executed with root privileges"
102 103 exit 1
103 104 fi
104 105
105 106 # Add packages required for kernel cross compilation
106 107 if [ "$BUILD_KERNEL" = true ] ; then
107 108 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
108 109 fi
109 110
110 111 # Check if all required packages are installed
111 112 for package in $REQUIRED_PACKAGES ; do
112 113 if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then
113 114 MISSING_PACKAGES="$MISSING_PACKAGES $package"
114 115 fi
115 116 done
116 117
117 118 # Ask if missing packages should get installed right now
118 119 if [ -n "$MISSING_PACKAGES" ] ; then
119 120 echo "the following packages needed by this script are not installed:"
120 121 echo "$MISSING_PACKAGES"
121 122
122 123 echo -n "\ndo you want to install the missing packages right now? [y/n] "
123 124 read confirm
124 125 if [ "$confirm" != "y" ] ; then
125 126 exit 1
126 127 fi
127 128 fi
128 129
129 130 # Make sure all required packages are installed
130 131 apt-get -qq -y install ${REQUIRED_PACKAGES}
131 132
132 133 # Don't clobber an old build
133 134 if [ -e "$BUILDDIR" ]; then
134 135 echo "directory $BUILDDIR already exists, not proceeding"
135 136 exit 1
136 137 fi
137 138
138 139 set -x
139 140
140 141 # Call "cleanup" function on various signals and errors
141 142 trap cleanup 0 1 2 3 6
142 143
143 144 # Set up chroot directory
144 145 mkdir -p $R
145 146
146 147 # Add required packages for the minbase installation
147 148 if [ "$ENABLE_MINBASE" = true ] ; then
148 149 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools"
149 150 else
150 151 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
151 152 fi
152 153
153 154 # Add parted package, required to get partprobe utility
154 155 if [ "$EXPANDROOT" = true ] ; then
155 156 APT_INCLUDES="${APT_INCLUDES},parted"
156 157 fi
157 158
158 159 # Add dbus package, recommended if using systemd
159 160 if [ "$ENABLE_DBUS" = true ] ; then
160 161 APT_INCLUDES="${APT_INCLUDES},dbus"
161 162 fi
162 163
163 164 # Add iptables IPv4/IPv6 package
164 165 if [ "$ENABLE_IPTABLES" = true ] ; then
165 166 APT_INCLUDES="${APT_INCLUDES},iptables"
166 167 fi
167 168
168 169 # Add openssh server package
169 170 if [ "$ENABLE_SSHD" = true ] ; then
170 171 APT_INCLUDES="${APT_INCLUDES},openssh-server"
171 172 fi
172 173
173 174 # Add alsa-utils package
174 175 if [ "$ENABLE_SOUND" = true ] ; then
175 176 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
176 177 fi
177 178
178 179 # Add rng-tools package
179 180 if [ "$ENABLE_HWRANDOM" = true ] ; then
180 181 APT_INCLUDES="${APT_INCLUDES},rng-tools"
181 182 fi
182 183
183 184 if [ "$ENABLE_USER" = true ]; then
184 185 APT_INCLUDES="${APT_INCLUDES},sudo"
185 186 fi
186 187
187 188 # Add fbturbo video driver
188 189 if [ "$ENABLE_FBTURBO" = true ] ; then
189 190 # Enable xorg package dependencies
190 191 ENABLE_XORG=true
191 192 fi
192 193
193 194 # Add user defined window manager package
194 195 if [ -n "$ENABLE_WM" ] ; then
195 196 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
196 197
197 198 # Enable xorg package dependencies
198 199 ENABLE_XORG=true
199 200 fi
200 201
201 202 # Add xorg package
202 203 if [ "$ENABLE_XORG" = true ] ; then
203 204 APT_INCLUDES="${APT_INCLUDES},xorg"
204 205 fi
205 206
206 207 ## Main bootstrap
207 208 for i in bootstrap.d/*.sh; do
208 209 . $i
209 210 done
210 211
211 212 for i in custom.d/*.sh; do
212 213 . $i
213 214 done
214 215
215 216 # Invoke custom scripts
216 217 if [ -n "${CHROOT_SCRIPTS}" ]; then
217 218 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
218 219 LANG=C chroot $R bash -c 'for SCRIPT in /chroot_scripts/*; do if [ -f $SCRIPT -a -x $SCRIPT ]; then $SCRIPT; fi done;'
219 220 rm -rf "${R}/chroot_scripts"
220 221 fi
221 222
222 223 ## Cleanup
223 224 chroot_exec apt-get -y clean
224 225 chroot_exec apt-get -y autoclean
225 226 chroot_exec apt-get -y autoremove
226 227
227 228 # Unmount mounted filesystems
228 229 umount -l $R/proc
229 230 umount -l $R/sys
230 231
231 232 # Clean up files
232 233 rm -f $R/etc/apt/sources.list.save
233 234 rm -f $R/etc/resolvconf/resolv.conf.d/original
234 235 rm -rf $R/run
235 236 mkdir -p $R/run
236 237 rm -f $R/etc/*-
237 238 rm -f $R/root/.bash_history
238 239 rm -rf $R/tmp/*
239 240 rm -f $R/var/lib/urandom/random-seed
240 241 [ -L $R/var/lib/dbus/machine-id ] || rm -f $R/var/lib/dbus/machine-id
241 242 rm -f $R/etc/machine-id
242 243 rm -fr $R/etc/apt/apt.conf.d/10proxy
243 244 rm -f $R/etc/resolv.conf
244 245
245 246 # Calculate size of the chroot directory in KB
246 247 CHROOT_SIZE=$(expr `du -s $R | awk '{ print $1 }'`)
247 248
248 249 # Calculate the amount of needed 512 Byte sectors
249 250 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
250 251 BOOT_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
251 252 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${BOOT_SECTORS})
252 253
253 254 # The root partition is EXT4
254 255 # This means more space than the actual used space of the chroot is used.
255 256 # As overhead for journaling and reserved blocks 20% are added.
256 257 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512)
257 258
258 259 # Calculate required image size in 512 Byte sectors
259 260 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${BOOT_SECTORS} + ${ROOT_SECTORS})
260 261
261 262 # Prepare date string for image file name
262 263 DATE="$(date +%Y-%m-%d)"
263 264
264 265 # Prepare image file
265 266 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS}
266 267 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS}
267 268
268 269 # Write partition table
269 270 sfdisk -q -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" <<EOM
270 271 unit: sectors
271 272
272 273 1 : start= ${TABLE_SECTORS}, size= ${BOOT_SECTORS}, Id= c, bootable
273 274 2 : start= ${ROOT_OFFSET}, size= ${ROOT_SECTORS}, Id=83
274 275 3 : start= 0, size= 0, Id= 0
275 276 4 : start= 0, size= 0, Id= 0
276 277 EOM
277 278
278 279 # Set up temporary loop devices and build filesystems
279 280 VFAT_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
280 281 EXT4_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
281 282 mkfs.vfat "$VFAT_LOOP"
282 283 mkfs.ext4 "$EXT4_LOOP"
283 284
284 285 # Mount the temporary loop devices
285 286 mkdir -p "$BUILDDIR/mount"
286 287 mount "$EXT4_LOOP" "$BUILDDIR/mount"
287 288
288 289 mkdir -p "$BUILDDIR/mount/boot/firmware"
289 290 mount "$VFAT_LOOP" "$BUILDDIR/mount/boot/firmware"
290 291
291 292 # Copy all files from the chroot to the loop device mount point directory
292 293 rsync -a "$R/" "$BUILDDIR/mount/"
293 294
294 295 # Unmount all temporary loop devices and mount points
295 296 cleanup
296 297
297 298 # (optinal) create block map file for "bmaptool"
298 299 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}.img"
299 300
300 301 # Image was successfully created
301 302 echo "$BASEDIR/${DATE}-debian-${RELEASE}.img (${IMAGE_SIZE})" ": successfully created"
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant