Vagrant, how to specify the disk size?
If your vagrant box uses LVM and is already created, additional steps are required compared to the answer of Firze:
- Install Vagrant plugin vagrant-disksize
vagrant plugin install vagrant-disksize
- Set desired disk size in Vagrantfile
vagrant.configure('2') do |config|
config.disksize.size = '300GB'
end
- Reboot the vagrant box (You should see something like "Resized disk...")
vagrant halt
vagrant up
SSH to the vagrant box
Check the old size with vgdisplay:
vgdisplay
--- Volume group ---
VG Name vagrant-vg
System ID
Format lvm2
...
Alloc PE / Size 16200 / 63.28 GiB
Free PE / Size 0 / 0
- Assuming that the device is /dev/sda you have to resize the extended and logic partition:
parted /dev/sda
p
Number Start End Size Type File system Flags
1 1049kB 768MB 767MB primary ext2 boot
2 769MB 68.7GB 67.9GB extended
5 769MB 68.7GB 67.9GB logical lvm
resizepart 2 321GB
resizepart 5 321GB
p
Number Start End Size Type File system Flags
1 1049kB 768MB 767MB primary ext2 boot
2 769MB 322GB 321GB extended
5 769MB 321GB 320GB logical lvm
quit
- Then, LVM should see the modification:
pvresize /dev/sda5
vgdisplay
Alloc PE / Size 16200 / 63.28 GiB
Free PE / Size 60148 / 234.95 GiB
- Extend the LVM group:
lvextend -L+234.95 /dev/vagrant-vg/root
Size of logical volume vagrant-vg/root changed from 62.32 GiB (15955 extents) to 297.27 GiB (76102 extents).
Logical volume root successfully resized.
vgdisplay
Alloc PE / Size 76347 / 298.23 GiB
Free PE / Size 1 / 4.00 MiB
- Finally, resize the filesystem:
resize2fs /dev/vagrant-vg/root
df -h
/dev/mapper/vagrant--vg-root 293G 59G 222G 21% /
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
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
- Do all of the above
- Run vagrant halt & vagrant up (You should see something like "Resized disk: old 32768 MB, req 51200 MB, new 51200 MB")
- SSH to vagrant box
- Run sudo cfdisk /dev/sda
- Use arrows to select your disk probably sdaX. Mine was sda3.
- Then select resize using arrow keys. Accept the suggested disk size.
- Then select write. And answer yes.
- You can select quit now.
- 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. "
- Run df and see that your disk size has increased.