From: Roland Hieber <rhi@pengutronix.de>
To: distrokit@pengutronix.de
Cc: Roland Hieber <rhi@pengutronix.de>
Subject: [DistroKit] [PATCH 05/10] datapartition: generate partitions via systemd-repart
Date: Fri, 3 Nov 2023 19:24:33 +0100 [thread overview]
Message-ID: <20231103182438.1051601-5-rhi@pengutronix.de> (raw)
In-Reply-To: <20231103182438.1051601-1-rhi@pengutronix.de>
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 <rhi@pengutronix.de>
---
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 <r.schwebel@pengutronix.de>
+# Copyright (C) 2023 Roland Hieber, Pengutronix <rhi@pengutronix.de>
#
# 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 <r.schwebel@pengutronix.de>")
@$(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
next prev parent reply other threads:[~2023-11-03 18:24 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-03 18:24 [DistroKit] [PATCH 01/10] treewide: images: unify partition labels Roland Hieber
2023-11-03 18:24 ` [DistroKit] [PATCH 02/10] v7a: image-stm32mp: set GPT Partition Type UUID Roland Hieber
2023-11-06 8:21 ` Ahmad Fatoum
2023-11-03 18:24 ` [DistroKit] [PATCH 03/10] treewide: images: remove size specifications for root partitions Roland Hieber
2023-11-06 8:21 ` Ahmad Fatoum
2023-11-06 9:40 ` Roland Hieber
2023-11-06 9:41 ` Ahmad Fatoum
2023-11-03 18:24 ` [DistroKit] [PATCH 04/10] treewide: images: increase size of all qemu images to 1 GiB Roland Hieber
2023-11-03 18:24 ` Roland Hieber [this message]
2023-11-03 18:24 ` [DistroKit] [PATCH 06/10] datapartition: add missing mount unit Roland Hieber
2023-11-03 18:24 ` [DistroKit] [PATCH 07/10] datapartition: set license Roland Hieber
2023-11-03 18:24 ` [DistroKit] [PATCH 08/10] treewide: images: remove root-B and data partitions Roland Hieber
2023-11-03 18:24 ` [DistroKit] [PATCH 09/10] rauc-udev: generate symlinks based on GPT partition labels Roland Hieber
2023-11-03 18:24 ` [DistroKit] [PATCH 10/10] v7a: barebox: bootchooser: use " Roland Hieber
2023-11-06 11:43 ` [DistroKit] [PATCH 01/10] treewide: images: unify " Robert Schwebel
2023-11-06 11:50 ` Robert Schwebel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231103182438.1051601-5-rhi@pengutronix.de \
--to=rhi@pengutronix.de \
--cc=distrokit@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox