How to Resize An Ubuntu 16.04 Vagrant VM
Vagrant is a convenient tool collection that can be used for controling Virtual Box based VMs. However, since it pull prebuilt vm from the web, there is no easy way to control the size of the given VM. After searching through the net and break one of vms, I came out with a solution, and I would like to write it down just in case I forget about it.
1. Power off the VM
2. Navigate to the directory where your vm disk is stored. You should be able to find them from the virtual box gui, on Mac it is located at ~/VirtualBox VMs/vm_name_default_some_random_value/
3. Clone the original disk just in case we do something wrong
Ubuntu 16.04 came with two vmdk files by default, leave the config-drive alone. We only need to deal with ubuntu-xenial-16.04-cloudimg.vmdk. We also change the format to vdi so it can be resize.
VBoxManage clonehd ubuntu-xenial-1604-cloudimg.vmdk clone.vdi -format vdi
4. Resize the vdi
VBoxManage modifyhd clone.vdi --resize NEW_SIZE_IN_MB
5. Add the vdi to your VM in virtual box gui
By default you should have two disks in your Virtual Box GUI Storage tab
SCSI0 - xenial...cloudimg.vmdk
SCSI1- xenial...cloudimg-configdrive.vmdk
Add you vdi to Port 2 so it becomes
SCSI0 - xenial...cloudimg.vmdk
SCSI1- xenial...cloudimg-configdrive.vmdk
Sata2- clone.vdi
6. Boot the VM and login
7. As root, run fdisk -l to find your resized vdi. In my case, the vdi is /dev/sdc.
I resized a 10G disk to 20G, so I would see a 20G /dev/sdc with a 10G /dev/sdc1
You can also check this by mounting the /dev/sdc1 using
mount -t ext4 /dev/sdc1 some_directory
8. Now we want to resize the partion
parted /dev/sdc
print free will list both the partitions and free space
use reiszepart to resize the partion
In my case
resizepart 1 21.0GB
than quit gparted
9. After reloading /etc/fstab by executing mount -a, we should see that the /dev/sdc1 take up to 20G space
10. The last step is to remove the original vmdk file from the vm and move clone.vdi to the SCSI0 so it will be used as the boot drive.
Thanks to
Resize a Vagrant VMDK drive - Thijs Lensselink's Blog
Reload fstab (/etc/fstab) – Chris Schuld