Gangmax Blog

How to Resize a VirtualBox Disk Image

This is a quite common problem for the VirtualBox user: after some time, you find the original image disk size is not enough and want to make it larger. How to make it?

1. Resize the image file

Use the VirtualBox utility tool “VBoxManage” to resize the image file(from here). You can find the “VBoxManage” tool inside the VirtualBox installation directory. Run the following commands:

1
2
3
4
5
6
7
# 1. If you image file is "vmdk" format, you need to run the following command to convert it
# into the "vdi" format first. If it's "vdi" already, just skip this command and go to next.
# I run this command on Windows, for Linux and Mac, it should be similar.
vboxmanage clonehd D:\vm\virtualbox\ubuntu64_14.04\ubuntu64_14.04.vmdk D:\copy.vdi --format vdi

# 2. Resize the image file(Number is in MB, the following is 60GB).
boxmanage modifyhd D:\copy.vdi --resize 61440

2. Create a new VM in VirtualBox with the new image file

In some posts, such as this one, they implies we can use the resized image file to overwrite the existing image file for an existing VM, then the VM works. But after I tried this, VirtualBox reports error when starting the VM. It seems VirtualBox has some verification on the image file. In our case after we modify the image file VirtualBox refuses to run on it.

So what I did is to create a new VM in VirtualBox by indicating the resized image file as the storage disk. It just works.

Go to VirtualBox “Machine -> New”, then in the wizard, remember at the “Hard drive” step, select the “Use an existing virtual hard drive file” option and use the resized image file in the last step.

3. Use “gparted” to resize the existing partition

Now you bigger size “hard drive” is ready, but your “hard drive” partition information is not changed which means the added space cannot be used. So we need to use the “gparted” tool to update the partition info.

First you need an ISO file that have the “gparted” utility. This post said using the official “gparted” iso file, but it cannot boot the WM with it in my VirtualBox. So I refer another post to use the official Ubuntu ISO file.

Add the ISO file into the CD drive in the VirtualBox storage setting and make sure the boot sequence is using CD drive before hard drive. Start the VM, select “Try Ubuntu”, start the “gparted” tool. It’s very straightforward to change the partition info to add the new space into your existing partication. After that, restart the VM and you should see the added disk space.

Comments