How to resize the GPT partition table itself on Linux?
I have cloned a 1GB pen drive to an 8GB one using
But the size of the GPT is still 1GB. For example the secondary (backup) GPT is still located at 1GB (it has to be moved to the end of the disk).
Also I think two fields inside the main GPT (at offset 32 and 48) have to be updated.
I’ve looked into
gdisk but couldn’t find anything.
write the partition table. You will see:
Warning! Secondary header is placed too early on the disk! Do you want to correct this problem? (Y/N):
yes. Confirm again if necessary. Done.
fdisk. You will see:
GPT PMBR size mismatch (…) will be corrected by write. The backup GPT table is not on the end of the device. This problem will be corrected by write.
write the partition table. Done.
# gdisk /dev/yourdisk Command (? for help): v Problem: The secondary header's self-pointer indicates that it doesn't reside at the end of the disk. If you've added a disk to a RAID array, use the 'e' option on the experts' menu to adjust the secondary header's and partition table's locations. Identified 1 problems!
gdisk can be a bit cryptic to use but here it tells you directly what to do to solve this problem through the experts menu (
Command (? for help): x Expert command (? for help): ? e relocate backup data structures to the end of the disk Expert command (? for help): e Relocating backup data structures to the end of the disk
At this point you can adjust partitions or just write it out as is:
Expert command (? for help): v No problems found. 15624933 free sectors (7.5 GiB) available in 1 segments, the largest of which is 15624933 (7.5 GiB) in size. Expert command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): Y OK; writing new GUID partition table (GPT) to /dev/yourdisk.
parted can also be used, it will ask you to fix it when you use any command:
# parted /dev/yourdisk print Warning: Not all of the space available to /dev/yourdisk appears to be used, you can fix the GPT to use all of the space (an extra 13671875 blocks) or continue with the current setting? Fix/Ignore?
fdisk will resize GPT by writing.
# fdisk /dev/yourdisk Welcome to fdisk (util-linux 2.39.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. GPT PMBR size mismatch (1953124 != 15624999) will be corrected by write. The backup GPT table is not on the end of the device. This problem will be corrected by write. Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table.