“dynamically allocated” disk (VDI) files • Great when we have several VMs, and each is small • But what happens when we put stuff on the VDI? LOG LOG LOG the disk grows on demand... … but does not shrink back on its own!
disk usage from inside the VM, the host machine still sees the storage as allocated. rm rf <stuff we no longer need> • So we go tell the guest OS to zero-out the freed-up space… sudo telinit 1 mount o remount,ro /dev/sda1 zerofree v /dev/sda1 • … and next tell VirtualBox to trim down the VDI file. vboxmanage modifyhd /path/to/thedisk.vdi compact Source: How to compact VirtualBox's VDI file size? - Super User
from CFTC project – Original size: 40+ GB – After shrinking and about 6 months of use: 11.3 GB – 250% saved • The famous “Manju-adroitLogic” Windows 7 MSSQL VM (Manju-adroitLogic.vdi) – Original size: 43.3 GB – After shrinking and about 6 months of use: 27.9 GB – 55% saved
experience: horrifying – Recovering a “swapping” VM is a nightmare • But may prevent unexpected out-of-memory errors in some situations • As long as you can allocate enough RAM, swap space would not be necessary Source: Do virtual machines need swap partitions? - Stack Overflow
• No need of a UI, or even an on-screen CLI • So, why clutter the desktop with unused VM windows? Headless: always “headless” (background) Detachable: starts in the foreground, can be switched to foreground/background on demand
Incompatible versions can cause unnecessarily high CPU/memory usage, spikes, etc. • Clean up old/unused images regularly – After updating an image, run the famous command docker rmi f `docker images f "dangling=true" q` – Unused images → disk expansion → problems! • Watch out for pull failures – Sometimes half-pulled content can accumulate – /var/lib/docker/tmp
Avoid cluttering up /home/yourusername • Use sparse files for disk image backups – Commands like rsync will usually copy the entire VDI file – ignoreexisting sparse followed by inplace copies only changed blocks How do you synchronise huge sparse files (VM disk images) between machines? - Server Fault • Use VMs to try out risky stuff, e.g. opening suspicious files With Virtual Machines, Getting Hacked Doesn’t Have to Be That Bad