]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sfdisk: ignore last-lba from script on --force
authorKarel Zak <kzak@redhat.com>
Mon, 2 Sep 2024 12:04:18 +0000 (14:04 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 2 Sep 2024 12:09:55 +0000 (14:09 +0200)
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>
disk-utils/sfdisk.8.adoc
disk-utils/sfdisk.c

index bc3ff9bb87998fe0d12c81728d78d9227d1563a4..b2e5279d268d7f6fcd73a40778ea6f7c3856c8d7 100644 (file)
@@ -243,7 +243,7 @@ Specify the partition table identifier. It should be a hexadecimal number (with
 *first-lba*::
 Specify the first usable sector for GPT partitions. This header is ignored if the script and device sector size differ. In this case *sfdisk* uses label specific default.
 *last-lba*::
-Specify the last usable sector for GPT partitions. This header is ignored if the script and device sector size differ. In this case *sfdisk* uses label specific default.
+Specify the last usable sector for GPT partitions. This header is ignored if the script and device sector size differ. In this case *sfdisk* uses label specific default. The last-lba header is ignored if *--force* is specified, making the script usable on disks with different sizes.
 *table-length*::
 Specify the maximal number of GPT partitions.
 *grain*::
index 0575373dcac1ec6c048bf90f31d10246f14393e3..71b0191d212ff54d3759a6af416d84fe3a80d4fb 100644 (file)
@@ -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);
                        }