diff --git a/sys/sys/disk/gpt.h b/sys/sys/disk/gpt.h --- a/sys/sys/disk/gpt.h +++ b/sys/sys/disk/gpt.h @@ -82,6 +82,13 @@ CTASSERT(offsetof(struct gpt_hdr, padding) == 92); #endif +/* + * The GPT standard (section 5.3 of UEFI standard version 2.10) requires + * we reserved at least 16k after the PMBR and the GPT header for the gpt + * array entries. + */ +#define GPT_MIN_RESERVED 16384 + struct gpt_ent { gpt_uuid_t ent_type; gpt_uuid_t ent_uuid; diff --git a/usr.bin/mkimg/gpt.c b/usr.bin/mkimg/gpt.c --- a/usr.bin/mkimg/gpt.c +++ b/usr.bin/mkimg/gpt.c @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -129,8 +130,14 @@ { u_int ents; + /* + * Round the number of sectors used by the existing partitions up to the + * sector size. The GPT standard (see section 5.3 of UEFI standard + * version 2.1) requires the reserved space be at last 16k (stated in an + * odd way), so enforce that minimum here as well. + */ ents = secsz / sizeof(struct gpt_ent); - return ((nparts + ents - 1) / ents); + return (MAX(GPT_MIN_RESERVED / secsz, (nparts + ents - 1) / ents)); } static lba_t