Here is how you can resize a VirtualBox Hard Disk (vdi) file. I found a couple of blogs about this but they didn’t quite work for me so here is the process I followed. You will need to download and use a third party Partition Editor, I used the GParted GNOME Partition Editor. If you don’t want to go down this route you could just add another hard disk, a blog on how to do that is here.
Before you start this process ensure your VM is closed down (not suspended), and close the VirtualBoxManager.
MAKE A BACKUP COPY OF YOUR VDI FILE IN CASE SOMETHING GOES WRONG.
Open a Command Prompt window, on your host system and set the path to your VirtualBox installation.
Then use the command below to resize the vdi file: (the size is in MB)
VBoxManage modifyhd <absolute path including the name and extension> –resize 20480
e.g. VBoxManage modifyhd C:\oracle\VirtualBox\VMs\ora12c\ora12c.vdi –resize 163480
Next we need to resize the Linux partition to use the space of the larger vdi file.
To do this we need the GNOME Partition Editor.
This can be downloaded from http://gparted.sourceforge.net/livecd.php
Click on the link to to ‘Install GParted Live on CD’., and then on the link below
Then click on the link below.
Then download the gparted-live-0.26.1-4-i686-pae.iso file.
Start the VirtualBox Manager and create a new Linux VM.
Enter a name and a version of Linux, then press Next.
Set the memory, then press Next.
Then pick the option not to add a disk, and press Create.
Press Continue at the warning about creating a VM without a disk.
Next, click on settings / storage / IDE controller, then press the Add Optical Disk icon,
Press the Choose Disk option.
Then browse to your GParted file and press Open.
If you have second empty drive, remove it.
Go back to settings / storage, then select the SATA controller and press the add Add Hard Disk icon.
Then press Choose Existing Disk.
Browse to the vdi file you are resizing and press Open.
Now, start the GParted vm.
Select the GParted Live (default settings) option and press Enter.
Select any default settings, then choose your language.
Then select 0 to run GParted automatically.
We then have the VM running.
Select the partition you want to resize, e.g. /dev/sda2, then press Resize/Move.
A Resize dialogue opens.
Enter the new size, select the Free Space opton: MiB, then press Resize.
Then press Apply to action the change.
Then press Apply again to confirm.
Then press Close.
We have now allocated the free space.
You can now shutdown the DParted VM.
Now start your original VM, the vdi file is still associated with.
Login as root, open a terminal window and use the fdisk -l command.
(The linux fdisk utility shows 1kB blocks so /dev/sda2 is about 160GB)
We added 100GB so we’ll try and use 99GB, some space will be reserved by the OS.
Next grow the logical volume:
lvextend /dev/mapper/ol-root -L+99G
Use the lvdisplay command and we can see the size is now 137GB.
Then you need to extend the file system on the logical volume:
fsadm resize /dev/mapper/ol-root
(If you don’t specify a size the file system will use all the available space.)
Now check the situation with the df -h command.
We have another 100GB of free space.
Shut down the VM.
In the VirtualBox Manager you can right-click on the DParted VM and remove it, and select the option to “delete all files”. (Our vdi file was in our original VM folder, not in the new DParted VM folder, so we only deleted the files created for the DParted VM.)