##// END OF EJS Templates
fix: ENABLE_CRYPTFS -> UBOOT, SPLITFS, EXPANDROOT - cleanup
Jan Wagner -
r82:d0f91512d9ca
parent child
Show More
@@ -0,0 +1,31
1 logger -t "rc.firstboot" "Regenerating initramfs to remove encrypted root partition auto-expand"
2
3 KERNEL_VERSION=$(uname -r)
4 KERNEL_ARCH=$(uname -m)
5 INITRAMFS="/boot/firmware/initramfs-${KERNEL_VERSION}"
6 INITRAMFS_UBOOT="${INITRAMFS}.uboot"
7
8 # Extract kernel arch
9 case "${KERNEL_ARCH}" in
10 arm*) KERNEL_ARCH=arm ;;
11 esac
12
13 # Regenerate initramfs
14 if [ -r "${INITRAMFS}" ] ; then
15 rm -f /etc/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs
16 rm -f /etc/initramfs-tools/scripts/local-premount/expand-premount
17 rm -f /etc/initramfs-tools/hooks/expand-tools
18 rm -f "${INITRAMFS}"
19 mkinitramfs -o "${INITRAMFS}" "${KERNEL_VERSION}"
20 fi
21
22 # Convert generated initramfs for U-Boot using mkimage
23 if [ -r "${INITRAMFS_UBOOT}" ] ; then
24 rm -f /etc/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs
25 rm -f /etc/initramfs-tools/scripts/local-premount/expand-premount
26 rm -f /etc/initramfs-tools/hooks/expand-tools
27 rm -f "${INITRAMFS_UBOOT}"
28 mkinitramfs -o "${INITRAMFS}" "${KERNEL_VERSION}"
29 mkimage -A "${KERNEL_ARCH}" -T ramdisk -C none -n "initramfs-${KERNEL_VERSION}" -d "${INITRAMFS}" "${INITRAMFS_UBOOT}"
30 rm -f "${INITRAMFS}"
31 fi
@@ -0,0 +1,19
1 #!/bin/sh
2
3 set -e
4
5 # Check for cryptdevice variable
6 if [ -z "$cryptdevice" ] ; then
7 echo "unable to get cryptdevice variable (local-premount)"
8 exit 1
9 fi
10
11 if [ -n "$ROOT" ] ; then
12 # Resize encrypted root partition
13 cryptsetup resize "${ROOT}"
14 e2fsck -fp "${ROOT}"
15 resize2fs -f "${ROOT}"
16 e2fsck -fp "${ROOT}"
17 fi
18
19 exit 0
@@ -0,0 +1,19
1 #!/bin/sh
2
3 set -e
4
5 # Use initramfs utility functions
6 . /usr/share/initramfs-tools/hook-functions
7
8 # Add binaries required for resizing the filesystem
9 copy_exec /bin/grep /bin
10 copy_exec /usr/bin/awk /bin
11 copy_exec /usr/bin/cut /bin
12 copy_exec /usr/bin/tail /bin
13 copy_exec /sbin/fdisk /sbin
14 copy_exec /sbin/parted /sbin
15 copy_exec /sbin/e2fsck /sbin
16 copy_exec /sbin/resize2fs /sbin
17 copy_exec /sbin/partprobe /sbin
18
19 exit 0
@@ -0,0 +1,85
1 #!/bin/sh
2 # expand_encrypted_rootfs initramfs-tools boot script
3
4 # dependencies: grep awk cut tail fdisk parted e2fsck resize2fs
5
6 set -e
7
8 # Wait for USB devices to be ready
9 sleep 5
10
11 # Use initramfs utility functions
12 if [ -r "/scripts/functions" ] ; then
13 . /scripts/functions
14 fi
15
16 # Check for cryptdevice variable
17 if [ -z "$cryptdevice" ] ; then
18 echo "unable to get cryptdevice variable (init-premount)"
19 return 1
20 fi
21
22 # Detect root partition device
23 ROOT_PART=$(echo $cryptdevice | awk -F"/|:" '{ print $3 }')
24 if [ -z "$ROOT_PART" ] ; then
25 log_warning_msg "unable to detect encrypted root partition device (cryptdevice)"
26 return 1
27 fi
28
29 # Extract root device name
30 case "${ROOT_PART}" in
31 mmcblk0*) ROOT_DEV=mmcblk0 ;;
32 sda*) ROOT_DEV=sda ;;
33 esac
34
35 # Check detected root partition name
36 PART_NUM=$(echo ${ROOT_PART} | grep -o '[1-9][0-9]*$')
37 if [ "$PART_NUM" = "$ROOT_PART" ] ; then
38 log_warning_msg "$ROOT_PART is not an SD card. Don't know how to expand"
39 return 1
40 fi
41
42 # NOTE: the NOOBS partition layout confuses parted. For now, let's only
43 # agree to work with a sufficiently simple partition layout
44 if [ "$PART_NUM" -gt 2 ] ; then
45 log_warning_msg "Your partition layout is not currently supported by this tool."
46 return 1
47 fi
48
49 # Check if last partition number
50 LAST_PART_NUM=$(parted /dev/${ROOT_DEV} -ms unit s p | tail -n 1 | cut -f 1 -d:)
51 if [ $LAST_PART_NUM -ne $PART_NUM ]; then
52 log_warning_msg "$ROOT_PART is not the last partition. Don't know how to expand"
53 return 1
54 fi
55
56 # Get the starting offset of the root partition
57 PART_START=$(parted /dev/${ROOT_DEV} -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g')
58 if [ -z "$PART_START" ] ; then
59 log_warning_msg "${ROOT_DEV} unable to get starting sector of the partition"
60 return 1
61 fi
62
63 # Get the possible last sector for the root partition
64 PART_LAST=$(fdisk -l /dev/${ROOT_DEV} | grep '^Disk.*sectors' | awk '{ print $7 - 1 }')
65 if [ -z "$PART_LAST" ] ; then
66 log_warning_msg "${ROOT_DEV} unable to get last sector of the partition"
67 return 1
68 fi
69
70 ### Since rc.local is run with "sh -e", let's add "|| true" to prevent premature exit
71 fdisk /dev/${ROOT_DEV} 2> /dev/null <<EOF2 || true
72 p
73 d
74 $PART_NUM
75 n
76 p
77 $PART_NUM
78 $PART_START
79 $PART_LAST
80 p
81 w
82 EOF2
83
84 partprobe
85 log_success_msg "Root partition successfully resized."
@@ -1,296 +1,297
1 # rpi2-gen-image
1 # rpi2-gen-image
2 ## Introduction
2 ## Introduction
3 `rpi2-gen-image.sh` is an advanced Debian Linux bootstrapping shell script for generating Debian OS images for the Raspberry 2 (RPi2) computer. The script at this time only supports the bootstrapping of the current stable Debian 8 "jessie" release.
3 `rpi2-gen-image.sh` is an advanced Debian Linux bootstrapping shell script for generating Debian OS images for the Raspberry 2 (RPi2) computer. The script at this time only supports the bootstrapping of the current stable Debian 8 "jessie" release.
4
4
5 ## Build dependencies
5 ## Build dependencies
6 The following list of Debian packages must be installed on the build system because they are essentially required for the bootstrapping process. The script will check if all required packages are installed and missing packages will be installed automatically if confirmed by the user.
6 The following list of Debian packages must be installed on the build system because they are essentially required for the bootstrapping process. The script will check if all required packages are installed and missing packages will be installed automatically if confirmed by the user.
7
7
8 ```debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git-core```
8 ```debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git```
9
9
10 ## Command-line parameters
10 ## Command-line parameters
11 The script accepts certain command-line parameters to enable or disable specific OS features, services and configuration settings. These parameters are passed to the `rpi2-gen-image.sh` script via (simple) shell-variables. Unlike environment shell-variables (simple) shell-variables are defined at the beginning of the command-line call of the `rpi2-gen-image.sh` script.
11 The script accepts certain command-line parameters to enable or disable specific OS features, services and configuration settings. These parameters are passed to the `rpi2-gen-image.sh` script via (simple) shell-variables. Unlike environment shell-variables (simple) shell-variables are defined at the beginning of the command-line call of the `rpi2-gen-image.sh` script.
12
12
13 #####Command-line examples:
13 #####Command-line examples:
14 ```shell
14 ```shell
15 ENABLE_UBOOT=true ./rpi2-gen-image.sh
15 ENABLE_UBOOT=true ./rpi2-gen-image.sh
16 ENABLE_CONSOLE=false ENABLE_IPV6=false ./rpi2-gen-image.sh
16 ENABLE_CONSOLE=false ENABLE_IPV6=false ./rpi2-gen-image.sh
17 ENABLE_WM=xfce4 ENABLE_FBTURBO=true ENABLE_MINBASE=true ./rpi2-gen-image.sh
17 ENABLE_WM=xfce4 ENABLE_FBTURBO=true ENABLE_MINBASE=true ./rpi2-gen-image.sh
18 ENABLE_HARDNET=true ENABLE_IPTABLES=true /rpi2-gen-image.sh
18 ENABLE_HARDNET=true ENABLE_IPTABLES=true /rpi2-gen-image.sh
19 APT_SERVER=ftp.de.debian.org APT_PROXY="http://127.0.0.1:3142/" ./rpi2-gen-image.sh
19 APT_SERVER=ftp.de.debian.org APT_PROXY="http://127.0.0.1:3142/" ./rpi2-gen-image.sh
20 ENABLE_MINBASE=true ./rpi2-gen-image.sh
20 ENABLE_MINBASE=true ./rpi2-gen-image.sh
21 BUILD_KERNEL=true ENABLE_MINBASE=true ENABLE_IPV6=false ./rpi2-gen-image.sh
21 BUILD_KERNEL=true ENABLE_MINBASE=true ENABLE_IPV6=false ./rpi2-gen-image.sh
22 BUILD_KERNEL=true KERNELSRC_DIR=/tmp/linux ./rpi2-gen-image.sh
22 BUILD_KERNEL=true KERNELSRC_DIR=/tmp/linux ./rpi2-gen-image.sh
23 ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi2-gen-image.sh
23 ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi2-gen-image.sh
24 ENABLE_CRYPTFS=true CRYPTFS_PASSWORD=changeme EXPANDROOT=false ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi2-gen-image.sh
24 ENABLE_CRYPTFS=true CRYPTFS_PASSWORD=changeme EXPANDROOT=false ENABLE_MINBASE=true ENABLE_REDUCE=true ENABLE_MINGPU=true BUILD_KERNEL=true ./rpi2-gen-image.sh
25 ```
25 ```
26
26
27 #### APT settings:
27 #### APT settings:
28 ##### `APT_SERVER`="ftp.debian.org"
28 ##### `APT_SERVER`="ftp.debian.org"
29 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 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.
30
30
31 ##### `APT_PROXY`=""
31 ##### `APT_PROXY`=""
32 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 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.
33
33
34 ##### `APT_INCLUDES`=""
34 ##### `APT_INCLUDES`=""
35 A comma separated list of additional packages to be installed during bootstrapping.
35 A comma separated list of additional packages to be installed during bootstrapping.
36
36
37 #### General system settings:
37 #### General system settings:
38 ##### `HOSTNAME`="rpi2-jessie"
38 ##### `HOSTNAME`="rpi2-jessie"
39 Set system host name. It's recommended that the host name is unique in the corresponding subnet.
39 Set system host name. It's recommended that the host name is unique in the corresponding subnet.
40
40
41 ##### `PASSWORD`="raspberry"
41 ##### `PASSWORD`="raspberry"
42 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 Set system `root` password. The same password is used for the created user `pi`. It's **STRONGLY** recommended that you choose a custom password.
43
43
44 ##### `DEFLOCAL`="en_US.UTF-8"
44 ##### `DEFLOCAL`="en_US.UTF-8"
45 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 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`.
46
46
47 ##### `TIMEZONE`="Europe/Berlin"
47 ##### `TIMEZONE`="Europe/Berlin"
48 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 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.
49
49
50 ##### `EXPANDROOT`=true
50 ##### `EXPANDROOT`=true
51 Expand the root partition and filesystem automatically on first boot.
51 Expand the root partition and filesystem automatically on first boot.
52
52
53 #### Keyboard settings:
53 #### Keyboard settings:
54 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 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.
55
55
56 ##### `XKB_MODEL`=""
56 ##### `XKB_MODEL`=""
57 Set the name of the model of your keyboard type.
57 Set the name of the model of your keyboard type.
58
58
59 ##### `XKB_LAYOUT`=""
59 ##### `XKB_LAYOUT`=""
60 Set the supported keyboard layout(s).
60 Set the supported keyboard layout(s).
61
61
62 ##### `XKB_VARIANT`=""
62 ##### `XKB_VARIANT`=""
63 Set the supported variant(s) of the keyboard layout(s).
63 Set the supported variant(s) of the keyboard layout(s).
64
64
65 ##### `XKB_OPTIONS`=""
65 ##### `XKB_OPTIONS`=""
66 Set extra xkb configuration options.
66 Set extra xkb configuration options.
67
67
68 #### Networking settings (DHCP):
68 #### Networking settings (DHCP):
69 This parameter is used to set up networking auto configuration in `/etc/systemd/network/eth.network`.
69 This parameter is used to set up networking auto configuration in `/etc/systemd/network/eth.network`.
70
70
71 #####`ENABLE_DHCP`=true
71 #####`ENABLE_DHCP`=true
72 Set the system to use DHCP. This requires an DHCP server.
72 Set the system to use DHCP. This requires an DHCP server.
73
73
74 #### Networking settings (static):
74 #### Networking settings (static):
75 These parameters are used to set up a static networking configuration in /etc/systemd/network/eth.network. The following static networking parameters are only supported if `ENABLE_DHCP` was set to `false`.
75 These parameters are used to set up a static networking configuration in /etc/systemd/network/eth.network. The following static networking parameters are only supported if `ENABLE_DHCP` was set to `false`.
76
76
77 #####`NET_ADDRESS`=""
77 #####`NET_ADDRESS`=""
78 Set a static IPv4 or IPv6 address and its prefix, separated by "/", eg. "192.169.0.3/24".
78 Set a static IPv4 or IPv6 address and its prefix, separated by "/", eg. "192.169.0.3/24".
79
79
80 #####`NET_GATEWAY`=""
80 #####`NET_GATEWAY`=""
81 Set the IP address for the default gateway.
81 Set the IP address for the default gateway.
82
82
83 #####`NET_DNS_1`=""
83 #####`NET_DNS_1`=""
84 Set the IP address for the first DNS server.
84 Set the IP address for the first DNS server.
85
85
86 #####`NET_DNS_2`=""
86 #####`NET_DNS_2`=""
87 Set the IP address for the second DNS server.
87 Set the IP address for the second DNS server.
88
88
89 #####`NET_DNS_DOMAINS`=""
89 #####`NET_DNS_DOMAINS`=""
90 Set the default DNS search domains to use for non fully qualified host names.
90 Set the default DNS search domains to use for non fully qualified host names.
91
91
92 #####`NET_NTP_1`=""
92 #####`NET_NTP_1`=""
93 Set the IP address for the first NTP server.
93 Set the IP address for the first NTP server.
94
94
95 #####`NET_NTP_2`=""
95 #####`NET_NTP_2`=""
96 Set the IP address for the second NTP server.
96 Set the IP address for the second NTP server.
97
97
98 #### Basic system features:
98 #### Basic system features:
99 ##### `ENABLE_CONSOLE`=true
99 ##### `ENABLE_CONSOLE`=true
100 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 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.
101
101
102 ##### `ENABLE_IPV6`=true
102 ##### `ENABLE_IPV6`=true
103 Enable IPv6 support. The network interface configuration is managed via systemd-networkd.
103 Enable IPv6 support. The network interface configuration is managed via systemd-networkd.
104
104
105 ##### `ENABLE_SSHD`=true
105 ##### `ENABLE_SSHD`=true
106 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 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.
107
107
108 ##### `ENABLE_RSYSLOG`=true
108 ##### `ENABLE_RSYSLOG`=true
109 If set to false, disable and uninstall rsyslog (so logs will be available only
109 If set to false, disable and uninstall rsyslog (so logs will be available only
110 in journal files)
110 in journal files)
111
111
112 ##### `ENABLE_SOUND`=true
112 ##### `ENABLE_SOUND`=true
113 Enable sound hardware and install Advanced Linux Sound Architecture.
113 Enable sound hardware and install Advanced Linux Sound Architecture.
114
114
115 ##### `ENABLE_HWRANDOM`=true
115 ##### `ENABLE_HWRANDOM`=true
116 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 Enable Hardware Random Number Generator. Strong random numbers are important for most network based communications that use encryption. It's recommended to be enabled.
117
117
118 ##### `ENABLE_MINGPU`=false
118 ##### `ENABLE_MINGPU`=false
119 Minimize the amount of shared memory reserved for the GPU. It doesn't seem to be possible to fully disable the GPU.
119 Minimize the amount of shared memory reserved for the GPU. It doesn't seem to be possible to fully disable the GPU.
120
120
121 ##### `ENABLE_DBUS`=true
121 ##### `ENABLE_DBUS`=true
122 Install and enable D-Bus message bus. Please note that systemd should work without D-bus but it's recommended to be enabled.
122 Install and enable D-Bus message bus. Please note that systemd should work without D-bus but it's recommended to be enabled.
123
123
124 ##### `ENABLE_XORG`=false
124 ##### `ENABLE_XORG`=false
125 Install Xorg open-source X Window System.
125 Install Xorg open-source X Window System.
126
126
127 ##### `ENABLE_WM`=""
127 ##### `ENABLE_WM`=""
128 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 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`.
129
129
130 #### Advanced system features:
130 #### Advanced system features:
131 ##### `ENABLE_MINBASE`=false
131 ##### `ENABLE_MINBASE`=false
132 Use debootstrap script variant `minbase` which only includes essential packages and apt. This will reduce the disk usage by about 65 MB.
132 Use debootstrap script variant `minbase` which only includes essential packages and apt. This will reduce the disk usage by about 65 MB.
133
133
134 ##### `ENABLE_REDUCE`=false
134 ##### `ENABLE_REDUCE`=false
135 Reduce the disk space usage by deleting packages and files. See `REDUCE_*` parameters for detailed information.
135 Reduce the disk space usage by deleting packages and files. See `REDUCE_*` parameters for detailed information.
136
136
137 ##### `ENABLE_UBOOT`=false
137 ##### `ENABLE_UBOOT`=false
138 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 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.
139
139
140 ##### `ENABLE_FBTURBO`=false
140 ##### `ENABLE_FBTURBO`=false
141 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 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.
142
142
143 ##### `ENABLE_IPTABLES`=false
143 ##### `ENABLE_IPTABLES`=false
144 Enable iptables IPv4/IPv6 firewall. Simplified ruleset: Allow all outgoing connections. Block all incoming connections except to OpenSSH service.
144 Enable iptables IPv4/IPv6 firewall. Simplified ruleset: Allow all outgoing connections. Block all incoming connections except to OpenSSH service.
145
145
146 ##### `ENABLE_USER`=true
146 ##### `ENABLE_USER`=true
147 Create pi user with password raspberry
147 Create pi user with password raspberry
148
148
149 ##### `ENABLE_ROOT`=true
149 ##### `ENABLE_ROOT`=true
150 Set root user password so root login will be enabled
150 Set root user password so root login will be enabled
151
151
152 ##### `ENABLE_ROOT_SSH`=true
152 ##### `ENABLE_ROOT_SSH`=true
153 Enable password root login via SSH. May be a security risk with default
153 Enable password root login via SSH. May be a security risk with default
154 password, use only in trusted environments.
154 password, use only in trusted environments.
155
155
156 ##### `ENABLE_HARDNET`=false
156 ##### `ENABLE_HARDNET`=false
157 Enable IPv4/IPv6 network stack hardening settings.
157 Enable IPv4/IPv6 network stack hardening settings.
158
158
159 ##### `ENABLE_SPLITFS`=false
159 ##### `ENABLE_SPLITFS`=false
160 Enable having root partition on an USB drive by creating two image files: one for the `/boot/firmware` mount point, and another for `/`.
160 Enable having root partition on an USB drive by creating two image files: one for the `/boot/firmware` mount point, and another for `/`.
161
161
162 ##### `CHROOT_SCRIPTS`=""
162 ##### `CHROOT_SCRIPTS`=""
163 Path to a directory with scripts that should be run in the chroot before the image is finally built. Every executable file in this directory is run in lexicographical order.
163 Path to a directory with scripts that should be run in the chroot before the image is finally built. Every executable file in this directory is run in lexicographical order.
164
164
165 ##### `ENABLE_INITRAMFS`=false
165 ##### `ENABLE_INITRAMFS`=false
166 Create an initramfs that that will be loaded during the Linux startup process. `ENABLE_INITRAMFS` will automatically get enabled if `ENABLE_CRYPTFS`=true. This parameter will be ignored if `BUILD_KERNEL`=false.
166 Create an initramfs that that will be loaded during the Linux startup process. `ENABLE_INITRAMFS` will automatically get enabled if `ENABLE_CRYPTFS`=true. This parameter will be ignored if `BUILD_KERNEL`=false.
167
167
168 #### Kernel compilation:
168 #### Kernel compilation:
169 ##### `BUILD_KERNEL`=false
169 ##### `BUILD_KERNEL`=false
170 Build and install the latest RPi2 Linux kernel. Currently only the default RPi2 kernel configuration is used.
170 Build and install the latest RPi2 Linux kernel. Currently only the default RPi2 kernel configuration is used.
171
171
172 ##### `KERNEL_REDUCE`=false
172 ##### `KERNEL_REDUCE`=false
173 Reduce the size of the generated kernel by removing unwanted device, network and filesystem drivers (experimental).
173 Reduce the size of the generated kernel by removing unwanted device, network and filesystem drivers (experimental).
174
174
175 ##### `KERNEL_THREADS`=1
175 ##### `KERNEL_THREADS`=1
176 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.
176 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.
177
177
178 ##### `KERNEL_HEADERS`=true
178 ##### `KERNEL_HEADERS`=true
179 Install kernel headers with built kernel.
179 Install kernel headers with built kernel.
180
180
181 ##### `KERNEL_MENUCONFIG`=false
181 ##### `KERNEL_MENUCONFIG`=false
182 Start `make menuconfig` interactive menu-driven kernel configuration. The script will continue after `make menuconfig` was terminated.
182 Start `make menuconfig` interactive menu-driven kernel configuration. The script will continue after `make menuconfig` was terminated.
183
183
184 ##### `KERNEL_REMOVESRC`=true
184 ##### `KERNEL_REMOVESRC`=true
185 Remove all kernel sources from the generated OS image after it was built and installed.
185 Remove all kernel sources from the generated OS image after it was built and installed.
186
186
187 ##### `KERNELSRC_DIR`=""
187 ##### `KERNELSRC_DIR`=""
188 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.
188 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.
189
189
190 ##### `KERNELSRC_CLEAN`=false
190 ##### `KERNELSRC_CLEAN`=false
191 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 parameter will be ignored if no `KERNELSRC_DIR` was specified or if `KERNELSRC_PREBUILT`=true.
191 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 parameter will be ignored if no `KERNELSRC_DIR` was specified or if `KERNELSRC_PREBUILT`=true.
192
192
193 ##### `KERNELSRC_CONFIG`=true
193 ##### `KERNELSRC_CONFIG`=true
194 Run `make bcm2709_defconfig` (and optional `make menuconfig`) to configure the kernel sources before building. This parameter is automatically set to `true` if no existing kernel sources directory was specified using `KERNELSRC_DIR`. This parameter is ignored if `KERNELSRC_PREBUILT`=true.
194 Run `make bcm2709_defconfig` (and optional `make menuconfig`) to configure the kernel sources before building. This parameter is automatically set to `true` if no existing kernel sources directory was specified using `KERNELSRC_DIR`. This parameter is ignored if `KERNELSRC_PREBUILT`=true.
195
195
196 ##### `KERNELSRC_PREBUILT`=false
196 ##### `KERNELSRC_PREBUILT`=false
197 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.
197 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.
198
198
199 #### Reduce disk usage:
199 #### Reduce disk usage:
200 The following list of parameters is ignored if `ENABLE_REDUCE`=false.
200 The following list of parameters is ignored if `ENABLE_REDUCE`=false.
201
201
202 ##### `REDUCE_APT`=true
202 ##### `REDUCE_APT`=true
203 Configure APT to use compressed package repository lists and no package caching files.
203 Configure APT to use compressed package repository lists and no package caching files.
204
204
205 ##### `REDUCE_DOC`=true
205 ##### `REDUCE_DOC`=true
206 Remove all doc files (harsh). Configure APT to not include doc files on future `apt-get` package installations.
206 Remove all doc files (harsh). Configure APT to not include doc files on future `apt-get` package installations.
207
207
208 ##### `REDUCE_MAN`=true
208 ##### `REDUCE_MAN`=true
209 Remove all man pages and info files (harsh). Configure APT to not include man pages on future `apt-get` package installations.
209 Remove all man pages and info files (harsh). Configure APT to not include man pages on future `apt-get` package installations.
210
210
211 ##### `REDUCE_VIM`=false
211 ##### `REDUCE_VIM`=false
212 Replace `vim-tiny` package by `levee` a tiny vim clone.
212 Replace `vim-tiny` package by `levee` a tiny vim clone.
213
213
214 ##### `REDUCE_BASH`=false
214 ##### `REDUCE_BASH`=false
215 Remove `bash` package and switch to `dash` shell (experimental).
215 Remove `bash` package and switch to `dash` shell (experimental).
216
216
217 ##### `REDUCE_HWDB`=true
217 ##### `REDUCE_HWDB`=true
218 Remove PCI related hwdb files (experimental).
218 Remove PCI related hwdb files (experimental).
219
219
220 ##### `REDUCE_SSHD`=true
220 ##### `REDUCE_SSHD`=true
221 Replace `openssh-server` with `dropbear`.
221 Replace `openssh-server` with `dropbear`.
222
222
223 ##### `REDUCE_LOCALE`=true
223 ##### `REDUCE_LOCALE`=true
224 Remove all `locale` translation files.
224 Remove all `locale` translation files.
225
225
226 #### Encrypted root partition:
226 #### Encrypted root partition:
227
227
228 ##### `ENABLE_CRYPTFS`=false
228 ##### `ENABLE_CRYPTFS`=false
229 Enable full system encryption with dm-crypt. Setup a fully LUKS encrypted root partition (aes-xts-plain64:sha512) and generate required initramfs. The /boot directory will not be encrypted. This parameter will be ignored if `BUILD_KERNEL`=false. `ENABLE_CRYPTFS` is experimental. `ENABLE_UBOOT`, `ENABLE_SPLITFS`, `EXPANDROOT` and SSH-to-initramfs are currently not supported but will be soon - feel free to help.
229 Enable full system encryption with dm-crypt. Setup a fully LUKS encrypted root partition (aes-xts-plain64:sha512) and generate required initramfs. The /boot directory will not be encrypted. This parameter will be ignored if `BUILD_KERNEL`=false. `ENABLE_CRYPTFS` is experimental. SSH-to-initramfs is currently not supported but will be soon - feel free to help.
230
230
231 ##### `CRYPTFS_PASSWORD`=""
231 ##### `CRYPTFS_PASSWORD`=""
232 Set password of the encrypted root partition. This parameter is mandatory if `ENABLE_CRYPTFS`=true.
232 Set password of the encrypted root partition. This parameter is mandatory if `ENABLE_CRYPTFS`=true.
233
233
234 ##### `CRYPTFS_MAPPING`="secure"
234 ##### `CRYPTFS_MAPPING`="secure"
235 Set name of dm-crypt managed device-mapper mapping.
235 Set name of dm-crypt managed device-mapper mapping.
236
236
237 ##### `CRYPTFS_CIPHER`="aes-xts-plain64:sha512"
237 ##### `CRYPTFS_CIPHER`="aes-xts-plain64:sha512"
238 Set cipher specification string. `aes-xts*` ciphers are strongly recommended.
238 Set cipher specification string. `aes-xts*` ciphers are strongly recommended.
239
239
240 ##### `CRYPTFS_XTSKEYSIZE`=512
240 ##### `CRYPTFS_XTSKEYSIZE`=512
241 Sets key size in bits. The argument has to be a multiple of 8.
241 Sets key size in bits. The argument has to be a multiple of 8.
242
242
243 ## Understanding the script
243 ## Understanding the script
244 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:
244 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:
245
245
246 | Script | Description |
246 | Script | Description |
247 | --- | --- |
247 | --- | --- |
248 | `10-bootstrap.sh` | Debootstrap basic system |
248 | `10-bootstrap.sh` | Debootstrap basic system |
249 | `11-apt.sh` | Setup APT repositories |
249 | `11-apt.sh` | Setup APT repositories |
250 | `12-locale.sh` | Setup Locales and keyboard settings |
250 | `12-locale.sh` | Setup Locales and keyboard settings |
251 | `13-kernel.sh` | Build and install RPi2 Kernel |
251 | `13-kernel.sh` | Build and install RPi2 Kernel |
252 | `20-networking.sh` | Setup Networking |
252 | `20-networking.sh` | Setup Networking |
253 | `21-firewall.sh` | Setup Firewall |
253 | `21-firewall.sh` | Setup Firewall |
254 | `30-security.sh` | Setup Users and Security settings |
254 | `30-security.sh` | Setup Users and Security settings |
255 | `31-logging.sh` | Setup Logging |
255 | `31-logging.sh` | Setup Logging |
256 | `41-uboot.sh` | Build and Setup U-Boot |
256 | `41-uboot.sh` | Build and Setup U-Boot |
257 | `42-fbturbo.sh` | Build and Setup fbturbo Xorg driver |
257 | `42-fbturbo.sh` | Build and Setup fbturbo Xorg driver |
258 | `50-firstboot.sh` | First boot actions |
258 | `50-firstboot.sh` | First boot actions |
259 | `99-reduce.sh` | Reduce the disk space usage |
259 | `99-reduce.sh` | Reduce the disk space usage |
260
260
261 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.
261 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.
262
262
263 | Directory | Description |
263 | Directory | Description |
264 | --- | --- |
264 | --- | --- |
265 | `apt` | APT management configuration files |
265 | `apt` | APT management configuration files |
266 | `boot` | Boot and RPi2 configuration files |
266 | `boot` | Boot and RPi2 configuration files |
267 | `dpkg` | Package Manager configuration |
267 | `dpkg` | Package Manager configuration |
268 | `firstboot` | Scripts that get executed on first boot |
268 | `firstboot` | Scripts that get executed on first boot |
269 | `initramfs` | Initramfs scripts |
269 | `iptables` | Firewall configuration files |
270 | `iptables` | Firewall configuration files |
270 | `locales` | Locales configuration |
271 | `locales` | Locales configuration |
271 | `modules` | Kernel Modules configuration |
272 | `modules` | Kernel Modules configuration |
272 | `mount` | Fstab configuration |
273 | `mount` | Fstab configuration |
273 | `network` | Networking configuration files |
274 | `network` | Networking configuration files |
274 | `sysctl.d` | Swapping and Network Hardening configuration |
275 | `sysctl.d` | Swapping and Network Hardening configuration |
275 | `xorg` | fbturbo Xorg driver configuration |
276 | `xorg` | fbturbo Xorg driver configuration |
276
277
277 ## Logging of the bootstrapping process
278 ## Logging of the bootstrapping process
278 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:
279 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:
279
280
280 ```shell
281 ```shell
281 script -c 'APT_SERVER=ftp.de.debian.org ./rpi2-gen-image.sh' ./build.log
282 script -c 'APT_SERVER=ftp.de.debian.org ./rpi2-gen-image.sh' ./build.log
282 ```
283 ```
283
284
284 ## Flashing the image file
285 ## Flashing the image file
285 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`.
286 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`.
286
287
287 #####Flashing examples:
288 #####Flashing examples:
288 ```shell
289 ```shell
289 bmaptool copy ./images/jessie/2015-12-13-debian-jessie.img /dev/mmcblk0
290 bmaptool copy ./images/jessie/2015-12-13-debian-jessie.img /dev/mmcblk0
290 dd bs=4M if=./images/jessie/2015-12-13-debian-jessie.img of=/dev/mmcblk0
291 dd bs=4M if=./images/jessie/2015-12-13-debian-jessie.img of=/dev/mmcblk0
291 ```
292 ```
292 If you have set `ENABLE_SPLITFS`, copy the `-frmw` image on the microSD card, then the `-root` one on the USB drive:
293 If you have set `ENABLE_SPLITFS`, copy the `-frmw` image on the microSD card, then the `-root` one on the USB drive:
293 ```shell
294 ```shell
294 bmaptool copy ./images/jessie/2015-12-13-debian-jessie-frmw.img /dev/mmcblk0
295 bmaptool copy ./images/jessie/2015-12-13-debian-jessie-frmw.img /dev/mmcblk0
295 bmaptool copy ./images/jessie/2015-12-13-debian-jessie-root.img /dev/sdc
296 bmaptool copy ./images/jessie/2015-12-13-debian-jessie-root.img /dev/sdc
296 ```
297 ```
@@ -1,28 +1,28
1 #
1 #
2 # Debootstrap basic system
2 # Debootstrap basic system
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 # Base debootstrap (unpack only)
8 # Base debootstrap (unpack only)
9 if [ "$ENABLE_MINBASE" = true ] ; then
9 if [ "$ENABLE_MINBASE" = true ] ; then
10 http_proxy=${APT_PROXY} debootstrap --arch="${RELEASE_ARCH}" --foreign --variant=minbase --include="${APT_INCLUDES}" "${RELEASE}" "$R" "http://${APT_SERVER}/debian"
10 http_proxy=${APT_PROXY} debootstrap --arch="${RELEASE_ARCH}" --foreign --variant=minbase --include="${APT_INCLUDES}" "${RELEASE}" "${R}" "http://${APT_SERVER}/debian"
11 else
11 else
12 http_proxy=${APT_PROXY} debootstrap --arch="${RELEASE_ARCH}" --foreign --include="${APT_INCLUDES}" "${RELEASE}" "$R" "http://${APT_SERVER}/debian"
12 http_proxy=${APT_PROXY} debootstrap --arch="${RELEASE_ARCH}" --foreign --include="${APT_INCLUDES}" "${RELEASE}" "${R}" "http://${APT_SERVER}/debian"
13 fi
13 fi
14
14
15 # Copy qemu emulator binary to chroot
15 # Copy qemu emulator binary to chroot
16 install_exec "${QEMU_BINARY}" "${R}${QEMU_BINARY}"
16 install_exec "${QEMU_BINARY}" "${R}${QEMU_BINARY}"
17
17
18 # Copy debian-archive-keyring.pgp
18 # Copy debian-archive-keyring.pgp
19 mkdir -p "$R/usr/share/keyrings"
19 mkdir -p "${R}/usr/share/keyrings"
20 install_readonly /usr/share/keyrings/debian-archive-keyring.gpg "$R/usr/share/keyrings/debian-archive-keyring.gpg"
20 install_readonly /usr/share/keyrings/debian-archive-keyring.gpg "${R}/usr/share/keyrings/debian-archive-keyring.gpg"
21
21
22 # Complete the bootstrapping process
22 # Complete the bootstrapping process
23 chroot_exec /debootstrap/debootstrap --second-stage
23 chroot_exec /debootstrap/debootstrap --second-stage
24
24
25 # Mount required filesystems
25 # Mount required filesystems
26 mount -t proc none "$R/proc"
26 mount -t proc none "${R}/proc"
27 mount -t sysfs none "$R/sys"
27 mount -t sysfs none "${R}/sys"
28 mount --bind /dev/pts "$R/dev/pts"
28 mount --bind /dev/pts "${R}/dev/pts"
@@ -1,37 +1,37
1 #
1 #
2 # Setup APT repositories
2 # Setup APT repositories
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 # Install and setup APT proxy configuration
8 # Install and setup APT proxy configuration
9 if [ -z "$APT_PROXY" ] ; then
9 if [ -z "$APT_PROXY" ] ; then
10 install_readonly files/apt/10proxy "$R/etc/apt/apt.conf.d/10proxy"
10 install_readonly files/apt/10proxy "${ETCDIR}/apt/apt.conf.d/10proxy"
11 sed -i "s/\"\"/\"${APT_PROXY}\"/" "$R/etc/apt/apt.conf.d/10proxy"
11 sed -i "s/\"\"/\"${APT_PROXY}\"/" "${ETCDIR}/apt/apt.conf.d/10proxy"
12 fi
12 fi
13
13
14 if [ "$BUILD_KERNEL" = false ] ; then
14 if [ "$BUILD_KERNEL" = false ] ; then
15 # Install APT pinning configuration for flash-kernel package
15 # Install APT pinning configuration for flash-kernel package
16 install_readonly files/apt/flash-kernel "$R/etc/apt/preferences.d/flash-kernel"
16 install_readonly files/apt/flash-kernel "${ETCDIR}/apt/preferences.d/flash-kernel"
17
17
18 # Install APT sources.list
18 # Install APT sources.list
19 install_readonly files/apt/sources.list "$R/etc/apt/sources.list"
19 install_readonly files/apt/sources.list "${ETCDIR}/apt/sources.list"
20 echo "deb https://repositories.collabora.co.uk/debian ${RELEASE} rpi2" >> "$R/etc/apt/sources.list"
20 echo "deb https://repositories.collabora.co.uk/debian ${RELEASE} rpi2" >> "${ETCDIR}/apt/sources.list"
21
21
22 # Upgrade collabora package index and install collabora keyring
22 # Upgrade collabora package index and install collabora keyring
23 chroot_exec apt-get -qq -y update
23 chroot_exec apt-get -qq -y update
24 chroot_exec apt-get -qq -y --force-yes install collabora-obs-archive-keyring
24 chroot_exec apt-get -qq -y --force-yes install collabora-obs-archive-keyring
25 else # BUILD_KERNEL=true
25 else # BUILD_KERNEL=true
26 # Install APT sources.list
26 # Install APT sources.list
27 install_readonly files/apt/sources.list "$R/etc/apt/sources.list"
27 install_readonly files/apt/sources.list "${ETCDIR}/apt/sources.list"
28
28
29 # Use specified APT server and release
29 # Use specified APT server and release
30 sed -i "s/\/ftp.debian.org\//\/${APT_SERVER}\//" "$R/etc/apt/sources.list"
30 sed -i "s/\/ftp.debian.org\//\/${APT_SERVER}\//" "${ETCDIR}/apt/sources.list"
31 sed -i "s/ jessie/ ${RELEASE}/" "$R/etc/apt/sources.list"
31 sed -i "s/ jessie/ ${RELEASE}/" "${ETCDIR}/apt/sources.list"
32 fi
32 fi
33
33
34 # Upgrade package index and update all installed packages and changed dependencies
34 # Upgrade package index and update all installed packages and changed dependencies
35 chroot_exec apt-get -qq -y update
35 chroot_exec apt-get -qq -y update
36 chroot_exec apt-get -qq -y -u dist-upgrade
36 chroot_exec apt-get -qq -y -u dist-upgrade
37 chroot_exec apt-get -qq -y check
37 chroot_exec apt-get -qq -y check
@@ -1,58 +1,58
1 #
1 #
2 # Setup Locales and keyboard settings
2 # Setup Locales and keyboard settings
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 # Install and setup timezone
8 # Install and setup timezone
9 echo ${TIMEZONE} > "$R/etc/timezone"
9 echo ${TIMEZONE} > "${ETCDIR}/timezone"
10 chroot_exec dpkg-reconfigure -f noninteractive tzdata
10 chroot_exec dpkg-reconfigure -f noninteractive tzdata
11
11
12 # Install and setup default locale and keyboard configuration
12 # Install and setup default locale and keyboard configuration
13 if [ "$ENABLE_MINBASE" = false ] ; then
13 if [ "$ENABLE_MINBASE" = false ] ; then
14 # Set locale choice in debconf db, even though dpkg-reconfigure ignores and overwrites them due to some bug
14 # Set locale choice in debconf db, even though dpkg-reconfigure ignores and overwrites them due to some bug
15 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=684134 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=685957
15 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=684134 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=685957
16 # ... so we have to set locales manually
16 # ... so we have to set locales manually
17 if [ "$DEFLOCAL" = "en_US.UTF-8" ] ; then
17 if [ "$DEFLOCAL" = "en_US.UTF-8" ] ; then
18 chroot_exec echo "locales locales/locales_to_be_generated multiselect ${DEFLOCAL} UTF-8" | debconf-set-selections
18 chroot_exec echo "locales locales/locales_to_be_generated multiselect ${DEFLOCAL} UTF-8" | debconf-set-selections
19 else
19 else
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
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 chroot_exec echo "locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8, ${DEFLOCAL} UTF-8" | debconf-set-selections
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/^#//" "${ETCDIR}/locale.gen"
23 fi
23 fi
24
24
25 sed -i "/${DEFLOCAL}/s/^#//" "$R/etc/locale.gen"
25 sed -i "/${DEFLOCAL}/s/^#//" "${ETCDIR}/locale.gen"
26 chroot_exec echo "locales locales/default_environment_locale select ${DEFLOCAL}" | debconf-set-selections
26 chroot_exec echo "locales locales/default_environment_locale select ${DEFLOCAL}" | debconf-set-selections
27 chroot_exec locale-gen
27 chroot_exec locale-gen
28 chroot_exec update-locale LANG="${DEFLOCAL}"
28 chroot_exec update-locale LANG="${DEFLOCAL}"
29
29
30 # Install and setup default keyboard configuration
30 # Install and setup default keyboard configuration
31 if [ "$XKB_MODEL" != "" ] ; then
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}\"/" "${ETCDIR}/default/keyboard"
33 fi
33 fi
34 if [ "$XKB_LAYOUT" != "" ] ; then
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}\"/" "${ETCDIR}/default/keyboard"
36 fi
36 fi
37 if [ "$XKB_VARIANT" != "" ] ; then
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}\"/" "${ETCDIR}/default/keyboard"
39 fi
39 fi
40 if [ "$XKB_OPTIONS" != "" ] ; then
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}\"/" "${ETCDIR}/default/keyboard"
42 fi
42 fi
43 chroot_exec dpkg-reconfigure -f noninteractive keyboard-configuration
43 chroot_exec dpkg-reconfigure -f noninteractive keyboard-configuration
44
44
45 # Install and setup font console
45 # Install and setup font console
46 case "${DEFLOCAL}" in
46 case "${DEFLOCAL}" in
47 *UTF-8)
47 *UTF-8)
48 sed -i 's/^CHARMAP.*/CHARMAP="UTF-8"/' "$R/etc/default/console-setup"
48 sed -i 's/^CHARMAP.*/CHARMAP="UTF-8"/' "${ETCDIR}/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"/' "${ETCDIR}/default/console-setup"
52 ;;
52 ;;
53 esac
53 esac
54 chroot_exec dpkg-reconfigure -f noninteractive console-setup
54 chroot_exec dpkg-reconfigure -f noninteractive console-setup
55 else # ENABLE_MINBASE=true
55 else # ENABLE_MINBASE=true
56 # Install POSIX default locale
56 # Install POSIX default locale
57 install_readonly files/locales/locale "$R/etc/default/locale"
57 install_readonly files/locales/locale "${ETCDIR}/default/locale"
58 fi
58 fi
@@ -1,252 +1,276
1 #
1 #
2 # Build and Setup RPi2 Kernel
2 # Build and Setup RPi2 Kernel
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 # Fetch and build latest raspberry kernel
8 # Fetch and build latest raspberry kernel
9 if [ "$BUILD_KERNEL" = true ] ; then
9 if [ "$BUILD_KERNEL" = true ] ; then
10 # Setup source directory
10 # Setup source directory
11 mkdir -p "$R/usr/src"
11 mkdir -p "${R}/usr/src"
12
12
13 # Copy existing kernel sources into chroot directory
13 # Copy existing kernel sources into chroot directory
14 if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then
14 if [ -n "$KERNELSRC_DIR" ] && [ -d "$KERNELSRC_DIR" ] ; then
15 # Copy kernel sources
15 # Copy kernel sources
16 cp -r "${KERNELSRC_DIR}" "${R}/usr/src"
16 cp -r "${KERNELSRC_DIR}" "${R}/usr/src"
17
17
18 # Clean the kernel sources
18 # Clean the kernel sources
19 if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then
19 if [ "$KERNELSRC_CLEAN" = true ] && [ "$KERNELSRC_PREBUILT" = false ] ; then
20 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" mrproper
20 make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" mrproper
21 fi
21 fi
22 else # KERNELSRC_DIR=""
22 else # KERNELSRC_DIR=""
23 # Fetch current raspberrypi kernel sources
23 # Fetch current raspberrypi kernel sources
24 git -C "$R/usr/src" clone --depth=1 https://github.com/raspberrypi/linux
24 git -C "${R}/usr/src" clone --depth=1 https://github.com/raspberrypi/linux
25 fi
25 fi
26
26
27 # Calculate optimal number of kernel building threads
27 # Calculate optimal number of kernel building threads
28 if [ "$KERNEL_THREADS" = "1" ] && [ -r /proc/cpuinfo ] ; then
28 if [ "$KERNEL_THREADS" = "1" ] && [ -r /proc/cpuinfo ] ; then
29 KERNEL_THREADS=$(grep -c processor /proc/cpuinfo)
29 KERNEL_THREADS=$(grep -c processor /proc/cpuinfo)
30 fi
30 fi
31
31
32 # Configure and build kernel
32 # Configure and build kernel
33 if [ "$KERNELSRC_PREBUILT" = false ] ; then
33 if [ "$KERNELSRC_PREBUILT" = false ] ; then
34 # Remove device, network and filesystem drivers from kernel configuration
34 # Remove device, network and filesystem drivers from kernel configuration
35 if [ "$KERNEL_REDUCE" = true ] ; then
35 if [ "$KERNEL_REDUCE" = true ] ; then
36 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
36 make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
37 sed -i\
37 sed -i\
38 -e "s/\(^CONFIG_SND.*\=\).*/\1n/"\
38 -e "s/\(^CONFIG_SND.*\=\).*/\1n/"\
39 -e "s/\(^CONFIG_SOUND.*\=\).*/\1n/"\
39 -e "s/\(^CONFIG_SOUND.*\=\).*/\1n/"\
40 -e "s/\(^CONFIG_AC97.*\=\).*/\1n/"\
40 -e "s/\(^CONFIG_AC97.*\=\).*/\1n/"\
41 -e "s/\(^CONFIG_VIDEO_.*\=\).*/\1n/"\
41 -e "s/\(^CONFIG_VIDEO_.*\=\).*/\1n/"\
42 -e "s/\(^CONFIG_MEDIA_TUNER.*\=\).*/\1n/"\
42 -e "s/\(^CONFIG_MEDIA_TUNER.*\=\).*/\1n/"\
43 -e "s/\(^CONFIG_DVB.*\=\)[ym]/\1n/"\
43 -e "s/\(^CONFIG_DVB.*\=\)[ym]/\1n/"\
44 -e "s/\(^CONFIG_REISERFS.*\=\).*/\1n/"\
44 -e "s/\(^CONFIG_REISERFS.*\=\).*/\1n/"\
45 -e "s/\(^CONFIG_JFS.*\=\).*/\1n/"\
45 -e "s/\(^CONFIG_JFS.*\=\).*/\1n/"\
46 -e "s/\(^CONFIG_XFS.*\=\).*/\1n/"\
46 -e "s/\(^CONFIG_XFS.*\=\).*/\1n/"\
47 -e "s/\(^CONFIG_GFS2.*\=\).*/\1n/"\
47 -e "s/\(^CONFIG_GFS2.*\=\).*/\1n/"\
48 -e "s/\(^CONFIG_OCFS2.*\=\).*/\1n/"\
48 -e "s/\(^CONFIG_OCFS2.*\=\).*/\1n/"\
49 -e "s/\(^CONFIG_BTRFS.*\=\).*/\1n/"\
49 -e "s/\(^CONFIG_BTRFS.*\=\).*/\1n/"\
50 -e "s/\(^CONFIG_HFS.*\=\).*/\1n/"\
50 -e "s/\(^CONFIG_HFS.*\=\).*/\1n/"\
51 -e "s/\(^CONFIG_JFFS2.*\=\)[ym]/\1n/"\
51 -e "s/\(^CONFIG_JFFS2.*\=\)[ym]/\1n/"\
52 -e "s/\(^CONFIG_UBIFS.*\=\).*/\1n/"\
52 -e "s/\(^CONFIG_UBIFS.*\=\).*/\1n/"\
53 -e "s/\(^CONFIG_SQUASHFS.*\=\)[ym]/\1n/"\
53 -e "s/\(^CONFIG_SQUASHFS.*\=\)[ym]/\1n/"\
54 -e "s/\(^CONFIG_W1.*\=\)[ym]/\1n/"\
54 -e "s/\(^CONFIG_W1.*\=\)[ym]/\1n/"\
55 -e "s/\(^CONFIG_HAMRADIO.*\=\).*/\1n/"\
55 -e "s/\(^CONFIG_HAMRADIO.*\=\).*/\1n/"\
56 -e "s/\(^CONFIG_CAN.*\=\).*/\1n/"\
56 -e "s/\(^CONFIG_CAN.*\=\).*/\1n/"\
57 -e "s/\(^CONFIG_IRDA.*\=\).*/\1n/"\
57 -e "s/\(^CONFIG_IRDA.*\=\).*/\1n/"\
58 -e "s/\(^CONFIG_BT_.*\=\).*/\1n/"\
58 -e "s/\(^CONFIG_BT_.*\=\).*/\1n/"\
59 -e "s/\(^CONFIG_WIMAX.*\=\)[ym]/\1n/"\
59 -e "s/\(^CONFIG_WIMAX.*\=\)[ym]/\1n/"\
60 -e "s/\(^CONFIG_6LOWPAN.*\=\).*/\1n/"\
60 -e "s/\(^CONFIG_6LOWPAN.*\=\).*/\1n/"\
61 -e "s/\(^CONFIG_IEEE802154.*\=\).*/\1n/"\
61 -e "s/\(^CONFIG_IEEE802154.*\=\).*/\1n/"\
62 -e "s/\(^CONFIG_NFC.*\=\).*/\1n/"\
62 -e "s/\(^CONFIG_NFC.*\=\).*/\1n/"\
63 -e "s/\(^CONFIG_FB_TFT=.*\=\).*/\1n/"\
63 -e "s/\(^CONFIG_FB_TFT=.*\=\).*/\1n/"\
64 -e "s/\(^CONFIG_TOUCHSCREEN.*\=\).*/\1n/"\
64 -e "s/\(^CONFIG_TOUCHSCREEN.*\=\).*/\1n/"\
65 -e "s/\(^CONFIG_USB_GSPCA_.*\=\).*/\1n/"\
65 -e "s/\(^CONFIG_USB_GSPCA_.*\=\).*/\1n/"\
66 -e "s/\(^CONFIG_DRM.*\=\).*/\1n/"\
66 -e "s/\(^CONFIG_DRM.*\=\).*/\1n/"\
67 "$R/usr/src/linux/.config"
67 "${KERNELDIR}/.config"
68 fi
68 fi
69
69
70 if [ "$KERNELSRC_CONFIG" = true ] ; then
70 if [ "$KERNELSRC_CONFIG" = true ] ; then
71 # Load default raspberry kernel configuration
71 # Load default raspberry kernel configuration
72 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
72 make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" "${KERNEL_DEFCONFIG}"
73
73
74 # Start menu-driven kernel configuration (interactive)
74 # Start menu-driven kernel configuration (interactive)
75 if [ "$KERNEL_MENUCONFIG" = true ] ; then
75 if [ "$KERNEL_MENUCONFIG" = true ] ; then
76 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig
76 make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" menuconfig
77 fi
77 fi
78 fi
78 fi
79
79
80 # Cross compile kernel and modules
80 # Cross compile kernel and modules
81 make -C "$R/usr/src/linux" -j${KERNEL_THREADS} ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" zImage modules dtbs
81 make -C "${KERNELDIR}" -j${KERNEL_THREADS} ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" zImage modules dtbs
82 fi
82 fi
83
83
84 # Check if kernel compilation was successful
84 # Check if kernel compilation was successful
85 if [ ! -r "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/zImage" ] ; then
85 if [ ! -r "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/zImage" ] ; then
86 echo "error: kernel compilation failed! (zImage not found)"
86 echo "error: kernel compilation failed! (zImage not found)"
87 cleanup
87 cleanup
88 exit 1
88 exit 1
89 fi
89 fi
90
90
91 # Install kernel modules
91 # Install kernel modules
92 if [ "$ENABLE_REDUCE" = true ] ; then
92 if [ "$ENABLE_REDUCE" = true ] ; then
93 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install
93 make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../.. modules_install
94 else
94 else
95 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install
95 make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_MOD_PATH=../../.. modules_install
96
96
97 # Install kernel firmware
97 # Install kernel firmware
98 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install
98 make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_FW_PATH=../../../lib firmware_install
99 fi
99 fi
100
100
101 # Install kernel headers
101 # Install kernel headers
102 if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then
102 if [ "$KERNEL_HEADERS" = true ] && [ "$KERNEL_REDUCE" = false ] ; then
103 make -C "$R/usr/src/linux" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install
103 make -C "${KERNELDIR}" ARCH="${KERNEL_ARCH}" CROSS_COMPILE="${CROSS_COMPILE}" INSTALL_HDR_PATH=../.. headers_install
104 fi
104 fi
105
105
106 # Prepare boot (firmware) directory
106 # Prepare boot (firmware) directory
107 mkdir "$R/boot/firmware/"
107 mkdir "${BOOTDIR}"
108
108
109 # Get kernel release version
109 # Get kernel release version
110 KERNEL_VERSION=`cat "$R/usr/src/linux/include/config/kernel.release"`
110 KERNEL_VERSION=`cat "${KERNELDIR}/include/config/kernel.release"`
111
111
112 # Copy kernel configuration file to the boot directory
112 # Copy kernel configuration file to the boot directory
113 install_readonly "$R/usr/src/linux/.config" "$R/boot/config-${KERNEL_VERSION}"
113 install_readonly "${KERNELDIR}/.config" "${R}/boot/config-${KERNEL_VERSION}"
114
114
115 # Copy dts and dtb device tree sources and binaries
115 # Copy dts and dtb device tree sources and binaries
116 mkdir "$R/boot/firmware/overlays/"
116 mkdir "${BOOTDIR}/overlays"
117 install_readonly "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/dts/"*.dtb "$R/boot/firmware/"
117 install_readonly "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/dts/"*.dtb "${BOOTDIR}/"
118 install_readonly "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb* "$R/boot/firmware/overlays/"
118 install_readonly "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/"*.dtb* "${BOOTDIR}/overlays/"
119 install_readonly "$R/usr/src/linux/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "$R/boot/firmware/overlays/README"
119 install_readonly "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/dts/overlays/README" "${BOOTDIR}/overlays/README"
120
120
121 # Convert and copy zImage kernel to the boot directory
121 if [ "$ENABLE_UBOOT" = false ] ; then
122 "$R/usr/src/linux/scripts/mkknlimg" "$R/usr/src/linux/arch/arm/boot/zImage" "$R/boot/firmware/kernel7.img"
122 # Convert and copy zImage kernel to the boot directory
123 "${KERNELDIR}/scripts/mkknlimg" "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/zImage" "${BOOTDIR}/${KERNEL_IMAGE}"
124 else
125 # Copy zImage kernel to the boot directory
126 install_readonly "${KERNELDIR}/arch/${KERNEL_ARCH}/boot/zImage" "${BOOTDIR}/${KERNEL_IMAGE}"
127 fi
123
128
124 # Remove kernel sources
129 # Remove kernel sources
125 if [ "$KERNEL_REMOVESRC" = true ] ; then
130 if [ "$KERNEL_REMOVESRC" = true ] ; then
126 rm -fr "$R/usr/src/linux"
131 rm -fr "${KERNELDIR}"
127 fi
132 fi
128
133
129 # Install latest boot binaries from raspberry/firmware github
134 # Install latest boot binaries from raspberry/firmware github
130 wget -q -O "$R/boot/firmware/bootcode.bin" https://github.com/raspberrypi/firmware/raw/master/boot/bootcode.bin
135 wget -q -O "${BOOTDIR}/bootcode.bin" https://github.com/raspberrypi/firmware/raw/master/boot/bootcode.bin
131 wget -q -O "$R/boot/firmware/fixup.dat" https://github.com/raspberrypi/firmware/raw/master/boot/fixup.dat
136 wget -q -O "${BOOTDIR}/fixup.dat" https://github.com/raspberrypi/firmware/raw/master/boot/fixup.dat
132 wget -q -O "$R/boot/firmware/fixup_cd.dat" https://github.com/raspberrypi/firmware/raw/master/boot/fixup_cd.dat
137 wget -q -O "${BOOTDIR}/fixup_cd.dat" https://github.com/raspberrypi/firmware/raw/master/boot/fixup_cd.dat
133 wget -q -O "$R/boot/firmware/fixup_x.dat" https://github.com/raspberrypi/firmware/raw/master/boot/fixup_x.dat
138 wget -q -O "${BOOTDIR}/fixup_x.dat" https://github.com/raspberrypi/firmware/raw/master/boot/fixup_x.dat
134 wget -q -O "$R/boot/firmware/start.elf" https://github.com/raspberrypi/firmware/raw/master/boot/start.elf
139 wget -q -O "${BOOTDIR}/start.elf" https://github.com/raspberrypi/firmware/raw/master/boot/start.elf
135 wget -q -O "$R/boot/firmware/start_cd.elf" https://github.com/raspberrypi/firmware/raw/master/boot/start_cd.elf
140 wget -q -O "${BOOTDIR}/start_cd.elf" https://github.com/raspberrypi/firmware/raw/master/boot/start_cd.elf
136 wget -q -O "$R/boot/firmware/start_x.elf" https://github.com/raspberrypi/firmware/raw/master/boot/start_x.elf
141 wget -q -O "${BOOTDIR}/start_x.elf" https://github.com/raspberrypi/firmware/raw/master/boot/start_x.elf
137
142
138 else # BUILD_KERNEL=false
143 else # BUILD_KERNEL=false
139 # Kernel installation
144 # Kernel installation
140 chroot_exec apt-get -qq -y --no-install-recommends install linux-image-"${COLLABORA_KERNEL}" raspberrypi-bootloader-nokernel
145 chroot_exec apt-get -qq -y --no-install-recommends install linux-image-"${COLLABORA_KERNEL}" raspberrypi-bootloader-nokernel
141
146
142 # Install flash-kernel last so it doesn't try (and fail) to detect the platform in the chroot
147 # Install flash-kernel last so it doesn't try (and fail) to detect the platform in the chroot
143 chroot_exec apt-get -qq -y install flash-kernel
148 chroot_exec apt-get -qq -y install flash-kernel
144
149
145 # Check if kernel installation was successful
150 # Check if kernel installation was successful
146 VMLINUZ="$(ls -1 $R/boot/vmlinuz-* | sort | tail -n 1)"
151 VMLINUZ="$(ls -1 ${R}/boot/vmlinuz-* | sort | tail -n 1)"
147 if [ -z "$VMLINUZ" ] ; then
152 if [ -z "$VMLINUZ" ] ; then
148 echo "error: kernel installation failed! (/boot/vmlinuz-* not found)"
153 echo "error: kernel installation failed! (/boot/vmlinuz-* not found)"
149 cleanup
154 cleanup
150 exit 1
155 exit 1
151 fi
156 fi
152 # Copy vmlinuz kernel to the boot directory
157 # Copy vmlinuz kernel to the boot directory
153 install_readonly "$VMLINUZ" "$R/boot/firmware/kernel7.img"
158 install_readonly "${VMLINUZ}" "${BOOTDIR}/${KERNEL_IMAGE}"
154 fi
159 fi
155
160
156 # Setup firmware boot cmdline
161 # Setup firmware boot cmdline
157 if [ "$ENABLE_SPLITFS" = true ] ; then
162 if [ "$ENABLE_SPLITFS" = true ] ; then
158 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}"
163 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}"
159 else
164 else
160 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}"
165 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}"
161 fi
166 fi
162
167
168 # Add encrypted root partition to cmdline.txt
169 if [ "$ENABLE_CRYPTFS" = true ] ; then
170 if [ "$ENABLE_SPLITFS" = true ] ; then
171 CMDLINE=$(echo ${CMDLINE} | sed "s/sda1/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/sda1:${CRYPTFS_MAPPING}/")
172 else
173 CMDLINE=$(echo ${CMDLINE} | sed "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/mmcblk0p2:${CRYPTFS_MAPPING}/")
174 fi
175 fi
176
163 # Add serial console support
177 # Add serial console support
164 if [ "$ENABLE_CONSOLE" = true ] ; then
178 if [ "$ENABLE_CONSOLE" = true ] ; then
165 CMDLINE="${CMDLINE} console=ttyAMA0,115200 kgdboc=ttyAMA0,115200"
179 CMDLINE="${CMDLINE} console=ttyAMA0,115200 kgdboc=ttyAMA0,115200"
166 fi
180 fi
167
181
168 # Remove IPv6 networking support
182 # Remove IPv6 networking support
169 if [ "$ENABLE_IPV6" = false ] ; then
183 if [ "$ENABLE_IPV6" = false ] ; then
170 CMDLINE="${CMDLINE} ipv6.disable=1"
184 CMDLINE="${CMDLINE} ipv6.disable=1"
171 fi
185 fi
172
186
173 # Install firmware boot cmdline
187 # Install firmware boot cmdline
174 echo "${CMDLINE}" > "$R/boot/firmware/cmdline.txt"
188 echo "${CMDLINE}" > "${BOOTDIR}/cmdline.txt"
175
176 # Add encrypted root partition to cmdline.txt
177 if [ "$ENABLE_CRYPTFS" = true ] ; then
178 sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING} cryptdevice=\/dev\/mmcblk0p2:${CRYPTFS_MAPPING}/" "$R/boot/firmware/cmdline.txt"
179 fi
180
189
181 # Install firmware config
190 # Install firmware config
182 install_readonly files/boot/config.txt "$R/boot/firmware/config.txt"
191 install_readonly files/boot/config.txt "${BOOTDIR}/config.txt"
183
192
184 # Setup minimal GPU memory allocation size: 16MB (no X)
193 # Setup minimal GPU memory allocation size: 16MB (no X)
185 if [ "$ENABLE_MINGPU" = true ] ; then
194 if [ "$ENABLE_MINGPU" = true ] ; then
186 echo "gpu_mem=16" >> "$R/boot/firmware/config.txt"
195 echo "gpu_mem=16" >> "${BOOTDIR}/config.txt"
187 fi
196 fi
188
197
189 # Setup boot with initramfs
198 # Setup boot with initramfs
190 if [ "$ENABLE_INITRAMFS" = true ] ; then
199 if [ "$ENABLE_INITRAMFS" = true ] ; then
191 echo "initramfs initramfs-${KERNEL_VERSION} followkernel" >> "$R/boot/firmware/config.txt"
200 echo "initramfs initramfs-${KERNEL_VERSION} followkernel" >> "${BOOTDIR}/config.txt"
192 fi
201 fi
193
202
194 # Create firmware configuration and cmdline symlinks
203 # Create firmware configuration and cmdline symlinks
195 ln -sf firmware/config.txt "$R/boot/config.txt"
204 ln -sf firmware/config.txt "${R}/boot/config.txt"
196 ln -sf firmware/cmdline.txt "$R/boot/cmdline.txt"
205 ln -sf firmware/cmdline.txt "${R}/boot/cmdline.txt"
197
206
198 # Install and setup kernel modules to load at boot
207 # Install and setup kernel modules to load at boot
199 mkdir -p "$R/lib/modules-load.d/"
208 mkdir -p "${R}/lib/modules-load.d/"
200 install_readonly files/modules/rpi2.conf "$R/lib/modules-load.d/rpi2.conf"
209 install_readonly files/modules/rpi2.conf "${R}/lib/modules-load.d/rpi2.conf"
201
210
202 # Load hardware random module at boot
211 # Load hardware random module at boot
203 if [ "$ENABLE_HWRANDOM" = true ] ; then
212 if [ "$ENABLE_HWRANDOM" = true ] && [ "$BUILD_KERNEL" = false ] ; then
204 sed -i "s/^# bcm2708_rng/bcm2708_rng/" "$R/lib/modules-load.d/rpi2.conf"
213 sed -i "s/^# bcm2708_rng/bcm2708_rng/" "${R}/lib/modules-load.d/rpi2.conf"
205 fi
214 fi
206
215
207 # Load sound module at boot
216 # Load sound module at boot
208 if [ "$ENABLE_SOUND" = true ] ; then
217 if [ "$ENABLE_SOUND" = true ] ; then
209 sed -i "s/^# snd_bcm2835/snd_bcm2835/" "$R/lib/modules-load.d/rpi2.conf"
218 sed -i "s/^# snd_bcm2835/snd_bcm2835/" "${R}/lib/modules-load.d/rpi2.conf"
210 fi
219 fi
211
220
212 # Install kernel modules blacklist
221 # Install kernel modules blacklist
213 mkdir -p "$R/etc/modprobe.d/"
222 mkdir -p "${ETCDIR}/modprobe.d/"
214 install_readonly files/modules/raspi-blacklist.conf "$R/etc/modprobe.d/raspi-blacklist.conf"
223 install_readonly files/modules/raspi-blacklist.conf "${ETCDIR}/modprobe.d/raspi-blacklist.conf"
215
224
216 # Install and setup fstab
225 # Install and setup fstab
217 install_readonly files/mount/fstab "$R/etc/fstab"
226 install_readonly files/mount/fstab "${ETCDIR}/fstab"
218
227
219 # Add usb/sda disk root partition to fstab
228 # Add usb/sda disk root partition to fstab
220 if [ "$ENABLE_SPLITFS" = true ] ; then
229 if [ "$ENABLE_SPLITFS" = true ] && [ "$ENABLE_CRYPTFS" = false ] ; then
221 sed -i "s/mmcblk0p2/sda1/" "$R/etc/fstab"
230 sed -i "s/mmcblk0p2/sda1/" "${ETCDIR}/fstab"
222 fi
231 fi
223
232
224 # Add encrypted root partition to fstab and crypttab
233 # Add encrypted root partition to fstab and crypttab
225 if [ "$ENABLE_CRYPTFS" = true ] ; then
234 if [ "$ENABLE_CRYPTFS" = true ] ; then
226 # Replace fstab root partition with encrypted partition mapping
235 # Replace fstab root partition with encrypted partition mapping
227 sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING}/" "$R/etc/fstab"
236 sed -i "s/mmcblk0p2/mapper\/${CRYPTFS_MAPPING}/" "${ETCDIR}/fstab"
228
237
229 # Add encrypted partition to crypttab and fstab
238 # Add encrypted partition to crypttab and fstab
230 install_readonly files/mount/crypttab "$R/etc/crypttab"
239 install_readonly files/mount/crypttab "${ETCDIR}/crypttab"
231 echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks" >> "$R/etc/crypttab"
240 echo "${CRYPTFS_MAPPING} /dev/mmcblk0p2 none luks" >> "${ETCDIR}/crypttab"
241
242 if [ "$ENABLE_SPLITFS" = true ] ; then
243 # Add usb/sda disk to crypttab
244 sed -i "s/mmcblk0p2/sda1/" "${ETCDIR}/crypttab"
245 fi
232 fi
246 fi
233
247
234 # Generate initramfs file
248 # Generate initramfs file
235 if [ "$ENABLE_INITRAMFS" = true ] ; then
249 if [ "$ENABLE_INITRAMFS" = true ] ; then
236 if [ "$ENABLE_CRYPTFS" = true ] ; then
250 if [ "$ENABLE_CRYPTFS" = true ] ; then
251 # Include initramfs scripts to auto expand encrypted root partition
252 if [ "$EXPANDROOT" = true ] ; then
253 install_exec files/initramfs/expand_encrypted_rootfs "${ETCDIR}/initramfs-tools/scripts/init-premount/expand_encrypted_rootfs"
254 install_exec files/initramfs/expand-premount "${ETCDIR}/initramfs-tools/scripts/local-premount/expand-premount"
255 install_exec files/initramfs/expand-tools "${ETCDIR}/initramfs-tools/hooks/expand-tools"
256 fi
257
258 # Disable SSHD inside initramfs
259 printf "#\n# DROPBEAR: [ y | n ]\n#\n\nDROPBEAR=n\n" >> "${ETCDIR}/initramfs-tools/initramfs.conf"
260
237 # Dummy mapping required by mkinitramfs
261 # Dummy mapping required by mkinitramfs
238 echo "0 1 crypt $(echo ${CRYPTFS_CIPHER} | cut -d ':' -f 1) ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0 7:0 4096" | chroot_exec dmsetup create "${CRYPTFS_MAPPING}"
262 echo "0 1 crypt $(echo ${CRYPTFS_CIPHER} | cut -d ':' -f 1) ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 0 7:0 4096" | chroot_exec dmsetup create "${CRYPTFS_MAPPING}"
239
263
240 # Generate initramfs with encrypted root partition support
264 # Generate initramfs with encrypted root partition support
241 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
265 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
242
266
243 # Remove dummy mapping
267 # Remove dummy mapping
244 chroot_exec cryptsetup close "${CRYPTFS_MAPPING}"
268 chroot_exec cryptsetup close "${CRYPTFS_MAPPING}"
245 else
269 else
246 # Generate initramfs without encrypted root partition support
270 # Generate initramfs without encrypted root partition support
247 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
271 chroot_exec mkinitramfs -o "/boot/firmware/initramfs-${KERNEL_VERSION}" "${KERNEL_VERSION}"
248 fi
272 fi
249 fi
273 fi
250
274
251 # Install sysctl.d configuration files
275 # Install sysctl.d configuration files
252 install_readonly files/sysctl.d/81-rpi-vm.conf "$R/etc/sysctl.d/81-rpi-vm.conf"
276 install_readonly files/sysctl.d/81-rpi-vm.conf "${ETCDIR}/sysctl.d/81-rpi-vm.conf"
@@ -1,72 +1,72
1 #
1 #
2 # Setup Networking
2 # Setup Networking
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 # Install and setup hostname
8 # Install and setup hostname
9 install_readonly files/network/hostname "$R/etc/hostname"
9 install_readonly files/network/hostname "${ETCDIR}/hostname"
10 sed -i "s/^rpi2-jessie/${HOSTNAME}/" "$R/etc/hostname"
10 sed -i "s/^rpi2-jessie/${HOSTNAME}/" "${ETCDIR}/hostname"
11
11
12 # Install and setup hosts
12 # Install and setup hosts
13 install_readonly files/network/hosts "$R/etc/hosts"
13 install_readonly files/network/hosts "${ETCDIR}/hosts"
14 sed -i "s/rpi2-jessie/${HOSTNAME}/" "$R/etc/hosts"
14 sed -i "s/rpi2-jessie/${HOSTNAME}/" "${ETCDIR}/hosts"
15
15
16 # Setup hostname entry with static IP
16 # Setup hostname entry with static IP
17 if [ "$NET_ADDRESS" != "" ] ; then
17 if [ "$NET_ADDRESS" != "" ] ; then
18 NET_IP=$(echo "${NET_ADDRESS}" | cut -f 1 -d'/')
18 NET_IP=$(echo "${NET_ADDRESS}" | cut -f 1 -d'/')
19 sed -i "s/^127.0.1.1/${NET_IP}/" "$R/etc/hosts"
19 sed -i "s/^127.0.1.1/${NET_IP}/" "${ETCDIR}/hosts"
20 fi
20 fi
21
21
22 # Remove IPv6 hosts
22 # Remove IPv6 hosts
23 if [ "$ENABLE_IPV6" = false ] ; then
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" "${ETCDIR}/hosts"
25 fi
25 fi
26
26
27 # Install hint about network configuration
27 # Install hint about network configuration
28 install_readonly files/network/interfaces "$R/etc/network/interfaces"
28 install_readonly files/network/interfaces "${ETCDIR}/network/interfaces"
29
29
30 # Install configuration for interface eth0
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 "${ETCDIR}/systemd/network/eth.network"
32
32
33 if [ "$ENABLE_DHCP" = true ] ; then
33 if [ "$ENABLE_DHCP" = true ] ; then
34 # Enable DHCP configuration for interface eth0
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" "${ETCDIR}/systemd/network/eth.network"
36
36
37 # Set DHCP configuration to IPv4 only
37 # Set DHCP configuration to IPv4 only
38 if [ "$ENABLE_IPV6" = false ] ; then
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/" "${ETCDIR}/systemd/network/eth.network"
40 fi
40 fi
41
41
42 else # ENABLE_DHCP=false
42 else # ENABLE_DHCP=false
43 # Set static network configuration for interface eth0
43 # Set static network configuration for interface eth0
44 sed -i\
44 sed -i\
45 -e "s|DHCP=.*|DHCP=no|"\
45 -e "s|DHCP=.*|DHCP=no|"\
46 -e "s|Address=\$|Address=${NET_ADDRESS}|"\
46 -e "s|Address=\$|Address=${NET_ADDRESS}|"\
47 -e "s|Gateway=\$|Gateway=${NET_GATEWAY}|"\
47 -e "s|Gateway=\$|Gateway=${NET_GATEWAY}|"\
48 -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_DNS_1}|"\
48 -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_DNS_1}|"\
49 -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_DNS_2}|"\
49 -e "0,/DNS=\$/ s|DNS=\$|DNS=${NET_DNS_2}|"\
50 -e "s|Domains=\$|Domains=${NET_DNS_DOMAINS}|"\
50 -e "s|Domains=\$|Domains=${NET_DNS_DOMAINS}|"\
51 -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_NTP_1}|"\
51 -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_NTP_1}|"\
52 -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_NTP_2}|"\
52 -e "0,/NTP=\$/ s|NTP=\$|NTP=${NET_NTP_2}|"\
53 "$R/etc/systemd/network/eth.network"
53 "${ETCDIR}/systemd/network/eth.network"
54 fi
54 fi
55
55
56 # Remove empty settings from network configuration
56 # Remove empty settings from network configuration
57 sed -i "/.*=\$/d" "$R/etc/systemd/network/eth.network"
57 sed -i "/.*=\$/d" "${ETCDIR}/systemd/network/eth.network"
58
58
59 # Enable systemd-networkd service
59 # Enable systemd-networkd service
60 chroot_exec systemctl enable systemd-networkd
60 chroot_exec systemctl enable systemd-networkd
61
61
62 # Install host.conf resolver configuration
62 # Install host.conf resolver configuration
63 install_readonly files/network/host.conf "$R/etc/host.conf"
63 install_readonly files/network/host.conf "${ETCDIR}/host.conf"
64
64
65 # Enable network stack hardening
65 # Enable network stack hardening
66 if [ "$ENABLE_HARDNET" = true ] ; then
66 if [ "$ENABLE_HARDNET" = true ] ; then
67 # Install sysctl.d configuration files
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 "${ETCDIR}/sysctl.d/82-rpi-net-hardening.conf"
69
69
70 # Setup resolver warnings about spoofed addresses
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/" "${ETCDIR}/host.conf"
72 fi
72 fi
@@ -1,44 +1,44
1 #
1 #
2 # Setup Firewall
2 # Setup Firewall
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 if [ "$ENABLE_IPTABLES" = true ] ; then
8 if [ "$ENABLE_IPTABLES" = true ] ; then
9 # Create iptables configuration directory
9 # Create iptables configuration directory
10 mkdir -p "$R/etc/iptables"
10 mkdir -p "${ETCDIR}/iptables"
11
11
12 # Install iptables systemd service
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 "${ETCDIR}/systemd/system/iptables.service"
14
14
15 # Install flush-table script called by iptables service
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 "${ETCDIR}/iptables/flush-iptables.sh"
17
17
18 # Install iptables rule file
18 # Install iptables rule file
19 install_readonly files/iptables/iptables.rules "$R/etc/iptables/iptables.rules"
19 install_readonly files/iptables/iptables.rules "${ETCDIR}/iptables/iptables.rules"
20
20
21 # Reload systemd configuration and enable iptables service
21 # Reload systemd configuration and enable iptables service
22 chroot_exec systemctl daemon-reload
22 chroot_exec systemctl daemon-reload
23 chroot_exec systemctl enable iptables.service
23 chroot_exec systemctl enable iptables.service
24
24
25 if [ "$ENABLE_IPV6" = true ] ; then
25 if [ "$ENABLE_IPV6" = true ] ; then
26 # Install ip6tables systemd service
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 "${ETCDIR}/systemd/system/ip6tables.service"
28
28
29 # Install ip6tables file
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 "${ETCDIR}/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 "${ETCDIR}/iptables/ip6tables.rules"
33
33
34 # Reload systemd configuration and enable iptables service
34 # Reload systemd configuration and enable iptables service
35 chroot_exec systemctl daemon-reload
35 chroot_exec systemctl daemon-reload
36 chroot_exec systemctl enable ip6tables.service
36 chroot_exec systemctl enable ip6tables.service
37 fi
37 fi
38 fi
38 fi
39
39
40 if [ "$ENABLE_SSHD" = false ] ; then
40 if [ "$ENABLE_SSHD" = false ] ; then
41 # Remove SSHD related iptables rules
41 # Remove SSHD related iptables rules
42 sed -i "/^#/! {/SSH/ s/^/# /}" "$R/etc/iptables/iptables.rules" 2> /dev/null
42 sed -i "/^#/! {/SSH/ s/^/# /}" "${ETCDIR}/iptables/iptables.rules" 2> /dev/null
43 sed -i "/^#/! {/SSH/ s/^/# /}" "$R/etc/iptables/ip6tables.rules" 2> /dev/null
43 sed -i "/^#/! {/SSH/ s/^/# /}" "${ETCDIR}/iptables/ip6tables.rules" 2> /dev/null
44 fi
44 fi
@@ -1,32 +1,32
1 #
1 #
2 # Setup users and security settings
2 # Setup users and security settings
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 # Generate crypt(3) password string
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 # Setup default user
11 # Setup default user
12 if [ "$ENABLE_USER" = true ] ; then
12 if [ "$ENABLE_USER" = true ] ; then
13 chroot_exec adduser --gecos pi --add_extra_groups --disabled-password pi
13 chroot_exec adduser --gecos pi --add_extra_groups --disabled-password pi
14 chroot_exec usermod -a -G sudo -p "${ENCRYPTED_PASSWORD}" pi
14 chroot_exec usermod -a -G sudo -p "${ENCRYPTED_PASSWORD}" pi
15 fi
15 fi
16
16
17 # Setup root password or not
17 # Setup root password or not
18 if [ "$ENABLE_ROOT" = true ] ; then
18 if [ "$ENABLE_ROOT" = true ] ; then
19 chroot_exec usermod -p "${ENCRYPTED_PASSWORD}" root
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 sed -i "s|[#]*PermitRootLogin.*|PermitRootLogin yes|g" "$R/etc/ssh/sshd_config"
22 sed -i "s|[#]*PermitRootLogin.*|PermitRootLogin yes|g" "${ETCDIR}/ssh/sshd_config"
23 fi
23 fi
24 else
24 else
25 # Set no root password to disable root login
25 # Set no root password to disable root login
26 chroot_exec usermod -p \'!\' root
26 chroot_exec usermod -p \'!\' root
27 fi
27 fi
28
28
29 # Enable serial console systemd style
29 # Enable serial console systemd style
30 if [ "$ENABLE_CONSOLE" = true ] ; then
30 if [ "$ENABLE_CONSOLE" = true ] ; then
31 chroot_exec systemctl enable serial-getty\@ttyAMA0.service
31 chroot_exec systemctl enable serial-getty\@ttyAMA0.service
32 fi
32 fi
@@ -1,13 +1,13
1 #
1 #
2 # Setup Logging
2 # Setup Logging
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 # Disable rsyslog
8 # Disable rsyslog
9 if [ "$ENABLE_RSYSLOG" = false ] ; then
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" "${ETCDIR}/systemd/journald.conf"
11 chroot_exec systemctl disable rsyslog
11 chroot_exec systemctl disable rsyslog
12 chroot_exec apt-get -qq -y --force-yes purge rsyslog
12 chroot_exec apt-get -qq -y --force-yes purge rsyslog
13 fi
13 fi
@@ -1,31 +1,67
1 #
1 #
2 # Build and Setup U-Boot
2 # Build and Setup U-Boot
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 # Install gcc/c++ build environment inside the chroot
8 # Install gcc/c++ build environment inside the chroot
9 if [ "$ENABLE_UBOOT" = true ] || [ "$ENABLE_FBTURBO" = true ] ; then
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
10 chroot_exec apt-get -q -y --force-yes --no-install-recommends install linux-compiler-gcc-4.8-arm g++ make bc
11 fi
11 fi
12
12
13 # Fetch and build U-Boot bootloader
13 # Fetch and build U-Boot bootloader
14 if [ "$ENABLE_UBOOT" = true ] ; then
14 if [ "$ENABLE_UBOOT" = true ] ; then
15 # Fetch U-Boot bootloader sources
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 # Build and install U-Boot inside chroot
18 # Build and install U-Boot inside chroot
19 chroot_exec make -C /tmp/u-boot/ rpi_2_defconfig all
19 chroot_exec make -C /tmp/u-boot/ ${UBOOT_CONFIG} all
20
20
21 # Copy compiled bootloader binary and set config.txt to load it
21 # Copy compiled bootloader binary and set config.txt to load it
22 install_readonly "$R/tmp/u-boot/u-boot.bin" "$R/boot/firmware/u-boot.bin"
22 install_exec "${R}/tmp/u-boot/tools/mkimage" "${R}/usr/sbin/mkimage"
23 printf "\n# boot u-boot kernel\nkernel=u-boot.bin\n" >> "$R/boot/firmware/config.txt"
23 install_readonly "${R}/tmp/u-boot/u-boot.bin" "${BOOTDIR}/u-boot.bin"
24 printf "\n# boot u-boot kernel\nkernel=u-boot.bin\n" >> "${BOOTDIR}/config.txt"
24
25
25 # Install and setup U-Boot command file
26 # Install and setup U-Boot command file
26 install_readonly files/boot/uboot.mkimage "$R/boot/firmware/uboot.mkimage"
27 install_readonly files/boot/uboot.mkimage "${BOOTDIR}/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 printf "# Set the kernel boot command line\nsetenv bootargs \"earlyprintk ${CMDLINE}\"\n\n$(cat ${BOOTDIR}/uboot.mkimage)" > "${BOOTDIR}/uboot.mkimage"
29
30 if [ "$ENABLE_INITRAMFS" = true ] ; then
31 # Convert generated initramfs for U-Boot using mkimage
32 chroot_exec /usr/sbin/mkimage -A "${KERNEL_ARCH}" -T ramdisk -C none -n "initramfs-${KERNEL_VERSION}" -d "/boot/firmware/initramfs-${KERNEL_VERSION}" "/boot/firmware/initramfs-${KERNEL_VERSION}.uboot"
33
34 # Remove original initramfs file
35 rm -f "${BOOTDIR}/initramfs-${KERNEL_VERSION}"
36
37 # Configure U-Boot to load generated initramfs
38 printf "# Set initramfs file\nsetenv initramfs initramfs-${KERNEL_VERSION}.uboot\n\n$(cat ${BOOTDIR}/uboot.mkimage)" > "${BOOTDIR}/uboot.mkimage"
39 printf "\nbootz \${kernel_addr_r} \${ramdisk_addr_r} \${fdt_addr_r}" >> "${BOOTDIR}/uboot.mkimage"
40 else # ENABLE_INITRAMFS=false
41 # Remove initramfs from U-Boot mkfile
42 sed -i '/.*initramfs.*/d' "${BOOTDIR}/uboot.mkimage"
43
44 if [ "$BUILD_KERNEL" = false ] ; then
45 # Remove dtbfile from U-Boot mkfile
46 sed -i '/.*dtbfile.*/d' "${BOOTDIR}/uboot.mkimage"
47 printf "\nbootz \${kernel_addr_r}" >> "${BOOTDIR}/uboot.mkimage"
48 else
49 printf "\nbootz \${kernel_addr_r} - \${fdt_addr_r}" >> "${BOOTDIR}/uboot.mkimage"
50 fi
51 fi
52
53 # Set mkfile to use dtb file
54 sed -i "s/^\(setenv dtbfile \).*/\1${DTB_FILE}/" "${BOOTDIR}/uboot.mkimage"
55
56 # Set mkfile to use kernel image
57 sed -i "s/^\(fatload mmc 0:1 \${kernel_addr_r} \).*/\1${KERNEL_IMAGE}/" "${BOOTDIR}/uboot.mkimage"
58
59 # Remove all leading blank lines
60 sed -i "/./,\$!d" "${BOOTDIR}/uboot.mkimage"
28
61
29 # Generate U-Boot bootloader image
62 # 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
63 chroot_exec /usr/sbin/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
64
65 # Remove U-Boot sources
66 rm -fr "${R}/tmp/u-boot"
31 fi
67 fi
@@ -1,34 +1,34
1 #
1 #
2 # Build and Setup fbturbo Xorg driver
2 # Build and Setup fbturbo Xorg driver
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 if [ "$ENABLE_FBTURBO" = true ] ; then
8 if [ "$ENABLE_FBTURBO" = true ] ; then
9 # Fetch fbturbo driver sources
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 # Install Xorg build dependencies
12 # Install Xorg build dependencies
13 chroot_exec apt-get -q -y --no-install-recommends install 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 # Build and install fbturbo driver inside chroot
15 # Build and install fbturbo driver inside chroot
16 chroot_exec /bin/bash -x <<'EOF'
16 chroot_exec /bin/bash -x <<'EOF'
17 cd /tmp/xf86-video-fbturbo
17 cd /tmp/xf86-video-fbturbo
18 autoreconf -vi
18 autoreconf -vi
19 ./configure --prefix=/usr
19 ./configure --prefix=/usr
20 make
20 make
21 make install
21 make install
22 EOF
22 EOF
23
23
24 # Install fbturbo driver Xorg configuration
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 # Remove Xorg build dependencies
27 # Remove Xorg build dependencies
28 chroot_exec apt-get -qq -y --auto-remove purge 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 fi
29 fi
30
30
31 # Remove gcc/c++ build environment from the chroot
31 # Remove gcc/c++ build environment from the chroot
32 if [ "$ENABLE_UBOOT" = true ] || [ "$ENABLE_FBTURBO" = true ] ; then
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
33 chroot_exec apt-get -qq -y --auto-remove purge bc binutils cpp cpp-4.8 cpp-4.9 g++ g++-4.8 g++-4.9 gcc gcc-4.8 gcc-4.9 libasan1 libatomic1 libc-dev-bin libc6-dev libcloog-isl4 libgcc-4.8-dev libgcc-4.9-dev libgomp1 libisl10 libmpc3 libmpfr4 libstdc++-4.9-dev libubsan0 linux-compiler-gcc-4.8-arm linux-libc-dev make
34 fi
34 fi
@@ -1,34 +1,39
1 #
1 #
2 # First boot actions
2 # First boot actions
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 # Prepare rc.firstboot script
8 # Prepare rc.firstboot script
9 cat files/firstboot/10-begin.sh > "$R/etc/rc.firstboot"
9 cat files/firstboot/10-begin.sh > "${ETCDIR}/rc.firstboot"
10
10
11 # Ensure openssh server host keys are regenerated on first boot
11 # Ensure openssh server host keys are regenerated on first boot
12 if [ "$ENABLE_SSHD" = true ] ; then
12 if [ "$ENABLE_SSHD" = true ] ; then
13 cat files/firstboot/21-generate-ssh-keys.sh >> "$R/etc/rc.firstboot"
13 cat files/firstboot/21-generate-ssh-keys.sh >> "${ETCDIR}/rc.firstboot"
14 fi
14 fi
15
15
16 # Prepare filesystem auto expand
16 # Prepare filesystem auto expand
17 if [ "$EXPANDROOT" = true ] ; then
17 if [ "$EXPANDROOT" = true ] ; then
18 cat files/firstboot/22-expandroot.sh >> "$R/etc/rc.firstboot"
18 if [ "$ENABLE_CRYPTFS" = false ] ; then
19 cat files/firstboot/22-expandroot.sh >> "${ETCDIR}/rc.firstboot"
20 else
21 # Regenerate initramfs to remove encrypted root partition auto expand
22 cat files/firstboot/23-regenerate-initramfs.sh >> "${ETCDIR}/rc.firstboot"
23 fi
19 fi
24 fi
20
25
21 # Ensure that dbus machine-id exists
26 # Ensure that dbus machine-id exists
22 cat files/firstboot/23-generate-machineid.sh >> "$R/etc/rc.firstboot"
27 cat files/firstboot/24-generate-machineid.sh >> "${ETCDIR}/rc.firstboot"
23
28
24 # Create /etc/resolv.conf symlink
29 # Create /etc/resolv.conf symlink
25 cat files/firstboot/24-create-resolv-symlink.sh >> "$R/etc/rc.firstboot"
30 cat files/firstboot/25-create-resolv-symlink.sh >> "${ETCDIR}/rc.firstboot"
26
31
27 # Finalize rc.firstboot script
32 # Finalize rc.firstboot script
28 cat files/firstboot/99-finish.sh >> "$R/etc/rc.firstboot"
33 cat files/firstboot/99-finish.sh >> "${ETCDIR}/rc.firstboot"
29 chmod +x "$R/etc/rc.firstboot"
34 chmod +x "${ETCDIR}/rc.firstboot"
30
35
31 # Add rc.firstboot script to rc.local
36 # Add rc.firstboot script to rc.local
32 sed -i '/exit 0/d' "$R/etc/rc.local"
37 sed -i '/exit 0/d' "${ETCDIR}/rc.local"
33 echo /etc/rc.firstboot >> "$R/etc/rc.local"
38 echo /etc/rc.firstboot >> "${ETCDIR}/rc.local"
34 echo exit 0 >> "$R/etc/rc.local"
39 echo exit 0 >> "${ETCDIR}/rc.local"
@@ -1,78 +1,78
1 #
1 #
2 # Reduce system disk usage
2 # Reduce system disk usage
3 #
3 #
4
4
5 # Load utility functions
5 # Load utility functions
6 . ./functions.sh
6 . ./functions.sh
7
7
8 # Reduce the image size by various operations
8 # Reduce the image size by various operations
9 if [ "$ENABLE_REDUCE" = true ] ; then
9 if [ "$ENABLE_REDUCE" = true ] ; then
10 if [ "$REDUCE_APT" = true ] ; then
10 if [ "$REDUCE_APT" = true ] ; then
11 # Install dpkg configuration file
11 # Install dpkg configuration file
12 if [ "$REDUCE_DOC" = true ] || [ "$REDUCE_MAN" = true ] ; then
12 if [ "$REDUCE_DOC" = true ] || [ "$REDUCE_MAN" = true ] ; then
13 install_readonly files/dpkg/01nodoc "$R/etc/dpkg/dpkg.cfg.d/01nodoc"
13 install_readonly files/dpkg/01nodoc "${ETCDIR}/dpkg/dpkg.cfg.d/01nodoc"
14 fi
14 fi
15
15
16 # Install APT configuration files
16 # Install APT configuration files
17 install_readonly files/apt/02nocache "$R/etc/apt/apt.conf.d/02nocache"
17 install_readonly files/apt/02nocache "${ETCDIR}/apt/apt.conf.d/02nocache"
18 install_readonly files/apt/03compress "$R/etc/apt/apt.conf.d/03compress"
18 install_readonly files/apt/03compress "${ETCDIR}/apt/apt.conf.d/03compress"
19 install_readonly files/apt/04norecommends "$R/etc/apt/apt.conf.d/04norecommends"
19 install_readonly files/apt/04norecommends "${ETCDIR}/apt/apt.conf.d/04norecommends"
20
20
21 # Remove APT cache files
21 # Remove APT cache files
22 rm -fr "$R/var/cache/apt/pkgcache.bin"
22 rm -fr "${R}/var/cache/apt/pkgcache.bin"
23 rm -fr "$R/var/cache/apt/srcpkgcache.bin"
23 rm -fr "${R}/var/cache/apt/srcpkgcache.bin"
24 fi
24 fi
25
25
26 # Remove all doc files
26 # Remove all doc files
27 if [ "$REDUCE_DOC" = true ] ; then
27 if [ "$REDUCE_DOC" = true ] ; then
28 find "$R/usr/share/doc" -depth -type f ! -name copyright | xargs rm || true
28 find "${R}/usr/share/doc" -depth -type f ! -name copyright | xargs rm || true
29 find "$R/usr/share/doc" -empty | xargs rmdir || true
29 find "${R}/usr/share/doc" -empty | xargs rmdir || true
30 fi
30 fi
31
31
32 # Remove all man pages and info files
32 # Remove all man pages and info files
33 if [ "$REDUCE_MAN" = true ] ; then
33 if [ "$REDUCE_MAN" = true ] ; then
34 rm -rf "$R/usr/share/man" "$R/usr/share/groff" "$R/usr/share/info" "$R/usr/share/lintian" "$R/usr/share/linda" "$R/var/cache/man"
34 rm -rf "${R}/usr/share/man" "${R}/usr/share/groff" "${R}/usr/share/info" "${R}/usr/share/lintian" "${R}/usr/share/linda" "${R}/var/cache/man"
35 fi
35 fi
36
36
37 # Remove all locale translation files
37 # Remove all locale translation files
38 if [ "$REDUCE_LOCALE" = true ] ; then
38 if [ "$REDUCE_LOCALE" = true ] ; then
39 find "$R/usr/share/locale" -mindepth 1 -maxdepth 1 ! -name 'en' | xargs rm -r
39 find "${R}/usr/share/locale" -mindepth 1 -maxdepth 1 ! -name 'en' | xargs rm -r
40 fi
40 fi
41
41
42 # Remove hwdb PCI device classes (experimental)
42 # Remove hwdb PCI device classes (experimental)
43 if [ "$REDUCE_HWDB" = true ] ; then
43 if [ "$REDUCE_HWDB" = true ] ; then
44 rm -fr "/lib/udev/hwdb.d/20-pci-*"
44 rm -fr "/lib/udev/hwdb.d/20-pci-*"
45 fi
45 fi
46
46
47 # Replace bash shell by dash shell (experimental)
47 # Replace bash shell by dash shell (experimental)
48 if [ "$REDUCE_BASH" = true ] ; then
48 if [ "$REDUCE_BASH" = true ] ; then
49 echo "Yes, do as I say!" | chroot_exec apt-get purge -qq -y --force-yes bash
49 echo "Yes, do as I say!" | chroot_exec apt-get purge -qq -y --force-yes bash
50 chroot_exec update-alternatives --install /bin/bash bash /bin/dash 100
50 chroot_exec update-alternatives --install /bin/bash bash /bin/dash 100
51 fi
51 fi
52
52
53 # Remove sound utils and libraries
53 # Remove sound utils and libraries
54 if [ "$ENABLE_SOUND" = false ] ; then
54 if [ "$ENABLE_SOUND" = false ] ; then
55 chroot_exec apt-get -qq -y --force-yes purge alsa-utils libsamplerate0 libasound2 libasound2-data
55 chroot_exec apt-get -qq -y --force-yes purge alsa-utils libsamplerate0 libasound2 libasound2-data
56 fi
56 fi
57
57
58 # Re-install tools for managing kernel moduless
58 # Re-install tools for managing kernel moduless
59 chroot_exec apt-get -qq -y --force-yes install module-init-tools
59 chroot_exec apt-get -qq -y --force-yes install module-init-tools
60
60
61 # Remove GPU kernels
61 # Remove GPU kernels
62 if [ "$ENABLE_MINGPU" = true ] ; then
62 if [ "$ENABLE_MINGPU" = true ] ; then
63 rm -f "$R/boot/firmware/start.elf"
63 rm -f "${BOOTDIR}/start.elf"
64 rm -f "$R/boot/firmware/fixup.dat"
64 rm -f "${BOOTDIR}/fixup.dat"
65 rm -f "$R/boot/firmware/start_x.elf"
65 rm -f "${BOOTDIR}/start_x.elf"
66 rm -f "$R/boot/firmware/fixup_x.dat"
66 rm -f "${BOOTDIR}/fixup_x.dat"
67 fi
67 fi
68
68
69 # Remove kernel and initrd from /boot (already in /boot/firmware)
69 # Remove kernel and initrd from /boot (already in /boot/firmware)
70 if [ "$BUILD_KERNEL" = false ] ; then
70 if [ "$BUILD_KERNEL" = false ] ; then
71 rm -r "$R/boot/vmlinuz--*"
71 rm -f "${R}/boot/vmlinuz-*"
72 rm -r "$R/boot/initrd.img-*"
72 rm -f "${R}/boot/initrd.img-*"
73 fi
73 fi
74
74
75 # Clean APT list of repositories
75 # Clean APT list of repositories
76 rm -fr "$R/var/lib/apt/lists/*"
76 rm -fr "${R}/var/lib/apt/lists/*"
77 chroot_exec apt-get -qq -y update
77 chroot_exec apt-get -qq -y update
78 fi
78 fi
@@ -1,11 +1,15
1 # Set device tree fdtfile
2 setenv dtbfile bcm2709-rpi-2-b.dtb
3
1 # Tell Linux that it is booting on a Raspberry Pi2
4 # Tell Linux that it is booting on a Raspberry Pi2
2 setenv machid 0x00000c42
5 setenv machid 0x00000c42
3
6
4 # Save these changes to u-boot's environment
7 # Save these changes to u-boot's environment
5 saveenv
8 saveenv
6
9
7 # Load the existing Linux kernel into RAM
10 # Load the existing Linux kernel into RAM
8 fatload mmc 0:1 ${kernel_addr_r} kernel7.img
11 fatload mmc 0:1 ${kernel_addr_r} kernel7.img
12 fatload mmc 0:1 ${fdt_addr_r} ${dtbfile}
13 fatload mmc 0:1 ${ramdisk_addr_r} ${initramfs}
9
14
10 # Boot the kernel we have just loaded
15 # Boot the kernel we have just loaded
11 bootz ${kernel_addr_r}
@@ -1,20 +1,26
1 logger -t "rc.firstboot" "Generating SSH host keys"
1 logger -t "rc.firstboot" "Generating SSH host keys"
2
2
3 if [ -d "/etc/ssh/" ] ; then
3 if [ -d "/etc/ssh/" ] ; then
4 # Remove ssh host keys
4 rm -f /etc/ssh/ssh_host_*
5 rm -f /etc/ssh/ssh_host_*
5 systemctl stop sshd
6 systemctl stop sshd
7
8 # Regenerate ssh host keys
6 ssh-keygen -q -t rsa -N "" -f /etc/ssh/ssh_host_rsa_key
9 ssh-keygen -q -t rsa -N "" -f /etc/ssh/ssh_host_rsa_key
7 ssh-keygen -q -t dsa -N "" -f /etc/ssh/ssh_host_dsa_key
10 ssh-keygen -q -t dsa -N "" -f /etc/ssh/ssh_host_dsa_key
8 ssh-keygen -q -t ecdsa -N "" -f /etc/ssh/ssh_host_ecdsa_key
11 ssh-keygen -q -t ecdsa -N "" -f /etc/ssh/ssh_host_ecdsa_key
9 ssh-keygen -q -t ed25519 -N "" -f /etc/ssh/ssh_host_ed25519_key
12 ssh-keygen -q -t ed25519 -N "" -f /etc/ssh/ssh_host_ed25519_key
10 systemctl start sshd
13 systemctl start sshd
11 fi
14 fi
12
15
13 if [ -d "/etc/dropbear/" ] ; then
16 if [ -d "/etc/dropbear/" ] ; then
17 # Remove ssh host keys
14 rm -f /etc/dropbear/dropbear_*
18 rm -f /etc/dropbear/dropbear_*
15 systemctl stop dropbear
19 systemctl stop dropbear
20
21 # Regenerate ssh host keys
16 dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key
22 dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key
17 dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key
23 dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key
18 dropbearkey -t ecdsa -f /etc/dropbear/dropbear_ecdsa_host_key
24 dropbearkey -t ecdsa -f /etc/dropbear/dropbear_ecdsa_host_key
19 systemctl start dropbear
25 systemctl start dropbear
20 fi
26 fi
@@ -1,56 +1,68
1 logger -t "rc.firstboot" "Expanding root"
1 logger -t "rc.firstboot" "Expanding root partition"
2
3 # Detect root partition device
2 ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
4 ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
3 PART_NUM=$(echo ${ROOT_PART} | grep -o '[1-9][0-9]*$')
5 if [ -z "$ROOT_PART" ] ; then
6 log_warning_msg "unable to detect root partition device"
7 return 1
8 fi
9
10 # Extract root device name
4 case "${ROOT_PART}" in
11 case "${ROOT_PART}" in
5 mmcblk0*) ROOT_DEV=mmcblk0 ;;
12 mmcblk0*) ROOT_DEV=mmcblk0 ;;
6 sda*) ROOT_DEV=sda ;;
13 sda*) ROOT_DEV=sda ;;
7 esac
14 esac
15
16 # Check detected root partition name
17 PART_NUM=$(echo ${ROOT_PART} | grep -o '[1-9][0-9]*$')
8 if [ "$PART_NUM" = "$ROOT_PART" ] ; then
18 if [ "$PART_NUM" = "$ROOT_PART" ] ; then
9 logger -t "rc.firstboot" "$ROOT_PART is not an SD card. Don't know how to expand"
19 logger -t "rc.firstboot" "$ROOT_PART is not an SD card. Don't know how to expand"
10 return 0
20 return 0
11 fi
21 fi
12
22
13 # NOTE: the NOOBS partition layout confuses parted. For now, let's only
23 # NOTE: the NOOBS partition layout confuses parted. For now, let's only
14 # agree to work with a sufficiently simple partition layout
24 # agree to work with a sufficiently simple partition layout
15 if [ "$PART_NUM" -gt 2 ] ; then
25 if [ "$PART_NUM" -gt 2 ] ; then
16 logger -t "rc.firstboot" "Your partition layout is not currently supported by this tool."
26 logger -t "rc.firstboot" "Your partition layout is not currently supported by this tool."
17 return 0
27 return 0
18 fi
28 fi
29
30 # Check if last partition number
19 LAST_PART_NUM=$(parted /dev/${ROOT_DEV} -ms unit s p | tail -n 1 | cut -f 1 -d:)
31 LAST_PART_NUM=$(parted /dev/${ROOT_DEV} -ms unit s p | tail -n 1 | cut -f 1 -d:)
20 if [ $LAST_PART_NUM -ne $PART_NUM ]; then
32 if [ $LAST_PART_NUM -ne $PART_NUM ]; then
21 logger -t "rc.firstboot" "$ROOT_PART is not the last partition. Don't know how to expand"
33 logger -t "rc.firstboot" "$ROOT_PART is not the last partition. Don't know how to expand"
22 return 0
34 return 0
23 fi
35 fi
24
36
25 # Get the starting offset of the root partition
37 # Get the starting offset of the root partition
26 PART_START=$(parted /dev/${ROOT_DEV} -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g')
38 PART_START=$(parted /dev/${ROOT_DEV} -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g')
27 if [ -z "$PART_START" ] ; then
39 if [ -z "$PART_START" ] ; then
28 logger -t "rc.firstboot" "${ROOT_DEV} unable to get starting sector of the partition"
40 logger -t "rc.firstboot" "${ROOT_DEV} unable to get starting sector of the partition"
29 return 1
41 return 1
30 fi
42 fi
31
43
32 # Get the possible last sector for the root partition
44 # Get the possible last sector for the root partition
33 PART_LAST=$(fdisk -l /dev/${ROOT_DEV} | grep '^Disk.*sectors' | awk '{ print $7 - 1 }')
45 PART_LAST=$(fdisk -l /dev/${ROOT_DEV} | grep '^Disk.*sectors' | awk '{ print $7 - 1 }')
34 if [ -z "$PART_LAST" ] ; then
46 if [ -z "$PART_LAST" ] ; then
35 logger -t "rc.firstboot" "${ROOT_DEV} unable to get last sector of the partition"
47 logger -t "rc.firstboot" "${ROOT_DEV} unable to get last sector of the partition"
36 return 1
48 return 1
37 fi
49 fi
38
50
39 ### Since rc.local is run with "sh -e", let's add "|| true" to prevent premature exit
51 ### Since rc.local is run with "sh -e", let's add "|| true" to prevent premature exit
40 fdisk /dev/${ROOT_DEV} <<EOF2 || true
52 fdisk /dev/${ROOT_DEV} <<EOF2 || true
41 p
53 p
42 d
54 d
43 $PART_NUM
55 $PART_NUM
44 n
56 n
45 p
57 p
46 $PART_NUM
58 $PART_NUM
47 $PART_START
59 $PART_START
48 $PART_LAST
60 $PART_LAST
49 p
61 p
50 w
62 w
51 EOF2
63 EOF2
52
64
53 # Reload the partition table, resize root filesystem then remove resizing code from this file
65 # Reload the partition table, resize root filesystem then remove resizing code from this file
54 partprobe &&
66 partprobe &&
55 resize2fs /dev/${ROOT_PART} &&
67 resize2fs /dev/${ROOT_PART} &&
56 logger -t "rc.firstboot" "Root partition successfuly resized."
68 logger -t "rc.firstboot" "Root partition successfully resized."
1 NO CONTENT: file renamed from files/firstboot/23-generate-machineid.sh to files/firstboot/24-generate-machineid.sh
NO CONTENT: file renamed from files/firstboot/23-generate-machineid.sh to files/firstboot/24-generate-machineid.sh
1 NO CONTENT: file renamed from files/firstboot/24-create-resolv-symlink.sh to files/firstboot/25-create-resolv-symlink.sh
NO CONTENT: file renamed from files/firstboot/24-create-resolv-symlink.sh to files/firstboot/25-create-resolv-symlink.sh
@@ -1,44 +1,44
1 # This file contains utility functions used by rpi2-gen-image.sh
1 # This file contains utility functions used by rpi2-gen-image.sh
2
2
3 cleanup (){
3 cleanup (){
4 set +x
4 set +x
5 set +e
5 set +e
6
6
7 # Identify and kill all processes still using files
7 # Identify and kill all processes still using files
8 echo "killing processes using mount point ..."
8 echo "killing processes using mount point ..."
9 fuser -k "$R"
9 fuser -k "${R}"
10 sleep 3
10 sleep 3
11 fuser -9 -k -v "$R"
11 fuser -9 -k -v "${R}"
12
12
13 # Clean up temporary .password file
13 # Clean up temporary .password file
14 if [ -r ".password" ] ; then
14 if [ -r ".password" ] ; then
15 shred -zu .password
15 shred -zu .password
16 fi
16 fi
17
17
18 # Clean up all temporary mount points
18 # Clean up all temporary mount points
19 echo "removing temporary mount points ..."
19 echo "removing temporary mount points ..."
20 umount -l "$R/proc" 2> /dev/null
20 umount -l "${R}/proc" 2> /dev/null
21 umount -l "$R/sys" 2> /dev/null
21 umount -l "${R}/sys" 2> /dev/null
22 umount -l "$R/dev/pts" 2> /dev/null
22 umount -l "${R}/dev/pts" 2> /dev/null
23 umount "$BUILDDIR/mount/boot/firmware" 2> /dev/null
23 umount "$BUILDDIR/mount/boot/firmware" 2> /dev/null
24 umount "$BUILDDIR/mount" 2> /dev/null
24 umount "$BUILDDIR/mount" 2> /dev/null
25 cryptsetup close "${CRYPTFS_MAPPING}" 2> /dev/null
25 cryptsetup close "${CRYPTFS_MAPPING}" 2> /dev/null
26 losetup -d "$ROOT_LOOP" 2> /dev/null
26 losetup -d "$ROOT_LOOP" 2> /dev/null
27 losetup -d "$FRMW_LOOP" 2> /dev/null
27 losetup -d "$FRMW_LOOP" 2> /dev/null
28 trap - 0 1 2 3 6
28 trap - 0 1 2 3 6
29 }
29 }
30
30
31 chroot_exec() {
31 chroot_exec() {
32 # Exec command in chroot
32 # Exec command in chroot
33 LANG=C LC_ALL=C DEBIAN_FRONTEND=noninteractive chroot $R $*
33 LANG=C LC_ALL=C DEBIAN_FRONTEND=noninteractive chroot ${R} $*
34 }
34 }
35
35
36 install_readonly() {
36 install_readonly() {
37 # Install file with user read-only permissions
37 # Install file with user read-only permissions
38 install -o root -g root -m 644 $*
38 install -o root -g root -m 644 $*
39 }
39 }
40
40
41 install_exec() {
41 install_exec() {
42 # Install file with root exec permissions
42 # Install file with root exec permissions
43 install -o root -g root -m 744 $*
43 install -o root -g root -m 744 $*
44 }
44 }
@@ -1,505 +1,513
1 #!/bin/sh
1 #!/bin/sh
2
2
3 ########################################################################
3 ########################################################################
4 # rpi2-gen-image.sh ver2a 12/2015
4 # rpi2-gen-image.sh ver2a 12/2015
5 #
5 #
6 # Advanced debian "jessie" bootstrap script for RPi2
6 # Advanced debian "jessie" bootstrap script for RPi2
7 #
7 #
8 # This program is free software; you can redistribute it and/or
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
11 # of the License, or (at your option) any later version.
12 #
12 #
13 # some parts based on rpi2-build-image:
13 # some parts based on rpi2-build-image:
14 # Copyright (C) 2015 Ryan Finnie <ryan@finnie.org>
14 # Copyright (C) 2015 Ryan Finnie <ryan@finnie.org>
15 # Copyright (C) 2015 Luca Falavigna <dktrkranz@debian.org>
15 # Copyright (C) 2015 Luca Falavigna <dktrkranz@debian.org>
16 ########################################################################
16 ########################################################################
17
17
18 # Are we running as root?
18 # Are we running as root?
19 if [ "$(id -u)" -ne "0" ] ; then
19 if [ "$(id -u)" -ne "0" ] ; then
20 echo "error: this script must be executed with root privileges!"
20 echo "error: this script must be executed with root privileges!"
21 exit 1
21 exit 1
22 fi
22 fi
23
23
24 # Check if ./functions.sh script exists
24 # Check if ./functions.sh script exists
25 if [ ! -r "./functions.sh" ] ; then
25 if [ ! -r "./functions.sh" ] ; then
26 echo "error: './functions.sh' required script not found!"
26 echo "error: './functions.sh' required script not found!"
27 exit 1
27 exit 1
28 fi
28 fi
29
29
30 # Load utility functions
30 # Load utility functions
31 . ./functions.sh
31 . ./functions.sh
32
32
33 # Introduce settings
33 # Introduce settings
34 set -e
34 set -e
35 echo -n -e "\n#\n# RPi2 Bootstrap Settings\n#\n"
35 echo -n -e "\n#\n# RPi2 Bootstrap Settings\n#\n"
36 set -x
36 set -x
37
37
38 # Debian release
38 # Debian release
39 RELEASE=${RELEASE:=jessie}
39 RELEASE=${RELEASE:=jessie}
40 KERNEL_ARCH=${KERNEL_ARCH:=arm}
40 KERNEL_ARCH=${KERNEL_ARCH:=arm}
41 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
41 RELEASE_ARCH=${RELEASE_ARCH:=armhf}
42 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
42 CROSS_COMPILE=${CROSS_COMPILE:=arm-linux-gnueabihf-}
43 COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2}
43 COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2}
44 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
44 KERNEL_DEFCONFIG=${KERNEL_DEFCONFIG:=bcm2709_defconfig}
45 KERNEL_IMAGE=${KERNEL_IMAGE:=kernel7.img}
46 DTB_FILE=${DTB_FILE:=bcm2709-rpi-2-b.dtb}
47 UBOOT_CONFIG=${UBOOT_CONFIG:=rpi_2_defconfig}
45 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
48 QEMU_BINARY=${QEMU_BINARY:=/usr/bin/qemu-arm-static}
46
49
47 # Build directories
50 # Build directories
48 BASEDIR="$(pwd)/images/${RELEASE}"
51 BASEDIR="$(pwd)/images/${RELEASE}"
49 BUILDDIR="${BASEDIR}/build"
52 BUILDDIR="${BASEDIR}/build"
53
54 # Chroot directories
50 R="${BUILDDIR}/chroot"
55 R="${BUILDDIR}/chroot"
56 ETCDIR="${R}/etc"
57 BOOTDIR="${R}/boot/firmware"
58 KERNELDIR="${R}/usr/src/linux"
51
59
52 # General settings
60 # General settings
53 HOSTNAME=${HOSTNAME:=rpi2-${RELEASE}}
61 HOSTNAME=${HOSTNAME:=rpi2-${RELEASE}}
54 PASSWORD=${PASSWORD:=raspberry}
62 PASSWORD=${PASSWORD:=raspberry}
55 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
63 DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"}
56 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
64 TIMEZONE=${TIMEZONE:="Europe/Berlin"}
57 EXPANDROOT=${EXPANDROOT:=true}
65 EXPANDROOT=${EXPANDROOT:=true}
58
66
59 # Keyboard settings
67 # Keyboard settings
60 XKB_MODEL=${XKB_MODEL:=""}
68 XKB_MODEL=${XKB_MODEL:=""}
61 XKB_LAYOUT=${XKB_LAYOUT:=""}
69 XKB_LAYOUT=${XKB_LAYOUT:=""}
62 XKB_VARIANT=${XKB_VARIANT:=""}
70 XKB_VARIANT=${XKB_VARIANT:=""}
63 XKB_OPTIONS=${XKB_OPTIONS:=""}
71 XKB_OPTIONS=${XKB_OPTIONS:=""}
64
72
65 # Network settings (DHCP)
73 # Network settings (DHCP)
66 ENABLE_DHCP=${ENABLE_DHCP:=true}
74 ENABLE_DHCP=${ENABLE_DHCP:=true}
67
75
68 # Network settings (static)
76 # Network settings (static)
69 NET_ADDRESS=${NET_ADDRESS:=""}
77 NET_ADDRESS=${NET_ADDRESS:=""}
70 NET_GATEWAY=${NET_GATEWAY:=""}
78 NET_GATEWAY=${NET_GATEWAY:=""}
71 NET_DNS_1=${NET_DNS_1:=""}
79 NET_DNS_1=${NET_DNS_1:=""}
72 NET_DNS_2=${NET_DNS_2:=""}
80 NET_DNS_2=${NET_DNS_2:=""}
73 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
81 NET_DNS_DOMAINS=${NET_DNS_DOMAINS:=""}
74 NET_NTP_1=${NET_NTP_1:=""}
82 NET_NTP_1=${NET_NTP_1:=""}
75 NET_NTP_2=${NET_NTP_2:=""}
83 NET_NTP_2=${NET_NTP_2:=""}
76
84
77 # APT settings
85 # APT settings
78 APT_PROXY=${APT_PROXY:=""}
86 APT_PROXY=${APT_PROXY:=""}
79 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
87 APT_SERVER=${APT_SERVER:="ftp.debian.org"}
80
88
81 # Feature settings
89 # Feature settings
82 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
90 ENABLE_CONSOLE=${ENABLE_CONSOLE:=true}
83 ENABLE_IPV6=${ENABLE_IPV6:=true}
91 ENABLE_IPV6=${ENABLE_IPV6:=true}
84 ENABLE_SSHD=${ENABLE_SSHD:=true}
92 ENABLE_SSHD=${ENABLE_SSHD:=true}
85 ENABLE_SOUND=${ENABLE_SOUND:=true}
93 ENABLE_SOUND=${ENABLE_SOUND:=true}
86 ENABLE_DBUS=${ENABLE_DBUS:=true}
94 ENABLE_DBUS=${ENABLE_DBUS:=true}
87 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
95 ENABLE_HWRANDOM=${ENABLE_HWRANDOM:=true}
88 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
96 ENABLE_MINGPU=${ENABLE_MINGPU:=false}
89 ENABLE_XORG=${ENABLE_XORG:=false}
97 ENABLE_XORG=${ENABLE_XORG:=false}
90 ENABLE_WM=${ENABLE_WM:=""}
98 ENABLE_WM=${ENABLE_WM:=""}
91 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
99 ENABLE_RSYSLOG=${ENABLE_RSYSLOG:=true}
92 ENABLE_USER=${ENABLE_USER:=true}
100 ENABLE_USER=${ENABLE_USER:=true}
93 ENABLE_ROOT=${ENABLE_ROOT:=false}
101 ENABLE_ROOT=${ENABLE_ROOT:=false}
94 ENABLE_ROOT_SSH=${ENABLE_ROOT_SSH:=false}
102 ENABLE_ROOT_SSH=${ENABLE_ROOT_SSH:=false}
95
103
96 # Advanced settings
104 # Advanced settings
97 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
105 ENABLE_MINBASE=${ENABLE_MINBASE:=false}
98 ENABLE_REDUCE=${ENABLE_REDUCE:=flase}
106 ENABLE_REDUCE=${ENABLE_REDUCE:=flase}
99 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
107 ENABLE_UBOOT=${ENABLE_UBOOT:=false}
100 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
108 ENABLE_FBTURBO=${ENABLE_FBTURBO:=false}
101 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
109 ENABLE_HARDNET=${ENABLE_HARDNET:=false}
102 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
110 ENABLE_IPTABLES=${ENABLE_IPTABLES:=false}
103 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
111 ENABLE_SPLITFS=${ENABLE_SPLITFS:=false}
104 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
112 ENABLE_INITRAMFS=${ENABLE_INITRAMFS:=false}
105
113
106 # Kernel compilation settings
114 # Kernel compilation settings
107 BUILD_KERNEL=${BUILD_KERNEL:=false}
115 BUILD_KERNEL=${BUILD_KERNEL:=false}
108 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
116 KERNEL_REDUCE=${KERNEL_REDUCE:=false}
109 KERNEL_THREADS=${KERNEL_THREADS:=1}
117 KERNEL_THREADS=${KERNEL_THREADS:=1}
110 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
118 KERNEL_HEADERS=${KERNEL_HEADERS:=true}
111 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
119 KERNEL_MENUCONFIG=${KERNEL_MENUCONFIG:=false}
112 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
120 KERNEL_REMOVESRC=${KERNEL_REMOVESRC:=true}
113
121
114 # Kernel compilation from source directory settings
122 # Kernel compilation from source directory settings
115 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
123 KERNELSRC_DIR=${KERNELSRC_DIR:=""}
116 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
124 KERNELSRC_CLEAN=${KERNELSRC_CLEAN:=false}
117 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
125 KERNELSRC_CONFIG=${KERNELSRC_CONFIG:=true}
118 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
126 KERNELSRC_PREBUILT=${KERNELSRC_PREBUILT:=false}
119
127
120 # Reduce disk usage settings
128 # Reduce disk usage settings
121 REDUCE_APT=${REDUCE_APT:=true}
129 REDUCE_APT=${REDUCE_APT:=true}
122 REDUCE_DOC=${REDUCE_DOC:=true}
130 REDUCE_DOC=${REDUCE_DOC:=true}
123 REDUCE_MAN=${REDUCE_MAN:=true}
131 REDUCE_MAN=${REDUCE_MAN:=true}
124 REDUCE_VIM=${REDUCE_VIM:=false}
132 REDUCE_VIM=${REDUCE_VIM:=false}
125 REDUCE_BASH=${REDUCE_BASH:=false}
133 REDUCE_BASH=${REDUCE_BASH:=false}
126 REDUCE_HWDB=${REDUCE_HWDB:=true}
134 REDUCE_HWDB=${REDUCE_HWDB:=true}
127 REDUCE_SSHD=${REDUCE_SSHD:=true}
135 REDUCE_SSHD=${REDUCE_SSHD:=true}
128 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
136 REDUCE_LOCALE=${REDUCE_LOCALE:=true}
129
137
130 # Encrypted filesystem settings
138 # Encrypted filesystem settings
131 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
139 ENABLE_CRYPTFS=${ENABLE_CRYPTFS:=false}
132 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
140 CRYPTFS_PASSWORD=${CRYPTFS_PASSWORD:=""}
133 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
141 CRYPTFS_MAPPING=${CRYPTFS_MAPPING:="secure"}
134 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
142 CRYPTFS_CIPHER=${CRYPTFS_CIPHER:="aes-xts-plain64:sha512"}
135 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
143 CRYPTFS_XTSKEYSIZE=${CRYPTFS_XTSKEYSIZE:=512}
136
144
137 # Stop the Crypto Wars
145 # Stop the Crypto Wars
138 DISABLE_FBI=${DISABLE_FBI:=false}
146 DISABLE_FBI=${DISABLE_FBI:=false}
139
147
140 # Chroot scripts directory
148 # Chroot scripts directory
141 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
149 CHROOT_SCRIPTS=${CHROOT_SCRIPTS:=""}
142
150
143 # Packages required in the chroot build environment
151 # Packages required in the chroot build environment
144 APT_INCLUDES=${APT_INCLUDES:=""}
152 APT_INCLUDES=${APT_INCLUDES:=""}
145 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo"
153 APT_INCLUDES="${APT_INCLUDES},apt-transport-https,apt-utils,ca-certificates,debian-archive-keyring,dialog,sudo"
146
154
147 # Packages required for bootstrapping
155 # Packages required for bootstrapping
148 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git"
156 REQUIRED_PACKAGES="debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git"
149 MISSING_PACKAGES=""
157 MISSING_PACKAGES=""
150
158
151 set +x
159 set +x
152
160
153 # Add packages required for kernel cross compilation
161 # Add packages required for kernel cross compilation
154 if [ "$BUILD_KERNEL" = true ] ; then
162 if [ "$BUILD_KERNEL" = true ] ; then
155 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
163 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} crossbuild-essential-armhf"
156 fi
164 fi
157
165
158 # Add libncurses5 to enable kernel menuconfig
166 # Add libncurses5 to enable kernel menuconfig
159 if [ "$KERNEL_MENUCONFIG" = true ] ; then
167 if [ "$KERNEL_MENUCONFIG" = true ] ; then
160 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
168 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} libncurses5-dev"
161 fi
169 fi
162
170
163 # Stop the Crypto Wars
171 # Stop the Crypto Wars
164 if [ "$DISABLE_FBI" = true ] ; then
172 if [ "$DISABLE_FBI" = true ] ; then
165 ENABLE_CRYPTFS=true
173 ENABLE_CRYPTFS=true
166 fi
174 fi
167
175
168 # Add cryptsetup package to enable filesystem encryption
176 # Add cryptsetup package to enable filesystem encryption
169 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
177 if [ "$ENABLE_CRYPTFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
170 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
178 REQUIRED_PACKAGES="${REQUIRED_PACKAGES} cryptsetup"
171 APT_INCLUDES="${APT_INCLUDES},cryptsetup"
179 APT_INCLUDES="${APT_INCLUDES},cryptsetup"
172
180
173 if [ -z "$CRYPTFS_PASSWORD" ] ; then
181 if [ -z "$CRYPTFS_PASSWORD" ] ; then
174 echo "error: no password defined (CRYPTFS_PASSWORD)!"
182 echo "error: no password defined (CRYPTFS_PASSWORD)!"
175 exit 1
183 exit 1
176 fi
184 fi
177 ENABLE_INITRAMFS=true
185 ENABLE_INITRAMFS=true
178 fi
186 fi
179
187
180 # Add initramfs generation tools
188 # Add initramfs generation tools
181 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
189 if [ "$ENABLE_INITRAMFS" = true ] && [ "$BUILD_KERNEL" = true ] ; then
182 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
190 APT_INCLUDES="${APT_INCLUDES},initramfs-tools"
183 fi
191 fi
184
192
185 # Check if all required packages are installed on the build system
193 # Check if all required packages are installed on the build system
186 for package in $REQUIRED_PACKAGES ; do
194 for package in $REQUIRED_PACKAGES ; do
187 if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then
195 if [ "`dpkg-query -W -f='${Status}' $package`" != "install ok installed" ] ; then
188 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
196 MISSING_PACKAGES="${MISSING_PACKAGES} $package"
189 fi
197 fi
190 done
198 done
191
199
192 # Ask if missing packages should get installed right now
200 # Ask if missing packages should get installed right now
193 if [ -n "$MISSING_PACKAGES" ] ; then
201 if [ -n "$MISSING_PACKAGES" ] ; then
194 echo "the following packages needed by this script are not installed:"
202 echo "the following packages needed by this script are not installed:"
195 echo "$MISSING_PACKAGES"
203 echo "$MISSING_PACKAGES"
196
204
197 echo -n "\ndo you want to install the missing packages right now? [y/n] "
205 echo -n "\ndo you want to install the missing packages right now? [y/n] "
198 read confirm
206 read confirm
199 [ "$confirm" != "y" ] && exit 1
207 [ "$confirm" != "y" ] && exit 1
200 fi
208 fi
201
209
202 # Make sure all required packages are installed
210 # Make sure all required packages are installed
203 apt-get -qq -y install ${REQUIRED_PACKAGES}
211 apt-get -qq -y install ${REQUIRED_PACKAGES}
204
212
205 # Check if ./bootstrap.d directory exists
213 # Check if ./bootstrap.d directory exists
206 if [ ! -d "./bootstrap.d/" ] ; then
214 if [ ! -d "./bootstrap.d/" ] ; then
207 echo "error: './bootstrap.d' required directory not found!"
215 echo "error: './bootstrap.d' required directory not found!"
208 exit 1
216 exit 1
209 fi
217 fi
210
218
211 # Check if ./files directory exists
219 # Check if ./files directory exists
212 if [ ! -d "./files/" ] ; then
220 if [ ! -d "./files/" ] ; then
213 echo "error: './files' required directory not found!"
221 echo "error: './files' required directory not found!"
214 exit 1
222 exit 1
215 fi
223 fi
216
224
217 # Check if specified KERNELSRC_DIR directory exists
225 # Check if specified KERNELSRC_DIR directory exists
218 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
226 if [ -n "$KERNELSRC_DIR" ] && [ ! -d "$KERNELSRC_DIR" ] ; then
219 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
227 echo "error: '${KERNELSRC_DIR}' specified directory not found (KERNELSRC_DIR)!"
220 exit 1
228 exit 1
221 fi
229 fi
222
230
223 # Check if specified CHROOT_SCRIPTS directory exists
231 # Check if specified CHROOT_SCRIPTS directory exists
224 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
232 if [ -n "$CHROOT_SCRIPTS" ] && [ ! -d "$CHROOT_SCRIPTS" ] ; then
225 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
233 echo "error: ${CHROOT_SCRIPTS} specified directory not found (CHROOT_SCRIPTS)!"
226 exit 1
234 exit 1
227 fi
235 fi
228
236
229 # Check if specified device mapping already exists (will be used by cryptsetup)
237 # Check if specified device mapping already exists (will be used by cryptsetup)
230 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
238 if [ -r "/dev/mapping/${CRYPTFS_MAPPING}" ] ; then
231 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
239 echo "error: mapping /dev/mapping/${CRYPTFS_MAPPING} already exists, not proceeding"
232 exit 1
240 exit 1
233 fi
241 fi
234
242
235 # Don't clobber an old build
243 # Don't clobber an old build
236 if [ -e "$BUILDDIR" ] ; then
244 if [ -e "$BUILDDIR" ] ; then
237 echo "error: directory ${BUILDDIR} already exists, not proceeding"
245 echo "error: directory ${BUILDDIR} already exists, not proceeding"
238 exit 1
246 exit 1
239 fi
247 fi
240
248
241 # Setup chroot directory
249 # Setup chroot directory
242 mkdir -p "$R"
250 mkdir -p "${R}"
243
251
244 # Check if build directory has enough of free disk space >512MB
252 # Check if build directory has enough of free disk space >512MB
245 if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then
253 if [ "$(df --output=avail ${BUILDDIR} | sed "1d")" -le "524288" ] ; then
246 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
254 echo "error: ${BUILDDIR} not enough space left to generate the output image!"
247 exit 1
255 exit 1
248 fi
256 fi
249
257
250 set -x
258 set -x
251
259
252 # Call "cleanup" function on various signals and errors
260 # Call "cleanup" function on various signals and errors
253 trap cleanup 0 1 2 3 6
261 trap cleanup 0 1 2 3 6
254
262
255 # Add required packages for the minbase installation
263 # Add required packages for the minbase installation
256 if [ "$ENABLE_MINBASE" = true ] ; then
264 if [ "$ENABLE_MINBASE" = true ] ; then
257 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
265 APT_INCLUDES="${APT_INCLUDES},vim-tiny,netbase,net-tools,ifupdown"
258 else
266 else
259 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
267 APT_INCLUDES="${APT_INCLUDES},locales,keyboard-configuration,console-setup"
260 fi
268 fi
261
269
262 # Add parted package, required to get partprobe utility
270 # Add parted package, required to get partprobe utility
263 if [ "$EXPANDROOT" = true ] ; then
271 if [ "$EXPANDROOT" = true ] ; then
264 APT_INCLUDES="${APT_INCLUDES},parted"
272 APT_INCLUDES="${APT_INCLUDES},parted"
265 fi
273 fi
266
274
267 # Add dbus package, recommended if using systemd
275 # Add dbus package, recommended if using systemd
268 if [ "$ENABLE_DBUS" = true ] ; then
276 if [ "$ENABLE_DBUS" = true ] ; then
269 APT_INCLUDES="${APT_INCLUDES},dbus"
277 APT_INCLUDES="${APT_INCLUDES},dbus"
270 fi
278 fi
271
279
272 # Add iptables IPv4/IPv6 package
280 # Add iptables IPv4/IPv6 package
273 if [ "$ENABLE_IPTABLES" = true ] ; then
281 if [ "$ENABLE_IPTABLES" = true ] ; then
274 APT_INCLUDES="${APT_INCLUDES},iptables"
282 APT_INCLUDES="${APT_INCLUDES},iptables"
275 fi
283 fi
276
284
277 # Add openssh server package
285 # Add openssh server package
278 if [ "$ENABLE_SSHD" = true ] ; then
286 if [ "$ENABLE_SSHD" = true ] ; then
279 APT_INCLUDES="${APT_INCLUDES},openssh-server"
287 APT_INCLUDES="${APT_INCLUDES},openssh-server"
280 fi
288 fi
281
289
282 # Add alsa-utils package
290 # Add alsa-utils package
283 if [ "$ENABLE_SOUND" = true ] ; then
291 if [ "$ENABLE_SOUND" = true ] ; then
284 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
292 APT_INCLUDES="${APT_INCLUDES},alsa-utils"
285 fi
293 fi
286
294
287 # Add rng-tools package
295 # Add rng-tools package
288 if [ "$ENABLE_HWRANDOM" = true ] ; then
296 if [ "$ENABLE_HWRANDOM" = true ] ; then
289 APT_INCLUDES="${APT_INCLUDES},rng-tools"
297 APT_INCLUDES="${APT_INCLUDES},rng-tools"
290 fi
298 fi
291
299
292 # Add fbturbo video driver
300 # Add fbturbo video driver
293 if [ "$ENABLE_FBTURBO" = true ] ; then
301 if [ "$ENABLE_FBTURBO" = true ] ; then
294 # Enable xorg package dependencies
302 # Enable xorg package dependencies
295 ENABLE_XORG=true
303 ENABLE_XORG=true
296 fi
304 fi
297
305
298 # Add user defined window manager package
306 # Add user defined window manager package
299 if [ -n "$ENABLE_WM" ] ; then
307 if [ -n "$ENABLE_WM" ] ; then
300 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
308 APT_INCLUDES="${APT_INCLUDES},${ENABLE_WM}"
301
309
302 # Enable xorg package dependencies
310 # Enable xorg package dependencies
303 ENABLE_XORG=true
311 ENABLE_XORG=true
304 fi
312 fi
305
313
306 # Add xorg package
314 # Add xorg package
307 if [ "$ENABLE_XORG" = true ] ; then
315 if [ "$ENABLE_XORG" = true ] ; then
308 APT_INCLUDES="${APT_INCLUDES},xorg"
316 APT_INCLUDES="${APT_INCLUDES},xorg"
309 fi
317 fi
310
318
311 # Replace selected packages with smaller clones
319 # Replace selected packages with smaller clones
312 if [ "$ENABLE_REDUCE" = true ] ; then
320 if [ "$ENABLE_REDUCE" = true ] ; then
313 # Add levee package instead of vim-tiny
321 # Add levee package instead of vim-tiny
314 if [ "$REDUCE_VIM" = true ] ; then
322 if [ "$REDUCE_VIM" = true ] ; then
315 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
323 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/vim-tiny/levee/")"
316 fi
324 fi
317
325
318 # Add dropbear package instead of openssh-server
326 # Add dropbear package instead of openssh-server
319 if [ "$REDUCE_SSHD" = true ] ; then
327 if [ "$REDUCE_SSHD" = true ] ; then
320 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")"
328 APT_INCLUDES="$(echo ${APT_INCLUDES} | sed "s/openssh-server/dropbear/")"
321 fi
329 fi
322 fi
330 fi
323
331
324 # Configure kernel sources if no KERNELSRC_DIR
332 # Configure kernel sources if no KERNELSRC_DIR
325 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
333 if [ "$BUILD_KERNEL" = true ] && [ -z "$KERNELSRC_DIR" ] ; then
326 KERNELSRC_CONFIG=true
334 KERNELSRC_CONFIG=true
327 fi
335 fi
328
336
329 # Configure reduced kernel
337 # Configure reduced kernel
330 if [ "$KERNEL_REDUCE" = true ] ; then
338 if [ "$KERNEL_REDUCE" = true ] ; then
331 KERNELSRC_CONFIG=false
339 KERNELSRC_CONFIG=false
332 fi
340 fi
333
341
334 # Execute bootstrap scripts
342 # Execute bootstrap scripts
335 for SCRIPT in bootstrap.d/*.sh; do
343 for SCRIPT in bootstrap.d/*.sh; do
336 head -n 3 "$SCRIPT"
344 head -n 3 "$SCRIPT"
337 . "$SCRIPT"
345 . "$SCRIPT"
338 done
346 done
339
347
340 ## Execute custom bootstrap scripts
348 ## Execute custom bootstrap scripts
341 if [ -d "custom.d" ] ; then
349 if [ -d "custom.d" ] ; then
342 for SCRIPT in custom.d/*.sh; do
350 for SCRIPT in custom.d/*.sh; do
343 . "$SCRIPT"
351 . "$SCRIPT"
344 done
352 done
345 fi
353 fi
346
354
347 # Execute custom scripts inside the chroot
355 # Execute custom scripts inside the chroot
348 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
356 if [ -n "$CHROOT_SCRIPTS" ] && [ -d "$CHROOT_SCRIPTS" ] ; then
349 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
357 cp -r "${CHROOT_SCRIPTS}" "${R}/chroot_scripts"
350 chroot_exec /bin/bash -x <<'EOF'
358 chroot_exec /bin/bash -x <<'EOF'
351 for SCRIPT in /chroot_scripts/* ; do
359 for SCRIPT in /chroot_scripts/* ; do
352 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
360 if [ -f $SCRIPT -a -x $SCRIPT ] ; then
353 $SCRIPT
361 $SCRIPT
354 fi
362 fi
355 done
363 done
356 EOF
364 EOF
357 rm -rf "$R/chroot_scripts"
365 rm -rf "${R}/chroot_scripts"
358 fi
366 fi
359
367
360 # Remove apt-utils
368 # Remove apt-utils
361 chroot_exec apt-get purge -qq -y --force-yes apt-utils
369 chroot_exec apt-get purge -qq -y --force-yes apt-utils
362
370
363 # Generate required machine-id
371 # Generate required machine-id
364 MACHINE_ID=$(dbus-uuidgen)
372 MACHINE_ID=$(dbus-uuidgen)
365 echo -n "${MACHINE_ID}" > "$R/var/lib/dbus/machine-id"
373 echo -n "${MACHINE_ID}" > "${R}/var/lib/dbus/machine-id"
366 echo -n "${MACHINE_ID}" > "$R/etc/machine-id"
374 echo -n "${MACHINE_ID}" > "${ETCDIR}/machine-id"
367
375
368 # APT Cleanup
376 # APT Cleanup
369 chroot_exec apt-get -y clean
377 chroot_exec apt-get -y clean
370 chroot_exec apt-get -y autoclean
378 chroot_exec apt-get -y autoclean
371 chroot_exec apt-get -y autoremove
379 chroot_exec apt-get -y autoremove
372
380
373 # Unmount mounted filesystems
381 # Unmount mounted filesystems
374 umount -l "$R/proc"
382 umount -l "${R}/proc"
375 umount -l "$R/sys"
383 umount -l "${R}/sys"
376
384
377 # Clean up directories
385 # Clean up directories
378 rm -rf "$R/run/*"
386 rm -rf "${R}/run/*"
379 rm -rf "$R/tmp/*"
387 rm -rf "${R}/tmp/*"
380
388
381 # Clean up files
389 # Clean up files
382 rm -f "$R/etc/ssh/ssh_host_*"
390 rm -f "${ETCDIR}/ssh/ssh_host_*"
383 rm -f "$R/etc/dropbear/dropbear_*"
391 rm -f "${ETCDIR}/dropbear/dropbear_*"
384 rm -f "$R/etc/apt/sources.list.save"
392 rm -f "${ETCDIR}/apt/sources.list.save"
385 rm -f "$R/etc/resolvconf/resolv.conf.d/original"
393 rm -f "${ETCDIR}/resolvconf/resolv.conf.d/original"
386 rm -f "$R/etc/*-"
394 rm -f "${ETCDIR}/*-"
387 rm -f "$R/root/.bash_history"
395 rm -f "${ETCDIR}/apt/apt.conf.d/10proxy"
388 rm -f "$R/var/lib/urandom/random-seed"
396 rm -f "${ETCDIR}/resolv.conf"
389 rm -f "$R/etc/apt/apt.conf.d/10proxy"
397 rm -f "${R}/root/.bash_history"
390 rm -f "$R/etc/resolv.conf"
398 rm -f "${R}/var/lib/urandom/random-seed"
391 rm -f "$R/initrd.img"
399 rm -f "${R}/initrd.img"
392 rm -f "$R/vmlinuz"
400 rm -f "${R}/vmlinuz"
393 rm -f "${R}${QEMU_BINARY}"
401 rm -f "${R}${QEMU_BINARY}"
394
402
395 # Calculate size of the chroot directory in KB
403 # Calculate size of the chroot directory in KB
396 CHROOT_SIZE=$(expr `du -s "$R" | awk '{ print $1 }'`)
404 CHROOT_SIZE=$(expr `du -s "${R}" | awk '{ print $1 }'`)
397
405
398 # Calculate the amount of needed 512 Byte sectors
406 # Calculate the amount of needed 512 Byte sectors
399 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
407 TABLE_SECTORS=$(expr 1 \* 1024 \* 1024 \/ 512)
400 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
408 FRMW_SECTORS=$(expr 64 \* 1024 \* 1024 \/ 512)
401 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS})
409 ROOT_OFFSET=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS})
402
410
403 # The root partition is EXT4
411 # The root partition is EXT4
404 # This means more space than the actual used space of the chroot is used.
412 # This means more space than the actual used space of the chroot is used.
405 # As overhead for journaling and reserved blocks 20% are added.
413 # As overhead for journaling and reserved blocks 20% are added.
406 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512)
414 ROOT_SECTORS=$(expr $(expr ${CHROOT_SIZE} + ${CHROOT_SIZE} \/ 100 \* 20) \* 1024 \/ 512)
407
415
408 # Calculate required image size in 512 Byte sectors
416 # Calculate required image size in 512 Byte sectors
409 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS})
417 IMAGE_SECTORS=$(expr ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS})
410
418
411 # Prepare date string for image file name
419 # Prepare date string for image file name
412 DATE="$(date +%Y-%m-%d)"
420 DATE="$(date +%Y-%m-%d)"
413
421
414 # Prepare image file
422 # Prepare image file
415 if [ "$ENABLE_SPLITFS" = true ] ; then
423 if [ "$ENABLE_SPLITFS" = true ] ; then
416 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=${TABLE_SECTORS}
424 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=${TABLE_SECTORS}
417 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS}
425 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" bs=512 count=0 seek=${FRMW_SECTORS}
418 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=${TABLE_SECTORS}
426 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=${TABLE_SECTORS}
419 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=0 seek=${ROOT_SECTORS}
427 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}-root.img" bs=512 count=0 seek=${ROOT_SECTORS}
420
428
421 # Write firmware/boot partition tables
429 # Write firmware/boot partition tables
422 sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" 2> /dev/null <<EOM
430 sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img" 2> /dev/null <<EOM
423 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
431 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
424 EOM
432 EOM
425
433
426 # Write root partition table
434 # Write root partition table
427 sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}-root.img" 2> /dev/null <<EOM
435 sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}-root.img" 2> /dev/null <<EOM
428 ${TABLE_SECTORS},${ROOT_SECTORS},83
436 ${TABLE_SECTORS},${ROOT_SECTORS},83
429 EOM
437 EOM
430
438
431 # Setup temporary loop devices
439 # Setup temporary loop devices
432 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-frmw.img)"
440 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-frmw.img)"
433 ROOT_LOOP="$(losetup -o 1M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-root.img)"
441 ROOT_LOOP="$(losetup -o 1M -f --show $BASEDIR/${DATE}-debian-${RELEASE}-root.img)"
434 else # ENABLE_SPLITFS=false
442 else # ENABLE_SPLITFS=false
435 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS}
443 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=${TABLE_SECTORS}
436 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS}
444 dd if=/dev/zero of="$BASEDIR/${DATE}-debian-${RELEASE}.img" bs=512 count=0 seek=${IMAGE_SECTORS}
437
445
438 # Write partition table
446 # Write partition table
439 sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" 2> /dev/null <<EOM
447 sfdisk -q -L -uS -f "$BASEDIR/${DATE}-debian-${RELEASE}.img" 2> /dev/null <<EOM
440 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
448 ${TABLE_SECTORS},${FRMW_SECTORS},c,*
441 ${ROOT_OFFSET},${ROOT_SECTORS},83
449 ${ROOT_OFFSET},${ROOT_SECTORS},83
442 EOM
450 EOM
443
451
444 # Setup temporary loop devices
452 # Setup temporary loop devices
445 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
453 FRMW_LOOP="$(losetup -o 1M --sizelimit 64M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
446 ROOT_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
454 ROOT_LOOP="$(losetup -o 65M -f --show $BASEDIR/${DATE}-debian-${RELEASE}.img)"
447 fi
455 fi
448
456
449 if [ "$ENABLE_CRYPTFS" = true ] ; then
457 if [ "$ENABLE_CRYPTFS" = true ] ; then
450 # Create dummy ext4 fs
458 # Create dummy ext4 fs
451 mkfs.ext4 "$ROOT_LOOP"
459 mkfs.ext4 "$ROOT_LOOP"
452
460
453 # Setup password keyfile
461 # Setup password keyfile
454 echo -n ${CRYPTFS_PASSWORD} > .password
462 echo -n ${CRYPTFS_PASSWORD} > .password
455 chmod 600 .password
463 chmod 600 .password
456
464
457 # Initialize encrypted partition
465 # Initialize encrypted partition
458 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
466 echo "YES" | cryptsetup luksFormat "${ROOT_LOOP}" -c "${CRYPTFS_CIPHER}" -s "${CRYPTFS_XTSKEYSIZE}" .password
459
467
460 # Open encrypted partition and setup mapping
468 # Open encrypted partition and setup mapping
461 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
469 cryptsetup luksOpen "${ROOT_LOOP}" -d .password "${CRYPTFS_MAPPING}"
462
470
463 # Secure delete password keyfile
471 # Secure delete password keyfile
464 shred -zu .password
472 shred -zu .password
465
473
466 # Update temporary loop device
474 # Update temporary loop device
467 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
475 ROOT_LOOP="/dev/mapper/${CRYPTFS_MAPPING}"
468
476
469 # Wipe encrypted partition (encryption cipher is used for randomness)
477 # Wipe encrypted partition (encryption cipher is used for randomness)
470 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count=$(blockdev --getsz "${ROOT_LOOP}")
478 dd if=/dev/zero of="${ROOT_LOOP}" bs=512 count=$(blockdev --getsz "${ROOT_LOOP}")
471 fi
479 fi
472
480
473 # Build filesystems
481 # Build filesystems
474 mkfs.vfat "$FRMW_LOOP"
482 mkfs.vfat "$FRMW_LOOP"
475 mkfs.ext4 "$ROOT_LOOP"
483 mkfs.ext4 "$ROOT_LOOP"
476
484
477 # Mount the temporary loop devices
485 # Mount the temporary loop devices
478 mkdir -p "$BUILDDIR/mount"
486 mkdir -p "$BUILDDIR/mount"
479 mount "$ROOT_LOOP" "$BUILDDIR/mount"
487 mount "$ROOT_LOOP" "$BUILDDIR/mount"
480
488
481 mkdir -p "$BUILDDIR/mount/boot/firmware"
489 mkdir -p "$BUILDDIR/mount/boot/firmware"
482 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
490 mount "$FRMW_LOOP" "$BUILDDIR/mount/boot/firmware"
483
491
484 # Copy all files from the chroot to the loop device mount point directory
492 # Copy all files from the chroot to the loop device mount point directory
485 rsync -a "$R/" "$BUILDDIR/mount/"
493 rsync -a "${R}/" "$BUILDDIR/mount/"
486
494
487 # Unmount all temporary loop devices and mount points
495 # Unmount all temporary loop devices and mount points
488 cleanup
496 cleanup
489
497
490 # Create block map file(s) of image(s)
498 # Create block map file(s) of image(s)
491 if [ "$ENABLE_SPLITFS" = true ] ; then
499 if [ "$ENABLE_SPLITFS" = true ] ; then
492 # Create block map files for "bmaptool"
500 # Create block map files for "bmaptool"
493 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img"
501 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img"
494 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-root.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-root.img"
502 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}-root.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}-root.img"
495
503
496 # Image was successfully created
504 # Image was successfully created
497 echo "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
505 echo "$BASEDIR/${DATE}-debian-${RELEASE}-frmw.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
498 echo "$BASEDIR/${DATE}-debian-${RELEASE}-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
506 echo "$BASEDIR/${DATE}-debian-${RELEASE}-root.img ($(expr \( ${TABLE_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
499 else
507 else
500 # Create block map file for "bmaptool"
508 # Create block map file for "bmaptool"
501 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}.img"
509 bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}.img"
502
510
503 # Image was successfully created
511 # Image was successfully created
504 echo "$BASEDIR/${DATE}-debian-${RELEASE}.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
512 echo "$BASEDIR/${DATE}-debian-${RELEASE}.img ($(expr \( ${TABLE_SECTORS} + ${FRMW_SECTORS} + ${ROOT_SECTORS} \) \* 512 \/ 1024 \/ 1024)M)" ": successfully created"
505 fi
513 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant