ptgen: do not create stub partition to fill a gap if gap caused by alignment
authorMikhail Kshevetskiy <[email protected]>
Mon, 30 Dec 2024 02:28:49 +0000 (05:28 +0300)
committerDaniel Golle <[email protected]>
Tue, 23 Sep 2025 22:15:33 +0000 (23:15 +0100)
ptgen tends to create stub partitions between the end of GPT entry table
and the start of the first disk. Normally fdisk/gdisk aligns partition
to 1MB boundary, so there is 2014 sectors gap before the first partition.
It is absolutely normal.

This patch somehow mimics fdisk/gdisk behavior and does NOT create stub
partition in the gap caused by alignment.

Signed-off-by: Mikhail Kshevetskiy <[email protected]>
src/ptgen.c

index cc5e744de85fce3712540b0f1b7e08692966255b..37eeac05db76da2762c3aa0c2ebd074a0b474042 100644 (file)
@@ -478,7 +478,8 @@ static int gen_gptable(uint32_t signature, guid_t guid, unsigned nr)
                printf("%" PRIu64 "\n", (sect - start) * DISK_SECTOR_SIZE);
        }
 
-       if (parts[0].actual_start > GPT_FIRST_ENTRY_SECTOR + GPT_SIZE) {
+       if ((parts[0].start != 0) &&
+           (parts[0].actual_start > GPT_FIRST_ENTRY_SECTOR + GPT_SIZE)) {
                gpte[GPT_ENTRY_MAX - 1].start = cpu_to_le64(GPT_FIRST_ENTRY_SECTOR + GPT_SIZE);
                gpte[GPT_ENTRY_MAX - 1].end = cpu_to_le64(parts[0].actual_start - 1);
                gpte[GPT_ENTRY_MAX - 1].type = GUID_PARTITION_BIOS_BOOT;