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