Žilinská univerzita > Fakulta riadenia a informatiky > Katedra informačných sietí

Resizing a VirtualBox Linux VDI Disk under Windows Host - VBoxManage error - Resize hard disk operation for this format is not implemented yet!

Using my VirtualBox linux machines (KaliLinux in my case) together with applying a couple of updates brought a problem, where the VB machine starts run out of disk space and I'm not able to update neither extend the system. This could be an often problem once we are trying to save some host system hard disk space using a small initial size of virtual machine disk partitions (12GB here).

The disk file cmd (df) reports:

root@kali:~# df -h
Filesystem                                              Size  Used Avail Use% Mounted on
rootfs                                                   12G  11G    0G  100% /

In this case there are several solutions available. We should either add a new virtual vdi drive, mount it inside of linux and move some folders on it. Or as the second option, we should extend the size of the main virtual disk.

The first case is from my point of view more suitable for situations where for example our personal /home folders become too big. However searching through my distro I see that the biggest folders are system folders

du -sh /*
0 /sys
36K /tmp
9.0G /usr
356M /var
0 /vmlinuz
root@kali:~# du -sh /usr/* | grep G
2.0G /usr/lib
6.6G /usr/share

This seems bigger linux system administration challenge and therefore the second option looks like less time consuming.

Searching the web we may find several nice tutorials, as for example Resize a VirtualBox guest Linux VDI Disk under Windows Host and Resizing VirtualBox and Linux Partitions with GParted. Both are using the VBoxManage tool together with the modifyhd and --resize switch defining the new size of the disk partition. Then we have to use some disk manager (the fdisk command line tool or the GParted GUI tool) to manage a new unallocated disk space.

However, following decribed steps I've got following error:

c:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd D:\VirtualBox\KaliLinux\KaliLinux.vdi --resize 20480
Progress state: VBOX_E_NOT_SUPPORTED
VBoxManage.exe: error: Resize hard disk operation for this format is not implemented yet!

The error, I think, is generated because my initial vdi file (KaliLinux.vdi) was created as a fixed size storage and not as a dynamically allocated. 

One of working solutions is following: 

1) Create a new linux machine with a new and bigger vdi storage (20GB in my case)

2) Use vboxmanage to clone the old vdi image to a new, just created, one

VBoxManage.exe clonehd OLD.vdii NEW_BIG.vdi --existing

in my case 

c:\Program Files\Oracle\VirtualBox>VBoxManage.exe clonehd D:\VirtualBox\KaliLinux\KaliLinux.vdi D:\VirtualBox\KaliLinux\KaliLinux2.vdi --existing

Clone hard disk created in format 'VDI'. UUID: 4983cdb9-1fd6-42a1-a8a3-15fb2bd9c11b

3) Booting a new machine with cloned disk is working, but shows that the system is still using the same size

root@kali:~# df -h
Filesystem                                              Size  Used Avail Use% Mounted on
rootfs                                                   12G  11G    0G  100% /

so we have to manage already created but still unallocated disk space. To do that we should use fdisk or as a windows user, some GUI based tool. As a right option seems to be GParted - A partition editor to graphically manage disk partitions.

Choosing GParted - we have to just follows steps described wthin already mentioned "Resize a VirtualBox guest Linux VDI Disk under Windows" tutorial (download GParted ISO, insert CD, boot, press return three times, delete swap and its logical drive, extend old logical drive to a new size, create a new swap...)

4) We will finnish applying changes, removing ISO image from VBox CD and rebooting the virtual guest machine. The disk is resized!