Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant, how to specify the disk size?

Tags:

vagrant

I want to make sure that my development environment has enough free space to install tools and other stuff. I can't find any configuration option about telling to Vagrant the minimum disk size that I want. Is this possible or I need to create my own box?

like image 678
geckos Avatar asked Apr 13 '18 17:04

geckos


People also ask

How do I change the size of my virtual drive?

Right-click the virtual machine. Click Edit Settings. Select Virtual Disk. Increase the size of the disk.

How do I use Vagrantfile vagrant?

The primary commands to get started are vagrant init and vagrant up . Open a command line and change directories to your test project folder. Run vagrant init and a new vagrant file will be created in the current directory called “Vagrantfile” (no extension) which holds a basic starter configuration.


2 Answers

I have used the vagrant plugin vagrant-disksize to resize the disk.

It worked. It can also help to specify the initial disk size.

Run the following at the command line:

vagrant plugin install vagrant-disksize 

and use the following in your Vagrantfile:

vagrant.configure('2') do |config|     config.vm.box = 'ubuntu/xenial64'     config.disksize.size = '50GB' end 
like image 69
Laurence Chen Avatar answered Oct 12 '22 11:10

Laurence Chen


Install Vagrant plugin vagrant-disksize

vagrant plugin install vagrant-disksize 

If you want to make sure user has the plugin installed, when starting vagrant, you can add this in the beginning of Vagrantfile

# Install vagrant-disksize to allow resizing the vagrant box disk. unless Vagrant.has_plugin?("vagrant-disksize")     raise  Vagrant::Errors::VagrantError.new, "vagrant-disksize plugin is missing. Please install it using 'vagrant plugin install vagrant-disksize' and rerun 'vagrant up'" end 

Set desired disk size in Vagrantfile

vagrant.configure('2') do |config|     config.disksize.size = '50GB' end 

Updating existing vagrant box

  1. Do all of the above
  2. Run vagrant halt & vagrant up (You should see something like "Resized disk: old 32768 MB, req 51200 MB, new 51200 MB")
  3. SSH to vagrant box
  4. Run sudo cfdisk /dev/sda
  5. Use arrows to select your disk probably sdaX. Mine was sda3.
  6. Then select resize using arrow keys. Accept the suggested disk size.
  7. Then select write. And answer yes.
  8. You can select quit now.
  9. Run sudo resize2fs -p -F /dev/sdaX You should see something like: "Filesystem at /dev/sda3 is mounted on /; on-line resizing required old_desc_blocks = 4, new_desc_blocks = 6 The filesystem on /dev/sda3 is now 11933952 (4k) blocks long. "
  10. Run df and see that your disk size has increased.
like image 35
Firze Avatar answered Oct 12 '22 10:10

Firze