My Blog

Resizing a VirtualBox 5.1.4 HDD vdi file

by Chris Carlsen-Jones on 10th February 2017 1 comment

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.

I am using VirtualBox 5.1.4 running Linux R7U2, there are also blogs about installing VirtualBox and creating a Linux 7 VM.

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.

1

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

2

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

3

Click on the link to to ‘Install GParted Live on CD’., and then on the link below

Stable directory (.iso/.zip)
(for i686, i686-pae and amd64 architectures)

Then click on the link below.

4

Then download the gparted-live-0.26.1-4-i686-pae.iso file.

Start the VirtualBox Manager and create a new Linux VM.

5

Enter a name and a version of Linux, then press Next.

6

Set the memory, then press Next.

7

Then pick the option not to add a disk, and press Create.

Press Continue at the warning about creating a VM without a disk.

8

Next, click on settings / storage / IDE controller, then press the Add Optical Disk icon,

9

Press the Choose Disk option.

10

Then browse to your GParted file and press Open.

If you have second empty drive, remove it.

11

Go back to settings / storage, then select the SATA controller and press the add Add Hard Disk icon.

12

Then press Choose Existing Disk.

Browse to the vdi file you are resizing and press Open.

13

Now, start the GParted vm.

14

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.

15

Select the partition you want to resize, e.g. /dev/sda2, then press Resize/Move.

16

A Resize dialogue opens.

17

Enter the new size, select the Free Space opton: MiB, then press Resize.

18

Then press Apply to action the change.

Then press Apply again to confirm.

19

Then press Close.

20

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.

21

(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

22

Use the lvdisplay command and we can see the size is now 137GB.

23

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.)

24

Now check the situation with the df -h command.

25

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.)

 

Chris Carlsen-JonesResizing a VirtualBox 5.1.4 HDD vdi file

Related Posts

Take a look at these posts

1 comment

Join the conversation
  • Gary - 13th June 2017 reply

    Just wanted to say that your method worked perfectly for me after a few other methods did not. Thanks for the tutorial! -gary

Join the conversation