]> err.no Git - util-linux/commitdiff
mkswap: Set UUID for swap space
authorLaMont Jones <lamont@debian.org>
Sun, 27 Jan 2008 06:27:27 +0000 (23:27 -0700)
committerLaMont Jones <lamont@debian.org>
Sun, 27 Jan 2008 06:37:34 +0000 (23:37 -0700)
Sent to me by: Martin Schulze <joey@infodrom.org>:

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.

His reseach lead him to

https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/66637

which refers to a patched version of mkswap:

http://free.nchc.org.tw/drbl-core/old/src/mkswap-uuid-0.1.0-2.tar.bz2
I'm attaching it for reference and in case the above URL becomes void.

It would be nice if you could apply this patch and send it upstream.

It's essential when partitions are to be recognised by their uuid and
not by their old device path anymore.

Regards,

        Joey

Addresses-Debian-Bug: 462662
Addresses-Ubuntu-Bug: 66637
Signed-off-by: LaMont Jones <lamont@debian.org>
disk-utils/mkswap.8
disk-utils/mkswap.c

index f4661c24aa8ba717544b6dd5d3766ba38e09deef..db7e6de3bd234c62327c5cb1a7c5dd255b2042b2 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.
+
 .SH "SEE ALSO"
 .BR fdisk (8),
 .BR swapon (8)
index 2394368b721326ab0144cb07254ebd6e82dabc30..59385f2272952620b1d9b1b1ae836d69c0ebd662 100644 (file)
@@ -351,7 +351,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);
 }
@@ -501,6 +501,8 @@ main(int argc, char ** argv) {
        char *pp;
        char *opt_label = NULL;
        unsigned char *uuid = NULL;
+       unsigned char *uuid_input = NULL;
+       int set_uuid = 0; // User Defined UUID, o: False, 1: True
 #ifdef HAVE_LIBUUID
        uuid_t uuid_dat;
 #endif
@@ -546,6 +548,12 @@ main(int argc, char ** argv) {
                                case 'v':
                                        version = atoi(argv[i]+2);
                                        break;
+                               case 'U':
+                                       set_uuid = 1;
+                                       uuid_input = argv[i]+2;
+                                       if (!*uuid_input && i+1 < argc)
+                                               uuid_input = argv[++i];
+                                       break;
                                default:
                                        usage();
                        }
@@ -558,8 +566,14 @@ main(int argc, char ** argv) {
        }
 
 #ifdef HAVE_LIBUUID
-       uuid_generate(uuid_dat);
-       uuid = uuid_dat;
+       if(!set_uuid)
+       {
+         uuid_generate(uuid_dat);
+         uuid = uuid_dat;
+       } else {
+         uuid_parse(uuid_input, uuid_dat);
+         uuid = uuid_dat;
+       }
 #endif
 
        init_signature_page();  /* get pagesize */