[PATCH] expand-on-first-boot: Switch from resize2fs to systemd-growfs

441 views
Skip to first unread message

Tobias Schmidl

unread,
May 25, 2022, 8:33:01 AM5/25/22
to isar-...@googlegroups.com, Joe MacDonald, Tobias Schmidl
We want to be more versatile in our approach of resizing the root
partition. Therefore we switch from resize2fs to systemd-growfs (on
systems with systemd-growfs).

This allows for ext4, btrfs, xfs, and dm-crypt partitions to be resized.

Signed-off-by: Tobias Schmidl <tobias...@siemens.com>
---
.../files/expand-last-partition.sh | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

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 bb371e9..f0dc66d 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
@@ -3,7 +3,7 @@
# Resize last partition to full medium size
#
# This software is a part of ISAR.
-# Copyright (c) Siemens AG, 2018
+# Copyright (c) Siemens AG, 2018-2022
#
# SPDX-License-Identifier: MIT

@@ -45,4 +45,15 @@ partx -u "${LAST_PART}"
# when using systemd mount units.
export EXT2FS_NO_MTAB_OK=1

-resize2fs "${LAST_PART}"
+# If we are on a systemd system, we call systemd-growfs, otherwise resize2fs
+if [ -x /lib/systemd/systemd-growfs ]; then
+ MOUNT_POINT=$(findmnt "${LAST_PART}" -o target -n)
+ if [ -z "$MOUNT_POINT" ]; then
+ echo "Cannot find mount point for ${LAST_PART}"
+ exit 1
+ fi
+ mount "${MOUNT_POINT}" || true
+ /lib/systemd/systemd-growfs "${MOUNT_POINT}"
+else
+ resize2fs "${LAST_PART}"
+fi
--
2.36.1

Jan Kiszka

unread,
May 25, 2022, 8:47:32 AM5/25/22
to Tobias Schmidl, isar-...@googlegroups.com, Joe MacDonald
On 25.05.22 14:32, Tobias Schmidl wrote:
> We want to be more versatile in our approach of resizing the root
> partition. Therefore we switch from resize2fs to systemd-growfs (on
> systems with systemd-growfs).

Just for the sake of completeness: Since which Debian version is this
the case? I assume buster is fine, right? But stretch was not.
I wonder if / how long we should keep the two paths...

Jan

--
Siemens AG, Technology
Competence Center Embedded Linux

Bezdeka, Florian

unread,
May 25, 2022, 8:57:33 AM5/25/22
to isar-...@googlegroups.com, jan.k...@siemens.com, Schmidl, Tobias, joe.ma...@siemens.com
Hi all,

On Wed, 2022-05-25 at 14:47 +0200, Jan Kiszka wrote:
> On 25.05.22 14:32, Tobias Schmidl wrote:
> > We want to be more versatile in our approach of resizing the root

Here your talking about the root partition, but when looking at the
lines below I feel we're talking about the "last" partition which might
be the root partition (in your case) but there is no guarantee for
that.
Same here. Quite sure that stretch would not be OK, but it's unclear to
me if we (should) still care...

Florian

Bezdeka, Florian

unread,
May 25, 2022, 9:03:15 AM5/25/22
to isar-...@googlegroups.com, jan.k...@siemens.com, Schmidl, Tobias, joe.ma...@siemens.com
Sorry, forgot something:

Is systemd-growfs able to handle the typical "resize boundary
problems"? While looking at the y2038 stuff last time we figured out
that inode size is calculated at file system creation time. So it is
quite dangerous to enlarge a quite small file system to a huge one. The
inode size can not be changed again during resize operation. So they
might "run out of space" / curious things can happen.

That was at least a problem for ext3/4 in the past. Don't know about
the others...

There should be an internal issue for that topic, but I was unable to
find it within a few seconds.

Schmidl, Tobias

unread,
May 25, 2022, 9:04:18 AM5/25/22
to isar-...@googlegroups.com, jan.k...@siemens.com, joe.ma...@siemens.com
Hi all,

Am Mittwoch, dem 25.05.2022 um 14:47 +0200 schrieb Jan Kiszka:
>
> Just for the sake of completeness: Since which Debian version is this
> the case? I assume buster is fine, right? But stretch was not.
>
>

That's correct, it was introduced with v236 [1], so halfway between
stretch (v232) and buster (v241).


[1]:
https://github.com/systemd/systemd/blob/ec5e113f099a3078194ae5fe43f72f52f41fe76b/NEWS#L6515-L6524

