How to extend the Ubuntu Linux hard disk drive root partition in VirtualBox?

If you are running out of space in Ubuntu Linux in VirtualBox then you will need to increase the hard disk size and then re-size the partition.  The following will show you how to do this.

I have a Ubuntu VM which has a hard disk size of 8Gb.  I want to increase the size to 16Gb.

How to extend the Ubuntu Linux hard disk drive root partition

  1. Make sure your VM is switched off.
  2. Go to the command prompt and go the the VirtualBox installation directory.  The default location usually is C:\Program Files\Oracle\VirtualBox
  3. In the command prompt enter:
    VBoxManage modifyhd “E:\VirtualBox VMs\Ubuntu 14.04.3\Ubuntu 14.04.3.vdi” --resize 16000
  4. Check the size in the VirtualBox GUI.  The size should have changed.
    How to extend the Ubuntu Linux hard disk drive root partition 2
  5. Now that the VirtualBox hard disk has changed the partition needs to be changed in Ubuntu so that it can be used.  In order to resize the partition use the gparted live CD which can be downloaded from here
  6. Once downloaded insert the GParted ISO file into the same VM CD drive and tick the live CD checkbox.  Start the VM booting into the CD drive.
  7. Once GParted has booted you should be able to see your partitions as well as the un-allocated partition.
    Resize Hard Disk Drive partition of Ubuntu Linux in VirtualBox using GParted
  8. Right click the partition that is nested under the extended partition with the file system lvm2 pv and deactivate the partition.
  9. Select the extended row and click the re-size/move.  Drag the arrow right to the end.
    Resize Hard Disk Drive partition of Ubuntu Linux in VirtualBox using GParted-2
  10. Select the partition that is nested under the extended partition with the file system lvm2 pv and click the re-size/move button.  Drag the arrow right to the end.
  11. Click the apply buttons to save the changes.
  12. Shutdown the VM and remove the GParted CD
  13. Start the VM to boot up the Ubuntu install
  14. Run disks by using the Ubuntu search
    Resize Hard Disk Drive partition of Ubuntu Linux in VirtualBox using GParted
    You can see that the hard disk size has increased but the space is not being used by the Ubuntu filesystem.  The root partition is only using 6.1gb of space.  We need to run a command to tell Ubuntu to use this space. Make a note of the logical volume for the root partition.  In this tutorial it is /dev/ubuntu-vg/root.
  15. Open terminal and type the following command replacing the logical volume name with your own:
    sudo lvextend -L13.385G /dev/ubuntu-vg/root
    The above uses the parameter -L which tells Ubuntu the size of the logical partition in gigabytes.  Change the size to your needs.  The above command can be run as many times as you need so don’t worry about making a mistake.
  16. Now we have set the size we need to tell Ubuntu to go ahead and re-size it.  Type the following to do this:
    sudo resize2fs /dev/ubuntu-vg/root
  17. Now check the disks utility.  The size of the root logical volume should now have increased.  Ubuntu is now using the extra disk space that we had increased in VirtualBox.
    Resize Hard Disk Drive partition of Ubuntu Linux in VirtualBox using GParted