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

10,439

Solution 1

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.

Solution 2

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.

Share:
10,439

Related videos on Youtube

Chris Snow
Author by

Chris Snow

Data (Architecture|Engineering|Science).

Updated on September 15, 2022

Comments

  • Chris Snow
    Chris Snow over 1 year

    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?