> >
> > +if [ -x /lib/systemd/systemd-growfs ]; then
> > +       MOUNT_POINT=$(findmnt "${LAST_PART}" -o target -n)
> > +       if [ -z "$MOUNT_POINT" ]; then
> > +               echo "Cannot find mount point for ${LAST_PART}"
> > +               exit 1
> > +       fi
> > +       mount "${MOUNT_POINT}" || true
> > +       /lib/systemd/systemd-growfs "${MOUNT_POINT}"
> > +else
> > +       resize2fs "${LAST_PART}"
> > +fi
>
> I wonder if / how long we should keep the two paths...
>

That's a strategic decision - do we want to keep the possibility of non-
systemd systems open? Otherwise this script should IMHO add a runtime
dependency to systemd (>=236).

Kind regards,

Tobias

Jan Kiszka

unread,
May 25, 2022, 9:08:20 AM5/25/22
to Schmidl, Tobias (T CED SES-DE), isar-...@googlegroups.com, MacDonald, Joe
Well, we already depend on systemd today and provide only systemd unit
files here. In that light, adding a version dependency to systemd would
be fine IMHO.

Tobias Schmidl

unread,
May 30, 2022, 7:37:51 AM5/30/22
to isar-...@googlegroups.com, Joe MacDonald, Tobias Schmidl
Diff to v1:
- Rewording on patch message ("root partition" --> "last partition",
added note to systemd-dependency and its impact)
- Added systemd-version dependency
- Removed runtime if case that allowed for non-systemd systems

Tobias Schmidl (1):
expand-on-first-boot: Switch from resize2fs to systemd-growfs

.../expand-on-first-boot/expand-on-first-boot_1.1.bb | 5 +++--
.../files/expand-last-partition.sh | 10 ++++++++--
2 files changed, 11 insertions(+), 4 deletions(-)

--
2.36.1

Tobias Schmidl

unread,
May 30, 2022, 7:37:51 AM5/30/22
to isar-...@googlegroups.com, Joe MacDonald, Tobias Schmidl
We want to be more versatile in our approach of resizing the last
partition. Therefore we switch from resize2fs to systemd-growfs.

This allows for ext4, btrfs, xfs, and dm-crypt partitions to be resized.

Since systemd-growfs landed in v236, this obsoletes expand-on-first-boot
on stretch (v232).

Signed-off-by: Tobias Schmidl <tobias...@siemens.com>
---
.../expand-on-first-boot/expand-on-first-boot_1.1.bb | 5 +++--
.../files/expand-last-partition.sh | 10 ++++++++--
2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.1.bb b/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.1.bb
index 1703a64..09ff234 100644
--- a/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.1.bb
+++ b/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.1.bb
@@ -1,15 +1,16 @@
# Resize last partition to full medium size on fist boot
#
# This software is a part of ISAR.
-# Copyright (c) Siemens AG, 2018
+# Copyright (c) Siemens AG, 2018-2022
#
# SPDX-License-Identifier: MIT

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, util-linux"
+DEBIAN_DEPENDS = "systemd (>=236), sed, grep, coreutils, mount, e2fsprogs, fdisk, util-linux"

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 bb371e9..37e94ca 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
@@ -3,7 +3,7 @@
# Resize last partition to full medium size
#
# This software is a part of ISAR.
-# Copyright (c) Siemens AG, 2018
+# Copyright (c) Siemens AG, 2018-2022
#
# SPDX-License-Identifier: MIT

@@ -45,4 +45,10 @@ partx -u "${LAST_PART}"
# when using systemd mount units.
export EXT2FS_NO_MTAB_OK=1

-resize2fs "${LAST_PART}"
+MOUNT_POINT=$(findmnt "${LAST_PART}" -o target -n)
+if [ -z "$MOUNT_POINT" ]; then
+ echo "Cannot find mount point for ${LAST_PART}"
+ exit 1
+fi
+mount "${MOUNT_POINT}" || true
+/lib/systemd/systemd-growfs "${MOUNT_POINT}"
--
2.36.1

Henning Schild

unread,
Jun 2, 2022, 10:47:27 AM6/2/22
to Tobias Schmidl, isar-...@googlegroups.com, Joe MacDonald
Am Mon, 30 May 2022 13:37:37 +0200
schrieb Tobias Schmidl <tobias...@siemens.com>:
Maybe e2fsprogs can be dropped now? If not ... maybe we need to add
something here to really enable btrfs?

