BLOG

 
Resize

Resize VirtualBox Hard Disk (Ubuntu guest OS)

25 Jan 2011, by Rodrigo Nascimento in Linux, Virtual Machine

I was creating a new virtual machine to install the latest Oracle SOA Suite (11.1.1.4) and, during my biased next/next/finish routine, forgot to configure the hard disk size. After installing almost everything, I realised that the VM was running out of space.

Instead of installing everything again, I’ve asked my friend Google to help me. Among a diversity of creative, complex, weird and dodgy ideas I could compile the solution described below (which can also be creative, complex, weird or/and dodgy for you!).

The procedure described below was tested with Oracle VirtualBox 4.0.2 and Ubuntu 10.04, so I’m not sure if it will work with older versions.

Because Ubuntu default installation uses a single partition layout (so you cannot “unmount” the partition to be extended), you will need the Ubuntu Live CD (installation media or image) to do the trick.

Resize VirtualBox hard disk

The following steps describe how to resize VirtualBox hard disk with Ubuntu:

1. Extend the VM hard disk file using VBoxManage.exe

Go to the VM hard disk folder and use the VBoxManage.exe tool to extend the hard disk file. For example:

“C:\Program Files\Oracle\VirtualBox\VBoxManage.exe” modifyhd testvm.vdi –resize 20480

2. Change the VM boot order

Go to the VM settings and set CD/DVD drive as the first device (make sure the CD/DVD drive for this VM is pointing to Ubuntu Live CD).

3. Choose the ‘Try Ubuntu’ and start the GParted tool

4. Remove swap partition (only if you have one)

The Ubuntu install wizard usually creates a swap partition and I couldn’t resize the main partition because the swap partition was in the middle (I am open for suggestions here!).

5. Resize partition

Right click on the partition that you want to extend and choose ‘Resize/Remove’ .

Choose the new size for your hard disk.

In this case I left 3Gb unallocated to be used by the swap partition

6. Create a swap partition

Create a extended partition with all the remaining space

Now create a logical partition and set ‘linux-swap’ as the file system.

Don’t forget to enable your swap partition by updating/adding the following line to the /etc/fstab file with the correct partition position. For example, if your swap partition position is /def/hda8:

Rodrigo Nascimento is an experienced Enterprise and Solution Architect driven by innovation and integrity.
The combination of his passion for technology (which started when he was only 7 years old with his first ZX Spectrum) and his strong academic business background (bachelor’s degree in Marketing and MBA) has been used in many organisations to optimise the utilisation of IT resources and capabilities to leverage competitive advantage over the past 20 years.
15 COMMENTS
  • TJ

    I had this exact problem as I ran outta disk space in my Ubuntu Virtualbox. Unfortunately, the swap partition was mounted even when booting from the “Live CD”. So, I downloaded the GParted iso image from http://sourceforge.net/projects/gparted/files/ and booted from that instead. Worked beatifully.
    Thanks Rodrigo

    TJ

  • Josh Schneider

    I just selected swapoff so I could resize the swap with the new unallocated space, then moved that space to the extended partition container and finally to the boot partition. No need to delete and recreate the swap, but same difference. Thanks for the tutorial. Worked like a charm.

  • KC JC

    Wow. Thank you soooo much. This is exactly what I needed and it worked perfectly (resizing an Ubuntu 11.04 guest in a Windows Vista host).

  • naturegirl

    thanks a lot! That’s exactly what I needed!
    Was getting the android source code and quickly ran out of space =.=

  • ramneek

    thanks!

  • diogo

    nice tutorial.. tks.

  • Excellent tutorial. Thank you very much.

    Just one thing I wanted to add. I was using my Ubuntu 12.04 live CD and getting a critical error from VirtualBox when resizing (a 40G partition). Instead I used the gparted live cd and everything else was fine.

    http://gparted.sourceforge.net/

  • gopu

    thanks its worked…Nice explanation

  • […] a ubuntu image to boot off.10. Use gparted tool off a Ubuntu CD to repartition the space ( see : http://connection.rnascimento.com/2011/01/25/expanding-virtual-box-hard-disk-ubuntu-guest-os/ […]

  • Graham

    Step 1 did not work for me because I am using a fixed size virtual HD so a quick search found this tool https://forums.virtualbox.org/viewtopic.php?t=22422

    Not sure if it was just this tool, but the swap was at the end for me. So I didn’t have to rebuild the swap, could just extend the partition.

  • Trent

    Great article, but I had to make 2 changes (I’m on Windows):

    1) 2 dashes for the “resize” option: –resize
    2) Expanding by 20480 gave me an error:

    0%…
    Progress state: VBOX_E_NOT_SUPPORTED
    VBoxManage.exe: error: Resize hard disk operation for this format is not implemented yet!

    I added an extra zero (204800) and it worked.

    Thanks.

  • CaptainPackers

    Thanks for this. Just curious about how big you made your new swap space. I see a lot of controversy over this.

  • […] Resize VirtualBox Hard Disk (Ubuntu guest OS) | Rod’s … – I had this exact problem as I ran outta disk space in my Ubuntu Virtualbox. Unfortunately, the swap partition was mounted even when booting from the “Live CD”…. […]

  • […] Como verifiquei que o espaço reservado para a instalação do Quartus II na máquina virtual criada não é suficiente, neste artigo, vamos redimensionar o disco. O procedimento a seguir é baseado nesse artigo do Rodrigo Nascimento. […]

  • Charles

    Note that if you’re partitionned with LVM, GParted won’t resize your virtual volume, you have to do this additional steps: http://askubuntu.com/a/707045/13714

LEAVE A COMMENT