From 103ddb150beaf88df5dc8e48a73e2ba9d0715dc9 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Mon, 28 Dec 2020 23:46:55 +0100 Subject: [PATCH] Use systemd-growfs (#1133) * Use systemd-growfs instead of resize2fs (#1106) Since systemd 236 systemd has a built-in file system growing mechanism. The mechanism relies on the kernels online file system resize capabilities instead of the external resize2fs utility. Online resizing is supposedly much faster since the kernel takes care of things. This also makes sure that external file systems get resized which previously have not been taken care of. * Drop HA OS specific file system resizing Since we have systemd-growfs in place now we can drop our file system resizing code. * Make sure /dev/disk/by-label/hassos-data is present after resizing Note: systemd will retry mnt-data.mount later, so at least in theory this shouldn't really matter. However, the journal has a lot of churn due to that reordering. --- buildroot-external/configs/intel_nuc_defconfig | 1 - buildroot-external/configs/odroid_c2_defconfig | 1 - buildroot-external/configs/odroid_c4_defconfig | 1 - buildroot-external/configs/odroid_n2_defconfig | 1 - .../configs/odroid_xu4_defconfig | 1 - buildroot-external/configs/ova_defconfig | 1 - buildroot-external/configs/rpi0_w_defconfig | 1 - buildroot-external/configs/rpi2_defconfig | 1 - buildroot-external/configs/rpi3_64_defconfig | 1 - buildroot-external/configs/rpi3_defconfig | 1 - buildroot-external/configs/rpi4_64_defconfig | 1 - buildroot-external/configs/rpi4_defconfig | 1 - buildroot-external/configs/rpi_defconfig | 1 - buildroot-external/configs/tinker_defconfig | 1 - .../usr/lib/systemd/system/mnt-data.mount | 2 +- .../lib/systemd/system/systemd-growfs@.service | 18 ++++++++++++++++++ .../rootfs-overlay/usr/libexec/hassos-expand | 16 +++++++++++----- 17 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 buildroot-external/rootfs-overlay/usr/lib/systemd/system/systemd-growfs@.service diff --git a/buildroot-external/configs/intel_nuc_defconfig b/buildroot-external/configs/intel_nuc_defconfig index e0a429417..e0e2925ad 100644 --- a/buildroot-external/configs/intel_nuc_defconfig +++ b/buildroot-external/configs/intel_nuc_defconfig @@ -35,7 +35,6 @@ BR2_PACKAGE_PROCPS_NG=y BR2_PACKAGE_JQ=y BR2_PACKAGE_E2FSPROGS=y BR2_PACKAGE_E2FSPROGS_E2IMAGE=y -BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y BR2_PACKAGE_SQUASHFS=y BR2_PACKAGE_LINUX_FIRMWARE=y BR2_PACKAGE_LINUX_FIRMWARE_IBT=y diff --git a/buildroot-external/configs/odroid_c2_defconfig b/buildroot-external/configs/odroid_c2_defconfig index 00a05c598..0c11a7881 100644 --- a/buildroot-external/configs/odroid_c2_defconfig +++ b/buildroot-external/configs/odroid_c2_defconfig @@ -37,7 +37,6 @@ BR2_PACKAGE_PROCPS_NG=y BR2_PACKAGE_JQ=y BR2_PACKAGE_E2FSPROGS=y BR2_PACKAGE_E2FSPROGS_E2IMAGE=y -BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y BR2_PACKAGE_SQUASHFS=y BR2_PACKAGE_LINUX_FIRMWARE=y BR2_PACKAGE_LINUX_FIRMWARE_RTL_81XX=y diff --git a/buildroot-external/configs/odroid_c4_defconfig b/buildroot-external/configs/odroid_c4_defconfig index 727067e50..9beae85b7 100644 --- a/buildroot-external/configs/odroid_c4_defconfig +++ b/buildroot-external/configs/odroid_c4_defconfig @@ -37,7 +37,6 @@ BR2_PACKAGE_PROCPS_NG=y BR2_PACKAGE_JQ=y BR2_PACKAGE_E2FSPROGS=y BR2_PACKAGE_E2FSPROGS_E2IMAGE=y -BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y BR2_PACKAGE_SQUASHFS=y BR2_PACKAGE_LINUX_FIRMWARE=y BR2_PACKAGE_LINUX_FIRMWARE_RTL_81XX=y diff --git a/buildroot-external/configs/odroid_n2_defconfig b/buildroot-external/configs/odroid_n2_defconfig index 09ef6af55..6508ea367 100644 --- a/buildroot-external/configs/odroid_n2_defconfig +++ b/buildroot-external/configs/odroid_n2_defconfig @@ -37,7 +37,6 @@ BR2_PACKAGE_PROCPS_NG=y BR2_PACKAGE_JQ=y BR2_PACKAGE_E2FSPROGS=y BR2_PACKAGE_E2FSPROGS_E2IMAGE=y -BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y BR2_PACKAGE_SQUASHFS=y BR2_PACKAGE_LINUX_FIRMWARE=y BR2_PACKAGE_LINUX_FIRMWARE_RTL_81XX=y diff --git a/buildroot-external/configs/odroid_xu4_defconfig b/buildroot-external/configs/odroid_xu4_defconfig index e32efb8df..24a8a2a3c 100644 --- a/buildroot-external/configs/odroid_xu4_defconfig +++ b/buildroot-external/configs/odroid_xu4_defconfig @@ -37,7 +37,6 @@ BR2_PACKAGE_PROCPS_NG=y BR2_PACKAGE_JQ=y BR2_PACKAGE_E2FSPROGS=y BR2_PACKAGE_E2FSPROGS_E2IMAGE=y -BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y BR2_PACKAGE_SQUASHFS=y BR2_PACKAGE_LINUX_FIRMWARE=y BR2_PACKAGE_LINUX_FIRMWARE_MFC_V8=y diff --git a/buildroot-external/configs/ova_defconfig b/buildroot-external/configs/ova_defconfig index 41e7d14c1..faa399973 100644 --- a/buildroot-external/configs/ova_defconfig +++ b/buildroot-external/configs/ova_defconfig @@ -36,7 +36,6 @@ BR2_PACKAGE_PROCPS_NG=y BR2_PACKAGE_JQ=y BR2_PACKAGE_E2FSPROGS=y BR2_PACKAGE_E2FSPROGS_E2IMAGE=y -BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y BR2_PACKAGE_SQUASHFS=y BR2_PACKAGE_LINUX_FIRMWARE=y BR2_PACKAGE_LINUX_FIRMWARE_USB_SERIAL_TI=y diff --git a/buildroot-external/configs/rpi0_w_defconfig b/buildroot-external/configs/rpi0_w_defconfig index ef6adaa6f..8d1e93a11 100644 --- a/buildroot-external/configs/rpi0_w_defconfig +++ b/buildroot-external/configs/rpi0_w_defconfig @@ -38,7 +38,6 @@ BR2_PACKAGE_PROCPS_NG=y BR2_PACKAGE_JQ=y BR2_PACKAGE_E2FSPROGS=y BR2_PACKAGE_E2FSPROGS_E2IMAGE=y -BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y BR2_PACKAGE_SQUASHFS=y BR2_PACKAGE_LINUX_FIRMWARE=y BR2_PACKAGE_LINUX_FIRMWARE_USB_SERIAL_TI=y diff --git a/buildroot-external/configs/rpi2_defconfig b/buildroot-external/configs/rpi2_defconfig index 6b0653ef1..ab9d18228 100644 --- a/buildroot-external/configs/rpi2_defconfig +++ b/buildroot-external/configs/rpi2_defconfig @@ -38,7 +38,6 @@ BR2_PACKAGE_PROCPS_NG=y BR2_PACKAGE_JQ=y BR2_PACKAGE_E2FSPROGS=y BR2_PACKAGE_E2FSPROGS_E2IMAGE=y -BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y BR2_PACKAGE_SQUASHFS=y BR2_PACKAGE_LINUX_FIRMWARE=y BR2_PACKAGE_LINUX_FIRMWARE_USB_SERIAL_TI=y diff --git a/buildroot-external/configs/rpi3_64_defconfig b/buildroot-external/configs/rpi3_64_defconfig index ac96b8bed..084f65eba 100644 --- a/buildroot-external/configs/rpi3_64_defconfig +++ b/buildroot-external/configs/rpi3_64_defconfig @@ -38,7 +38,6 @@ BR2_PACKAGE_PROCPS_NG=y BR2_PACKAGE_JQ=y BR2_PACKAGE_E2FSPROGS=y BR2_PACKAGE_E2FSPROGS_E2IMAGE=y -BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y BR2_PACKAGE_SQUASHFS=y BR2_PACKAGE_LINUX_FIRMWARE=y BR2_PACKAGE_LINUX_FIRMWARE_USB_SERIAL_TI=y diff --git a/buildroot-external/configs/rpi3_defconfig b/buildroot-external/configs/rpi3_defconfig index 0e2a7185d..d8f020818 100644 --- a/buildroot-external/configs/rpi3_defconfig +++ b/buildroot-external/configs/rpi3_defconfig @@ -38,7 +38,6 @@ BR2_PACKAGE_PROCPS_NG=y BR2_PACKAGE_JQ=y BR2_PACKAGE_E2FSPROGS=y BR2_PACKAGE_E2FSPROGS_E2IMAGE=y -BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y BR2_PACKAGE_SQUASHFS=y BR2_PACKAGE_LINUX_FIRMWARE=y BR2_PACKAGE_LINUX_FIRMWARE_USB_SERIAL_TI=y diff --git a/buildroot-external/configs/rpi4_64_defconfig b/buildroot-external/configs/rpi4_64_defconfig index ca62b9366..5bba50344 100644 --- a/buildroot-external/configs/rpi4_64_defconfig +++ b/buildroot-external/configs/rpi4_64_defconfig @@ -38,7 +38,6 @@ BR2_PACKAGE_PROCPS_NG=y BR2_PACKAGE_JQ=y BR2_PACKAGE_E2FSPROGS=y BR2_PACKAGE_E2FSPROGS_E2IMAGE=y -BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y BR2_PACKAGE_SQUASHFS=y BR2_PACKAGE_LINUX_FIRMWARE=y BR2_PACKAGE_LINUX_FIRMWARE_USB_SERIAL_TI=y diff --git a/buildroot-external/configs/rpi4_defconfig b/buildroot-external/configs/rpi4_defconfig index 899ab50f2..93a3c5440 100644 --- a/buildroot-external/configs/rpi4_defconfig +++ b/buildroot-external/configs/rpi4_defconfig @@ -38,7 +38,6 @@ BR2_PACKAGE_PROCPS_NG=y BR2_PACKAGE_JQ=y BR2_PACKAGE_E2FSPROGS=y BR2_PACKAGE_E2FSPROGS_E2IMAGE=y -BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y BR2_PACKAGE_SQUASHFS=y BR2_PACKAGE_LINUX_FIRMWARE=y BR2_PACKAGE_LINUX_FIRMWARE_USB_SERIAL_TI=y diff --git a/buildroot-external/configs/rpi_defconfig b/buildroot-external/configs/rpi_defconfig index 3f8f0426f..f1d3946bb 100644 --- a/buildroot-external/configs/rpi_defconfig +++ b/buildroot-external/configs/rpi_defconfig @@ -38,7 +38,6 @@ BR2_PACKAGE_PROCPS_NG=y BR2_PACKAGE_JQ=y BR2_PACKAGE_E2FSPROGS=y BR2_PACKAGE_E2FSPROGS_E2IMAGE=y -BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y BR2_PACKAGE_SQUASHFS=y BR2_PACKAGE_LINUX_FIRMWARE=y BR2_PACKAGE_LINUX_FIRMWARE_USB_SERIAL_TI=y diff --git a/buildroot-external/configs/tinker_defconfig b/buildroot-external/configs/tinker_defconfig index 1536df585..f2127ae2f 100644 --- a/buildroot-external/configs/tinker_defconfig +++ b/buildroot-external/configs/tinker_defconfig @@ -39,7 +39,6 @@ BR2_PACKAGE_PROCPS_NG=y BR2_PACKAGE_JQ=y BR2_PACKAGE_E2FSPROGS=y BR2_PACKAGE_E2FSPROGS_E2IMAGE=y -BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y BR2_PACKAGE_SQUASHFS=y BR2_PACKAGE_LINUX_FIRMWARE=y BR2_PACKAGE_LINUX_FIRMWARE_RTL_87XX=y diff --git a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/mnt-data.mount b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/mnt-data.mount index cb38aff6e..8409e63bb 100644 --- a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/mnt-data.mount +++ b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/mnt-data.mount @@ -6,7 +6,7 @@ After=hassos-expand.service Before=umount.target local-fs.target Conflicts=umount.target After=systemd-fsck@dev-disk-by\x2dlabel-hassos\x2ddata.service -Wants=systemd-fsck@dev-disk-by\x2dlabel-hassos\x2ddata.service +Wants=systemd-fsck@dev-disk-by\x2dlabel-hassos\x2ddata.service systemd-growfs@mnt-data.service [Mount] What=/dev/disk/by-label/hassos-data diff --git a/buildroot-external/rootfs-overlay/usr/lib/systemd/system/systemd-growfs@.service b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/systemd-growfs@.service new file mode 100644 index 000000000..c46286552 --- /dev/null +++ b/buildroot-external/rootfs-overlay/usr/lib/systemd/system/systemd-growfs@.service @@ -0,0 +1,18 @@ +# +# Extracted from fstab-generator +# + +[Unit] +Description=Grow File System on %f +Documentation=man:systemd-growfs@.service(8) +DefaultDependencies=no +BindsTo=%i.mount +Conflicts=shutdown.target +After=%i.mount +Before=shutdown.target local-fs.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/lib/systemd/systemd-growfs %f +TimeoutSec=0 diff --git a/buildroot-external/rootfs-overlay/usr/libexec/hassos-expand b/buildroot-external/rootfs-overlay/usr/libexec/hassos-expand index 013416d9d..1af9bf53c 100755 --- a/buildroot-external/rootfs-overlay/usr/libexec/hassos-expand +++ b/buildroot-external/rootfs-overlay/usr/libexec/hassos-expand @@ -52,11 +52,17 @@ else sfdisk -V "${DEVICE_ROOT}" fi +# Reload partition table partx -u "${DEVICE_ROOT}" +udevadm settle -# Resize filesystem -echo "[INFO] Resize hassos-data filesystem" -e2fsck -y "${DEVICE_CHILD}" -resize2fs -f "${DEVICE_CHILD}" +# Make sure /dev/disk/by-label/hassos-data is actually present before exiting. +# This avoids a race condition with mnt-data.mount which might fail to bind +# otherwise: +# Bound to unit dev-disk-by\x2dlabel-hassos\x2ddata.device, but unit isn't active. +if ! systemctl start "dev-disk-by\\x2dlabel-hassos\\x2ddata.device"; then + echo "[ERROR] Data partition not found!" + exit 1 +fi -echo "[INFO] Finish hassos-data resizing" +echo "[INFO] Finished hassos-data partition resizing"