expand-on-first-boot: switch back away from systemd-growfs

Message ID 20221209162237.13420-1-henning.schild@siemens.com
State Accepted, archived
Headers show
Series expand-on-first-boot: switch back away from systemd-growfs | expand

Commit Message

Henning Schild Dec. 9, 2022, 4:22 p.m. UTC
From: Henning Schild <henning.schild@siemens.com>

systemd-growfs in some versions has runtime deps on symlinks created
by udev and we have a race there that shows especially on smaller/slower
devices.
We had patches dealing with that but they ended up looking rather
complex.
The gain of systemd-growfs is potentially a bunch more filesystems. But
we can add them as well in sort of a switch-case. We never used it the
way it is intended because it did not really fit, so better not use it.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
---
 ...oot_1.2.bb => expand-on-first-boot_1.3.bb} |  0
 .../files/expand-last-partition.sh            | 26 ++++---------------
 2 files changed, 5 insertions(+), 21 deletions(-)
 rename meta/recipes-support/expand-on-first-boot/{expand-on-first-boot_1.2.bb => expand-on-first-boot_1.3.bb} (100%)

Comments

Henning Schild Dec. 9, 2022, 4:30 p.m. UTC | #1
This is almost a full revert of some recently applied patches. We only
keep the bail-out in case "x-systemd.growfs" is somewhere in fstab.

Tested on an rpi that was affected and now is not any more.

We are kind of removing btrfs or other filesystem support for the last
partition. I would suggest to take them in as they are actually
requested. And i will at some point start with btrfs support and a
target actually using that.

Henning

Am Fri,  9 Dec 2022 17:22:37 +0100
schrieb henning.schild@siemens.com:

> From: Henning Schild <henning.schild@siemens.com>
> 
> systemd-growfs in some versions has runtime deps on symlinks created
> by udev and we have a race there that shows especially on
> smaller/slower devices.
> We had patches dealing with that but they ended up looking rather
> complex.
> The gain of systemd-growfs is potentially a bunch more filesystems.
> But we can add them as well in sort of a switch-case. We never used
> it the way it is intended because it did not really fit, so better
> not use it.
> 
> Signed-off-by: Henning Schild <henning.schild@siemens.com>
> ---
>  ...oot_1.2.bb => expand-on-first-boot_1.3.bb} |  0
>  .../files/expand-last-partition.sh            | 26
> ++++--------------- 2 files changed, 5 insertions(+), 21 deletions(-)
>  rename
> meta/recipes-support/expand-on-first-boot/{expand-on-first-boot_1.2.bb
> => expand-on-first-boot_1.3.bb} (100%)
> 
> diff --git
> a/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.2.bb
> b/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.3.bb
> similarity index 100% rename from
> meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.2.bb
> rename to
> meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.3.bb
> diff --git
> a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
> b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
> index 57055ccdcbd8..93eddda2a3b7 100755 ---
> a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
> +++
> b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
> @@ -57,29 +57,13 @@ sfdisk -d "${BOOT_DEV}" 2>/dev/null | \ # Inform
> the kernel about the partitioning change partx -u "${LAST_PART}" -#
> this is for debian stretch or systemd < 236 -if [ ! -x
> /lib/systemd/systemd-growfs ]; then
> -	# Do not fail resize2fs if no mtab entry is found, e.g.,
> -	# when using systemd mount units.
> -	export EXT2FS_NO_MTAB_OK=1
> -
> -	resize2fs "${LAST_PART}"
> -	exit 0
> -fi
> -
>  if grep -q x-systemd.growfs /etc/fstab; then
> -	echo "Found x-systemd.growfs option in /etc/fstab, won't
> call it explicitly." >&2
> +	echo "Found x-systemd.growfs option in /etc/fstab, won't
> grow." >&2 exit 0
>  fi
>  
> -# mount $LAST_PART out of tree, so we won't conflict with other
> mounts -MOUNT_POINT=$(mktemp -d -p /mnt "$(basename "$0").XXXXXXXXXX")
> -if [ ! -d "${MOUNT_POINT}" ]; then
> -	echo "Cannot create temporary mount point ${MOUNT_POINT}."
> >&2
> -	exit 1
> -fi
> +# Do not fail resize2fs if no mtab entry is found, e.g.,
> +# when using systemd mount units.
> +export EXT2FS_NO_MTAB_OK=1
>  
> -mount "${LAST_PART}" "${MOUNT_POINT}"
> -/lib/systemd/systemd-growfs "${MOUNT_POINT}"
> -umount "${MOUNT_POINT}"
> -rmdir "${MOUNT_POINT}"
> +resize2fs "${LAST_PART}"
Tobias Schaffner Dec. 13, 2022, 2:16 p.m. UTC | #2
On 09.12.22 17:22, Schild, Henning (T CED SES-DE) wrote:
> From: Henning Schild <henning.schild@siemens.com>
> 
> systemd-growfs in some versions has runtime deps on symlinks created
> by udev and we have a race there that shows especially on smaller/slower
> devices.
> We had patches dealing with that but they ended up looking rather
> complex.
> The gain of systemd-growfs is potentially a bunch more filesystems. But
> we can add them as well in sort of a switch-case. We never used it the
> way it is intended because it did not really fit, so better not use it.
> 
> Signed-off-by: Henning Schild <henning.schild@siemens.com>
> ---
>   ...oot_1.2.bb => expand-on-first-boot_1.3.bb} |  0
>   .../files/expand-last-partition.sh            | 26 ++++---------------
>   2 files changed, 5 insertions(+), 21 deletions(-)
>   rename meta/recipes-support/expand-on-first-boot/{expand-on-first-boot_1.2.bb => expand-on-first-boot_1.3.bb} (100%)
> 
> diff --git a/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.2.bb b/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.3.bb
> similarity index 100%
> rename from meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.2.bb
> rename to meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.3.bb
> diff --git a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
> index 57055ccdcbd8..93eddda2a3b7 100755
> --- a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
> +++ b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
> @@ -57,29 +57,13 @@ sfdisk -d "${BOOT_DEV}" 2>/dev/null | \
>   # Inform the kernel about the partitioning change
>   partx -u "${LAST_PART}"
>   
> -# this is for debian stretch or systemd < 236
> -if [ ! -x /lib/systemd/systemd-growfs ]; then
> -	# Do not fail resize2fs if no mtab entry is found, e.g.,
> -	# when using systemd mount units.
> -	export EXT2FS_NO_MTAB_OK=1
> -
> -	resize2fs "${LAST_PART}"
> -	exit 0
> -fi
> -
>   if grep -q x-systemd.growfs /etc/fstab; then
> -	echo "Found x-systemd.growfs option in /etc/fstab, won't call it explicitly." >&2
> +	echo "Found x-systemd.growfs option in /etc/fstab, won't grow." >&2
>   	exit 0
>   fi
>   
> -# mount $LAST_PART out of tree, so we won't conflict with other mounts
> -MOUNT_POINT=$(mktemp -d -p /mnt "$(basename "$0").XXXXXXXXXX")
> -if [ ! -d "${MOUNT_POINT}" ]; then
> -	echo "Cannot create temporary mount point ${MOUNT_POINT}." >&2
> -	exit 1
> -fi
> +# Do not fail resize2fs if no mtab entry is found, e.g.,
> +# when using systemd mount units.
> +export EXT2FS_NO_MTAB_OK=1
>   
> -mount "${LAST_PART}" "${MOUNT_POINT}"
> -/lib/systemd/systemd-growfs "${MOUNT_POINT}"
> -umount "${MOUNT_POINT}"
> -rmdir "${MOUNT_POINT}"
> +resize2fs "${LAST_PART}"

Tested in QEMU and worked as expected. Looks good!