Henning

Schmidl, Tobias

unread,
Jun 2, 2022, 12:26:08 PM6/2/22
to Schild, Henning, isar-...@googlegroups.com, joe.ma...@siemens.com
Hi all,
while I'm on it, should I also do a version bump for the package to 1.2,
since there a lot of new stuff in it?

Kind regards,

Tobias

Henning Schild

unread,
Jun 2, 2022, 2:37:37 PM6/2/22
to Schmidl, Tobias (T CED SES-DE), isar-...@googlegroups.com, MacDonald, Joe (DI SW CAS ES EPT)
Am Thu, 2 Jun 2022 18:26:05 +0200
schrieb "Schmidl, Tobias (T CED SES-DE)" <tobias...@siemens.com>:
Very good point, yes please bump when you touch. Version is up to you
but 1.2 sounds good.

Henning

> Kind regards,
>
> Tobias

Tobias Schmidl

unread,
Jun 2, 2022, 3:46:15 PM6/2/22
to isar-...@googlegroups.com, Joe MacDonald, Tobias Schmidl
Diff to v1:
- Rewording on patch message ("root partition" --> "last partition",
added note to systemd-dependency and its impact)
- Added systemd-version dependency
- Removed runtime if case that allowed for non-systemd systems

Doff to v2:
- Version bump to v1.2
- Removed e2fsprogs as dependency

Tobias Schmidl (1):
expand-on-first-boot: Switch from resize2fs to systemd-growfs

...n-first-boot_1.1.bb => expand-on-first-boot_1.2.bb} | 5 +++--
.../files/expand-last-partition.sh | 10 ++++++++--
2 files changed, 11 insertions(+), 4 deletions(-)
rename meta/recipes-support/expand-on-first-boot/{expand-on-first-boot_1.1.bb => expand-on-first-boot_1.2.bb} (78%)

--
2.36.1

Tobias Schmidl

unread,
Jun 2, 2022, 3:46:16 PM6/2/22
to isar-...@googlegroups.com, Joe MacDonald, Tobias Schmidl
We want to be more versatile in our approach of resizing the last
partition. Therefore we switch from resize2fs to systemd-growfs.

This allows for ext4, btrfs, xfs, and dm-crypt partitions to be resized.

Since systemd-growfs landed in v236, this obsoletes expand-on-first-boot
on stretch (v232).

Signed-off-by: Tobias Schmidl <tobias...@siemens.com>
---
...n-first-boot_1.1.bb => expand-on-first-boot_1.2.bb} | 5 +++--
.../files/expand-last-partition.sh | 10 ++++++++--
2 files changed, 11 insertions(+), 4 deletions(-)
rename meta/recipes-support/expand-on-first-boot/{expand-on-first-boot_1.1.bb => expand-on-first-boot_1.2.bb} (78%)

diff --git a/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.1.bb b/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.2.bb
similarity index 78%
rename from meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.1.bb
rename to meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.2.bb
index 1703a64..48d30d3 100644
--- a/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.1.bb
+++ b/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.2.bb
@@ -1,15 +1,16 @@
# Resize last partition to full medium size on fist boot
#
# This software is a part of ISAR.
-# Copyright (c) Siemens AG, 2018
+# Copyright (c) Siemens AG, 2018-2022
#
# SPDX-License-Identifier: MIT

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, util-linux"
+DEBIAN_DEPENDS = "systemd (>=236), sed, grep, coreutils, mount, fdisk, util-linux"

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 bb371e9..37e94ca 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
@@ -3,7 +3,7 @@
# Resize last partition to full medium size
#
# This software is a part of ISAR.
-# Copyright (c) Siemens AG, 2018
+# Copyright (c) Siemens AG, 2018-2022
#
# SPDX-License-Identifier: MIT

@@ -45,4 +45,10 @@ partx -u "${LAST_PART}"
# when using systemd mount units.
export EXT2FS_NO_MTAB_OK=1

-resize2fs "${LAST_PART}"
+MOUNT_POINT=$(findmnt "${LAST_PART}" -o target -n)
+if [ -z "$MOUNT_POINT" ]; then
+ echo "Cannot find mount point for ${LAST_PART}"
+ exit 1
+fi
+mount "${MOUNT_POINT}" || true
+/lib/systemd/systemd-growfs "${MOUNT_POINT}"
--
2.36.1

