How to increase the size of virtual machines in Virtualbox

If you have created a 20G vm in the first place and want to double the disk size, how do you do it?? There are alot of posts in different forums but there is no easy way of doing it. However, the theory behind increasing the disk size is not difficult and should work for all distros.

step 1. Create a new empty disk (set it to the new size you want) and attach it to the SATA controller, ie you will now boot up with 2 disks instead of 1. In this instance, say my old 20G ubuntu drive is /dev/sda2 and my new 40G ubuntu drive is /dev/sda1

step 2. Get a linux rescue disk – Some installation iso comes with it. Boot up with the iso. The idea is to be able to boot up without using the hard disk so that we can perform some magic on the disks. I am using the ubuntu 8.1 installation iso and it works cool for me. Upon booting up, I simple select “repair installation” and follow the prompts. At the end of everything, you should be in the command prompt.

step 3. copy /dev/sda2 over to /dev/sda1

dd if=/dev/sda2 of=/dev/sda1 conv=notrunc

step 4. Shut down the vm. Now in virtualbox, detach the old 20G drive so that the ubuntu vm boots up with the new 40G drive. Now boot up the vm.

step 5. Depending on the way you partition your tables, you can expand whichever partition you wish. My partition table is simple:

root@ubuntu:~/projects/blogs# fdisk -l /dev/sda

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000b73d4

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1        4973    39945591   83  Linux
/dev/sda2            4974        5221     1992060   82  Linux swap / Solaris

/dev/sda1 is mapped to my root folder and I want to expand it, so I

resize2fs /dev/sda1

**** ALL DONE!!

Author: bpeh

Bernard Peh is a great passioner of web technologies and one of the co-founder of Sitecritic.net Website Design and Reviews. He works with experienced web designers and developers everyday, developing and designing commercial websites. He specialises mainly in SEO and PHP programming.