Vagrant is a great tool to provision virtual machines! As I’m a passionated Windows user, Vagrant is the weapon of my choice whenever I need to use some Linux-only tools such as Docker. I spinn up a new Linux VM, already configured with the things I need and start working. However, when it comes to resizing a disk, Vagrant is not nice to you…
The problem
Vagrant doesn’t provide any out-of-the-box option to configure or to change the disk size. The disk size of a VM totally depends on the base image used for the VM. There are base images with a 10 GB disk, some with a 20 GB disk and some other with a 40 GB disk. There is no Vagrant option to change this – and even worse: most Vagrant boxes use VMDK disks which cannot be resized!
Resizing (manually) with VirtualBox
As Vagrant doesn’t provide any out-of-the-box functionality, we need to do the resizing “manually”. Of course, we can write a script for this, too, but for now we keep it simple and do it by hand.
- First we need to convert the VMDK disk to a VDI disk which can be resized. We do this with the
VBoxManage
tool which comes with the VirtualBox installation:
1VBoxManage clonehd "box-disk1.vmdk" "cloned.vdi" --format vdi - Now we can easily resize this VDI disk, e.g. to 50 GB:
1VBoxManage modifyhd "cloned.vdi" --resize 51200 - The last step we need to do is just to use the new disk instead of the old one. We can do this by cloning the VDI disk back to the original VMDK disk or within a view clicks in VirtualBox:
That’s it! Now start your VM with vagrant up
and check the disk space. It’s at 50 GB and we have new free space again!
1 2 3 4 5 6 7 8 9 10 11 12 |
vagrant@vagrant-ubuntu-trusty-64:~$ df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 51572348 39944676 9472380 81% / none 4 0 4 0% /sys/fs/cgroup udev 2010488 12 2010476 1% /dev tmpfs 404804 356 404448 1% /run none 5120 0 5120 0% /run/lock none 2024000 0 2024000 0% /run/shm none 102400 0 102400 0% /run/user overflow 1024 0 1024 0% /tmp var_vagrant 487250940 373334608 113916332 77% /var/vagrant vagrant@vagrant-ubuntu-trusty-64:~$ |
Best regards,
Thomas
Please don’t give incomplete advice. You still need to mount it to the OS since it regenerates the UUID.
Can you quickly show how this can be done? Really need to get a bigger disk 😉
There are people who only criticize but do not make thinks. Please. Check this guide. https://www.rootusers.com/use-gparted-to-increase-disk-size-of-a-linux-native-partition/
If that was criticizing, I don’t really know how you can live in our current world…
I’ve tried the steps but failed. Chris pointed out that you still had to do something. Seems pretty logical to think that that’s the step i’m missing to complete my process. Don’t you?
Sorry, I make a mistake on this answer, is not for you…It was for @chrispunches:disqus
You can complete this cool guide following this link https://www.rootusers.com/use-gparted-to-increase-disk-size-of-a-linux-native-partition/
It was very useful.
Resizing (automatically) with VirtualBox
This section is missing.
1. How, through the Vagrantfile, can the VirtualBox image be copied and expanded?
2. How can the Vagrantfile be modified to install parted and used to expand the partition internally.
Making a second disk is not acceptable. Vagrant Box should be as lean as possible by default. Vagrant is written in ruby and not Python. 🙁
You can try it https://github.com/sprotheroe/vagrant-disksize
I have followed this steps, and I could see the new size, after ssh to box, isnt that enough?
I mean, why fdisk or gparted?
PS: I am using official ubuntu xenial box
This is a much more complete process; https://tvi.al/resize-sda1-disk-of-your-vagrant-virtualbox-vm/
Thanks Carlos, the above article had complete process and helped me in quickly resizing my vm.
This was exactly what I needed for resizing a couple of vagrant boxes that were too small for my purposes. Simple stuff, but it was baffling me. Thanks for posting this.
Now you can just use the plugin: https://github.com/sprotheroe/vagrant-disksize