Resizing partition fdisk fails with invalid argument
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.
The problem is that the protective MBR (PMBR) is too small. You can change the protective MBR using:
-
x
for extra functionality -
M
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 partition -
n
to create a new partition and 4xenter to accept defaults settings (primary, partition number 1 and full size) -
t
andee
to change type to GPT -
x
for extra functionality -
M
to leave protective/hybrid MBR mode -
r
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
.
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
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.