Macos – After doubling virtual disk size in VirtualBox, fdisk -l still shows old disk size in guest CentOS

centosfdiskmacosvirtualbox

I'm running CentOS 6.1 as a guest in VirtualBox 4.1.18 on a Mac OS X (Snow Leopard) host. Since 50 GB for my CentOS guest proved to be insufficient, I resolved to double its available disk space. After extensively searching the internet for a viable course of action, I settled on the following:

  1. Double size of VDI file through "vboxmanage modifyhd centos6.1.vdi –resize 102400"
  2. Verify in VirtualBox GUI that disk size is now indeed 100 GB
  3. Download Parted Magic ISO file and boot VM into Parted Magic
  4. In Parted Magic, fire up Partition Editor
  5. In Partition Editor, see ~ 50 GB of "unallocated" space
  6. In Partition Editor, resize /dev/sda2 (managed by LVM in my case) to use up all unallocated space, effectively increasing its size by 50 GB
  7. Shut down VM
  8. Boot VM into CentOS 6.1 and use lvm tools to grow existing volumes.

However, I fail at step 5. Partition Editor shows /dev/sda's size to still be 50 GB, NOT 100 GB. There is no "unallocated" space I could use to grow /dev/sda2's size. This is consistent with the output of fdisk -l, run either in Parted Magic or CentOS:

[root@dev ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes  
255 heads, 63 sectors/track, 6527 cylinders  
Units = cylinders of 16065 * 512 = 8225280 bytes  
Sector size (logical/physical): 512 bytes / 512 bytes  
I/O size (minimum/optimal): 512 bytes / 512 bytes  
Disk identifier: 0x0006702c

Device Boot Start End Blocks Id System  
/dev/sda1 * 1 32 256000 83 Linux  
Partition 1 does not end on cylinder boundary.  
/dev/sda2 32 6528 52171776 8e Linux LVM

In step 2 above, I verified that VirtualBox' GUI does indeed show my VM's virtual hard drive to be 100 GB in size. Could someone explain why neither fdisk nor Parted Magic see those extra 50 GB?

Best Answer

OK, turns out that modifyhd --resize does not work as expected if the VM to be resized uses snapshots. A user is supposed to know that in this case modifyhd --resize is to be run against the latest snapshot, not the original VDI file. Something that isn't mentioned in the docs and that doesn't strike me as being obvious either. Two days lost, sigh.

Related Question