diff --git a/README.md b/README.md index bd4a821..ee8ee9b 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,8 @@ ENABLE_WM=xfce4 ENABLE_FBTURBO=true ENABLE_MINBASE=true ./rpi2-gen-image.sh ENABLE_HARDNET=true ENABLE_IPTABLES=true /rpi2-gen-image.sh APT_SERVER=ftp.de.debian.org APT_PROXY="http://127.0.0.1:3142/" ./rpi2-gen-image.sh ENABLE_MINBASE=true ./rpi2-gen-image.sh - ``` +BUILD_KERNEL=true ENABLE_MINBASE=true ENABLE_IPV6=false ./rpi2-gen-image.sh +``` #### APT settings: ##### `APT_SERVER`="ftp.debian.org" @@ -49,25 +50,25 @@ Expand the root partition and filesystem automatically on first boot. #### Keyboard settings: 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. -##### `XKBMODEL`="" +##### `XKB_MODEL`="" Set the name of the model of your keyboard type. -##### `XKBLAYOUT`="" +##### `XKB_LAYOUT`="" Set the supported keyboard layout(s). -##### `XKBVARIANT`="" +##### `XKB_VARIANT`="" Set the supported variant(s) of the keyboard layout(s). -##### `XKBOPTIONS`="" +##### `XKB_OPTIONS`="" Set extra xkb configuration options. -#### Networking settings (DHCP) +#### Networking settings (DHCP): This setting is used to set up networking auto configuration in `/etc/systemd/network/eth.network`. #####`ENABLE_DHCP`=true Set the system to use DHCP. This requires an DHCP server. -#### Networking settings (static) +#### Networking settings (static): 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`. #####`NET_ADDRESS`="" @@ -156,8 +157,14 @@ Path to a directory with scripts that should be run in the chroot before the ima ##### `BUILD_KERNEL`=false 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. +##### `KERNEL_THREADS`=1 +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. + ##### `KERNEL_HEADERS`=true -If true, also install kernel headers with built kernel. +Install kernel headers with built kernel. + +##### `KERNEL_RMSRC`=true +Remove all kernel sources from the generated OS image after building. ## Understanding the script 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: @@ -169,11 +176,11 @@ The functions of this script that are required for the different stages of the b | `12-locale.sh` | Setup Locales and keyboard settings | | `13-kernel.sh` | Build and install RPi2 Kernel | | `20-networking.sh` | Setup Networking | -| `21-firewall.sh` | Setup iptables Firewall | -| `30-security.sh` | Setup users and security settings | -| `31-logging.sh` | Setup logging | +| `21-firewall.sh` | Setup Firewall | +| `30-security.sh` | Setup Users and Security settings | +| `31-logging.sh` | Setup Logging | | `41-uboot.sh` | Build and Setup Uboot | -| `42-fbturbo.sh` | Buld and Setup fbturbo Xorg driver | +| `42-fbturbo.sh` | Build and Setup fbturbo Xorg driver | | `50-firstboot.sh` | First boot actions | 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. @@ -183,6 +190,7 @@ All the required configuration files that will be copied to the generated OS ima | `boot` | Boot and RPi2 configuration files | | `firstboot` | Scripts that get executed on first boot | | `iptables` | Firewall configuration files | +| `locales` | Locales configuration | | `modprobe.d` | Kernel Module Blacklist configuration | | `mount` | Fstab configuration | | `network` | Networking configuration files | diff --git a/bootstrap.d/10-bootstrap.sh b/bootstrap.d/10-bootstrap.sh index fdccfba..7899dbf 100644 --- a/bootstrap.d/10-bootstrap.sh +++ b/bootstrap.d/10-bootstrap.sh @@ -2,6 +2,7 @@ # Debootstrap basic system # +# Load utility functions . ./functions.sh # Base debootstrap (unpack only) diff --git a/bootstrap.d/11-apt.sh b/bootstrap.d/11-apt.sh index 9a4739d..e70a6e7 100644 --- a/bootstrap.d/11-apt.sh +++ b/bootstrap.d/11-apt.sh @@ -2,19 +2,17 @@ # Setup APT repositories # +# Load utility functions . ./functions.sh # Use proxy inside chroot if [ -z "$APT_PROXY" ] ; then - echo "Acquire::http::Proxy \"$APT_PROXY\";" >> $R/etc/apt/apt.conf.d/10proxy + install_readonly files/apt/10proxy $R/etc/apt/apt.conf.d/10proxy + sed -i -e "s/\"\"/\"${APT_PROXY}\"/" $R/etc/apt/apt.conf.d/10proxy fi # Pin package flash-kernel to repositories.collabora.co.uk -cat <$R/etc/apt/preferences.d/flash-kernel -Package: flash-kernel -Pin: origin repositories.collabora.co.uk -Pin-Priority: 1000 -EOM +install_readonly files/apt/flash-kernel $R/etc/apt/preferences.d/flash-kernel # Upgrade collabora package index and install collabora keyring echo "deb https://repositories.collabora.co.uk/debian ${RELEASE} rpi2" >$R/etc/apt/sources.list @@ -22,18 +20,9 @@ chroot_exec apt-get -qq -y update chroot_exec apt-get -qq -y --force-yes install collabora-obs-archive-keyring # Set up initial sources.list -cat <$R/etc/apt/sources.list -deb http://${APT_SERVER}/debian ${RELEASE} main contrib -#deb-src http://${APT_SERVER}/debian ${RELEASE} main contrib - -deb http://${APT_SERVER}/debian/ ${RELEASE}-updates main contrib -#deb-src http://${APT_SERVER}/debian/ ${RELEASE}-updates main contrib - -deb http://security.debian.org/ ${RELEASE}/updates main contrib -#deb-src http://security.debian.org/ ${RELEASE}/updates main contrib - -deb https://repositories.collabora.co.uk/debian ${RELEASE} rpi2 -EOM +install_readonly files/apt/sources.list $R/etc/apt/sources.list +sed -i -e "s/\/ftp.debian.org\//\/${APT_SERVER}\//" $R/etc/apt/sources.list +sed -i -e "s/ jessie/ ${RELEASE}/" $R/etc/apt/sources.list # Upgrade package index and update all installed packages and changed dependencies chroot_exec apt-get -qq -y update diff --git a/bootstrap.d/12-locale.sh b/bootstrap.d/12-locale.sh index de1ecc9..cc19ed0 100644 --- a/bootstrap.d/12-locale.sh +++ b/bootstrap.d/12-locale.sh @@ -1,7 +1,8 @@ # -# Setup locales and keyboard settings +# Setup Locales and keyboard settings # +# Load utility functions . ./functions.sh # Set up timezone @@ -20,25 +21,27 @@ if [ "$ENABLE_MINBASE" = false ] ; then chroot_exec echo "locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8, ${DEFLOCAL} UTF-8" | debconf-set-selections chroot_exec sed -i "/en_US.UTF-8/s/^#//" /etc/locale.gen fi + chroot_exec sed -i "/${DEFLOCAL}/s/^#//" /etc/locale.gen chroot_exec echo "locales locales/default_environment_locale select ${DEFLOCAL}" | debconf-set-selections chroot_exec locale-gen chroot_exec update-locale LANG=${DEFLOCAL} # Keyboard configuration, if requested - if [ "$XKBMODEL" != "" ] ; then - chroot_exec sed -i "s/^XKBMODEL.*/XKBMODEL=\"${XKBMODEL}\"/" /etc/default/keyboard + if [ "$XKB_MODEL" != "" ] ; then + chroot_exec sed -i "s/^XKBMODEL.*/XKBMODEL=\"${XKB_MODEL}\"/" /etc/default/keyboard fi - if [ "$XKBLAYOUT" != "" ] ; then - chroot_exec sed -i "s/^XKBLAYOUT.*/XKBLAYOUT=\"${XKBLAYOUT}\"/" /etc/default/keyboard + if [ "$XKB_LAYOUT" != "" ] ; then + chroot_exec sed -i "s/^XKBLAYOUT.*/XKBLAYOUT=\"${XKB_LAYOUT}\"/" /etc/default/keyboard fi - if [ "$XKBVARIANT" != "" ] ; then - chroot_exec sed -i "s/^XKBVARIANT.*/XKBVARIANT=\"${XKBVARIANT}\"/" /etc/default/keyboard + if [ "$XKB_VARIANT" != "" ] ; then + chroot_exec sed -i "s/^XKBVARIANT.*/XKBVARIANT=\"${XKB_VARIANT}\"/" /etc/default/keyboard fi - if [ "$XKBOPTIONS" != "" ] ; then - chroot_exec sed -i "s/^XKBOPTIONS.*/XKBOPTIONS=\"${XKBOPTIONS}\"/" /etc/default/keyboard + if [ "$XKB_OPTIONS" != "" ] ; then + chroot_exec sed -i "s/^XKBOPTIONS.*/XKBOPTIONS=\"${XKB_OPTIONS}\"/" /etc/default/keyboard fi chroot_exec dpkg-reconfigure -f noninteractive keyboard-configuration + # Set up font console case "${DEFLOCAL}" in *UTF-8) @@ -49,4 +52,7 @@ if [ "$ENABLE_MINBASE" = false ] ; then ;; esac chroot_exec dpkg-reconfigure -f noninteractive console-setup +else + # Set POSIX default locales + install_readonly files/locales/locale $R/etc/default/locale fi diff --git a/bootstrap.d/13-kernel.sh b/bootstrap.d/13-kernel.sh index 0ca889c..87a33b7 100644 --- a/bootstrap.d/13-kernel.sh +++ b/bootstrap.d/13-kernel.sh @@ -1,43 +1,56 @@ # -# Kernel installation +# Build and Setup RPi2 Kernel # +# Load utility functions . ./functions.sh # Fetch and build latest raspberry kernel if [ "$BUILD_KERNEL" = true ] ; then # Fetch current raspberrypi kernel sources - git -C $R/usr/local/src clone --depth=1 https://github.com/raspberrypi/linux + git -C $R/usr/src clone --depth=1 https://github.com/raspberrypi/linux # Load default raspberry kernel configuration - make -C $R/usr/local/src/linux ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig + make -C $R/usr/src/linux ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig + + # Calculate optimal number of kernel building threads + if [ "KERNEL_THREADS" = 1 ] ; then + if [ -f /proc/cpuinfo ] ; then + KERNEL_THREADS=$(grep -c processor /proc/cpuinfo) + fi + fi # Cross compile kernel and modules - make -C $R/usr/local/src/linux -j$(grep -c processor /proc/cpuinfo) ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs + make -C $R/usr/src/linux -j${KERNEL_THREADS} ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs # Install kernel modules - make -C $R/usr/local/src/linux ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=../.. modules_install + make -C $R/usr/src/linux ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=../../.. modules_install # Install kernel headers if [ "$KERNEL_HEADERS" = true ]; then - make -C $R/usr/local/src/linux ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_HDR_PATH=../../usr headers_install + make -C $R/usr/src/linux ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_HDR_PATH=../.. headers_install fi # Copy and rename compiled kernel to boot directory mkdir $R/boot/firmware/ - $R/usr/local/src/linux/scripts/mkknlimg $R/usr/local/src/linux/arch/arm/boot/zImage $R/boot/firmware/kernel7.img + $R/usr/src/linux/scripts/mkknlimg $R/usr/src/linux/arch/arm/boot/zImage $R/boot/firmware/kernel7.img # Copy dts and dtb device definitions mkdir $R/boot/firmware/overlays/ - cp $R/usr/local/src/linux/arch/arm/boot/dts/*.dtb $R/boot/firmware/ - cp $R/usr/local/src/linux/arch/arm/boot/dts/overlays/*.dtb* $R/boot/firmware/overlays/ - cp $R/usr/local/src/linux/arch/arm/boot/dts/overlays/README $R/boot/firmware/overlays/ + cp $R/usr/src/linux/arch/arm/boot/dts/*.dtb $R/boot/firmware/ + cp $R/usr/src/linux/arch/arm/boot/dts/overlays/*.dtb* $R/boot/firmware/overlays/ + cp $R/usr/src/linux/arch/arm/boot/dts/overlays/README $R/boot/firmware/overlays/ + + # Remove kernel sources + if [ "$KERNEL_RMSRC" = true ]; then + rm -fr $R/usr/src/linux + fi # Install raspberry bootloader and flash-kernel chroot_exec apt-get -qq -y --no-install-recommends install raspberrypi-bootloader-nokernel else # Kernel installation - chroot_exec apt-get -qq -y --no-install-recommends install linux-image-${KERNEL} raspberrypi-bootloader-nokernel + chroot_exec apt-get -qq -y --no-install-recommends install linux-image-${COLLABORA_KERNEL} raspberrypi-bootloader-nokernel # Install flash-kernel last so it doesn't try (and fail) to detect the platform in the chroot chroot_exec apt-get -qq -y install flash-kernel @@ -63,7 +76,7 @@ fi echo "${CMDLINE}" >$R/boot/firmware/cmdline.txt # Set up firmware config -install -o root -g root -m 644 files/config.txt $R/boot/firmware/config.txt +install_readonly files/boot/config.txt $R/boot/firmware/config.txt # Load snd_bcm2835 kernel module at boot time if [ "$ENABLE_SOUND" = true ] ; then @@ -93,10 +106,10 @@ fi mkdir -p $R/etc/modprobe.d/ # Blacklist sound modules -install -o root -g root -m 644 files/modprobe.d/raspi-blacklist.conf $R/etc/modprobe.d/raspi-blacklist.conf +install_readonly files/modprobe.d/raspi-blacklist.conf $R/etc/modprobe.d/raspi-blacklist.conf # Create default fstab -install -o root -g root -m 644 files/fstab $R/etc/fstab +install_readonly files/mount/fstab $R/etc/fstab # Avoid swapping and increase cache sizes -install -o root -g root -m 644 files/sysctl.d/81-rpi-vm.conf $R/etc/sysctl.d/81-rpi-vm.conf +install_readonly files/sysctl.d/81-rpi-vm.conf $R/etc/sysctl.d/81-rpi-vm.conf diff --git a/bootstrap.d/20-networking.sh b/bootstrap.d/20-networking.sh index 4df6793..051c172 100644 --- a/bootstrap.d/20-networking.sh +++ b/bootstrap.d/20-networking.sh @@ -1,24 +1,25 @@ # -# Setup networking +# Setup Networking # +# Load utility functions . ./functions.sh # Set up IPv4 hosts -echo ${HOSTNAME} >$R/etc/hostname -cat <$R/etc/hosts -127.0.0.1 localhost -127.0.1.1 ${HOSTNAME} -EOM +install_readonly files/network/hostname $R/etc/hostname +sed -i -e "s/^rpi2-jessie/${HOSTNAME}/" $R/etc/hostname + +install_readonly files/network/hosts $R/etc/hosts +sed -i -e "s/rpi2-jessie/${HOSTNAME}/" $R/etc/hosts if [ "$NET_ADDRESS" != "" ] ; then -NET_IP=$(echo ${NET_ADDRESS} | cut -f 1 -d'/') -sed -i "s/^127.0.1.1/${NET_IP}/" $R/etc/hosts + NET_IP=$(echo ${NET_ADDRESS} | cut -f 1 -d'/') + sed -i "s/^127.0.1.1/${NET_IP}/" $R/etc/hosts fi # Set up IPv6 hosts if [ "$ENABLE_IPV6" = true ] ; then -cat <>$R/etc/hosts + cat <>$R/etc/hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes @@ -27,28 +28,18 @@ EOM fi # Place hint about network configuration -cat <$R/etc/network/interfaces -# Debian switched to systemd-networkd configuration files. -# please configure your networks in '/etc/systemd/network/' -source /etc/interfaces.d/*.conf -EOM +install_readonly files/network/interfaces $R/etc/network/interfaces if [ "$ENABLE_DHCP" = true ] ; then # Enable systemd-networkd DHCP configuration for interface eth0 -cat <$R/etc/systemd/network/eth.network -[Match] -Name=eth0 - -[Network] -DHCP=yes -EOM +install_readonly files/network/eth.network $R/etc/systemd/network/eth.network # Set DHCP configuration to IPv4 only -if [ "$ENABLE_IPV6" = false ] ; then - sed -i "s/^DHCP=yes/DHCP=v4/" $R/etc/systemd/network/eth.network -fi + if [ "$ENABLE_IPV6" = false ] ; then + sed -i "s/^DHCP=yes/DHCP=v4/" $R/etc/systemd/network/eth.network + fi else # ENABLE_DHCP=false -cat <$R/etc/systemd/network/eth.network + cat <$R/etc/systemd/network/eth.network [Match] Name=eth0 @@ -69,7 +60,7 @@ chroot_exec systemctl enable systemd-networkd # Enable network stack hardening if [ "$ENABLE_HARDNET" = true ] ; then - install -o root -g root -m 644 files/sysctl.d/81-rpi-net-hardening.conf $R/etc/sysctl.d/81-rpi-net-hardening.conf + install_readonly files/sysctl.d/81-rpi-net-hardening.conf $R/etc/sysctl.d/81-rpi-net-hardening.conf # Enable resolver warnings about spoofed addresses cat <>$R/etc/host.conf diff --git a/bootstrap.d/21-firewall.sh b/bootstrap.d/21-firewall.sh index 5563d06..89cf37f 100644 --- a/bootstrap.d/21-firewall.sh +++ b/bootstrap.d/21-firewall.sh @@ -1,7 +1,8 @@ # -# Enable firewall based on iptables started by systemd service +# Setup Firewall # +# Load utility functions . ./functions.sh if [ "$ENABLE_IPTABLES" = true ] ; then @@ -9,13 +10,13 @@ if [ "$ENABLE_IPTABLES" = true ] ; then mkdir -p "$R/etc/iptables" # Create iptables systemd service - install -o root -g root -m 644 files/iptables/iptables.service $R/etc/systemd/system/iptables.service + install_readonly files/iptables/iptables.service $R/etc/systemd/system/iptables.service # Create flush-table script called by iptables service - install -o root -g root -m 755 files/iptables/flush-iptables.sh $R/etc/iptables/flush-iptables.sh + install_exec files/iptables/flush-iptables.sh $R/etc/iptables/flush-iptables.sh # Create iptables rule file - install -o root -g root -m 644 files/iptables/iptables.rules $R/etc/iptables/iptables.rules + install_readonly files/iptables/iptables.rules $R/etc/iptables/iptables.rules # Reload systemd configuration and enable iptables service chroot_exec systemctl daemon-reload @@ -23,12 +24,12 @@ if [ "$ENABLE_IPTABLES" = true ] ; then if [ "$ENABLE_IPV6" = true ] ; then # Create ip6tables systemd service - install -o root -g root -m 644 files/iptables/ip6tables.service $R/etc/systemd/system/ip6tables.service + install_readonly files/iptables/ip6tables.service $R/etc/systemd/system/ip6tables.service # Create ip6tables file - install -o root -g root -m 755 files/iptables/flush-ip6tables.sh $R/etc/iptables/flush-ip6tables.sh + install_exec files/iptables/flush-ip6tables.sh $R/etc/iptables/flush-ip6tables.sh - install -o root -g root -m 644 files/iptables/ip6tables.rules $R/etc/iptables/ip6tables.rules + install_readonly files/iptables/ip6tables.rules $R/etc/iptables/ip6tables.rules # Reload systemd configuration and enable iptables service chroot_exec systemctl daemon-reload diff --git a/bootstrap.d/30-security.sh b/bootstrap.d/30-security.sh index 31aa782..86f1c00 100644 --- a/bootstrap.d/30-security.sh +++ b/bootstrap.d/30-security.sh @@ -2,6 +2,7 @@ # Setup users and security settings # +# Load utility functions . ./functions.sh # Generate crypt(3) password string diff --git a/bootstrap.d/31-logging.sh b/bootstrap.d/31-logging.sh index a09e623..14c4f44 100644 --- a/bootstrap.d/31-logging.sh +++ b/bootstrap.d/31-logging.sh @@ -1,7 +1,8 @@ # -# Setup logging +# Setup Logging # +# Load utility functions . ./functions.sh # Disable rsyslog diff --git a/bootstrap.d/41-uboot.sh b/bootstrap.d/41-uboot.sh index 507be55..d3e4573 100644 --- a/bootstrap.d/41-uboot.sh +++ b/bootstrap.d/41-uboot.sh @@ -1,7 +1,8 @@ # -# Setup Uboot +# Build and Setup Uboot # +# Load utility functions . ./functions.sh # Install gcc/c++ build environment inside the chroot @@ -22,23 +23,9 @@ if [ "$ENABLE_UBOOT" = true ] ; then printf "\n# boot u-boot kernel\nkernel=u-boot.bin\n" >> $R/boot/firmware/config.txt # Set U-Boot command file - cat <$R/boot/firmware/uboot.mkimage -# Tell Linux that it is booting on a Raspberry Pi2 -setenv machid 0x00000c42 - -# Set the kernel boot command line -setenv bootargs "earlyprintk ${CMDLINE}" - -# Save these changes to u-boot's environment -saveenv - -# Load the existing Linux kernel into RAM -fatload mmc 0:1 \${kernel_addr_r} kernel7.img - -# Boot the kernel we have just loaded -bootz \${kernel_addr_r} -EOM + install_readonly files/boot/uboot.mkimage $R/boot/firmware/uboot.mkimage + printf "# Set the kernel boot command line\nsetenv bootargs \"earlyprintk ${CMDLINE}\"\n\n$(cat $R/boot/firmware/uboot.mkimage)" > $R/boot/firmware/uboot.mkimage # Generate U-Boot image from command file - chroot_exec mkimage -A arm -O linux -T script -C none -a 0x00000000 -e 0x00000000 -n "RPi2 Boot Script" -d /boot/firmware/uboot.mkimage /boot/firmware/boot.scr + chroot_exec /tmp/u-boot/tools/mkimage -A arm -O linux -T script -C none -a 0x00000000 -e 0x00000000 -n RPi2 -d /boot/firmware/uboot.mkimage /boot/firmware/boot.scr fi diff --git a/bootstrap.d/42-fbturbo.sh b/bootstrap.d/42-fbturbo.sh index 4d99016..b5c9147 100644 --- a/bootstrap.d/42-fbturbo.sh +++ b/bootstrap.d/42-fbturbo.sh @@ -1,7 +1,8 @@ # -# Fetch and build fbturbo Xorg driver +# Build and Setup fbturbo Xorg driver # +# Load utility functions . ./functions.sh if [ "$ENABLE_FBTURBO" = true ] ; then @@ -12,17 +13,16 @@ if [ "$ENABLE_FBTURBO" = true ] ; then chroot_exec apt-get install -q -y --no-install-recommends xorg-dev xutils-dev x11proto-dri2-dev libltdl-dev libtool automake libdrm-dev # Build and install fbturbo driver inside chroot - chroot_exec /bin/bash -c "cd /tmp/xf86-video-fbturbo; autoreconf -vi; ./configure --prefix=/usr; make; make install" + chroot_exec /bin/bash -x <<'EOF' +cd /tmp/xf86-video-fbturbo +autoreconf -vi +./configure --prefix=/usr +make +make install +EOF # Add fbturbo driver to Xorg configuration - cat <$R/usr/share/X11/xorg.conf.d/99-fbturbo.conf -Section "Device" - Identifier "Allwinner A10/A13 FBDEV" - Driver "fbturbo" - Option "fbdev" "/dev/fb0" - Option "SwapbuffersWait" "true" -EndSection -EOM + install_readonly files/xorg/99-fbturbo.conf $R/usr/share/X11/xorg.conf.d/99-fbturbo.conf # Remove Xorg build dependencies chroot_exec apt-get -q -y purge --auto-remove xorg-dev xutils-dev x11proto-dri2-dev libltdl-dev libtool automake libdrm-dev diff --git a/bootstrap.d/50-firstboot.sh b/bootstrap.d/50-firstboot.sh index b9f1d76..78197fd 100644 --- a/bootstrap.d/50-firstboot.sh +++ b/bootstrap.d/50-firstboot.sh @@ -2,8 +2,10 @@ # First boot actions # +# Load utility functions . ./functions.sh +# Prepare rc.firstboot script cat files/firstboot/10-begin.sh > $R/etc/rc.firstboot # Ensure openssh server host keys are regenerated on first boot @@ -12,13 +14,16 @@ if [ "$ENABLE_SSHD" = true ] ; then rm -f $R/etc/ssh/ssh_host_* fi +# Prepare filesystem auto expand if [ "$EXPANDROOT" = true ] ; then cat files/firstboot/22-expandroot.sh >> $R/etc/rc.firstboot fi +# Finalize rc.firstboot script cat files/firstboot/99-finish.sh >> $R/etc/rc.firstboot chmod +x $R/etc/rc.firstboot +# Add rc.firstboot script to rc.local sed -i '/exit 0/d' $R/etc/rc.local echo /etc/rc.firstboot >> $R/etc/rc.local echo exit 0 >> $R/etc/rc.local diff --git a/files/apt/10proxy b/files/apt/10proxy new file mode 100644 index 0000000..2a02a0c --- /dev/null +++ b/files/apt/10proxy @@ -0,0 +1 @@ +Acquire::http:Proxy ""; diff --git a/files/apt/flash-kernel b/files/apt/flash-kernel new file mode 100644 index 0000000..579e562 --- /dev/null +++ b/files/apt/flash-kernel @@ -0,0 +1,3 @@ +Package: flash-kernel +Pin: origin repositories.collabora.co.uk +Pin-Priority: 1000 diff --git a/files/apt/sources.list b/files/apt/sources.list new file mode 100644 index 0000000..36472fc --- /dev/null +++ b/files/apt/sources.list @@ -0,0 +1,10 @@ +deb http://ftp.debian.org/debian jessie main contrib +#deb-src http://ftp.debian.org/debian jessie main contrib + +deb http://ftp.debian.org/debian/ jessie-updates main contrib +#deb-src http://ftp.debian.org/debian/ jessie-updates main contrib + +deb http://security.debian.org/ jessie/updates main contrib +#deb-src http://security.debian.org/ jessie/updates main contrib + +deb https://repositories.collabora.co.uk/debian jessie rpi2 diff --git a/files/config.txt b/files/boot/config.txt similarity index 100% rename from files/config.txt rename to files/boot/config.txt diff --git a/files/boot/uboot.mkimage b/files/boot/uboot.mkimage new file mode 100644 index 0000000..cd71de6 --- /dev/null +++ b/files/boot/uboot.mkimage @@ -0,0 +1,11 @@ +# Tell Linux that it is booting on a Raspberry Pi2 +setenv machid 0x00000c42 + +# Save these changes to u-boot's environment +saveenv + +# Load the existing Linux kernel into RAM +fatload mmc 0:1 ${kernel_addr_r} kernel7.img + +# Boot the kernel we have just loaded +bootz ${kernel_addr_r} diff --git a/files/locales/locale b/files/locales/locale new file mode 100644 index 0000000..91f267a --- /dev/null +++ b/files/locales/locale @@ -0,0 +1,3 @@ +# File generated by rpi2-gen-image +LANG=C +LC_ALL=C diff --git a/files/fstab b/files/mount/fstab similarity index 100% rename from files/fstab rename to files/mount/fstab diff --git a/files/network/eth.network b/files/network/eth.network new file mode 100644 index 0000000..e871c69 --- /dev/null +++ b/files/network/eth.network @@ -0,0 +1,5 @@ +[Match] +Name=eth0 + +[Network] +DHCP=yes diff --git a/files/network/hostname b/files/network/hostname new file mode 100644 index 0000000..03a61be --- /dev/null +++ b/files/network/hostname @@ -0,0 +1 @@ +rpi2-jessie diff --git a/files/network/hosts b/files/network/hosts new file mode 100644 index 0000000..be7c5cb --- /dev/null +++ b/files/network/hosts @@ -0,0 +1,2 @@ +127.0.0.1 localhost +127.0.1.1 rpi2-jessie diff --git a/files/network/interfaces b/files/network/interfaces new file mode 100644 index 0000000..241b666 --- /dev/null +++ b/files/network/interfaces @@ -0,0 +1,2 @@ +# Debian switched to systemd-networkd configuration files. +# please configure your networks in '/etc/systemd/network/' diff --git a/files/xorg/99-fbturbo.conf b/files/xorg/99-fbturbo.conf new file mode 100644 index 0000000..a7124c9 --- /dev/null +++ b/files/xorg/99-fbturbo.conf @@ -0,0 +1,6 @@ +Section "Device" + Identifier "Allwinner A10/A13 FBDEV" + Driver "fbturbo" + Option "fbdev" "/dev/fb0" + Option "SwapbuffersWait" "true" +EndSection diff --git a/functions.sh b/functions.sh index e94a42c..f64fb97 100644 --- a/functions.sh +++ b/functions.sh @@ -1,11 +1,16 @@ +# This file contains utility functions used by rpi2-gen-image.sh + cleanup (){ - # Clean up all temporary mount points set +x set +e + + # Identify and kill all processes still using files echo "killing processes using mount point ..." fuser -k $R sleep 3 fuser -9 -k -v $R + + # Clean up all temporary mount points echo "removing temporary mount points ..." umount -l $R/proc 2> /dev/null umount -l $R/sys 2> /dev/null @@ -21,3 +26,13 @@ chroot_exec() { # Exec command in chroot LANG=C LC_ALL=C DEBIAN_FRONTEND=noninteractive chroot $R $* } + +install_readonly() { + # Install file with user read-only permissions + install -o root -g root -m 644 $* +} + +install_exec() { + # Install file with root exec permissions + install -o root -g root -m 744 $* +} diff --git a/rpi2-gen-image.sh b/rpi2-gen-image.sh index 59ff79d..2cb1277 100755 --- a/rpi2-gen-image.sh +++ b/rpi2-gen-image.sh @@ -15,14 +15,16 @@ # Copyright (C) 2015 Luca Falavigna ######################################################################## -source ./functions.sh +# Load utility functions +. ./functions.sh set -e +echo -n -e "\n#\n# RPi2 Bootstrap Settings\n#\n" set -x # Debian release RELEASE=${RELEASE:=jessie} -KERNEL=${KERNEL:=3.18.0-trunk-rpi2} +COLLABORA_KERNEL=${COLLABORA_KERNEL:=3.18.0-trunk-rpi2} # Build settings BASEDIR=$(pwd)/images/${RELEASE} @@ -33,16 +35,19 @@ HOSTNAME=${HOSTNAME:=rpi2-${RELEASE}} PASSWORD=${PASSWORD:=raspberry} DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"} TIMEZONE=${TIMEZONE:="Europe/Berlin"} -XKBMODEL=${XKBMODEL:=""} -XKBLAYOUT=${XKBLAYOUT:=""} -XKBVARIANT=${XKBVARIANT:=""} -XKBOPTIONS=${XKBOPTIONS:=""} EXPANDROOT=${EXPANDROOT:=true} -# Network settings +# Keyboard settings +XKB_MODEL=${XKB_MODEL:=""} +XKB_LAYOUT=${XKB_LAYOUT:=""} +XKB_VARIANT=${XKB_VARIANT:=""} +XKB_OPTIONS=${XKB_OPTIONS:=""} + +# Network settings (DHCP) ENABLE_DHCP=${ENABLE_DHCP:=true} -# NET_* settings are ignored when ENABLE_DHCP=true -# NET_ADDRESS is an IPv4 or IPv6 address and its prefix, separated by "/" + +# Network settings (static) +# only used on ENABLE_DHCP=false NET_ADDRESS=${NET_ADDRESS:=""} NET_GATEWAY=${NET_GATEWAY:=""} NET_DNS_1=${NET_DNS_1:=""} @@ -79,7 +84,9 @@ ENABLE_IPTABLES=${ENABLE_IPTABLES:=false} # Kernel compilation settings BUILD_KERNEL=${BUILD_KERNEL:=false} +KERNEL_THREADS=${KERNEL_THREADS:=1} KERNEL_HEADERS=${KERNEL_HEADERS:=true} +KERNEL_RMSRC=${KERNEL_RMSRC:=true} # Image chroot path R=${BUILDDIR}/chroot @@ -206,6 +213,7 @@ fi ## Main bootstrap for i in bootstrap.d/*.sh; do + head -n 3 $i . $i done @@ -298,7 +306,7 @@ rsync -a "$R/" "$BUILDDIR/mount/" # Unmount all temporary loop devices and mount points cleanup -# (optinal) create block map file for "bmaptool" +# Create block map file for "bmaptool" bmaptool create -o "$BASEDIR/${DATE}-debian-${RELEASE}.bmap" "$BASEDIR/${DATE}-debian-${RELEASE}.img" # Image was successfully created