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
  • 411
  • 1
  • 3
  • 7

5 Answers5

20

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
  • 411
  • 1
  • 3
  • 7
  • Glad that you got it fixed. Cheers mate. – ZVIK Aug 24 '15 at 15:19
  • I had the same issue when I was trying to delete partitions in fdisk - with the same error message (failed to write disklabel: Invalid argument) - and parted prompted me to Fix/Cancel, and after that I was able to delete the partition. Thanks for the answer. – datu-puti Aug 14 '16 at 00:02
  • parted or gparted? – tokland Feb 05 '17 at 21:25
  • 1
    I run into the same issue and parted solved GPT problem. Use resizepart command in parted to resize partition and then use resize2fs to resize file system. – Sergei G Aug 03 '17 at 16:43
  • parted solved it for me! And of course, I also had to do a sudo resize2fs in order to have the changes applied – gciochina Sep 04 '20 at 11:08
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.

mwfearnley
  • 757
  • 9
  • 21
falstaff
  • 121
  • 2
  • In windows we can just do right click expand partition. I am regretting creating a too small partition now its taking me ages to resize this damn thing :( – Piotr Kula Nov 15 '18 at 14:18
  • +1 for explaining the cause of the problem.. Not sure if it matters, but `fdisk` wouldn't let me start the new partition on sector 1 unless I enabled DOS compatibility mode (`c` in main menu) and explicitly give 1 as the start sector. Alternatively, `gdisk` can rebuild the PMBR with `n` from the advanced menu. – mwfearnley Feb 25 '20 at 09:17
  • This didn't work for me with util-linux 2.29.2: I still got the same error on `w`. The problem was that `fdisk` was trying to validate the GPT and found that backup GPT wasn't at the end of the disk. My fix was to use the `g` command and re-create the partitions manually, using the results of the `p` command I had run beforehand. – Ruslan Aug 15 '21 at 09:33
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
ZVIK
  • 535
  • 3
  • 11
  • Strangely it's not letting me create the bigger partition. `Created a new partition 3 of type 'Linux filesystem' and of size 42 GiB.` while the maximum should be ~242GB. Trying to create it bigger: `First sector (16809984-104857566, default 16809984): 629145599 Value out of range.`. – Bart Pelle Aug 24 '15 at 11:11
1

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
  • 111
  • 2
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.

masterxilo
  • 119
  • 3