Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize a VirtualBox vmdk file [closed]

Tags:

virtualbox

People also ask

How do I resize a disk in VirtualBox?

VirtualBox 6 added a graphical option for enlarging and resizing virtual disks. To access it, click File > Virtual Media Manager in the main VirtualBox window. Select a virtual hard disk in the list and use the “Size” slider at the bottom of the window to change its size. Click “Apply” when you're done.


If you want to end having back a vmdk hard disk (maybe you are interested in using the disk in vwmare too), the complete steps are:

VBoxManage clonemedium "source.vmdk" "cloned.vdi" --format vdi
VBoxManage modifymedium "cloned.vdi" --resize 51200
VBoxManage clonemedium "cloned.vdi" "resized.vmdk" --format vmdk

The above will resize the hard disk up to 50GB (50 * 1024MB).

To complete things you need to resize the drive too! To achieve this, you might want to download gparted iso and boot from that iso to resize your drive (select the iso from within the virtualbox settings).

P.S. If your new size is too small, you'll get the same error even with your new vdi file.


I was able to resize the vmdk by cloning it and then modifying and resizing.

vboxmanage clonehd "virtualdisk.vmdk" "new-virtualdisk.vdi" --format vdi
vboxmanage modifyhd "new-virtualdisk.vdi" --resize 30720

I have a Windows 7 client on a Mac host and this post was VERY helpful. Thanks.

I would add that I didn't use gparted. I did this:

  1. Launch new enlarged vmdk image.
  2. Go to Start and right click Computer and select Manage.
  3. Click Disk Management
  4. You should see some grayed space on your (in my case) C drive
  5. Right click the C drive and select Extend Volume.
  6. Choose size and go

Sweet! I preferred that to using a 3rd party tool with warnings about data loss.

Cheers!


vmdk's :

  • Rather fixed size allocation (step 1,2).
  • Even after expansion, not readily available inside the vmdk's OS (step 3,4,5)

STEPS:

1) convert to ".vdi" first - VBoxManage clonehd v1.vmdk v1.vdi --format vdi

2) expand the size using command-line (Ref: tvial's blog for step by step info)

OR

expand from the Virtual Media Manager in VirtualBox.

[ NOW - INSIDE VM ]

3) Expand the size of drive, with new allocation (e.g. for Ubuntu running on virtual-machine : use GParted) enter image description here enter image description here

4) Extend the filesystem - lvextend -L +50G <file-system-identifier>

ILLUSTRATION:

$ lsblk
NAME                       MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
...
sda                          8:0    0   200G  0 disk 
└─sda1                       8:1    0   200G  0 part 
  ├─myfs-vg-cloud          253:0    0    99G  0 lvm  /
  └─myfs-vg-swap-1         253:1    0   980M  0 lvm  [SWAP]


$ lvextend -L +100G /dev/mapper/myfs-vg-cloud

$ lsblk
NAME                       MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
...
sda                          8:0    0   200G  0 disk 
└─sda1                       8:1    0   200G  0 part 
  ├─myfs-vg-cloud          253:0    0   199G  0 lvm  /
  └─myfs-vg-swap-1         253:1    0   980M  0 lvm  [SWAP]

5) Extend the "/home" - resize2fs <file-system-identifier>

ILLUSTRATION:

$ df -h /home/
Filesystem                        Size  Used Avail Use% Mounted on
/dev/mapper/myfs-vg-cloud         97G   87G  6.0G  94%   /

$ resize2fs /dev/mapper/myfs-vg-cloud

$ df -h /home/
Filesystem                        Size  Used Avail Use% Mounted on
/dev/mapper/myfs-vg-cloud         196G   87G  101G  47%  /

Your system must now be ready to use, with extended allocations !!


Actually, Only this these commands are needed:

VBoxManage clonehd "source.vmdk" "cloned.vdi" --format vdi
VBoxManage modifyhd "cloned.vdi" --resize 51200

Then, you can select cloned.dvi in Virtualbox GUI storage.

After that, start the virtual windows and expand your C disk as the methods of Code Chops.

It is not necessary to convert the *.vdi file to *.vmdk file back.