Resizing partition fdisk fails with invalid argument
Solution 1
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.
Solution 2
The problem is that the protective MBR (PMBR) is too small. You can change the protective MBR using:
x
for extra functionalityM
to enter protective/hybrid MBR- (
p
allows to show the protective MBR) r
to return to main menu (still in protective MBR mode!)d
to delete the wrongly sized protective MBR partitionn
to create a new partition and 4xenter to accept defaults settings (primary, partition number 1 and full size)t
andee
to change type to GPTx
for extra functionalityM
to leave protective/hybrid MBR moder
to return to main menu (now in GPT mode again)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
.
Solution 3
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.
Solution 4
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
Related videos on Youtube
Bart Pelle
Updated on September 18, 2022Comments
-
Bart Pelle over 1 year
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 almost 9 yearsStrangely 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.
. -
ZVIK almost 9 yearsGlad that you got it fixed. Cheers mate.
-
datu-puti almost 8 yearsI 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.
-
tokland over 7 yearsparted or gparted?
-
Sergei G almost 7 yearsI 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.
-
Piotr Kula over 5 yearsIn 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 :(
-
mwfearnley about 4 years+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 withn
from the advanced menu. -
gciochina over 3 yearsparted solved it for me! And of course, I also had to do a sudo resize2fs in order to have the changes applied
-
Ruslan almost 3 yearsThis didn't work for me with util-linux 2.29.2: I still got the same error on
w
. The problem was thatfdisk
was trying to validate the GPT and found that backup GPT wasn't at the end of the disk. My fix was to use theg
command and re-create the partitions manually, using the results of thep
command I had run beforehand.