]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
gpt-auto symlinks: take factory reset mode into consideration
authorLennart Poettering <lennart@poettering.net>
Fri, 21 Feb 2025 16:18:12 +0000 (17:18 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 5 Mar 2025 11:38:25 +0000 (12:38 +0100)
In relevant factory reset situation the root disk itself is subject to
removal. This somewhat conflicts with automatic root disk discovery,
since the system first comes up with one candidate for the root disk,
which is then replaced by another.

Let's address this by determining at the moment of probing for the
gpt-root logic what the factory reset state currently is. This is then
used to maintain two distinct symlinks to the gpt auto root device: one
which is always available and one that is only available if factory
reset is off or complete.

The new symlinks is not used by anything yet. This will be added in a
later commit.

rules.d/99-systemd.rules.in

index ae05c75bb532a0735877b960b89cae4ee78a4006..3fd3ea3ecd05d065f8cf5f2f7c3eb8dc443da439 100644 (file)
@@ -34,10 +34,25 @@ SUBSYSTEM=="block", ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}=="1", ENV{SYSTEMD_READ
 # we are probably still calling mke2fs or mkswap on it.
 SUBSYSTEM=="block", ENV{DM_UUID}=="CRYPT-*", ENV{ID_PART_TABLE_TYPE}=="", ENV{ID_FS_USAGE}=="", ENV{SYSTEMD_READY}="0"
 
-# add symlink to GPT root disk
-SUBSYSTEM=="block", ENV{ID_PART_GPT_AUTO_ROOT}=="1", ENV{ID_FS_TYPE}!="crypto_LUKS", SYMLINK+="gpt-auto-root"
-SUBSYSTEM=="block", ENV{ID_PART_GPT_AUTO_ROOT}=="1", ENV{ID_FS_TYPE}=="crypto_LUKS", SYMLINK+="gpt-auto-root-luks"
-SUBSYSTEM=="block", ENV{DM_UUID}=="CRYPT-*", ENV{DM_NAME}=="root", SYMLINK+="gpt-auto-root"
+# Add symlink to GPT root disk – in two flavours: one which takes the factory
+# reset state into account, and one which does not. The former is useful for
+# wipe-rootfs-on-factory-reset scenarios where we should not be tempted to use
+# the root fs before factory reset is complete. The latter is useful for
+# wipe-only-/var-on-factory-reset where we should use it (because that's where
+# repart.d/ definitions are placed which tell us what to wipe).
+SUBSYSTEM!="block", GOTO="gpt_auto_root_end"
+ENV{ID_PART_GPT_AUTO_ROOT}!="1", GOTO="gpt_auto_root_end"
+IMPORT{builtin}="factory_reset status"
+ENV{ID_FS_TYPE}!="crypto_LUKS", ENV{ID_FACTORY_RESET}!="on", SYMLINK+="gpt-auto-root"
+ENV{ID_FS_TYPE}!="crypto_LUKS", ENV{ID_FACTORY_RESET}=="on|complete", SYMLINK+="gpt-auto-root-ignore-factory-reset"
+ENV{ID_FS_TYPE}=="crypto_LUKS", ENV{ID_FACTORY_RESET}!="on", SYMLINK+="gpt-auto-root-luks"
+ENV{ID_FS_TYPE}=="crypto_LUKS", ENV{ID_FACTORY_RESET}=="on|complete", SYMLINK+="gpt-auto-root-luks-ignore-factory-reset"
+LABEL="gpt_auto_root_end"
+# Note we don't need to condition the gpt-auto-root LUKS symlink for
+# auto-discovered LUKS devices, because it's sufficient if we do this for the
+# underlying partition block device, which is covered by the above.
+SUBSYSTEM=="block", ENV{DM_UUID}=="CRYPT-*", ENV{DM_NAME}=="root", SYMLINK+="gpt-auto-root", IMPORT{builtin}="factory_reset status"
+SUBSYSTEM=="block", ENV{DM_UUID}=="CRYPT-*", ENV{DM_NAME}=="root", ENV{ID_FACTORY_RESET}=="on|complete", SYMLINK+="gpt-auto-root-ignore-factory-reset"
 
 # Ignore raid devices that are not yet assembled and started
 SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", KERNEL=="md*", TEST!="md/array_state", ENV{SYSTEMD_READY}="0"