Best,
Tobias
Quirin Gylstorff Dec. 14, 2022, 11:18 a.m. UTC | #3
On 12/9/22 17:22, henning.schild@siemens.com wrote:
> From: Henning Schild <henning.schild@siemens.com>
> 
> systemd-growfs in some versions has runtime deps on symlinks created
> by udev and we have a race there that shows especially on smaller/slower
> devices.
> We had patches dealing with that but they ended up looking rather
> complex.
> The gain of systemd-growfs is potentially a bunch more filesystems. But
> we can add them as well in sort of a switch-case. We never used it the
> way it is intended because it did not really fit, so better not use it.
> 
> Signed-off-by: Henning Schild <henning.schild@siemens.com>
> ---
>   ...oot_1.2.bb => expand-on-first-boot_1.3.bb} |  0
>   .../files/expand-last-partition.sh            | 26 ++++---------------
>   2 files changed, 5 insertions(+), 21 deletions(-)
>   rename meta/recipes-support/expand-on-first-boot/{expand-on-first-boot_1.2.bb => expand-on-first-boot_1.3.bb} (100%)
> 
> diff --git a/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.2.bb b/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.3.bb
> similarity index 100%
> rename from meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.2.bb
> rename to meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.3.bb
> diff --git a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
> index 57055ccdcbd8..93eddda2a3b7 100755
> --- a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
> +++ b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
> @@ -57,29 +57,13 @@ sfdisk -d "${BOOT_DEV}" 2>/dev/null | \
>   # Inform the kernel about the partitioning change
>   partx -u "${LAST_PART}"
>   
> -# this is for debian stretch or systemd < 236
> -if [ ! -x /lib/systemd/systemd-growfs ]; then
> -	# Do not fail resize2fs if no mtab entry is found, e.g.,
> -	# when using systemd mount units.
> -	export EXT2FS_NO_MTAB_OK=1
> -
> -	resize2fs "${LAST_PART}"
> -	exit 0
> -fi
> -
>   if grep -q x-systemd.growfs /etc/fstab; then
> -	echo "Found x-systemd.growfs option in /etc/fstab, won't call it explicitly." >&2
> +	echo "Found x-systemd.growfs option in /etc/fstab, won't grow." >&2
>   	exit 0
>   fi
>   
> -# mount $LAST_PART out of tree, so we won't conflict with other mounts
> -MOUNT_POINT=$(mktemp -d -p /mnt "$(basename "$0").XXXXXXXXXX")
> -if [ ! -d "${MOUNT_POINT}" ]; then
> -	echo "Cannot create temporary mount point ${MOUNT_POINT}." >&2
> -	exit 1
> -fi
> +# Do not fail resize2fs if no mtab entry is found, e.g.,
> +# when using systemd mount units.
> +export EXT2FS_NO_MTAB_OK=1
>   
> -mount "${LAST_PART}" "${MOUNT_POINT}"
> -/lib/systemd/systemd-growfs "${MOUNT_POINT}"
> -umount "${MOUNT_POINT}"
> -rmdir "${MOUNT_POINT}"
> +resize2fs "${LAST_PART}"

Tested with read-only rootfs. Looks good.

Quirin
Anton Mikanovich Dec. 23, 2022, 6:27 a.m. UTC | #4
09.12.2022 19:22, henning.schild@siemens.com wrote:
> From: Henning Schild <henning.schild@siemens.com>
>
> systemd-growfs in some versions has runtime deps on symlinks created
> by udev and we have a race there that shows especially on smaller/slower
> devices.
> We had patches dealing with that but they ended up looking rather
> complex.
> The gain of systemd-growfs is potentially a bunch more filesystems. But
> we can add them as well in sort of a switch-case. We never used it the
> way it is intended because it did not really fit, so better not use it.
>
> Signed-off-by: Henning Schild <henning.schild@siemens.com>

Applied to next, thanks.

Patch

diff --git a/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.2.bb b/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.3.bb
similarity index 100%
rename from meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.2.bb
rename to meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.3.bb
diff --git a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
index 57055ccdcbd8..93eddda2a3b7 100755
--- a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
+++ b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
@@ -57,29 +57,13 @@  sfdisk -d "${BOOT_DEV}" 2>/dev/null | \
 # Inform the kernel about the partitioning change
 partx -u "${LAST_PART}"
 
-# this is for debian stretch or systemd < 236
-if [ ! -x /lib/systemd/systemd-growfs ]; then
-	# Do not fail resize2fs if no mtab entry is found, e.g.,
-	# when using systemd mount units.
-	export EXT2FS_NO_MTAB_OK=1
-
-	resize2fs "${LAST_PART}"
-	exit 0
-fi
-
 if grep -q x-systemd.growfs /etc/fstab; then
-	echo "Found x-systemd.growfs option in /etc/fstab, won't call it explicitly." >&2
+	echo "Found x-systemd.growfs option in /etc/fstab, won't grow." >&2
 	exit 0
 fi
 
-# mount $LAST_PART out of tree, so we won't conflict with other mounts
-MOUNT_POINT=$(mktemp -d -p /mnt "$(basename "$0").XXXXXXXXXX")
-if [ ! -d "${MOUNT_POINT}" ]; then
-	echo "Cannot create temporary mount point ${MOUNT_POINT}." >&2
-	exit 1
-fi
+# Do not fail resize2fs if no mtab entry is found, e.g.,
+# when using systemd mount units.
+export EXT2FS_NO_MTAB_OK=1
 
-mount "${LAST_PART}" "${MOUNT_POINT}"
-/lib/systemd/systemd-growfs "${MOUNT_POINT}"
-umount "${MOUNT_POINT}"
-rmdir "${MOUNT_POINT}"
+resize2fs "${LAST_PART}"