Upgrade to Pro — share decks privately, control downloads, hide ads and more …

VirtualBox Tips

AdroitLogic
September 06, 2017

VirtualBox Tips

Ugh, the (215|216) disk is full!
A Solution: Manual Shrinking
How Effective?
Using Swap Space in VMs
Headless Mode
Docker in VMs
Some More Tips...

https://www.adroitlogic.com
https://developer.adroitlogic.com

AdroitLogic

September 06, 2017
Tweet

More Decks by AdroitLogic

Other Decks in Programming

Transcript

  1. Ugh, the (215|216) disk is full! • We generally use

    “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!
  2. A Solution: Manual Shrinking • Although we can free up

    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
  3. How Effective? • Oracle 11g VM (SGX - Trojan 2.vdi)

    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
  4. Using Swap Space in VMs • Arguable! • My personal

    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
  5. Headless Mode • We generally use VMs as “service nodes”

    • 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
  6. Docker in VMs • Maintain the correct Docker version –

    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
  7. Some More Tips… • Change your VirtualBox home directory –

    Avoid cluttering up /home/yourusername • Use sparse files for disk image backups – Commands like rsync will usually copy the entire VDI file – ­­ignore­existing ­­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