]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mkswap: support -U {clear,random,time,uuid}
authorKarel Zak <kzak@redhat.com>
Thu, 23 Sep 2021 09:53:26 +0000 (11:53 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 23 Sep 2021 09:53:26 +0000 (11:53 +0200)
Let's follow -U from mkfs.ext4 and make it easy to fully control
UUIDs for the swap area.

Fixes: https://github.com/karelzak/util-linux/issues/1453
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/mkswap.8.adoc
disk-utils/mkswap.c

index 8a305a2e4d8786e9fdcdc07b2c0ebff499c7564d..3a6029f2c2373f0c0b240a3d4c6331ebc456a15c 100644 (file)
@@ -56,7 +56,16 @@ Use exclusive BSD lock for device or file it operates. The optional argument _mo
 Specify the page _size_ (in bytes) to use. This option is usually unnecessary; *mkswap* reads the size from the kernel.
 
 *-U*, *--uuid* _UUID_::
-Specify the _UUID_ to use. The default is to generate a UUID.
+Specify the _UUID_ to use. The default is to generate a UUID. The format of the UUID is a series of
+hex digits separated by hyphens, like this: "c1b9d5a2-f162-11cf-9ece-0020afc76f16". The UUID parameter
+may also be one of the following:
++
+*clear*;;
+clear the filesystem UUID
+*random*;;
+generate a new randomly-generated UUID
+*time*;;
+generate a new time-based UUID
 
 *-v*, *--swapversion 1*::
 Specify the swap-space version. (This option is currently pointless, as the old *-v 0* option has become obsolete and now only *-v 1* is supported. The kernel has not supported v0 swap-space format since 2.5.22 (June 2002). The new version v1 is supported since 2.1.117 (August 1998).)
index c45a3a317e4ba29fd4d56a35523848f861b8fb2e..6221499e04bfa88a056257b0966e64929dd3dd62 100644 (file)
@@ -172,6 +172,7 @@ static void __attribute__((__noreturn__)) usage(void)
 
        fprintf(out,
              _("     --lock[=<mode>]       use exclusive device lock (%s, %s or %s)\n"), "yes", "no", "nonblock");
+
        printf(USAGE_HELP_OPTIONS(27));
 
        printf(USAGE_MAN_TAIL("mkswap(8)"));
@@ -541,7 +542,13 @@ int main(int argc, char **argv)
 
 #ifdef HAVE_LIBUUID
        if(opt_uuid) {
-               if (uuid_parse(opt_uuid, uuid_dat) != 0)
+               if (strcmp(opt_uuid, "clear") == 0)
+                       uuid_clear(uuid_dat);
+               else if (strcmp(opt_uuid, "random") == 0)
+                       uuid_generate_random(uuid_dat);
+               else if (strcmp(opt_uuid, "time") == 0)
+                       uuid_generate_time(uuid_dat);
+               else if (uuid_parse(opt_uuid, uuid_dat) != 0)
                        errx(EXIT_FAILURE, _("error: parsing UUID failed"));
        } else
                uuid_generate(uuid_dat);