How to compact / shrink a Dynamically Allocated virtual box vmdk file on a ubuntu guest after deleting a bunch of files?

6,599

The virtual disk image is a VMDK file or VDI file?

VBoxManage only shrinks VDI file based disk images.

To do that...

First, zero fill your virtual disk. Boot the VM and run:

sudo dd if=/dev/zero of=/bigemptyfile bs=4096k status=progress
sudo rm -f /bigemptyfile

Shut down the VM and VirtualBox.

Then on the host run:

vboxmanage modifymedium x:\path\to\disk.vdi --compact

Note: You'll have to specify the path of vboxmanage (generally 'C:\Program Files\Oracle\VirtualBox').

Share:
6,599

Related videos on Youtube

Patoshi パトシ
Author by

Patoshi パトシ

MIT graduate developer living and working from Tokyo! (◠‿◠) Open to freelance opportunities in Crypto or Drupal. Supporting: https://girlswhocode.com https://www.liftcommunities.org https://www.pursuit.org https://www.womenwhocode.com

Updated on September 18, 2022

Comments

  • Patoshi パトシ
    Patoshi パトシ over 1 year

    I have a very old virtual box with ubuntu 14 guest installed. Its currently taking up over 50GB and I just deletect 35GB of data on this virtualbox, but since the hard drive is Dynamically allocated the vmdk file is still its original huge size. What is an easy way to compact / shrink this vmdk file? I'm on Windows 10 as host.

  • Patoshi パトシ
    Patoshi パトシ over 5 years
    its my vmdk file that is over 50GB. so i'm out of luck?
  • Kanchu
    Kanchu over 5 years
    You can convert VMDK to VDI using the command: vboxmanage clonehd --format VDI x:\path\to\disk.vmdk x:\path\to\disk.vdi
  • Patoshi パトシ
    Patoshi パトシ over 5 years
    Does zero fill my virtual disk would require me to fill it up to my max capacity of 500GB? that is what I have set. But my SSD is only 500GB and I only have 20gb free right now.
  • Patoshi パトシ
    Patoshi パトシ over 5 years
    screenshot: prntscr.com/klgl74
  • Kanchu
    Kanchu over 5 years
    After zero filling, remove/delete the /bigemptyfile, shutdown the VM and then compact the disk.
  • Patoshi パトシ
    Patoshi パトシ over 5 years
    doesn't clonehd command makes a copy of my vmdk file? which means its 2x50GB = 100GB of free space I need right?
  • Kanchu
    Kanchu over 5 years
    Yes, it does, but once it gets converted (and it works properly) you can compact it and then delete the VMDK, retaining the VDI.