]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
rules: split out gpt-root rules from 99-systemd.rules
authorLennart Poettering <lennart@poettering.net>
Wed, 5 Mar 2025 15:24:32 +0000 (16:24 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 2 Apr 2025 19:32:18 +0000 (04:32 +0900)
All other rules in 99-systemd.rules are pretty much concerned about
SYSTEMD_READY=1 and tagging devices the service manager shall track. But
the gpt-root symlink is different, and it makes sense independently of
the service manager. Hence give it a separate file.

This introduces indentation for inner sections skipped via GOTO=. The
rules parser supports that. In order to make this more readable, let's
maybe make use of this.

rules.d/90-image-dissect.rules [new file with mode: 0644]
rules.d/99-systemd.rules.in
rules.d/meson.build

diff --git a/rules.d/90-image-dissect.rules b/rules.d/90-image-dissect.rules
new file mode 100644 (file)
index 0000000..e606d26
--- /dev/null
@@ -0,0 +1,33 @@
+#  SPDX-License-Identifier: LGPL-2.1-or-later
+#
+#  This file is part of systemd.
+#
+#  systemd is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU Lesser General Public License as published by
+#  the Free Software Foundation; either version 2.1 of the License, or
+#  (at your option) any later version.
+
+ACTION=="remove", GOTO="image_dissect_end"
+SUBSYSTEM!="block", GOTO="image_dissect_end"
+
+# 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).
+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.
+ENV{DM_UUID}=="CRYPT-*", ENV{DM_NAME}=="root", IMPORT{builtin}="factory_reset status", SYMLINK+="gpt-auto-root"
+ENV{DM_UUID}=="CRYPT-*", ENV{DM_NAME}=="root", ENV{ID_FACTORY_RESET}=="on|complete", SYMLINK+="gpt-auto-root-ignore-factory-reset"
+
+LABEL="image_dissect_end"
index 18622d6bf25516d7436d3fe105deb73087064c19..bebc4d7d09cc330cb3680d0e477eb753bd05d688 100644 (file)
@@ -34,26 +34,6 @@ 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 – 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"
 SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", KERNEL=="md*", ATTR{md/array_state}=="|clear|inactive", ENV{SYSTEMD_READY}="0"
index 4ee964c630ae06f7fe4a9d3e21bfc2f23d8a19ed..997cab8699468f42955d970ed29131a606b6595b 100644 (file)
@@ -32,6 +32,7 @@ rules = [
                '80-net-setup-link.rules',
                '81-net-bridge.rules',
                '81-net-dhcp.rules',
+               '90-image-dissect.rules',
                '90-iocost.rules',
               )],