No space left on device. How to expand VM/Vagrant memory storage

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:

df -h

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:

rm ubuntu-xenial-16.04-cloudimg.vmdk

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 -hYou 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!


2 thoughts on “No space left on device. How to expand VM/Vagrant memory storage

  1. Thanks for the write up on this! I’m a bit confused on the comment to “Change format back to .vmdk” and the mv command it refers to. Is it just renaming the file and changing the extension? Or should it do something like:

    VBoxManage clonehd “ubuntu-xenial-16.04-cloudimg.vdi” “ubuntu-xenial-16.04-cloudimg-new-50gb.vmdk” –format vdmk

    or does it even matter? Thanks again!


    1. Hey Scott and thank you for your comment! You just need to change the file extension here. To put it simply, first we clone the file to another format to create a copy, which we can modify (by using clonehd). When we are done modifying the file we can simply rename it to change the extension.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s