Resize Your Vagrant / VirtualBox Disk

Ben Hirsch
Feb 1, 2015 · 2 min read

I recently ran into a disk size issue when working in Vagrant. Vagrant, by default, creates a 10GB space for storage but I needed to resize to 50GB in order to sync with my Dropbox account.

I have tried using the detailed guide here, but have not been able to get it to work with any Debian boxes. I am using the box for Debian 7 “Wheezy”, puphpet/debian75-x64.

~/host> vagrant halt
~/host> cd /path/where/your/vbox/.vmdk/files/are
~/host> VBoxManage clonehd my.vmdk out.vdi --format VDI
~/host> VBoxManage modifyhd out.vdi --resize 51200

The above procedure is halting your VM, changing directories to where you have the storage drive image saved. Cloning it and converting it to .vdi and resizing it to 50GBs.

Next, launch your VirtualBox GUI and remove your existing hard drive completely (select VM > settings > storage > remove existing hard drive > add new hard drive) and add the new .vdi image.

~/host> vagrant up
~/host> vagrant ssh
~/guest> sudo cfdisk /dev/sda

This will launch an interactive screen displaying all partitions. Select the largest space available > select “New” > select “Primary” > select “Write”. /sda3 should now appear as a new partition. (I sometimes get an error when the system tried to re-read the partition tables. You can ignore this.)

~/guest> exit~/host> vagrant reload
~/host> vagrant ssh
~/guest> sudo pvcreate /dev/sda3

If the pvcreate command is not found just sudo apt-get install lvm2 to install it.

~/guest> sudo pvdisplay | grep "VG Name"

This will display the volume group name, referred to as VG-NAME (below). Replace VG-NAME with your own.

~/guest> sudo vgextend VG-NAME /dev/sda3
~/guest> sudo lvextend /dev/VG-NAME/root /dev/sda3
~/guest> sudo resize2fs /dev/VG-NAME/root
~/guest> df -h

The last command should display your new resized disk volume.

Hope this helps!

Ben Hirsch

Written by

Co-founder and Lead Developer at http://www.locally.com (@locally)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade