
Shrink Virtual Harddisk
Over the course of many system upgrades, logging, etc. the image files can grow substantially. Deletion of obsolete files does not automatically shrink the disk size back as it has “grown” to accommodate the data needed.
A tool called zerofree free is needed to shrink the backing virtual disk file. Since the default are ext4 partitions, the process might be bit involved:
1. Install the package zerofree
in the virtual machine you want to shrink.
2. Erase what you need in the VM, run apt-get purge, apt-get autoremove, apt-get clean, etc. as needed.
3. Reboot your virtual machine in recovery mode.
4. At the command prompt, type Click = Copy Copied to clipboard!
5. When the VM shuts down, open a terminal on your host.
6. Switch to root. Click = Copy Copied to clipboard!
Click = Copy Copied to clipboard!
7. Create a back up of the disk you want to shrink. Click = Copy Copied to clipboard!
8. Shrink the disk. Click = Copy Copied to clipboard!
9. Boot up the VM and see if it is working. If it is, you can delete the backup of the qcow file.
There are ways you can get more creative with this using thin provisioned images that are based on a static qcow2 backing file, a preferred method. However the above is a basic method for getting a shrunken qcow2 disk file.[1]
- ↑ Credit goes to forum user tempest https://forums.whonix.org/t/is-it-possible-to-re-shrink-the-qcow2-image-files/13228/3p