Over the course of many system upgrades, logging, etc. the image files have grown substantially. I have deleted as much of such files as I can to drop their sizes back down to about 5 gigs, but their usage on disk still stands at about twice that amount. I am guessing that they must have “grown” to accommodate the data needed, but is there a way I can shrink them back?
yes. for your whonix images, you can use a tool called zerofree free to work, since the disks are ext4 partitions. it’s a little bit involved. but this is how i’ve gotten the best results:
- install the package “zerofree” in the virtual machine you want to shrink.
- erase what you need in the vm, run apt-get purge, apt-get autoremove, apt-get clean, etc. as needed.
- reboot your virtual machine in recovery mode.
- at the command prompt, type “systemctl stop systemd-journald.socket && systemctl stop systemd-journald.service && mount -o remount,ro / && zerofree -v /dev/vda1 && shutdown now”
- when the vm shuts down, open a terminal on your host.
- switch to root. type “sudo -s”
- type “cd /var/lib/libvirt/images”
- create a back up of the disk you want to shrink. type “mv YourVirtualMachineDisk.qcow2 YourVirtualMachineDisk.qcow2.backup”
- shrink the disk. type “qemu-img convert -o qcow2 -p YourVirtualMachineDisk.qcow2.backup YourVirtualMachineDisk.qcow2”
- 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. that’s the method i prefer. but, the above is a basic method for getting a shrunken qcow2 disk file.
Would you like to add this to the Kicksecure wiki?
That’s a real long standing thing asked every now and then that is missing in the wiki.
Where does this belong on both wikis?
only 1 wiki might be sufficient, new wiki page:
Added and credited. Thanks @tempest for sharing.