Adding more disk space to a Linux Virtual Machine

There comes a time where you set-up a VM and don't set the hard-disk size to be big enough for what you are going to do. I hit that problem just the other day and I needed to increase the size of my home dir on a Ubuntu Lucid LTS vm before I ran out of space.

The method I used is just to add a second disk to the vm and mount that to free-up space. In my case I decide to create a new hard-disk and mount that at /home.

Note: be very careful doing the following - it goes without saying following these instructions are at your own risk.

Adding the hard-disk to the virtual machine

Add the disk to your VM through the route specific to your Virtualisation software in my case I'm using VirtualBox, but there will be a similar method for VMware, Parallels etc. Note, you'll need to stop your VM to do this.

Here's a screenshot of the dialogs in VirtualBox:

Here are the steps in text:

Open the Virtual Media Manger using Ctrl-D or File => Virtual Media Manager

Under the hard disks tab click "New"

Follow the wizard

Go back to the VM settings, select storage and select "Add Hard Disk" (To the far right of IDE Controller)

The first disk in the list is selected. Use the drop down on the right to select the new disk you created

Partitioning and formatting the new drive

All of the following commands are carried out as root

In my case I've run out of space in my home directory so I'm going to move my home partition to the new drive. To do that as root I've renamed /home to /home.bck
e.g:

mv /home{,.bck}

if you're wondering what the curly braces are this is just shorthand for saying mv /home /home.bck the shell expands that syntax into the full version when running it. If this is confusing then just run:

mv /home /home.bck

Once rebooted you should see you have an unpartitioned hard-drive ready to go. To check this run from the terminal: