HOWTO - Add space to a dynamically allocated VMDK
I had a VM set up with a dynamically-allocated VMDK with a max size of 60GB. I reached near 100% capacity on the VMDK, and used the following steps to grow the VMDK.
Note: YMMV; I did this using a Windows 8 host, Fedora 20 guest, and VirtualBox 4.3.12
Create new VMDK
- Shut down your VM
- Within VirtualBox Manager, open the Settings for your existing VM, then choose Storage
- Add a hard disk to the controller. Make it the same type as your current disk, and make it the size you need
- Once it’s created open a command prompt and head to the directory containing
vboxmanage.exe– typically inC:\Program Files\Oracle\VirtualBox\ - Run the following, altering the paths to match your current and new VMDK files:
vboxmanage clonehd "C:\vm\fedora20-disk1.vmdk" "C:\vm\NewVirtualDisk.vmdk" --existing - Once that’s complete, reopen the VirtualBox Manager and head back to Settings > Storage
- Add an existing hard disk to your controller, choosing your new drive
- Disconnect your original drive
- Select your new drive and set it to SATA Port 0
Boot into live CD
I booted into a live CD so that my /dev/sda2 partition wasn’t mounted. This may have actually been optional, since
my partitions were setup with LVM.
- Download Fedora Desktop live CD ISO
- Mount it to your VM using
Devices > CD/DVD Devices > Choose... - Restart your VM to boot into the live CD
Resize the /dev/sda2 partition
Again, you might be able to just use gparted, depending on your setup. Fedora 20 doesn’t have any graphical partition manager that I’m aware of, so I did the following:
- Open a terminal and do the following:
$ sudo fdisk -l # View partition layout; typically we're dealing with /dev/sda2 $ sudo fdisk /dev/sda d # Delete a partition 2 # If we want to grow /dev/sda2; NOTE: This does not delete any data on disk n # Create a new partition p # Primary partition 2 <return> # Default starting block <return> # Default ending block, full size of the partition # Make sure partition type is 8e for Linux LVM: t 8e w # Write changes to disk - Restart your VM to get the new partition table
Resize home volume
- Again boot into the live CD, open a terminal, and do the following:
$ sudo pvresize /dev/sda2 $ sudo pvscan # Should show new larger size $ sudo lvextend -l +100%FREE /dev/fedora/home $ sudo e2fsck -f /dev/fedora/home $ sudo resize2fs /dev/fedora/home - At this point,
dfshould show the new space