]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
id128: add 'var-partition-uuid' verb
authorLuca Boccassi <bluca@debian.org>
Tue, 16 Jul 2024 15:53:08 +0000 (16:53 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 17 Jul 2024 16:05:40 +0000 (18:05 +0200)
As per DPS the UUID for /var/ should be keyed by the local machine-id,
which is non-trivial to do in a script. Enhance 'systemd-id128' to
take 'var-partition-uuid' as a verb, and if so perform the
calculation.

man/systemd-gpt-auto-generator.xml
man/systemd-id128.xml
shell-completion/bash/systemd-id128
src/id128/id128.c
test/units/TEST-74-AUX-UTILS.id128.sh

index 0893b3f4e8216b5b5a9626f07d84608fbcc1d330..07587f289b18315f574af9ad4c90bd338f2ab2e3 100644 (file)
             <entry><constant>4d21b016-b534-45c2-a9fb-5c16e091fd2d</constant></entry>
             <entry>Variable Data Partition</entry>
             <entry><filename>/var/</filename></entry>
-            <entry>The first partition with this type UUID on the same disk as the root partition is mounted to <filename>/var/</filename> — under the condition its partition UUID matches the first 128 bit of the HMAC-SHA256 of the GPT type uuid of this partition keyed by the machine ID of the installation stored in <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</entry>
+            <entry>The first partition with this type UUID on the same disk as the root partition is mounted
+            to <filename>/var/</filename> — under the condition its partition UUID matches the first 128 bit
+            of the HMAC-SHA256 of the GPT type uuid of this partition keyed by the machine ID of the
+            installation stored in
+            <citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
+            This can be generated using <citerefentry><refentrytitle>systemd-id128</refentrytitle><manvolnum>1</manvolnum></citerefentry>.</entry>
           </row>
           <row>
             <entry><constant>SD_GPT_TMP</constant></entry>
index e23532d65d883b0d3b5969000de13729930d590e..126facf7e966604c48c560346ebdaea92e370a6d 100644 (file)
       <arg choice="plain">invocation-id</arg>
     </cmdsynopsis>
 
+    <cmdsynopsis>
+      <command>systemd-id128</command>
+      <arg choice="opt" rep="repeat">OPTIONS</arg>
+      <arg choice="plain">var-partition-uuid</arg>
+    </cmdsynopsis>
+
     <cmdsynopsis>
       <command>systemd-id128</command>
       <arg choice="opt" rep="repeat">OPTIONS</arg>
     <citerefentry><refentrytitle>sd_id128_get_machine</refentrytitle><manvolnum>3</manvolnum></citerefentry>
     for the discussion when this is useful. Support for <command>show --app-specific=</command> was added in
     version 255.</para>
+
+    <para><command>var-partition-uuid</command> prints a UUID which, following the <ulink
+    url="https://uapi-group.org/specifications/specs/discoverable_partitions_specification">Discoverable
+    Partitions Specification</ulink>, should be used as the GPT partition UUID for
+    <filename>/var/</filename>, being derived from the GPT partition type, keyed by the local
+    <filename>/etc/machine-id</filename>. Added in version 257.</para>
   </refsect1>
 
   <refsect1>
index 54d4ec8f7a554c9773aba96ed98d0b3d92f9e6e8..a072770438fb5e1f8e9f3aad7d6b741533ebc71f 100644 (file)
@@ -34,7 +34,7 @@ _systemd_id128() {
     )
 
     local -A VERBS=(
-        [STANDALONE]='new machine-id boot-id invocation-id help'
+        [STANDALONE]='new machine-id boot-id invocation-id var-partition-uuid help'
         [ARG]='show'
     )
 
index 6d62538da95c5dd214311665051b9e0a07beb695..ed444c8022e4f1069075239c579a2418b8409f4c 100644 (file)
@@ -71,6 +71,22 @@ static int verb_invocation_id(int argc, char **argv, void *userdata) {
         return id128_pretty_print(id, arg_mode);
 }
 
+static int verb_var_uuid(int argc, char **argv, void *userdata) {
+        sd_id128_t id;
+        int r;
+
+        if (!sd_id128_is_null(arg_app))
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Verb \"var-partition-uuid\" cannot be combined with --app-specific=.");
+
+        /* The DPS says that the UUID for /var/ should be keyed with machine-id. */
+        r = sd_id128_get_machine_app_specific(SD_GPT_VAR, &id);
+        if (r < 0)
+                return log_error_errno(r, "Failed to generate machine-specific /var/ UUID: %m");
+
+        return id128_pretty_print(id, arg_mode);
+}
+
 static int show_one(Table **table, const char *name, sd_id128_t uuid, bool first) {
         int r;
 
@@ -180,6 +196,7 @@ static int help(void) {
                "  machine-id              Print the ID of current machine\n"
                "  boot-id                 Print the ID of current boot\n"
                "  invocation-id           Print the ID of current invocation\n"
+               "  var-partition-uuid      Print the UUID for the /var/ partition\n"
                "  show [NAME|UUID]        Print one or more UUIDs\n"
                "  help                    Show this help\n"
                "\nOptions:\n"
@@ -295,12 +312,13 @@ static int parse_argv(int argc, char *argv[]) {
 
 static int id128_main(int argc, char *argv[]) {
         static const Verb verbs[] = {
-                { "new",            VERB_ANY, 1,        0,  verb_new           },
-                { "machine-id",     VERB_ANY, 1,        0,  verb_machine_id    },
-                { "boot-id",        VERB_ANY, 1,        0,  verb_boot_id       },
-                { "invocation-id",  VERB_ANY, 1,        0,  verb_invocation_id },
-                { "show",           VERB_ANY, VERB_ANY, 0,  verb_show          },
-                { "help",           VERB_ANY, VERB_ANY, 0,  verb_help          },
+                { "new",                VERB_ANY, 1,        0,  verb_new           },
+                { "machine-id",         VERB_ANY, 1,        0,  verb_machine_id    },
+                { "boot-id",            VERB_ANY, 1,        0,  verb_boot_id       },
+                { "invocation-id",      VERB_ANY, 1,        0,  verb_invocation_id },
+                { "var-partition-uuid", VERB_ANY, 1,        0,  verb_var_uuid      },
+                { "show",               VERB_ANY, VERB_ANY, 0,  verb_show          },
+                { "help",               VERB_ANY, VERB_ANY, 0,  verb_help          },
                 {}
         };
 
index f91cd5f78d63eee7de3b3cf9043a844426305aed..b9db1f1454215c87a96b13b96d95e779507c3a89 100755 (executable)
@@ -28,6 +28,8 @@ systemd-id128 show --json=short
 systemd-id128 show --no-legend
 systemd-id128 show --no-pager --no-legend
 systemd-id128 show root -P -u
+[[ -n "$(systemd-id128 var-partition-uuid)" ]]
+[[ "$(systemd-id128 var-partition-uuid)" != "4d21b016b53445c2a9fb5c16e091fd2d" ]]
 
 [[ "$(systemd-id128 new | wc -c)" -eq 33 ]]
 systemd-id128 new -p