mkswap: support -U {clear,random,time,uuid}

Let's follow -U from mkfs.ext4 and make it easy to fully control
UUIDs for the swap area.

Signed-off-by: Karel Zak <>
This commit is contained in:
Karel Zak 2021-09-23 11:53:26 +02:00
parent 10fd91d389
commit 54ef08ed37
2 changed files with 18 additions and 2 deletions

View 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 the filesystem UUID
generate a new randomly-generated UUID
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).)

View File

@ -172,6 +172,7 @@ static void __attribute__((__noreturn__)) usage(void)
_(" --lock[=<mode>] use exclusive device lock (%s, %s or %s)\n"), "yes", "no", "nonblock");
@ -541,7 +542,13 @@ int main(int argc, char **argv)
if(opt_uuid) {
if (uuid_parse(opt_uuid, uuid_dat) != 0)
if (strcmp(opt_uuid, "clear") == 0)
else if (strcmp(opt_uuid, "random") == 0)
else if (strcmp(opt_uuid, "time") == 0)
else if (uuid_parse(opt_uuid, uuid_dat) != 0)
errx(EXIT_FAILURE, _("error: parsing UUID failed"));
} else