From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Fri, 03 Nov 2023 19:24:48 +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.94.2) (envelope-from ) id 1qyyqe-00HSfU-Ax for lore@lore.pengutronix.de; Fri, 03 Nov 2023 19:24:48 +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 1qyyqc-00046c-V7; Fri, 03 Nov 2023 19:24:46 +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 1qyyqW-0003zh-M5; Fri, 03 Nov 2023 19:24:40 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.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 1qyyqW-006Nqx-46; Fri, 03 Nov 2023 19:24:40 +0100 Received: from rhi by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1qyyqW-004Pak-0E; Fri, 03 Nov 2023 19:24:40 +0100 From: Roland Hieber To: distrokit@pengutronix.de Date: Fri, 3 Nov 2023 19:24:33 +0100 Message-Id: <20231103182438.1051601-5-rhi@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231103182438.1051601-1-rhi@pengutronix.de> References: <20231103182438.1051601-1-rhi@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [DistroKit] [PATCH 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: , Cc: Roland Hieber 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 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 --- 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