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