Resizing a VirtualBox Hard Drive HOWTO

Update: There’s another method here that skips the use of clonezilla and does everything with gparted: Re-sizing a VirtualBox Virtual Disk Image File

VirtualBox doesn’t currently offer any tools for directly resizing a hard drive image (VDI). This method, using only free software tools, allows you to perform that task without any risk of losing the data you currently have on the image.

First, we’ll create a new, larger VDI, then we’ll use Clonezilla to clone our old one to the new one, then we’ll use Parted Magic to resize our partitions to fill our new, larger VDI, and finally will remove our old VDI from our machine image. This method assumes a linux client, but it should be equally applicable to a windows client (probably easier, given that there is no swap partition).

Download clonezilla live (stable release):
Right click on the machine, settings
Storage, click on the SATA Controller, Add Hard Disk
Create new (larger) VDI disk image
You should now see two VDI images listed under SATA controller
Click on the CD drive, underneath the IDE controller
Under attributes, click the CD icon, choose a virtual CD/DVD disk file…
choose the clonezilla live iso image you downloaded
Click OK
Boot the machine
Start Clonezilla live
– English
– Select keymap from full list
– pc / qwerty / British / Standard / Standard
– Start Clonezilla
– device-device
– Expert
– local disk to local disk clone
– sda as source
– sdb as target
– check the -r and -q1 options. -q1 is required because the faster methods fail in virtualbox for some reason. Slower, but works. 🙁
– Use partition table from source disk
– Enter to continue
– yes, we’re sure we want to continue
– yes, again, we’re sure
– yes, clone the bootloader
– yes, we’re sure!
– once it completes, 0 to power off
– Enter
Download Parted Magic:
Go into settings of the machine again. Change the sata ports around so that the new drive is on SATA Port 0 and the old one on SATA Port 1. We can remove the old one once we’re sure the new one works.
Click on the CD drive, underneath the IDE controller
Under attributes, click the CD icon, choose a virtual CD/DVD disk file…
choose the pmagic iso image
Start the machine
– Boot with default settings
– Button bottom left -> System Tools -> Parition editor
– Resize the extended partion to take up all remaining space (right click -> resize/move)
– Then do the Resize/move on /dev/sda5 (swap). Change the free space following to 0 (this moves it to the end). Click OK on the warning dialogue.
– Resize the extended partition down to maximise the free space preceding it. OK on the warning message.
– Resize /dev/sda1 to use up all the free space.
– Click the Apply button.
– Click Apply to continue.
– Click close when it’s done.
– Bottom left button -> logout -> shut down
Settings of the machine again
Remove the iso image from the CD drive, then click OK.
Start the machine. If it boots OK (did for me), we can shut it down and remove and delete the old VDI hard disk image.

This entry was posted in HOWTOs and tagged , , , , , , , , , , , , , , , , . Bookmark the permalink.

4 Responses to Resizing a VirtualBox Hard Drive HOWTO

  1. M. Smith says:

    As of VirtualBox 4.0, there is a tool for directly resizing a hard drive image (VDI),

  2. rwh says:

    Great stuff! I’m glad there’s an easier way.

    While I’m here I should say that I think that the fast imaging method most likely failed because of an inconsistency in the filesystem which can be fixed by doing an fsck before creating the image. Not that we need it now. 😉

  3. Kent Mestayer says:

    Great instructions until GParted. Partition editor shows /dev/sda1 ext3 with label /boot, /dev/sda2 File System: lvm2 as 7.90 GiB and unallocated as 4.00 GiB. There is a warning information icon next to /dev/sda2. Device information shows: Model: ATA VBOX HARDDISK, Size: 12.00 GiB, Path: /dev/sda. /dev/sda2 cannot be edited. The information page states: Warning: Logical Volume Management is not yet supported

  4. Darius says:

    These instructions were complete and worked perfectly for me. Note that when I rebooted into my enlarged drive I get a GRUB “error, no argument specified” screen but hit to continue and waited a few seconds and boot succeeded.

Leave a Reply

Your email address will not be published. Required fields are marked *