From: Martin Schulze Date: Sun, 27 Jan 2008 06:31:06 +0000 (-0700) Subject: mkswap: set UUID for swap space (add -U option) X-Git-Tag: v2.14-rc1~90 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=93bf0f285d2479a9cccfa569d0fa70377b531f81;p=thirdparty%2Futil-linux.git mkswap: set UUID for swap space (add -U option) A friend of mine is looking into the possibility of cloning Debian (and other) systems automatically and stomped over swap partitions getting assigned new UUIDs every time the new harddisk is partitioned and swap is created. It's essential when partitions are to be recognised by their uuid and not by their old device path anymore. Addresses-Ubuntu-Bug: #66637 Signed-off-by: LaMont Jones Signed-off-by: Karel Zak --- diff --git a/disk-utils/mkswap.8 b/disk-utils/mkswap.8 index f4661c24aa..2f5f0a8801 100644 --- a/disk-utils/mkswap.8 +++ b/disk-utils/mkswap.8 @@ -7,7 +7,7 @@ .SH NAME mkswap \- set up a Linux swap area .SH SYNOPSIS -.BI "mkswap [\-c] [\-v" N "] [\-f] [\-p " PSZ "] [\-L " label "] " device " [" size "]" +.BI "mkswap [\-c] [\-v" N "] [\-f] [\-p " PSZ "] [\-L " label "] [\-U " uuid "] " device " [" size "]" .SH DESCRIPTION .B mkswap sets up a Linux swap area on a device or in a file. @@ -156,6 +156,10 @@ when creating the swapspace. Version 0 (-v0) swap space format is no longer supported in 2.5+ kernels. +.TP +.B \-U uuid +Specify the uuid to use. The default is to generate UUIDs. + .SH "SEE ALSO" .BR fdisk (8), .BR swapon (8) diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index bb126726b7..e2eafa5429 100644 --- a/disk-utils/mkswap.c +++ b/disk-utils/mkswap.c @@ -329,7 +329,7 @@ bit_test_and_clear (unsigned long *addr, unsigned int nr) { static void usage(void) { fprintf(stderr, - _("Usage: %s [-c] [-v0|-v1] [-pPAGESZ] [-L label] /dev/name [blocks]\n"), + _("Usage: %s [-c] [-v0|-v1] [-pPAGESZ] [-L label] [-U UUID] /dev/name [blocks]\n"), program_name); exit(1); } @@ -479,6 +479,7 @@ main(int argc, char ** argv) { char *opt_label = NULL; unsigned char *uuid = NULL; #ifdef HAVE_LIBUUID + unsigned char *opt_uuid = NULL; uuid_t uuid_dat; #endif @@ -523,6 +524,16 @@ main(int argc, char ** argv) { case 'v': version = atoi(argv[i]+2); break; + case 'U': +#ifdef HAVE_LIBUUID + opt_uuid = argv[i]+2; + if (!*opt_uuid && i+1 < argc) + opt_uuid = argv[++i]; +#else + fprintf(stderr, _("%1$s: warning: ignore -U (UUIDs are unsupported by %1$s)\n"), + program_name); +#endif + break; default: usage(); } @@ -535,7 +546,11 @@ main(int argc, char ** argv) { } #ifdef HAVE_LIBUUID - uuid_generate(uuid_dat); + if(opt_uuid) { + if (uuid_parse(opt_uuid, uuid_dat) != 0) + die(_("error: UUID parsing failed")); + } else + uuid_generate(uuid_dat); uuid = uuid_dat; #endif