]> err.no Git - util-linux/commitdiff
mkswap: set UUID for swap space (add -U option)
authorMartin Schulze <joey@infodrom.org>
Sun, 27 Jan 2008 06:31:06 +0000 (23:31 -0700)
committerKarel Zak <kzak@redhat.com>
Fri, 15 Feb 2008 00:31:50 +0000 (01:31 +0100)
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 <lamont@debian.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/mkswap.8
disk-utils/mkswap.c

index f4661c24aa8ba717544b6dd5d3766ba38e09deef..2f5f0a8801f2ee714ea3d4c002308d3e7310d2c5 100644 (file)
@@ -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)
index bb126726b72009309b88b543d41aa36e5fdd2938..e2eafa542940076d234e719806945b2a849a7f02 100644 (file)
@@ -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