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!

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

    Liked by 1 person

    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.

      Like

  2. I actually have a question, why would the size of the *.vdi file remain the same after executing VBoxManage modifyhd to resize the file?

    The programs just zips thru the file and does not expand it, only the timestamp changes!

    I would appreciate some help, thanks in advance.

    Grum

    Like

  3. Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your website? My blog site is in the exact same niche as yours and my visitors would definitely benefit from some of the information you provide here. Please let me know if this alright with you. Thanks a lot!|

    Like

Leave a comment