shrink a Virtual Box disk image (dynamic)

In the Virtual machine itself

sudo apt install zerofree 

boot into emergency mode with GRUB by pressing 'e' and appending the line beginning with 'linux' with the text

systemd.unit=emergency.target

F10 to boot. Log in as root and then run:

mount -o remount,ro / #makes the partition read-only, which zerofree requires

Then run:

zerofree -v /dev/sda1 #(or whatever you want to target)

Exit. Shutdown the VM and open a terminal in the host OS.

In the host OS terminal

$ vboxmanage list hdds #see all virtual disks and identify the one you want
$ vboxmanage modifymedium disk ./VirtualBox/MyDebian/MyDebian.vdi --compact #substituting the path for the disk you want to target

Done.

Proxy Information
Original URL
gemini://nuacht.flounder.online/gemlog/2022-08-17-shrink-virtualbox-disk.gmi
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
663.847957 milliseconds
Gemini-to-HTML Time
0.16423 milliseconds

This content has been proxied by September (ba2dc).