From f1f98b0b8456e89f6c959d8f028c5204da82365e Mon Sep 17 00:00:00 2001 From: Mikhail Kshevetskiy Date: Mon, 30 Dec 2024 05:28:49 +0300 Subject: [PATCH] ptgen: do not create stub partition to fill a gap if gap caused by alignment 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 --- src/ptgen.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ptgen.c b/src/ptgen.c index cc5e744..37eeac0 100644 --- a/src/ptgen.c +++ b/src/ptgen.c @@ -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; -- 2.30.2