summaryrefslogtreecommitdiffstats
path: root/disk-utils/mkswap.c
diff options
context:
space:
mode:
authorKarel Zak2009-03-12 16:01:59 +0100
committerKarel Zak2009-03-12 16:01:59 +0100
commitff3bed806863d1c2075d0efda70b39ea6af9ecba (patch)
treef6419d715aefe7da1fc9d367fc4fc151ccfba5e3 /disk-utils/mkswap.c
parentlibs: pttype - fix typo (diff)
downloadkernel-qcow2-util-linux-ff3bed806863d1c2075d0efda70b39ea6af9ecba.tar.gz
kernel-qcow2-util-linux-ff3bed806863d1c2075d0efda70b39ea6af9ecba.tar.xz
kernel-qcow2-util-linux-ff3bed806863d1c2075d0efda70b39ea6af9ecba.zip
mkswap: zap bootbits
/dev/sdb1 originally initialized by cryptsetup: and OLD mkswap: # vol_id /dev/sdb1 | grep TYPE ID_FS_TYPE=swap # blkid -s TYPE /dev/sdb1 /dev/sdb1: TYPE="crypt_LUKS" So, we have two different *valid* signatures on the device now! NEW mkswap: # blkid -s TYPE /dev/sdb1 /dev/sdb1: TYPE="swap" # /lib/udev/vol_id /dev/sdb1 | grep TYPE ID_FS_TYPE=swap the bootbits (first 1024 bytes) was erased. We shouldn't zap disk labels (BSD, SUN, ...) and boot loaders (on whole disk): # mkswap /dev/sdb2 mkswap: /dev/sdb2: warning: don't erase bootbits sectors (BSD partition table detected). Use -f to force. Setting up swapspace version 1, size = 4348 KiB no label, UUID=69d87cef-71ac-4fb0-a689-ce3e930dea17 # mkswap /dev/sdb mkswap: /dev/sdb: warning: don't erase bootbits sectors on whole disk. Use -f to force. Setting up swapspace version 1, size = 8188 KiB no label, UUID=97757ad7-8a84-43d9-bcb4-16fefd93a2ac Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/mkswap.c')
-rw-r--r--disk-utils/mkswap.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c
index 6e151af38..4acc73b23 100644
--- a/disk-utils/mkswap.c
+++ b/disk-utils/mkswap.c
@@ -53,6 +53,8 @@
#include "nls.h"
#include "blkdev.h"
#include "pathnames.h"
+#include "pttype.h"
+#include "wholedisk.h"
#ifdef HAVE_LIBUUID
#include <uuid/uuid.h>
@@ -379,6 +381,47 @@ write_all(int fd, const void *buf, size_t count) {
return 0;
}
+static void
+zap_bootbits(int fd, const char *devname, int force)
+{
+ const char *type = NULL;
+ int zap = 1;
+
+ if (!force) {
+ if (lseek(fd, 0, SEEK_SET) != 0)
+ die(_("unable to rewind swap-device"));
+
+ if (is_whole_disk_fd(fd, devname))
+ /* don't zap bootbits on whole disk -- we know nothing
+ * about bootloaders on the device */
+ zap = 0;
+
+ else if ((type = get_pt_type_fd(fd)))
+ /* don't zap partition table */
+ zap = 0;
+ }
+
+ if (zap) {
+ char buf[1024];
+
+ if (lseek(fd, 0, SEEK_SET) != 0)
+ die(_("unable to rewind swap-device"));
+
+ memset(buf, 0, sizeof(buf));
+ if (write_all(fd, buf, sizeof(buf)))
+ die(_("unable to erase bootbits sectors"));
+ return;
+ }
+
+ fprintf(stderr, _("%s: %s: warning: don't erase bootbits sectors\n"),
+ program_name, devname);
+ if (type)
+ fprintf(stderr, _(" (%s partition table detected). "), type);
+ else
+ fprintf(stderr, _(" on whole disk. "));
+ fprintf(stderr, "Use -f to force.\n");
+}
+
int
main(int argc, char ** argv) {
struct stat statbuf;
@@ -561,6 +604,8 @@ main(int argc, char ** argv) {
if (check)
check_blocks();
+ zap_bootbits(DEV, device_name, force);
+
p->version = 1;
p->last_page = PAGES-1;
p->nr_badpages = badpages;