From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Thu, 09 Nov 2023 09:13:50 +0100 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1r10Af-003tSl-36 for lore@lore.pengutronix.de; Thu, 09 Nov 2023 09:13:50 +0100 Received: from localhost ([127.0.0.1] helo=metis.whiteo.stw.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1r10Ag-0002W7-2u; Thu, 09 Nov 2023 09:13:50 +0100 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r10AW-0002VJ-RB for distrokit@pengutronix.de; Thu, 09 Nov 2023 09:13:40 +0100 Received: from [2a0a:edc0:2:b01:1d::c5] (helo=pty.whiteo.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r10AW-007jUZ-Eq for distrokit@pengutronix.de; Thu, 09 Nov 2023 09:13:40 +0100 Received: from rhi by pty.whiteo.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1r10AW-00DB7w-3N for distrokit@pengutronix.de; Thu, 09 Nov 2023 09:13:40 +0100 Date: Thu, 9 Nov 2023 09:13:40 +0100 From: Roland Hieber To: distrokit@pengutronix.de Message-ID: <20231109081340.e5ist5yizbksoeyf@pengutronix.de> References: <20231103225253.1349209-1-rhi@pengutronix.de> <20231103225253.1349209-6-rhi@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231103225253.1349209-6-rhi@pengutronix.de> Subject: Re: [DistroKit] [PATCH v2 05/10] datapartition: generate partitions via systemd-repart X-BeenThere: distrokit@pengutronix.de X-Mailman-Version: 2.1.29 Precedence: list List-Id: DistroKit Mailinglist List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "DistroKit" X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: distrokit-bounces@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false On Fri, Nov 03, 2023 at 11:52:48PM +0100, Roland Hieber wrote: > Generating the second rootfs and the data partition on the first boot > has the advantage that the generated images can get even smaller, and we > can resize the data partition on-the-fly to fill the available space on > the boot medium. > > Specify a minimum of 200 MiB for the first and second root partitions > just so that both are of equal size. (This will fit any root.ext2 in any > of our platforms with about 25% of space left.) If the first root > partition in the image is smaller, it will get resized too, including > the filesystem it contains. > > Remove the old systemd-autoformat service and the mkfs-ext4 udev rule, > which also only handled the case where the data partition was the third > partition on the disk (which is not always the case anymore since we > have partitions for barebox-state or device-specific firmware). > > Signed-off-by: Roland Hieber For some reason this is breaking on some platforms in a way which I didn't encounter during development, leading to a failed boot ending in a rescue shell, with systemd-repart showing error message like: Can't fit requested partitions into available free space (768.0K), refusing. Automatically determined minimal disk image size as 604.2M, current image size is 14.7G. …on a mmcblk0 of 14.7 GiB which only has 85 MiB of partitioned space… 🤔 I'll look into that, looks like I have to tickle systemd-repart to be a bit more verbose about what it is trying to match. - Roland > --- > projectroot/etc/rc.once.d/repart | 3 +++ > projectroot/etc/repart.rc-once.d/10-root.conf | 5 +++++ > projectroot/etc/repart.rc-once.d/20-root.conf | 6 ++++++ > projectroot/etc/repart.rc-once.d/30-data.conf | 6 ++++++ > .../systemd/system/systemd-autoformat@.service | 15 --------------- > .../usr/lib/udev/rules.d/91-mkfs-ext4.rules | 5 ----- > rules/datapartition.in | 3 +++ > rules/datapartition.make | 11 +++++++---- > 8 files changed, 30 insertions(+), 24 deletions(-) > create mode 100755 projectroot/etc/rc.once.d/repart > create mode 100644 projectroot/etc/repart.rc-once.d/10-root.conf > create mode 100644 projectroot/etc/repart.rc-once.d/20-root.conf > create mode 100644 projectroot/etc/repart.rc-once.d/30-data.conf > delete mode 100644 projectroot/usr/lib/systemd/system/systemd-autoformat@.service > delete mode 100644 projectroot/usr/lib/udev/rules.d/91-mkfs-ext4.rules > > diff --git a/projectroot/etc/rc.once.d/repart b/projectroot/etc/rc.once.d/repart > new file mode 100755 > index 000000000000..675c4e3e57f4 > --- /dev/null > +++ b/projectroot/etc/rc.once.d/repart > @@ -0,0 +1,3 @@ > +#!/bin/sh > +echo "Repartitioning the root disk..." > +systemd-repart --dry-run=no --definitions=/etc/repart.rc-once.d/ > diff --git a/projectroot/etc/repart.rc-once.d/10-root.conf b/projectroot/etc/repart.rc-once.d/10-root.conf > new file mode 100644 > index 000000000000..ae6f2c21e286 > --- /dev/null > +++ b/projectroot/etc/repart.rc-once.d/10-root.conf > @@ -0,0 +1,5 @@ > +[Partition] > +Label=root-A > +Type=root > +SizeMinBytes=200M > +Weight=1 > diff --git a/projectroot/etc/repart.rc-once.d/20-root.conf b/projectroot/etc/repart.rc-once.d/20-root.conf > new file mode 100644 > index 000000000000..3408b6ad156a > --- /dev/null > +++ b/projectroot/etc/repart.rc-once.d/20-root.conf > @@ -0,0 +1,6 @@ > +[Partition] > +Label=root-B > +Type=root > +SizeMinBytes=200M > +Weight=1 > +Format=ext4 > diff --git a/projectroot/etc/repart.rc-once.d/30-data.conf b/projectroot/etc/repart.rc-once.d/30-data.conf > new file mode 100644 > index 000000000000..cc5aebfd87d3 > --- /dev/null > +++ b/projectroot/etc/repart.rc-once.d/30-data.conf > @@ -0,0 +1,6 @@ > +[Partition] > +Label=data > +Type=linux-generic > +SizeMinBytes=200M > +Weight=999999 > +Format=ext4 > diff --git a/projectroot/usr/lib/systemd/system/systemd-autoformat@.service b/projectroot/usr/lib/systemd/system/systemd-autoformat@.service > deleted file mode 100644 > index 75221403398c..000000000000 > --- a/projectroot/usr/lib/systemd/system/systemd-autoformat@.service > +++ /dev/null > @@ -1,15 +0,0 @@ > -[Unit] > -Before=mnt-data.mount systemd-fsck@%i.service > -Description=Create ext4 Data Partition > -ConditionPathExists=/dev/%i > - > -[Service] > -Environment=DATAPARTITION=3 > -Type=oneshot > -# resize partition to maximum > -ExecStart=/bin/sh -c 'echo ",+" | sfdisk --force -N$DATAPARTITION /dev/mmcblk0' > -# force kernel to reload the partition size of partition 3 > -ExecStart=/usr/sbin/partx -d -n $DATAPARTITION /dev/mmcblk0 > -ExecStart=/usr/sbin/partx -a -n $DATAPARTITION /dev/mmcblk0 > -# create filesystem (this service is only started if we have none) > -ExecStart=/sbin/mkfs.ext4 /dev/%i > diff --git a/projectroot/usr/lib/udev/rules.d/91-mkfs-ext4.rules b/projectroot/usr/lib/udev/rules.d/91-mkfs-ext4.rules > deleted file mode 100644 > index 8af8f6cd39ba..000000000000 > --- a/projectroot/usr/lib/udev/rules.d/91-mkfs-ext4.rules > +++ /dev/null > @@ -1,5 +0,0 @@ > -ACTION!="add", GOTO="systemd-autoformat-ext4-devices_end" > -SUBSYSTEM!="block", GOTO="systemd-autoformat-ext4-devices_end" > -ENV{ID_FS_USAGE}!="filesystem", SUBSYSTEMS=="mmc", KERNEL=="mmcblk0p3", ENV{ID_PART_ENTRY_TYPE}=="0x83", ENV{ID_FS_TYPE}!="ext4", ENV{SYSTEMD_WANTS}+="systemd-autoformat@$name.service" > - > -LABEL="systemd-autoformat-ext4-devices_end" > diff --git a/rules/datapartition.in b/rules/datapartition.in > index 4343e7c4e430..5b8c737fb8ad 100644 > --- a/rules/datapartition.in > +++ b/rules/datapartition.in > @@ -2,4 +2,7 @@ > > config DATAPARTITION > tristate > + select RC_ONCE > + select SYSTEMD > + select SYSTEMD_REPART > default y > diff --git a/rules/datapartition.make b/rules/datapartition.make > index b79bcf01efcc..808448033eee 100644 > --- a/rules/datapartition.make > +++ b/rules/datapartition.make > @@ -1,6 +1,7 @@ > # -*-makefile-*- > # > # Copyright (C) 2016 by Robert Schwebel > +# Copyright (C) 2023 Roland Hieber, Pengutronix > # > # For further information about the PTXdist project and license conditions > # see the README file. > @@ -26,10 +27,12 @@ $(STATEDIR)/datapartition.targetinstall: > @$(call install_fixup,datapartition,AUTHOR,"Robert Schwebel ") > @$(call install_fixup,datapartition,DESCRIPTION,missing) > > - @$(call install_alternative, datapartition, 0, 0, 0644, \ > - /usr/lib/systemd/system/systemd-autoformat@.service) > - @$(call install_alternative, datapartition, 0, 0, 0644, \ > - /usr/lib/udev/rules.d/91-mkfs-ext4.rules) > + @# Note: we only want to call systemd-repart in rc-once, so don't > + @# install the configs to any path picked up by systemd-repart.service > + @$(call install_alternative_tree, datapartition, 0, 0, \ > + /etc/repart.rc-once.d/) > + @$(call install_alternative, datapartition, 0, 0, 0755, \ > + /etc/rc.once.d/repart) > > @$(call install_finish,datapartition) > > -- > 2.39.2 > > > -- Roland Hieber, Pengutronix e.K. | r.hieber@pengutronix.de | Steuerwalder Str. 21 | https://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |