[PATCH] In expand last partition script btrfs support added

1 view
Skip to first unread message

roberto....@gmail.com

unread,
Dec 9, 2022, 10:25:32 PM12/9/22
to isar-...@googlegroups.com, roberto....@gmail.com
From: "Roberto A. Foglietta" <roberto....@gmail.com>

improvement, expand-on-first-boot: support for btrfs added

Signed-off-by: Roberto A. Foglietta <roberto....@gmail.com>
---
.../expand-on-first-boot_1.2.bb | 2 +-
.../files/expand-last-partition.sh | 37 ++++++-------------
2 files changed, 13 insertions(+), 26 deletions(-)

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.2.bb
index 0996000..fe7b72b 100644
--- 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.2.bb
@@ -10,7 +10,7 @@ inherit dpkg-raw
DESCRIPTION = "This service grows the last partition to the full medium during first boot"
MAINTAINER = "isar-users <isar-...@googlegroups.com>"

-DEBIAN_DEPENDS = "systemd, sed, grep, coreutils, mount, e2fsprogs, fdisk (>=2.29.2-3) | util-linux (<2.29.2-3), util-linux"
+DEBIAN_DEPENDS = "systemd, sed, grep, coreutils, mount, e2fsprogs, fdisk (>=2.29.2-3) | util-linux (<2.29.2-3), util-linux, btrfs-progs"

SRC_URI = " \
file://expand-on-first-boot.service \
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 57055cc..acfef8a 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,16 @@ 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
+# 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
- 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
-
-mount "${LAST_PART}" "${MOUNT_POINT}"
-/lib/systemd/systemd-growfs "${MOUNT_POINT}"
-umount "${MOUNT_POINT}"
-rmdir "${MOUNT_POINT}"
+case $(lsblk -fno FSTYPE "${LAST_PART}") in
+ ext4) resize2fs "${LAST_PART}"
+ ;;
+ btrfs) mkdir -p /tmp/btrfs
+ mount "${LAST_PART}" /tmp/btrfs
+ btrfs filesystem resize max /tmp/btrfs
+ umount /tmp/btrfs && rmdir /tmp/btrfs
+ ;;
+esac
--
2.34.1


https://16F0H.trk.elasticemail.com/tracking/unsubscribe?d=W3iSTwOIK-DOHnpemvzC8EMM0CgLGAUKd7tKCfVd6H8-zPuoxhzkljzRv-DkOJP1mOBhEL2zRDmb5aSeS31LMukikI75Ea3tHaNqA3GIw-_o0

roberto....@gmail.com

unread,
Dec 13, 2022, 12:59:01 AM12/13/22
to isar-...@googlegroups.com, roberto....@gmail.com
From: "Roberto A. Foglietta" <roberto....@gmail.com>

Improvement, expand-on-first-boot: support for btrfs added
The mount point for btrfs filesystem to resizes is under /dev/shm
by default but a variable defined in the running enviroment can
change the temporary directory path. The /dev/shm has been choosen
because in some system /tmp can be on a RO root filesystem and
/tmp not yet mounted with tmpfs. This requires the system has
/dev/shm configured into the kernel.

Signed-off-by: Roberto A. Foglietta <roberto....@gmail.com>
---
.../expand-on-first-boot_1.2.bb | 2 +-
.../files/expand-last-partition.sh | 38 +++++++------------
2 files changed, 14 insertions(+), 26 deletions(-)

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.2.bb
index 0996000..fe7b72b 100644
--- 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.2.bb
@@ -10,7 +10,7 @@ inherit dpkg-raw
DESCRIPTION = "This service grows the last partition to the full medium during first boot"
MAINTAINER = "isar-users <isar-...@googlegroups.com>"

-DEBIAN_DEPENDS = "systemd, sed, grep, coreutils, mount, e2fsprogs, fdisk (>=2.29.2-3) | util-linux (<2.29.2-3), util-linux"
+DEBIAN_DEPENDS = "systemd, sed, grep, coreutils, mount, e2fsprogs, fdisk (>=2.29.2-3) | util-linux (<2.29.2-3), util-linux, btrfs-progs"

SRC_URI = " \
file://expand-on-first-boot.service \
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 4d55645..e314f70 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
@@ -59,29 +59,17 @@ sfdisk -d "${BOOT_DEV}" 2>/dev/null | \
+tmp=${BOOT_DEV_TMPDIR:-/dev/shm}
+case $(lsblk -fno FSTYPE "${LAST_PART}") in
+ ext4) resize2fs "${LAST_PART}"
+ ;;
+ btrfs) mkdir -p $tmp/btrfs
+ mount "${LAST_PART}" $tmp/btrfs
+ btrfs filesystem resize max $tmp/btrfs
+ umount $tmp/btrfs && rmdir $tmp/btrfs
+ ;;
+esac
--
2.34.1


