From 29decc7b374ab522bbcf814c3e0536b090a3aac5 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 15 Oct 2020 12:04:15 +0200 Subject: [PATCH] sfdisk: disable bootbits protection on '--wipe always' Addresses: https://github.com/karelzak/util-linux/issues/1156 Signed-off-by: Karel Zak --- disk-utils/sfdisk.8 | 14 ++++++++++++-- disk-utils/sfdisk.c | 6 ++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/disk-utils/sfdisk.8 b/disk-utils/sfdisk.8 index bd5a2b11d..b993d955c 100644 --- a/disk-utils/sfdisk.8 +++ b/disk-utils/sfdisk.8 @@ -36,6 +36,14 @@ never been important for Linux, and this addressing concept does not make any sense for new devices. .sp .B sfdisk +protects the first disk sector when create a new disk label. +The option \fB\-\-wipe always\fR disables this protection. Note that +.BR fdisk (8) +and +.BR cfdisk (8) +completely erase this area by default. +.sp +.B sfdisk (since version 2.26) .B aligns the start and end of partitions to block-device I/O limits when relative sizes are specified, when the default @@ -315,8 +323,10 @@ to avoid possible collisions. The argument \fIwhen\fR can be \fBauto\fR, \fBnever\fR or \fBalways\fR. When this option is not given, the default is \fBauto\fR, in which case signatures are wiped only when in interactive mode; except the old partition-table signatures which are always wiped before create -a new partition-table if the argument \fIwhen\fR is not \fBnever\fR. In all -cases detected signatures are reported by warning messages before a new +a new partition-table if the argument \fIwhen\fR is not \fBnever\fR. +The \fBauto\fR mode also does not wipe the first sector (boot sector), it is +necessary to use the \fBalways\fR mode to wipe this area. +In all cases detected signatures are reported by warning messages before a new partition table is created. See also the .BR wipefs (8) command. diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index 54d3b60e7..2e8d7ea0e 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -230,7 +230,9 @@ static void sfdisk_init(struct sfdisk *sf) if (!sf->cxt) err(EXIT_FAILURE, _("failed to allocate libfdisk context")); fdisk_set_ask(sf->cxt, ask_callback, (void *) sf); - fdisk_enable_bootbits_protection(sf->cxt, 1); + + if (sf->wipemode != WIPEMODE_ALWAYS) + fdisk_enable_bootbits_protection(sf->cxt, 1); if (sf->label_nested) { struct fdisk_context *x = fdisk_new_nested_context(sf->cxt, @@ -1627,7 +1629,7 @@ static void follow_wipe_mode(struct sfdisk *sf) if (dowipe) { if (!fdisk_is_ptcollision(sf->cxt)) { fdisk_warnx(sf->cxt, _( - "The device contains '%s' signature and it will be removed by a write command. " + "The device contains '%s' signature and it may be removed by a write command. " "See sfdisk(8) man page and --wipe option for more details."), fdisk_get_collision(sf->cxt)); fputc('\n', stdout);