aboutsummaryrefslogtreecommitdiffstats
path: root/disk-utils/sfdisk.c
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2024-09-02 14:04:18 +0200
committerKarel Zak <kzak@redhat.com>2024-09-02 14:09:55 +0200
commit4877d7f61a72e46aba3fc52f347d1cd74124dba5 (patch)
tree0c0f4f6c44300f464c53eb561aa2795f1fbe5b9c /disk-utils/sfdisk.c
parent728659867e56378542ec86a3229a3d7cc973c76e (diff)
downloadutil-linux-4877d7f61a72e46aba3fc52f347d1cd74124dba5.tar.gz
sfdisk: ignore last-lba from script on --force
The last LBA depends on the disk size. It seems like a good idea to ignore it when using the --force option, in order to make it possible to apply the script on smaller disks. Addresses: https://github.com/util-linux/util-linux/issues/3186 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/sfdisk.c')
-rw-r--r--disk-utils/sfdisk.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c
index 0575373dca..71b0191d21 100644
--- a/disk-utils/sfdisk.c
+++ b/disk-utils/sfdisk.c
@@ -1925,7 +1925,14 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
ignored++;
continue;
}
- if (!created) { /* create a new disklabel */
+ if (!created) {
+ /* ignore "last-lba" and use default if --force specified */
+ if (sf->force && fdisk_script_get_header(dp, "last-lba")) {
+ fdisk_info(sf->cxt, _("Ignoring last-lba script header."));
+ fdisk_script_set_header(dp, "last-lba", NULL);
+ }
+
+ /* create a new disklabel */
rc = fdisk_apply_script_headers(sf->cxt, dp);
created = !rc;
if (rc) {
@@ -1933,7 +1940,6 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
fdisk_warn(sf->cxt, _(
"Failed to apply script headers, disk label not created"));
}
-
if (rc == 0 && fdisk_get_collision(sf->cxt))
follow_wipe_mode(sf);
}