Problem: You are trying to create new files, unzip heavy folders or populate a database in your Vagrant box, but you are getting an error: No space left on device.
In this tutorial VM is installed on Ubuntu. If you use Mac OS, please be careful and read comments. Windows is not covered in this tutorial at all!
First, check how much space do you actually have, by executing:
In the output table search for /dev/sda1 and its size. If it’s smaller than you expected, you probably need to take actions.
Go to VirtualBox application on your computer, stop/halt your VM.
On your computer go to <home_dir>/VirtualBox VMs/. In this folder you’ll see vbox and vmdk files. If you use Ubuntu image, then something like ubuntu-xenial-16.04-cloudimg.vmdk is what you need. We need to edit this file to expand space, but this file is not editable. So, first convert it to .vdi format:
VBoxManage clonehd "ubuntu-xenial-16.04-cloudimg.vmdk" "ubuntu-xenial-16.04-cloudimg.vdi" --format vdi
Note, using sudo when executing this commands is not recommended, as it may lead to permissions problems. If avoiding using sudo is not possible for you, then after the process is over, you should go and fix permissions of your VM directory.
Then, execute the following to allow more space. In this case VM is expanded to 50Gb of storage space:
VBoxManage modifyhd "ubuntu-xenial-16.04-cloudimg.vdi" --resize 51200
Change format back to .vmdk. Note, we change the name of the new file too. This is important in order to avoid errors, as your vmbox will not recognize the file immediately:
mv ubuntu-xenial-16.04-cloudimg.vdi ubuntu-xenial-16.04-cloudimg-new-50gb.vmdk
Remove old disk:
Register you VM, if not yet registered:
VBoxManage registervm /<home_dir>/VirtualBox\ VMs/<your_box_name(folder_name)>/yourbox_name.vbox
Now we need to attach this new disk to our VM.
--storagectl might be different than”IDE Controller”. On Mac OS it is usually “SATAController”. But to be sure, open <your_box_name>.vbox in the same directory and search for <StorageControllers> tag.
VBoxManage storageattach <your_box_name> --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium ubuntu-xenial-16.04-cloudimg-new-50gb.vmdk
Finally, go to your VirtualBox application and choose your_machine_name > Settings > Storage > Controller in the Storage tree. Remove old vmdk. If you used sudo, there may be permissions problems. Go back to the VM dir and fix those!
After that you will be able to vagrant reload and ssh. If that go successfully, you will be able to check the storage space again by executing:
df -h. You should see a size of 50Gb instead of standard 10Gb.
Let us know if that worked for you. If there’s something you’re confused about then contact us or leave a comment below!