[parted-devel] [PATCH 0/2] gpt: Preserve relocated primary partition table

Pascal Hambourg pascal at plouf.fr.eu.org
Mon Dec 22 17:29:10 GMT 2025


On 12/12/2025 at 17:29, Brian C. Lane wrote:
> On Thu, Dec 11, 2025 at 09:44:39PM +0100, Pascal Hambourg wrote:
>>>
>>> I'm not really comfortable with guessing at the
>>> location of the primary partition array when using the backup header. It
>>> would be better to use the backup table to try and search for the
>>> primary, maybe?

According to my observations, the primary PEA created, moved or resized 
with util-linux (s)fdisk or (s)gdisk may only be located either just 
after the primary header or just before the first usable LBA. And I see 
no good reason to put it elsewhere. So I propose the following logic:

- If the size of the partition entry array is equal to the size of the 
space between the primary header and the first usable LBA, then put the 
primary PEA just after the primary header.
- Else if the primary header CRC is good, then use the PEA LBA field of 
the primary header.
- Else compare data at the two locations just after the primary header 
and just before the first usable LBA with the backup PEA.
- If one location matches, then put the primary PEA at this location.
- If none or both match, then "guess" as last resort:
- If FirstUsableLBA <= 1MiB then put the primary PEA just
before the first usable LBA.
- Else put the primary PEA just after the primary header.

Any comments ?



More information about the parted-devel mailing list