https://16F0H.trk.elasticemail.com/tracking/unsubscribe?d=GzJMTaKIgCv2mECxUheEZNcgtj9lZzFDoDfbv1IE7z_lAkMPcVw8snRiOYjJ9ATVm-TWPHObr98Hm9MMf2Ds6wgOsQ2uhqQGg7Zz3tSFwiKq0

roberto....@gmail.com

unread,
Dec 13, 2022, 2:17:02 AM12/13/22
to isar-...@googlegroups.com, roberto....@gmail.com
From: "Roberto A. Foglietta" <roberto....@gmail.com>

Improvement, expand-on-first-boot: support for btrfs added

v2: the mount point for btrfs filesystem to resizes is under /dev/shm
by default but a variable defined in the running enviroment can
change the temporary directory path. The /dev/shm has been choosen
because in some system /tmp can be on a RO root filesystem and
/tmp not yet mounted with tmpfs. This requires the system has
/dev/shm configured into the kernel.

v3: the previous version was using a bashism but the shebang is /bin/sh
this means that the script will fail in customised system in which /bin/sh
do not link to bash or bash in even not available.

Signed-off-by: Roberto A. Foglietta <roberto....@gmail.com>
---
.../expand-on-first-boot_1.2.bb | 2 +-
.../files/expand-last-partition.sh | 38 +++++++------------
2 files changed, 15 insertions(+), 25 deletions(-)

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.2.bb
index 0996000..fe7b72b 100644
--- 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.2.bb
@@ -10,7 +10,7 @@ inherit dpkg-raw
DESCRIPTION = "This service grows the last partition to the full medium during first boot"
MAINTAINER = "isar-users <isar-...@googlegroups.com>"

-DEBIAN_DEPENDS = "systemd, sed, grep, coreutils, mount, e2fsprogs, fdisk (>=2.29.2-3) | util-linux (<2.29.2-3), util-linux"
+DEBIAN_DEPENDS = "systemd, sed, grep, coreutils, mount, e2fsprogs, fdisk (>=2.29.2-3) | util-linux (<2.29.2-3), util-linux, btrfs-progs"

SRC_URI = " \
file://expand-on-first-boot.service \
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 4d55645..038124e 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
@@ -59,29 +59,19 @@ 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
+# 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
- exit 0
+if [ -n "$BOOT_DEV_TMPDIR" ]; then
+ tmp=$BOOT_DEV_TMPDIR
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
-
-mount "${LAST_PART}" "${MOUNT_POINT}"
-/lib/systemd/systemd-growfs "${MOUNT_POINT}"
-umount "${MOUNT_POINT}"
-rmdir "${MOUNT_POINT}"
+case $(lsblk -fno FSTYPE "${LAST_PART}") in
+ ext4) resize2fs "${LAST_PART}"
+ ;;
+ btrfs) mkdir -p $tmp/btrfs
+ mount "${LAST_PART}" $tmp/btrfs
+ btrfs filesystem resize max $tmp/btrfs
+ umount $tmp/btrfs && rmdir $tmp/btrfs
+ ;;
+esac
--
2.34.1


https://16F0H.trk.elasticemail.com/tracking/unsubscribe?d=unZHvcPZ03nwvR7FeZPfZjAJ9sdzS7mbgsfYadSUExg-vUTSxmdtkBjHq8md3O-B_itXi6uT6_fRNl2jAEemwDdvhBVp0Z8opmxBveITbTFb0

Roberto A. Foglietta

unread,
Dec 13, 2022, 4:47:17 PM12/13/22
to isar-...@googlegroups.com, Joe MacDonald, Moessbauer, Felix
Improvement, expand-on-first-boot: support for btrfs added

v2: the mount point for btrfs filesystem to resize is under /dev/shm
by default but a variable defined in the running environment can
change the temporary directory path. The /dev/shm has been chosen
because in some systems /tmp can be on a RO root filesystem and
/tmp not yet mounted with tmpfs. This requires the system to have
/dev/shm configured into the kernel.

v3: the previous version was using a bashism but the shebang is /bin/sh
this means that the script will fail in a customized system in which /bin/sh
do not link to bash or bash is not available.

v4: Felix suggested using mktemp for the temporary directory in which to
mount the btrfs filesystem to resize. The default path /tmp could be changed
using the variable TMPDIR to set in the running environment.

v5: typo fixes into the patch description

Sent as usual with elastic mail SMTP and went in moderation mode.
Here in attachment.

Best, R-
v5-0001-In-expand-last-partition-script-btrfs-support-add.patch

Roberto A. Foglietta

unread,
Dec 14, 2022, 2:23:21 AM12/14/22
to isar-...@googlegroups.com, Joe MacDonald, Moessbauer, Felix
In expand last partition script btrfs support added
v6: mktemp does a reasonable second try with -p /dev/shm before failing

Sent by elastic mail SMTP and gone in moderation, also here in attachment.

Best, R-
v6-0001-In-expand-last-partition-script-btrfs-support-add.patch
Reply all
Reply to author
Forward
0 new messages