0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

How to increase disk size of VM in VirtualBox and Vagrant

Last updated at Posted at 2020-02-14

The problem

I have a VM with default disk size set to 10Gb, it's too small after running some days, and I have to increase its' size to continue to work in it.

What I have tried

I'm using Vagrant indeed, but not directly operate VirtualBox.

So first I tried vagrant-disksize plugin, with this:

  config.disksize.size = '30GB'

But failed to increase the disk size:

==> default: Running 'pre-boot' VM customizations...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["modifymedium", "/Users/bin/VirtualBox VMs/vmm_default_1580704342870_60830/ubuntu-xenial-16.04-cloudimg.vmdk", "--resize", "30720"]

Stderr: 0%...
Progress state: VBOX_E_NOT_SUPPORTED
VBoxManage: error: Failed to resize medium
VBoxManage: error: Resizing to new size 32212254720 is not yet supported for medium '/Users/bin/VirtualBox VMs/vmm_default_1580704342870_60830/ubuntu-xenial-16.04-cloudimg.vmdk'
VBoxManage: error: Details: code VBOX_E_NOT_SUPPORTED (0x80bb0009), component MediumWrap, interface IMedium
VBoxManage: error: Context: "RTEXITCODE handleModifyMedium(HandlerArg *)" at line 816 of file VBoxManageDisk.cpp

After that I also tried using VBoxManage modifyhd 49ae1c84-ceba-44c3-8ad3-8299474d89dd --resize 20480, but failed too, with the same error messages:

0%...
Progress state: VBOX_E_NOT_SUPPORTED
VBoxManage: error: Failed to resize medium
VBoxManage: error: Resizing to new size 21474836480 is not yet supported for medium '/Users/bin/VirtualBox VMs/vmm_default_1580704342870_60830/ubuntu-xenial-16.04-cloudimg.vmdk'
VBoxManage: error: Details: code VBOX_E_NOT_SUPPORTED (0x80bb0009), component MediumWrap, interface IMedium
VBoxManage: error: Context: "RTEXITCODE handleModifyMedium(HandlerArg *)" at line 816 of file VBoxManageDisk.cpp

The solution

So I had to do more research using Google, and find the right solution. The reason is that disk with vmdk format dose not support change disk size, first you should convert it to vdi format and then change the disk size(but only support for increasing), and finally convert it back to vmdk formt.

Here are all steps.

Convert vmdk to vdi disk (by clone new disk)


$ VBoxManage clonehd "/Users/bin/VirtualBox VMs/vmm_default_1580704342870_60830/ubuntu-xenial-16.04-cloudimg.vmdk" "/Users/bin/VirtualBox VMs/vmm_default_1580704342870_60830/ubuntu-xenial-16.04-cloudimg.vdi" --format vdi
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone medium created in format 'vdi'. UUID: 72691a55-83e3-4f65-846b-0fec2c6599db

Resize vdi disk


$ VBoxManage modifyhd "/Users/bin/VirtualBox VMs/vmm_default_1580704342870_60830/ubuntu-xenial-16.04-cloudimg.vdi" --resize 20480
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Convert vdi to vmdk disk (by clone new disk)


$ VBoxManage clonehd "/Users/bin/VirtualBox VMs/vmm_default_1580704342870_60830/ubuntu-xenial-16.04-cloudimg.vdi" "/Users/bin/VirtualBox VMs/vmm_default_1580704342870_60830/ubuntu-xenial-16.04-cloudimg-new.vmdk" --format vmdk
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone medium created in format 'vmdk'. UUID: 3ae8ed1e-d0fb-438a-8140-80625a043f81

Confirm new disk size

Using VBoxManage list hdds command(only showing new created disk):

UUID:           3ae8ed1e-d0fb-438a-8140-80625a043f81
Parent UUID:    base
State:          locked write
Type:           normal (base)
Location:       /Users/bin/VirtualBox VMs/vmm_default_1580704342870_60830/ubuntu-xenial-16.04-cloudimg-new.vmdk
Storage format: vmdk
Capacity:       20480 MBytes
Encryption:     disabled

Attach new created disk to VM

In VirtualBox main window, select the VM -> Settings -> Storage -> Disk, you will see something like this:

image.png

Click hard disk icon in the Hard Disk item, then click "Choose a disk file" to chose the new vmdk file, finally click Ok to save the settings.

After that using vagrant up, after VM booted, ssh to it and check the disk size in VM:


$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        20G  9.5G  9.9G  50% /

That's all.

References

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?