Thursday, January 5, 2017

Shrink a Ubuntu Guest VDI File

When using a Ubuntu virtual box guest, sometimes we want to shrink the dynamic expanding VDI file to release the unused disk space. Here is the steps to archive that.

  1. Install ZeroFree

    sudo apt-get install zerofree
  2. Reboot into recovery mode
    a. sudo shutdown -r now
    b. Holding the left Shift key while rebooting
    c. Select Advanced and then Recovery mode and finally Drop to root shell prompt option.

  3. Remount the root partition

    mount -n -o remount,ro -t ext4 /dev/sda1 /
  4. Run ZeroFree

    sudo zerofree -v /dev/sda1
  5. Shutdown the VM

    shutdown -h now
  6. Shrink the VDI file is host OS

    SET PATH=%PATH%;"c:\Program Files\Oracle\VirtualBox
    VBoxManage modifyhd Ubuntu.vdi -compact


Reference: How to shrink a dynamically-expanding guest virtualbox image

No comments:

Post a Comment