VirtualBox is a beautiful piece of virtualisation software created for users, first acquired by Sun and then by Oracle as a part of Sun acquisition. I have been using VirtualBox for quite a few testing projects, however until today have never needed to expand my hard drive on a guest. I am running a Windows 7 guest for some client side related tests. I started with a 25Gb disk for Windows 7, but after applying all security patches (I like my machines patched and upto-date), I realised that 25GB is all gone.
This is where I love virtualisation. I do not need to buy a new disk if I need more space on my virtual machine (as far as my physical disk has enough space). I can just expand the existing virtual hard disk and get all the space I need. VirtualBox does not yet have a GUI option to do storage expansion work, but fortunately VirtualBox comes with an excellent command line, so I followed the following steps in order to increase my hard drive space.
In order to see the virtual hard disk info, following command can be used.
$ VBoxManage showhdinfo VirtualBox\ VMs/Win764/Win764.vdi UUID: e2272600-df31-4dbc-a71d-56af5f5714df Parent UUID: base State: created Type: normal (base) Location: /Users/ajitabhp/VirtualBox VMs/Win764/Win764.vdi Storage format: VDI Format variant: dynamic default Capacity: 25600 MBytes Size on disk: 25502 MBytes In use by VMs: Win764 (UUID: 1beda97f-4222-49ad-993e-342e1d44e288)
To expand this to 50GB and then verify that the operation is done
$ VBoxManage modifyhd --resize 50000 VirtualBox\ VMs/Win764/Win764.vdi 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% $ VBoxManage showhdinfo VirtualBox\ VMs/Win764/Win764.vdi UUID: e2272600-df31-4dbc-a71d-56af5f5714df Parent UUID: base State: created Type: normal (base) Location: /Users/ajitabhp/VirtualBox VMs/Win764/Win764.vdi Storage format: VDI Format variant: dynamic default Capacity: 50000 MBytes Size on disk: 25502 MBytes In use by VMs: Win764 (UUID: 1beda97f-4222-49ad-993e-342e1d44e288)
Now so far we have only been able to expand the Hard disk drive, but the partition table still would say that the NTFS filesystem is still the original size. However, we can not use Windows to expand the partition table of the same partition wherein it is installed. The System Rescue CD came to help here. I attached the System Rescue CD ISO to the windows virtual machine and booted the system.
In the command prompt, I used the GNU parted to expand the partition table (partition 2 in my case)
% parted resizepart 2 50GB /dev/sda
In case you want to check which is your NTFS partition, which you want to expand use the following command –
% parted print /dev/sda
After expanding the partition table, we need to expand the NTFS filesystem on it, which can be done by ntfsresize utility as below. First I ran the utility in info mode to find out the exact size to which to expand to and then in dry run (test) mode and finally actually ran it.
% ntfsresize --info /dev/sda2 % ntfsresize -n -s 52294093824 /dev/sda2 % ntfsresize -s 52294093824 /dev/sda2
Finally remove the the System Rescue CD ISO file and boot the system normally in windows, a check will be force and you are done.