From 93bf0f285d2479a9cccfa569d0fa70377b531f81 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sat, 26 Jan 2008 23:31:06 -0700 Subject: [PATCH] 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 --- disk-utils/mkswap.8 | 6 +++++- disk-utils/mkswap.c | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/disk-utils/mkswap.8 b/disk-utils/mkswap.8 index f4661c24..2f5f0a88 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 bb126726..e2eafa54 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 -- 2.39.5