[PATCH] mkswap: Set UUID for swap space

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sent to me by: Martin Schulze <joey@xxxxxxxxxxxx>:

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

Signed-off-by: LaMont Jones <lamont@xxxxxxxxxx>
---
 disk-utils/mkswap.8 |    6 +++++-
 disk-utils/mkswap.c |   20 +++++++++++++++++---
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/disk-utils/mkswap.8 b/disk-utils/mkswap.8
index f4661c2..db7e6de 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 bb12672..79dde72 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);
 }
@@ -478,6 +478,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
@@ -523,6 +525,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();
 			}
@@ -535,8 +543,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 */
-- 
1.5.3.8

-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux