From: LaMont Jones Date: Sun, 27 Jan 2008 06:27:27 +0000 (-0700) Subject: mkswap: Set UUID for swap space X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19326ffd497c1987bdc50c67d101b761ea331dff;p=util-linux mkswap: Set UUID for swap space Sent to me by: Martin Schulze : 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 --- diff --git a/disk-utils/mkswap.8 b/disk-utils/mkswap.8 index f4661c24..db7e6de3 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. + .SH "SEE ALSO" .BR fdisk (8), .BR swapon (8) diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index 2394368b..59385f22 100644 --- a/disk-utils/mkswap.c +++ b/disk-utils/mkswap.c @@ -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 */