Wednesday, August 27, 2014

Increase Disk Size in VirtualBox

First of all if the virtual disk is using the VMDK format, it needs to be converted to the VDI format. Unfortunately, this can't really be done, at least not on the original virtual disk. You'll have to make a clone of it. After detaching the drive from the VM via the VirtualBox GUI, do this on the command line on the host system.
VBoxManage clonehd old-disk.vmdk new-disk.vdi --format VDI --variant Standard

Then, resize the clone to e.g. 100GB
VBoxManage modifyhd new-disk.vdi --resize 100000

Attach this virtual disk to the VM but at this point, the VM will not have access to the extra space. It needs to first be added as a partition and the recommended way to do this is to use the GParted live CD. Download the ISO file and then assign it as the CD to boot from in the VM. Make sure that the boot order of the VM is to boot from CD first. Both these steps are done via the VirtualBox GUI.

In GParted, assign the new space to an existing or new partition. After this, shutdown the VM, remove the CD (i.e. ISO) from the CD, and boot up the VM again.

The following steps are for CentOS users who have LVM setup by default. The next step is to configure the LVM to use the additional space for the volume. Here, I added 90GB to the LVM volume from the device /dev/sda2.
lvextend -L +90G /dev/mapper/vg_thevm-lv_root /dev/sda2

After this, the final step is to make the ext3 filesystem use the extra space.
resize2fs -p /dev/mapper/vg_thevm-lv_root

After this, do a "df" and you should see the extra disk space available.

References:

No comments:

Post a Comment