How to enlarge a VirtualBox VDI disk file

Posted Almost 13 years ago. Visible to the public.

VirtualBox does not offer anything for this task -- you need to do it yourself. It's not that hard:

Get more disk space

  1. Add an extra virtual hard disk to the machine with the disk size you want to achieve.
  2. Get a Linux live CD (like the Ubuntu live image) that offers fdisk, dd and gParted.
  3. Boot the guest from the CD, open a terminal (on the guest, not the host!) and become root: sudo su
  4. fdisk -l to see the disk information. \
    There should be one drive with some partitions and one without any. The first is the source (e.g. /dev/sda), the latter your target for cloning (e.g. /dev/sdb).
  5. Clone the drive content with dd:
    dd if=/dev/sda of=/dev/sdb bs=1024000
    This will copy any content from your source to the target. Be careful to not use the wrong device names, dd does not ask for confirmation! The bs parameter sets the block size and may increase transfer speed. If you are curious about dd's progress, check the corresponding note.

Expand partition

Now your virtual drive has more space but the partition is still of the same size. You probably also want to enlarge it as well (these step are especially useful for Windows guests as they cannot resize their system partition themselves):

  1. Shutdown the virtual machine, disconnect the old drive, boot the live CD again. If you do not restart after cloning, gParted will be confused by the disk layout.
  2. Start gParted (on Ubuntu: System → Administration) and resize the partition on the target drive to its full size.
  3. Shutdown the VM, remove the live CD and boot up your guest system.

This should be it. Windows will notice the drive change and run CHKDSK on its next boot but should come up fine afterwards.


As always: Have a backup of important data before doing such things.

Arne Hartherz
Last edit
About 7 years ago
Keywords
resize, disk
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2011-07-15 12:57)