diff --git a/README.md b/README.md index 8257fc8..fd0b552 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,9 @@ Set default system timezone. All available timezones can be found in the `/usr/s ##### `EXPANDROOT`=true Expand the root partition and filesystem automatically on first boot. +##### `ENABLE_SWAP`=true +Enable swap. The size of the swapfile is chosen relative to the size of the root partition. It'll use the `dphys-swapfile` package for that. + ##### `ENABLE_QEMU`=false Generate kernel (`vexpress_defconfig`), file system image (`qcow2`) and DTB files that can be used for QEMU full system emulation (`vexpress-A15`). The output files are stored in the `$(pwd)/images/qemu` directory. You can find more information about running the generated image in the QEMU section of this readme file. diff --git a/bootstrap.d/50-firstboot.sh b/bootstrap.d/50-firstboot.sh index cc76f34..b8c31a3 100644 --- a/bootstrap.d/50-firstboot.sh +++ b/bootstrap.d/50-firstboot.sh @@ -10,28 +10,33 @@ cat files/firstboot/10-begin.sh > "${ETC_DIR}/rc.firstboot" # Ensure openssh server host keys are regenerated on first boot if [ "$ENABLE_SSHD" = true ] ; then - cat files/firstboot/21-generate-ssh-keys.sh >> "${ETC_DIR}/rc.firstboot" + cat files/firstboot/20-generate-ssh-keys.sh >> "${ETC_DIR}/rc.firstboot" fi # Prepare filesystem auto expand if [ "$EXPANDROOT" = true ] ; then if [ "$ENABLE_CRYPTFS" = false ] ; then - cat files/firstboot/22-expandroot.sh >> "${ETC_DIR}/rc.firstboot" + cat files/firstboot/30-expandroot.sh >> "${ETC_DIR}/rc.firstboot" + + # Restart dphys-swapfile so the size of the swap file is relative to the resized root partition + if [ "$ENABLE_SWAP" = true ] ; then + cat files/firstboot/31-restart-dphys-swapfile.sh >> "${ETC_DIR}/rc.firstboot" + fi else # Regenerate initramfs to remove encrypted root partition auto expand - cat files/firstboot/23-regenerate-initramfs.sh >> "${ETC_DIR}/rc.firstboot" + cat files/firstboot/33-regenerate-initramfs.sh >> "${ETC_DIR}/rc.firstboot" fi fi # Ensure that dbus machine-id exists -cat files/firstboot/24-generate-machineid.sh >> "${ETC_DIR}/rc.firstboot" +cat files/firstboot/40-generate-machineid.sh >> "${ETC_DIR}/rc.firstboot" # Create /etc/resolv.conf symlink -cat files/firstboot/25-create-resolv-symlink.sh >> "${ETC_DIR}/rc.firstboot" +cat files/firstboot/41-create-resolv-symlink.sh >> "${ETC_DIR}/rc.firstboot" # Configure automatic network interface names if [ "$ENABLE_IFNAMES" = true ] ; then - cat files/firstboot/26-config-ifnames.sh >> "${ETC_DIR}/rc.firstboot" + cat files/firstboot/42-config-ifnames.sh >> "${ETC_DIR}/rc.firstboot" fi # Finalize rc.firstboot script diff --git a/files/firstboot/21-generate-ssh-keys.sh b/files/firstboot/20-generate-ssh-keys.sh similarity index 100% rename from files/firstboot/21-generate-ssh-keys.sh rename to files/firstboot/20-generate-ssh-keys.sh diff --git a/files/firstboot/22-expandroot.sh b/files/firstboot/30-expandroot.sh similarity index 100% rename from files/firstboot/22-expandroot.sh rename to files/firstboot/30-expandroot.sh diff --git a/files/firstboot/31-restart-dphys-swapfile.sh b/files/firstboot/31-restart-dphys-swapfile.sh new file mode 100644 index 0000000..ad0c3a0 --- /dev/null +++ b/files/firstboot/31-restart-dphys-swapfile.sh @@ -0,0 +1,5 @@ +logger -t "rc.firstboot" "Restarting dphys-swapfile" + +if systemctl is-enabled dphys-swapfile ; then + systemctl restart dphys-swapfile +fi diff --git a/files/firstboot/23-regenerate-initramfs.sh b/files/firstboot/33-regenerate-initramfs.sh similarity index 100% rename from files/firstboot/23-regenerate-initramfs.sh rename to files/firstboot/33-regenerate-initramfs.sh diff --git a/files/firstboot/24-generate-machineid.sh b/files/firstboot/40-generate-machineid.sh similarity index 100% rename from files/firstboot/24-generate-machineid.sh rename to files/firstboot/40-generate-machineid.sh diff --git a/files/firstboot/25-create-resolv-symlink.sh b/files/firstboot/41-create-resolv-symlink.sh similarity index 100% rename from files/firstboot/25-create-resolv-symlink.sh rename to files/firstboot/41-create-resolv-symlink.sh diff --git a/files/firstboot/26-config-ifnames.sh b/files/firstboot/42-config-ifnames.sh similarity index 100% rename from files/firstboot/26-config-ifnames.sh rename to files/firstboot/42-config-ifnames.sh diff --git a/rpi23-gen-image.sh b/rpi23-gen-image.sh index 575252a..2f90f95 100755 --- a/rpi23-gen-image.sh +++ b/rpi23-gen-image.sh @@ -83,6 +83,7 @@ USER_PASSWORD=${USER_PASSWORD:=raspberry} DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"} TIMEZONE=${TIMEZONE:="Europe/Berlin"} EXPANDROOT=${EXPANDROOT:=true} +ENABLE_SWAP=${ENABLE_SWAP:=true} # Keyboard settings XKB_MODEL=${XKB_MODEL:=""} @@ -484,6 +485,11 @@ if [ "$EXPANDROOT" = true ] ; then APT_INCLUDES="${APT_INCLUDES},parted" fi +# Add dphys-swapfile package, required to enable swap +if [ "$ENABLE_SWAP" = true ] ; then + APT_INCLUDES="${APT_INCLUDES},dphys-swapfile" +fi + # Add dbus package, recommended if using systemd if [ "$ENABLE_DBUS" = true ] ; then APT_INCLUDES="${APT_INCLUDES},dbus"