11

I recently resized a VPS from a 50GB SSD to a 300GB SSD through my hoster's control panel. I now am trying to resize my main partition with fdisk to be able to use all the new space. However, fdisk gives me a warning upon starting:

GPT PMBR size mismatch (104857599 != 629145599) will be corrected by w(rite).
GPT PMBR size mismatch (104857599 != 629145599) will be corrected by w(rite).

It seems obvious that it's a sixfold of the previous size, as I went from 50GB to 300GB. So, I decide to follow the hint and write the table...

Command (m for help): w
GPT PMBR size mismatch (104857599 != 629145599) will be corrected by w(rite).
fdisk: failed to write disklabel: Invalid argument

.. which does not work. I can't find what causes that error anywhere despite many search queries. I do not use LVM and my partition table looks like:

Disk /dev/vda: 300 GiB, 322122547200 bytes, 629145600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 30D92031-0C13-42FF-AC16-D34F36DD3907

Device        Start       End  Sectors Size Type
/dev/vda1      2048     32767    30720  15M BIOS boot
/dev/vda2     32768  16809983 16777216   8G Linux swap
/dev/vda3  16809984 104857566 88047583  42G Linux filesystem

Notice how the disk shows it as 300GiB, so it does recognize the size change.

Bart Pelle
  • 421
  • 1
  • 3
  • 7

5 Answers5

21

I managed to solve this rather simply. I installed parted and when I ran that it informed me that the partition table didn't cover the full disk (duh), so it asked me Fix/Cancel to which I responded with Fix. Apparently, that did the trick as I was able to modify the partition to the full size using sudo fdisk /dev/vda, but afterwards I did need to run sudo resize2fs /dev/vda3 to have the changes applied.

Bart Pelle
  • 421
  • 1
  • 3
  • 7
2

The problem is that the protective MBR (PMBR) is too small. You can change the protective MBR using:

  1. x for extra functionality
  2. M to enter protective/hybrid MBR
  3. (p allows to show the protective MBR)
  4. r to return to main menu (still in protective MBR mode!)
  5. d to delete the wrongly sized protective MBR partition
  6. n to create a new partition and 4xenter to accept defaults settings (primary, partition number 1 and full size)
  7. t and ee to change type to GPT
  8. x for extra functionality
  9. M to leave protective/hybrid MBR mode
  10. r to return to main menu (now in GPT mode again)
  11. w to write

With that I could fix the GPT PMBR size mismatch.

To fix the disklabel issue I had to dump the partition table using O and change last-lba in the exported script to the disksize as reported in fdisk, minus 34 (for secondary GPT). I then reimported the script using I.

falstaff
  • 121
2

This is what worked for me when trying to enlarge a GPT partition. As always, when changing a partition table, a backup is vital in case this doesn't go as planned.

First, not all fdisks are created equal. On Ubuntu 18.04, this is the version of fdisk I am using:

$ fdisk -v
fdisk from util-linux 2.31.1

Start up fdisk. Print your partition table with 'p' and verify the existing partition table is GPT:

Disklabel type: gpt

Copy and paste the partition information to another window so you can recreate the partitions with precisely the same start sectors.

Replace the old GPT partition table with a new GPT partition table by pressing 'g'.

Press 'p' again to print out the new table information to verify it now shows the larger size.

Press 'n' to recreate your partitions. All partitions must be recreated with the exact same start and last sectors, except for your last partition, which must have the same start sector but can have a greater ending sector.

If your partitions have filesystems on it, you should see something like this:

Partition #1 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: N

Respond with 'N' as you want to keep your filesystem signatures.

Back at the fdisk prompt, type 'p' one more time to look at the table to confirm everything looks as it should.

Type 'w' to write (commit) the changes.

From there, exit fdisk and follow a standard procedure to resize your filesystem (e.g., e2fsck -f then resize2fs if ext4). If you're working with a raw disk image file (i.e., for QEMU), then you can use kpartx -av disk.img to get loop devices for your partitions so that you can run e2fsck and resize2fs on those loop devices.

acker9
  • 121
1

You may need to delete the partition vda3 without writing the changes to the partition table by pressing 'w' and then re-create the partition with the new sector size so that you wont loose the data. You may need to unmount the partition and do a e2fsck before executing the below:

Eg:fdisk /dev/vda

Enter p
Delete the partition 'd' (Partition number is 3)'
Create new partition 'n'
Select the Start sector:
Select the end sector:(New Size)
Write the changes to the disk:
Update the partition table: (partprobe /dev/vda)
#resize2fs /dev/vda3
#mount the partition
0

I fixed the problem with gdisk. Here is what I did:

sudo fdisk --list

GPT PMBR size mismatch (41943039 != 62914559) will be corrected by w(rite). Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disklabel type: gpt Disk identifier: 62D6A220-B955-44BE-9730-CC89FE5CA928

Naive fix attempt:

sudo fdisk /dev/sda w

^^ fails with:

GPT PMBR size mismatch (62914559 != 83886079) will be corrected by w(rite).

fdisk: failed to write disklabel: Invalid argument

try (because it is a GPT disk?)

viradmin@instance-2:~$ sudo gdisk /dev/sda GPT fdisk (gdisk) version 1.0.3

Partition table scan: MBR: protective BSD: not present APM: not present GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): ? b back up GPT data to a file c change a partition's name d delete a partition i show detailed information on a partition l list known partition types n add a new partition o create a new empty GUID partition table (GPT) p print the partition table q quit without saving changes r recovery and transformation options (experts only) s sort partitions t change a partition's type code v verify disk w write table to disk and exit x extra functionality (experts only) ? print this menu

Command (? for help): w Warning! Secondary header is placed too early on the disk! Do you want to correct this problem? (Y/N): y Have moved second header and partition table to correct location.

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/sda. Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully.

then

sudo reboot

then I also did the following, because this was on an Ubuntu machine in the Google Cloud (following the guide https://slacker.ro/2019/07/17/how-to-increase-google-cloud-virtual-machine-disk-size/ ):

sudo apt install -y cloud-guest-utils
sudo growpart /dev/sda 1
sudo resize2fs /dev/sda1

stage@instance-2:/$ df Filesystem 1K-blocks Used Available Use% Mounted on /dev/root 30308240 16684136 13607720 56% /

fixed:

sudo fdisk --list

Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disklabel type: gpt Disk identifier: 62D6A220-B955-44BE-9730-CC89FE5CA928

Device Start End Sectors Size Type /dev/sda1 227328 83886046 83658719 39.9G Linux filesystem /dev/sda14 2048 10239 8192 4M BIOS boot /dev/sda15 10240 227327 217088 106M EFI System

After this, the disk and partition where properly grown to the new size:

I hope this helps.