How to increase the size of your VirtualBox HDD WITHOUT losing any Data

Has it ever happened that you are working on a dev Virtual Machine and suddenly you realised that you have run out of hard disk space ? And then, you had to do the tedious job of manually transferring all your changes, repos, config files, etc. to a new VM ? Well, in this post, I am going to tell you how to increase the size of your Virtual HDD, whether the HDD is in the native VDI format or a different format like VMDK, without losing ANY data and continue your work.

Virtualbox Logo

The steps mentioned in this post are for *NIX OSes like Linux and Mac OS. I have personally performed this on the Mac OS X 10.9 (Mavericks), but the exact same steps are applicable for Linux. I guess, there should not be any different for Windows either.

A quick background : The reason I wanted to increase my Virtual HDD size is because I ran out of space trying to download the Android source code. That’s right, I am trying to build Android from scratch and after downloading 17GB  of source code from the Cyanogenmod github repos, over a period of 5 days, I suddenly ran out of disk space. The Android story is for another day, another post.

As mentioned earlier, I have performed this on a Mac OS X Host machine with Ubuntu 12.04.3 (32-bit) as my Guest OS. The VM had a mere 20GB HDD and that too I had configured as a VMDK disk as opposed to the native VDI (Don’t ask!!)

So, without further ado, here’s how the magic happens :

Step 1a) : Backup your disk

Can’t stress this enough. Always, …. Always backup your disk. If I had to download 17GBs again, I would have to kill someone first to justify the action.

Now, you can’t just “cp” your virtual HDD file and hope it will work with your VM. There’s a whole lot of UUID issues with VirtualBox. To cut a long story short, don’t “cp”. Execute the following command instead :

$ VBoxManage clonehd <path to>old_ubuntu_hdd.vdi <path_to>backup_ubuntu_hdd.vdi

With this, VirtualBox assigns a different UUID to the backed up vdi and you can use this HDD as if it were your old one.

Now, if I were you, I would do just that. To be on the safe side, Release your current HDD from the Virtual Media Manager GUI tool.

VirtualBox Media Manager


Then go to your VM’s settings and add the newly backed-up VDI as the HDD for your VM. Then boot into it and verify that everything looks good.

Ok, We’re done backing-up. Unless, you are like me and had configured your virtual HDD in Vmware’s VMDK format.In that case, you need to execute Step 1b) below rather than Step 1a) above.

Step 1b) Convert your disk to VDI and backup your disk

Actually, it’s exactly like Step 1a) above ,except that you have an additional parameter to VBoxManage. Execute the following command :

$ VBoxManage clonehd <path to>old_ubuntu_hdd.vmdk <path_to>ubuntu_hdd.vdi --format VDI

Again, as above and especially after the conversion, make sure that you bootup the backed-up HDD and ensure that you can everything is working.

With our HDD safely backed up, lets tread on to more dangerous waters !!

Step 2) Increase the size of your Virtual HDD

This step is actually the easiest step. Just execute the following command :

$ VBoxManage modifyhd <path_to>Ubuntu_Hdd.vdi --resize <size in MB>

For example, in my case , I wanted to increase the size to 100GB, so the command was something like this :

$ VBoxManage modifyhd ./AndroidDev.vdi --resize 102400

That’s it !! We are done increasing the HDD. You can check this my opening the VirtualBox GUI tool , selecting your VM, clicking on Settings, then Storage and checking-out the value of the “Virtual Size:”

In my case it shows 100GB.

Forward march !!!

Step 3) Increase the size of the Linux Guest OS partition

With the above step, if you try to boot, you might either get an error, or see the same disk size from the Guest OS. What we need to do is resize the filesystem of the GuestOS to match the size of the partition or HDD we just increased.

For this, you need another Live Linux CD/DVD/iso like Ubuntu or GParted. Actually, we are going to use the gparted utility to do the resizing. So, as long as you have any OS which has this tool, it’s ok.

Now, add the Live Linux CD/DVD/iso to your VM and boot into.

Fire up Gparted session and resize your filesystem


That’s it !! That’s truly, finally it !!!

You have successfully resized your virtual hard disk keeping intact all your data.

I, have successfully resumed downloading the Android source.

Virtualisation | No Comments

More on Virtualisation

I had written briefly about Virtualisation and the different avtaars currently available.

I recently found this article comparing the four leading Virtualisation techniques on Linux.

Although I had covered the popular ones like Vmware , VirtualBox and Xen, I missed out on Qemu and Parallels.

Speaking of Xen, Citrix, appears to be in a dead sprint to remove any and all value from open source, virtualisation buzz, etc. that it may have acquired when it bought XenSource.

Meanwhile, it is reported that Ubuntu is has already dropped Xen in fabour of KVM for it’s virtualisation engine.

Have you tried any of the Virtualisation softwares ?

Do let me know which one you prefer for running your Virtual machines.

Virtualisation | No Comments


I hate to Pray… or worship…. especially non-existent creatures like God. But everytime I don’t attend a Pooja or refuse to enter a place of worship, I see the look of disappointment in my Parent’s face. I wish I could just load a Virtual “Me” who would go ahead and do all these awful things for me.
Better still, imagine having a few more virtual “Me”s so that I can try Pepe, Levi’s and Wrangler simultaneously and get over with the tedious task of buying a Jeans as soon as possible.

I think, Virtualisation is one of the most intriguing technologies among the sea of software innovations that surrounds us.

My first tryst with virtualisation was when I first used Vmware.
“A software computer !!!” That was my first impression. I was thoroughly impressed by the technology. Not so much with the fact that I could run an OS within an OS, but more so because I could decided how much RAM can be allocated by sliding a button. How cool was that ?!!

Sadly though, this was at a time when I used only Windows (unaware of the existence of Linux) and any new App held my attention for approximately 30 mins.
Here I am, a few years later and the full realization of what virtualisation means has just started hitting me !!!

The actual concept and theory behind virtualisation is not in the scope of this post, but I would like to leave the reader to dig more on the word “Hypervisor“.

An open source alternative to Vmware is VirtualBox. I have personally used it and although, frankly, it does not match up to Vmware, I think its pretty good.
Vmware also has an open source product, the Vmware player.

But recently, another player entered this market, Xen. It was recently acquired by Citrix , who now boast of end-to-end virtualisation solutions. Although it still maintains a homepage, its commercial website has been moved.

Finally, with the 2.6.20 kernel release sometime around Jan 2007, the kvm was introduced. The kernel developers, realizing the potential and need of virtualisation, added a kernel level support to aid the specialised hardware that had started proliferating the market.

As I mentioned earlier, I have already used Vmware ( only a few of its products , that too as Shareware) and VirtualBox. I know Xensource was part of Knoppix and even CentOS 5, but I never really got to using it. And kvm, is a topic I am immensely interested in and plan to keep track of it as part of my endeavour to keep abreast with this fascinating technology.

Virtualisation | No Comments