modille.github.io

Personal GitHub Page

View on GitHub

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

  1. Shut down your VM
  2. Within VirtualBox Manager, open the Settings for your existing VM, then choose Storage
  3. Add a hard disk to the controller. Make it the same type as your current disk, and make it the size you need
  4. Once it’s created open a command prompt and head to the directory containing vboxmanage.exe – typically in C:\Program Files\Oracle\VirtualBox\
  5. 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
  6. Once that’s complete, reopen the VirtualBox Manager and head back to Settings > Storage
  7. Add an existing hard disk to your controller, choosing your new drive
  8. Disconnect your original drive
  9. 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.

  1. Download Fedora Desktop live CD ISO
  2. Mount it to your VM using Devices > CD/DVD Devices > Choose...
  3. 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:

  1. 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
  2. Restart your VM to get the new partition table

Resize home volume

  1. 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
  2. At this point, df should show the new space