Problem resizing vagrant box storage space

533 views
Skip to first unread message

yvolo...@gmail.com

unread,
May 2, 2019, 11:41:23 PM5/2/19
to Vagrant
Hi all,

I'm not sure if this is the right forum to ask this, but as it may be.. I'm trying to increase the storage space on my vagrant box from 18 GB to 50 GB. I went through the steps described in a blog post, which involved 

1) using clonehd to convert the machine's .vmdk file to .vmi file,
2) using modifyhd to resize the disk
3) converting it back to a .vmdk file
4) attaching the new disk to the VM.

After these steps were done, the virtual hard disk was shown to have 50 GB of "virtual" storage and 18 GB of "actual" storage, as the image below shows.

virtualbox manager with expanded storage.JPG



Running "df -h" showed the results below, which are exactly the same as before I went through the steps to expand storage (18 GB in "/").

virtualbox storage usage.JPG



From what I understand, virtual storage means that that the storage space is supposed to expand as data is added to it. But in my case, the virtual disk throws an "insufficient space" error when I try to add more than 18 GB to it. According to a tutorial on the VirtualBox forum, I need to resize the hard disk partition to use the new space. This involves booting up the hard drive from a GParted Live image. I can see how this can be done on a physical hard disk, but how can I do this for a virtual hard disk? Are there any tutorials/resources for this? Is there anything else that I'm missing? 

Jim McGinness

unread,
May 3, 2019, 2:46:07 AM5/3/19
to Vagrant
It looks like you're using Virtualbox, so the following plugin may help solve your problem. It allows you to specify a new disk size when you run "vagrant up".


As a general statement, the provider may have facilities to change the size of the disk when it creates it the VM, but the instructions you add to your Vagrantfile will be specific to the provider. Aside from that plugin, I don't see that the vbox provider has such a facility, but - as an example - the libvirt provider has a parameter "machine_virtual_size".

=====

If you want to resize the disk later, after the VM has been created with Vagrant, you would need to use whatever facilities, if any, are provided by the target environment for enlarging virtual disks. In most cases, this increases the size of the virtual disk without modifying the filesystem to _use_ the extra space. The steps you followed appear to be a standard way (from the command line) to modify the virtual size of a VMDK; this operation is common enough that the GUI for the virtual environment usually has a resize operation somewhere. For Virtualbox, it's under File->VirtualMediaManager. Select the disk, select properties and move the slider to the new size - but it only works for VDI not VMDK, and only while the VM is halted.

I said "while the VM is halted", but the usual way to handle this for VMs is to boot the VM from a virtual ISO image containing a live or rescue image. The VM isn't halted, but the root disk of the vagrant-created machine is not in use and can be manipulated by the tools.

=====

After the disk is resized, either at creation or afterwards, the partition and filesystem have to be extended to use the additional space. Windows NTFS can be extended live with DISKPART. Linux systems generally use a tool like gparted and it's not advisable to try to apply it to a running system's root disk. Gparted can extend or shrink partitions and, for file systems it knows about, move the contents of the partition to their new size and location. But you can also change the partitions with a tool like fdisk.

But extending a partition is not the same operation as extending a file system to make use of the new space. For ext234 partitions, there is a command resizefs and for xfs file systems there is a command xfs_growfs that can perform this third step.

=====

Resources:

Reply all
Reply to author
Forward
0 new messages