Updated July 31, 2021
Often, people find their virtual machine hard disks are too small for usage needs. Below are steps showing you how to resize and expand an existing VMDK or VDI virtual hard drive in VirtualBox for use with a guest virtual machine (VM).
Things to Know Before You Start
- If you already have a dynamically allocated disk that is VDI or VHD linked to the virtual machine, simply use the VBoxManage modifyhd –resize command. e.x.
VBoxManage modifyhd <your filename> --resize 100000. That command would be for 100GB. You can then skip to the resize your guest OS step in this guide. If you’re not sure or don’t have it, read on.
- If your hard drive is VDI, you can try the CloneVDI tool to resize your disk easily without and skip to the resize your guest OS step in this guide.
- There are suggestions below to help you avoid having to resize virtual drives ever again by using large dynamically expanding storage and can be completed in 10-20 minutes.
- Ensure your guest VM is powered off before executing the steps and that all hard disks involved are not connected to VMs.
Step 1: Create a New Hard Disk
Use VirtualBox to create a new hard disk (vdi) with your desired size. You can use the dynamically expanding storage or a fixed size disk. If you are expanding the hard disk capacity, choose a size significantly larger (e.g. double the size) than the original hard disk to avoid problems.
Note: Starting with version 4.0 of VirtualBox, to create new disk images, use the “Storage” page in a virtual machine’s settings dialog because disk images are now by default stored in each machine’s own folder. The screenshot below pertains to VirtualBox 3.0.
Disk Type should be the Same
Make sure the new disk you create is of the same type as your old disk you want to expand. So if you have an IDE hard disk already, create a new IDE disk. The same applies for a SATA disk.
Recommendation: Use a large size dynamically expanding storage
It is to your advantage to use a large dynamic hard disk with a high maximum storage space to save you from having to go through this resizing process frequently. Having a dynamic 300 GB or 2 TB virtual disk won’t actually take up 300 GB or 2 TB on your hard drive and only takes up the actual disk space used on the disk. The exception to the recommendation would be if the system storing your virtual hard disks has space restrictions and your hard disks tend to grow quickly (e.g. a virtualized database server sitting on a host machine with a small hard drive).
Use of a fixed-size storage
It is best to use dynamic storage; however, some people have experienced problems using the dynamically expanding storage and using the fixed-size storage solved their problems.
Step 2: Clone Your Old Hard Disk
You can clone your old hard disk with the VirtualBox VBoxManage command. Make sure your VirtualBox directory containing the VBoxManage command is in your operating system path or you can execute the command below from the VirtualBox with absolute paths (e.g. ~/.VirtualBox/HardDisks/old_hard_disk.vdi). If you are in the directory containing your HardDisk folder (e.g. ~/.VirtualBox/HardDisks), run the following:
VBoxManage clonehd old_hard_disk.vdi new_hard_disk.vdi ––existing
Notes on using VBoxManage:
- There are *2* dashes before ––existing.
- The commands shown are case sensitive and should be entered as shown. VirtualBox documentation contains more info on VBoxManage and command syntax.
- If you are running VBoxManage in Windows and are not running the command in the same directory as the hard disks you are cloning, you may have to add quotations ” ” around your hard disk paths so the command can recognize the location of the hard disks. For example:
C:Program FilesOracleVirtualBox>VBoxManage clonehd "c:extUbuntu64Studio.vdi" "C:Folder With SpaceNewHardDisk.vdi" --existing
- Make sure to follow the syntax ordering given by the VBoxManage command, otherwise you may get an error like Invalid parameter ‘C:FolderWithSpaceNewHardDisk.vdi’.
The command will work if your old disk is in the vdi and also the VMDK format. The “–existing” parameter tells VirtualBox that the clone operation is to an already existing destination medium. Only the portion of the source medium which fits into the destination medium is copied. Since the new_hard_disk.vdi for us is larger than the old_hard_disk.vdi, all the source will be copied to the destination (e.g. entire guest hard disk).
Note for VMDK images: Your original VMDK guest image could be in one VMDK file or split into multiple VMDK files done by a virtualization program like VMWare. The advantage of having split files is it makes it easier to backup to DVDs and discs. After the cloning, you will only have one large VDI. To back up to disc media you’ll have to use a program to split the guest image (e.g. guest’s own tools or file splitters)
Cloning hard disks… you see something like the following
Oracle VM VirtualBox Command Line Management Interface Version 3.2.12
(C) 2005-2010 Oracle Corporation All rights reserved.
Clone hard disk created in format 'VDI'. UUID: ee28ab8b-8232-4c76-8c1b-184afdd1dd27
Step 3: Update the Guest Hard Disk
Replace the old guest hard disk with your new hard disk (i.e. new_hard_disk.vdi):
- Go to the settings for the guest VM and choose the “Storage” options.
- Select the appropriate controller (e.g. IDE Controller, SATA Controller) and add your new hard disk.
- Remove the old hard disk from the Storage section of your guest.
Step 4: Resize the Guest File System
If you boot into your guest operating system (OS), the file system will continue to only use the old hard disk partition set up. To use the increased disk space visible the OS, you can use disk partition management commands. The steps for the resizing the disk can depend on your operating system.
For Windows environments
Windows 7/10, Windows Server 2008
You can boot into Windows using the new hard disk and use the “Disk Management” utility to extend your hard disk volume. Right click on the drive you are extending and select the extend command.
Windows XP, Windows Server 2003, Windows 2000
Microsoft has a good knowledge base article on partition management for these versions of windows. Alternatively, you can use this partition manager tool from Aomei which works on a variety versions of Windows.
For other environments like Linux and Mac
You can use a Gnome Partition Editor GParted boot disk / live CD to resize the disk partition so the guest file system knows about the increased disk space. To use GParted on the guest, configure the guest to boot from the GParted CD (General -> Advanced tab set CD/DVD Rom as the first boot device, then select GParted CD). Instructions for using GParted and resizing disk partitions can be found at the GParted website or Google GParted resizing for several walkthroughs.
Note on Logical Volume Management (LVM) disks / partitions (common for Fedora installations)
You can graphically manage lvm partitions using the system-config-lvm Linux tool. Documentation for system-config-lvm is available for various flavors of Linux online and a comment from David in the comments section has confirmed this method works on Ubuntu 10 Server.
If you cannot use system-config-lvm, here are other options:
- Try GParted. GParted currently (December 2012) has some support for lvm (source: http://en.wikipedia.org/wiki/GParted). There is no easy way to expand a partition using lvm with the file system in the logical volume as supposed to ext3 or ext4 partitions.
- If the lvm partition does not contain the operating system, just create a new partition using GParted with ext3 or 4 (ext3 is safe) with the new virtual disk space. Go into the OS and copy all files from the lvm to the ext partition. Remove the lvm partition later after you have confirmed the files are converted and not in use.
- If the lvm partition contains your operating system (root lvm), either (1) copy your key files (e.g. /home/) to a backup and reinstall the OS or (2) attempt to convert the lvm to a different kind of partition or expand it. The (2) second option’s instructions are more complex due the active root partition and other things like resizing the file system. However, if you know Logical Volume Management (LVM) administration well, you can find some instructions on the internet and comments on this article from “zuzu”.
- Gnome Partition Editor – http://gparted.sourceforge.net/
People’s Experience with These Steps
You can find in the comment section of this article other people’s experiences with these steps and their tips.
THANK YOU Readers!
This post has been enhanced several times thanks to reader comments.