How to Resize a Out-of-Space VirtualBox Disk

1 minute read

I installed an CentOS 6.5 64-bit guest on my VirtualBox host. Later I found the 10-Gigabyte disk space I’d allocated was used up. I needed to add more space to it. I found the solution after some study. Here is how:

  1. Shutdown the guest virtual machine. Find the disk image file(.vdi) on the host server, use this command to resize it (say increasing it to 20G): vboxmanage modifyhd your_guest.vdi –resize 20000

  2. Download the live cd file (.iso) of GParted tool, (like gparted-live-0.17.0-4-i486.iso). Start up the guest vm with booting from that iso file.

  3. In GParted tool, resize the partition. It’s pretty straightforward, just remember to save the change.

  4. Reboot the guest vm, starting from disk, of course. Change the LVM(using a LVM to manager your disk is a good idea, especially useful in such occasion. So, don’t change this default setting when installing a new vm) setting:

lvextend /dev/vg_nile/lv_root /dev/sda2;
resize2fs /dev/vg_nile/lv_root

// assume the lvm group name is “vg_nile”, logical volume to be extended is “lv_root”, and the new partition shown up is “/dev/sda2”.

It’s all set. Verify that with df command.

It is said I can achieve the same goal by creating a new virtual disk and cloning all current data to it from the old one. Then replace the old vdi with the new one. I haven’t try it yet.

Categories: Tech