Henning Schild

unread,
Jun 2, 2022, 3:56:19 PM6/2/22
to Tobias Schmidl, isar-...@googlegroups.com, Joe MacDonald
Am Thu, 2 Jun 2022 21:46:00 +0200
schrieb Tobias Schmidl <tobias...@siemens.com>:

> We want to be more versatile in our approach of resizing the last
> partition. Therefore we switch from resize2fs to systemd-growfs.
>
> This allows for ext4, btrfs, xfs, and dm-crypt partitions to be
> resized.

LGTM!

We are missing resize test cases, we always have been. I assume you did
test all the filesystems listed here somehow manually.

At some point in the future we might really want those resize test
cases with several wks files to make sure it works and works for all
the filesystems we do care about. Probably extX and btrfs to start with.

Thanks!
Henning

Schmidl, Tobias

unread,
Jun 3, 2022, 2:48:14 AM6/3/22
to isar-...@googlegroups.com, joe.ma...@siemens.com
Hi all,

Am Donnerstag, dem 02.06.2022 um 21:56 +0200 schrieb Henning Schild:
> Am Thu, 2 Jun 2022 21:46:00 +0200
> schrieb Tobias Schmidl <tobias...@siemens.com>:
>
> > We want to be more versatile in our approach of resizing the last
> > partition. Therefore we switch from resize2fs to systemd-growfs.
> >
> > This allows for ext4, btrfs, xfs, and dm-crypt partitions to be
> > resized.
>
> LGTM!
>
> We are missing resize test cases, we always have been. I assume you did
> test all the filesystems listed here somehow manually.
>

I did test with btrfs and ext4, on both root partition and additional
partition.

Kind regards,

Tobias

Moessbauer, Felix

unread,
Jun 3, 2022, 3:55:50 AM6/3/22
to Schmidl, Tobias, isar-...@googlegroups.com, joe.ma...@siemens.com
> -----Original Message-----
> From: isar-...@googlegroups.com <isar-...@googlegroups.com> On
> Behalf Of Schmidl, Tobias
> Sent: Friday, June 3, 2022 8:48 AM
> To: isar-...@googlegroups.com
> Cc: MacDonald, Joe (DI SW CAS ES EPT) <joe.ma...@siemens.com>
> Subject: Re: [PATCH v3 1/1] expand-on-first-boot: Switch from resize2fs to
> systemd-growfs
>
> Hi all,
>
> Am Donnerstag, dem 02.06.2022 um 21:56 +0200 schrieb Henning Schild:
> > Am Thu, 2 Jun 2022 21:46:00 +0200
> > schrieb Tobias Schmidl <tobias...@siemens.com>:
> >
> > > We want to be more versatile in our approach of resizing the last
> > > partition. Therefore we switch from resize2fs to systemd-growfs.
> > >
> > > This allows for ext4, btrfs, xfs, and dm-crypt partitions to be
> > > resized.
> >
> > LGTM!
> >
> > We are missing resize test cases, we always have been. I assume you
> > did test all the filesystems listed here somehow manually.

These kinds of tests currently cannot be added to the testsuite as they likely require mounting the partition.
For details, see the discussion on patches 4,5 of the "wic: Update to the latest revision" series.

IMO we should not spend too much time on writing CI tests for that until we have a proper testing infrastructure.
But this will also require some tools to be present on the host / the kas container.
It's more of a long term goal. I learned that the hard way...

Felix

> >
>
> I did test with btrfs and ext4, on both root partition and additional partition.
>
> Kind regards,
>
> Tobias
>
> --
> You received this message because you are subscribed to the Google Groups
> "isar-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to isar-users+...@googlegroups.com.
> To view this discussion on the web visit
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgrou
> ps.google.com%2Fd%2Fmsgid%2Fisar-
> users%2F9b00c86807b1c682cb21201f479031e6fe3e2844.camel%2540siemens
> .com&amp;data=05%7C01%7Cfelix.moessbauer%40siemens.com%7Cb7f84f
> d5400e44f31a1a08da452d091b%7C38ae3bcd95794fd4addab42e1495d55a%7C
> 1%7C0%7C637898357688435689%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiM
> C4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000
> %7C%7C%7C&amp;sdata=jaiFxftc%2B818u%2F71uSmFnI%2F2G1Jcr4hZY8FNi
> bCNZQ8%3D&amp;reserved=0.
Reply all
Reply to author
Forward
0 new messages