Skip to content

Instantly share code, notes, and snippets.

@fredjoseph
Last active May 31, 2020 10:07
Show Gist options
  • Save fredjoseph/78303f4be48476b64b8d3de0aa41b3c3 to your computer and use it in GitHub Desktop.
Save fredjoseph/78303f4be48476b64b8d3de0aa41b3c3 to your computer and use it in GitHub Desktop.
Vagrant

Error

If an error 'initialize': negative string size (or size too big) occurs, the solution is to remove the index file in ~\.vagrant.d\data\machine-index

Disk size

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. Moreover, most Vagrant boxes use VMDK disks which cannot be resized!

vagrant-disksize plugin

This plugin allows to resize the disk size.

Installation

vagrant plugin install vagrant-disksize

Usage

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

Depending on the guest, you may need to resize the partition and the filesystem from within the guest. At present the plugin only resizes the underlying disk.

Resizing manually

  1. 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:
    VBoxManage clonemedium "box-disk1.vmdk" "cloned.vdi" --format vdi

  2. Now we can easily resize this VDI disk, e.g. to 50 GB:
    VBoxManage modifymedium "cloned.vdi" --resize 51200

If we want a Fixed size, we can now make a new clone with the option --variant Fixed (the disk can't be resized anymore).

  1. Then 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 by replacing the VMDK disk by this new one in VirtualBox.

  2. The last step is to resize the guest filesystem partition with the new available disk space (not explained here)

An other alternative is to create a new disk VBoxManage createmedium --filenane "new_disk.vdi" --format VDI --size 51200
Then, to attach this disk to the VM in addition to the previous one.

See also

Resize a Hard Disk for a Virtual Machine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment