summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Schulze2008-01-27 07:31:06 +0100
committerKarel Zak2008-02-15 01:31:50 +0100
commit93bf0f285d2479a9cccfa569d0fa70377b531f81 (patch)
tree6df4473ade57cd46c5fc563afa5fac708c9bc7f3
parentmount: "can't create lock file" message sometimes means failure, sometimes not (diff)
downloadkernel-qcow2-util-linux-93bf0f285d2479a9cccfa569d0fa70377b531f81.tar.gz
kernel-qcow2-util-linux-93bf0f285d2479a9cccfa569d0fa70377b531f81.tar.xz
kernel-qcow2-util-linux-93bf0f285d2479a9cccfa569d0fa70377b531f81.zip
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 <lamont@debian.org> Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--disk-utils/mkswap.86
-rw-r--r--disk-utils/mkswap.c19
2 files changed, 22 insertions, 3 deletions
diff --git a/disk-utils/mkswap.8 b/disk-utils/mkswap.8
index f4661c24a..2f5f0a880 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 bb126726b..e2eafa542 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