From e8ebe4a99dc71aed6c3de5353c7d0ecc78ec7836 2018-12-29 10:38:21 From: drtyhlpr Date: 2018-12-29 10:38:21 Subject: [PATCH] Merge pull request #182 from BrainStone/swap Added ENABLE_DPHYSSWAP (the second) --- diff --git a/README.md b/README.md index 01021c5..621191a 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,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_DPHYSSWAP`=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/15-rpi-config.sh b/bootstrap.d/15-rpi-config.sh index e576f28..0aacfed 100644 --- a/bootstrap.d/15-rpi-config.sh +++ b/bootstrap.d/15-rpi-config.sh @@ -193,6 +193,11 @@ else echo "enable_uart=0" >> "${BOOT_DIR}/config.txt" fi +# Disable dphys-swapfile service. Will get enabled on first boot +if [ "$ENABLE_DPHYSSWAP" = true ] ; then + chroot_exec systemctl disable dphys-swapfile +fi + if [ "$ENABLE_SYSTEMDSWAP" = true ] ; then # Create temporary directory for systemd-swap sources temp_dir=$(as_nobody mktemp -d) diff --git a/bootstrap.d/50-firstboot.sh b/bootstrap.d/50-firstboot.sh index cc76f34..1b17876 100644 --- a/bootstrap.d/50-firstboot.sh +++ b/bootstrap.d/50-firstboot.sh @@ -8,30 +8,35 @@ # Prepare rc.firstboot script 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" -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/20-expandroot.sh >> "${ETC_DIR}/rc.firstboot" else # Regenerate initramfs to remove encrypted root partition auto expand - cat files/firstboot/23-regenerate-initramfs.sh >> "${ETC_DIR}/rc.firstboot" + cat files/firstboot/21-regenerate-initramfs.sh >> "${ETC_DIR}/rc.firstboot" + fi + + # Restart dphys-swapfile so the size of the swap file is relative to the resized root partition + if [ "$ENABLE_DPHYSSWAP" = true ] ; then + cat files/firstboot/23-restart-dphys-swapfile.sh >> "${ETC_DIR}/rc.firstboot" fi fi +# Ensure openssh server host keys are regenerated on first boot +if [ "$ENABLE_SSHD" = true ] ; then + cat files/firstboot/30-generate-ssh-keys.sh >> "${ETC_DIR}/rc.firstboot" +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/22-expandroot.sh b/files/firstboot/20-expandroot.sh similarity index 95% rename from files/firstboot/22-expandroot.sh rename to files/firstboot/20-expandroot.sh index c2590a2..235c411 100644 --- a/files/firstboot/22-expandroot.sh +++ b/files/firstboot/20-expandroot.sh @@ -66,11 +66,3 @@ EOF2 partprobe && resize2fs /dev/${ROOT_PART} && logger -t "rc.firstboot" "Root partition successfully resized." - -# Restart dphys-swapfile service if it exists -if systemctl list-units | grep -q dphys-swapfile ; then - if systemctl is-enabled dphys-swapfile ; then - logger -t "rc.firstboot" "Restarting dphys-swapfile" - systemctl restart dphys-swapfile - fi -fi diff --git a/files/firstboot/23-regenerate-initramfs.sh b/files/firstboot/21-regenerate-initramfs.sh similarity index 100% rename from files/firstboot/23-regenerate-initramfs.sh rename to files/firstboot/21-regenerate-initramfs.sh diff --git a/files/firstboot/23-restart-dphys-swapfile.sh b/files/firstboot/23-restart-dphys-swapfile.sh new file mode 100644 index 0000000..32c8638 --- /dev/null +++ b/files/firstboot/23-restart-dphys-swapfile.sh @@ -0,0 +1,5 @@ +# Restart dphys-swapfile service if it exists +logger -t "rc.firstboot" "Restarting dphys-swapfile" + +systemctl enable dphys-swapfile +systemctl restart dphys-swapfile diff --git a/files/firstboot/21-generate-ssh-keys.sh b/files/firstboot/30-generate-ssh-keys.sh similarity index 100% rename from files/firstboot/21-generate-ssh-keys.sh rename to files/firstboot/30-generate-ssh-keys.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 503c364..a530b04 100755 --- a/rpi23-gen-image.sh +++ b/rpi23-gen-image.sh @@ -97,6 +97,7 @@ USER_PASSWORD=${USER_PASSWORD:=raspberry} DEFLOCAL=${DEFLOCAL:="en_US.UTF-8"} TIMEZONE=${TIMEZONE:="Europe/Berlin"} EXPANDROOT=${EXPANDROOT:=true} +ENABLE_DPHYSSWAP=${ENABLE_DPHYSSWAP:=true} # Keyboard settings XKB_MODEL=${XKB_MODEL:=""} @@ -542,6 +543,11 @@ if [ "$EXPANDROOT" = true ] ; then APT_INCLUDES="${APT_INCLUDES},parted" fi +# Add dphys-swapfile package, required to enable swap +if [ "$ENABLE_DPHYSSWAP" = 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"