Help us understand the problem. What is going on with this article?

How to increase disk size of VM in VirtualBox and Vagrant

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

liubin
Nothing to share
http://liubin.org
gamba
「笑顔ではたらく」をつくる gamba!
http://www.getgamba.com/top
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした