Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically resize the vagrant disk image size for linux guests?

Tags:

vagrant

There are numerous steps online for manually increasing the vagrant disk size, for example: link

It would be great if the resize could be done automatically in the Vagrantfile, something like this:

  config.vm.provider :virtualbox do |vb|
    if first_up      # only run on the first 'up' command
      disk_uuid = ?  # how to get the disk_uuid?
      vb.customize ["modifyhd", disk_uuid, "--resize", "15360"]
      config.vm.provision "shell", path: "resize2fs -p -F /dev/sda"
    end
  end

Question: How can I find out the disk uuid in a cross platform way?

Question: Is this all that is required to resize the guest's disk?

like image 579
Chris Snow Avatar asked Jan 18 '14 21:01

Chris Snow


People also ask

How do I destroy vagrant box?

Command: vagrant destroy [name|id] This command stops the running machine Vagrant is managing and destroys all resources that were created during the machine creation process. After running this command, your computer should be left at a clean state, as if you never created the guest machine in the first place.


Video Answer


2 Answers

I have found the following options to be useful:

1) Add another disk to the Vagrant box.

See my answer to a similar question on AskUbuntu here.

2) Use Opscode Vagrant boxes which tend to have 40Gb disks

See the opscode page for more information.

3) Use packer to create your own box.

After reading the packer tutorials, you can start by copying the packer definitions from somewhere else (e.g. opscode) and tweak the disk size.


Some more information:

An issue was raised on Vagrant's issue tracker about extending vagrant disks.

like image 89
Chris Snow Avatar answered Oct 17 '22 08:10

Chris Snow


There is a vagrant-disksize plugin.

You can install it by executing:

vagrant plugin install vagrant-disksize

Then you can include it in the Vagrantfile like this:

Vagrant.configure('2') do |config|
  config.vm.box = 'ubuntu/xenial64'
  config.disksize.size = '50GB'
end

Its limited at the moment only to the first disk.

like image 42
GuySoft Avatar answered Oct 17 '22 10:10

GuySoft