jueves, 27 de marzo de 2008

How To Resize a VirtualBox Virtual Disk

I had installed Linux Mint into a 4GB dynamic virtual disk in VirtualBox, and I wanted to resize that disk up to 10GB. VirtualBox does not offer any tool for resizing virtual disks so far, so the only way to achieve my goal was to clone my current Linux Mint disk into a bigger virtual disk and later resize that clone to fill the whole space of the bigger disk.

There are two ways to clone the disk, the first uses the terminal program cfdisk, which comes with most live CD distros; the later uses Clonezilla live CD. The latter is easier and faster because it does not clone empty space.

The instructions for the cfdisk method are here; I will write about how to do it with Clonezilla.
  1. Create a bigger dynamic virtual disk from VirtualBox Disk Manager
  2. Download Clonezilla
  3. Set up your virtual machine (VM) to mount Clonezilla ISO disk image and boot from it.
  4. Add the new bigger virtual disk image as the VM's primary slave hard disk
  5. Boot Clonezilla and choose the disk-to-disk cloning mode
  6. Deselect the option "Resintall Grub bootloader" if you want to preserve Linux Mint styled bootloader.
  7. When the cloning is done, shutdown the VM.
  8. Set up the VM to boot from a Linux Mint ISO image (if you have it) or from Linux Mint live CD, Gparted live CD, or any ISO image or live CD which includes Gparted.
  9. Unselect the use of the VM's primary slave hard disk and set the bigger virtual disk (which now contains the clone) as the primary master disk.
  10. Boot the live CD you chose and start Gparted (it's called Partition tool in Linux Mint).
  11. If Gparted shows a swap partition it must be moved all the way to the right (together with the extended partition it is on) before you are able to resize the root partition. First you have to enlarge the extended partition, then the swap, preserving their sizes. But before you can do that you must click the swap partition and click the option "swapoff". Gparted will close, that's OK, just run it again.
  12. When you have your partitions as you like, apply the changes and shut down the VM.
  13. Set up the VM to mount from the primary master disk and eventually remove your old primary master disk from the Virtual Disk Manager.
Voila! Wasn't that easy?

2 comentarios:

Anónimo dijo...

awesome !
worked like a charm...
thanks so much !

Anónimo dijo...

You can use VBoxManage, VirtualBox commandline interface to resize your disk image. You can find detailed instructions in the user manual pdf that's distributed with Virtual Box. It goes something like:

VBoxManage modifyhd path_to_your_vdi --resize megabytes