I've been using for more than one year and a half an Ubuntu 12 VM for daily development. I know we now live in an era of Vagrants and containers, but I haven't had good experiences with the former, and having Windows host OS containers with Linux guests are not possible. Also, with a proper configuration & decent CPU, assigning one or two cores and a few GB of RAM to a VM makes for a wonderful development environment (which you can backup, rollback and duplicate easily).
So, I decided that might be interesting to write down my findings and some quick optimizations anybody can apply to get a faster guest Linux VM.
I have tested this VMs both with Windows hosts (Windows 8, 8.1 and 10) and Ubuntu 15, with a 4th gen i7 and a 5th gen i5 (both mobile CPUs), 8 GB of host RAM and SSD HDDs.
- Always use the latest VirtualBox version: For example version 5.0 has speed improvements and USB 3.0 support, but in general it is nice to keep updating them as Linux kernels get new releases quickly and I wouldn't trust an old "Virtualbox Guest Additions" build.
- Assign 1 or 2 CPUs to the VM: My rule is up to half the physical ones, but if you are going to "mono-task" a lot, maybe one is enough. For background processes, jobs and similar tasks 2 assigned processors work better.
- There's no need to change the chipset setting. I found some posts telling people to change from PIIX3 to ICH9. Most are about old generations of CPUs and I noticed no increase in performance changing it so went back to the "safe and proven" setting.
- 2 to 3 GB of RAM are usually more than enough: I run 2 Node.js apps, PostgreSQL, Ruby on Rails, Resque jobs, Sublime text, PGAdmin... all of them usually under 2GB of used RAM. Just keep an eye for swap usage, swapping is the devil.
- Enable all the System tab options that you can: Nested paging, PAE/NX... all of them are good, and you can even try setting them on and if something breaks just turn them off again. Shared /bi-directional clipboard is great but I don't know why comes off by default.
- Linux Acceleration is still crappy with VirtualBox: Forget about 3D acceleration, and if you prefer speed to fancy animations, disable also 2D acceleration and see more tweaks below. You will get pixelated zoom effects when switching applications but the OS performs faster overall. This also allows to setup 18 or 24MB of RAM without problems.
- Check the "Solid-State Drive" option in the Storage section when the Host HDD is an SSD: This also should be an automatic check but... anyway do it because not only I/O will be faster you'll also increase the lifespan of your SSD drive.
- Port forwarding is dead easy between VMs: I had to comunicate two VMs recently, and found that each VM can communicate with the outside just calling the default route (10.0.2.2 by default) and a given port, and then forwarding that port to another VM's IP (e.g. 10.0.2.15 calls 10.0.2.2:2222 which gets forwarded to 10.0.2.14:222)
- Shared folders are so great: Windows with Samba can read and write Linux folders, so don't be afraid to use them.
- Toolset for many of this tweaks: CompizConfig Settings Manager, Ubuntu Tweak, MyUnity. Depending on the Ubuntu version some might not be available.
- Disabling fancy effects, fadings and animations, and for those animations you cannot remove, just set them as fast as possible. You can even fully disable VSync waits to squeeze some FPS if your hardware is not great.
- If you have a good resolution setup, disabling font antialiasing also speeds up. And at the bare minimum you can disable it from the window titles.
- Disabling background (just place a plain solid color) and sounds. I directly disable sound at the VM.
- Missing a right click context menu "open in Terminal" option? Try this:
sudo apt-get install nautilus-open-terminal
- Remove all unwanted software: Upon install, Ubuntu each day feels more like Windows, full of OpenOffice applications, viewers, crappy games and other stuff you probably will never use. Do yourself a favor and spend 20 minutes checking all installed packages and removing the unused ones.
- Ubuntu Tweak has a nice feature call "Janitor". It allows you to clean unused packages and dependencies and, most importantly, remove old kernel versions and old cached packages. Each time I use it I regain around 1GB of space and delete hundreds of files.
- Linux filesystem uses a "journal" to write changes in a way there is no data loss. You can change it to be faster at the expense of less reilability in case of errors (I haven't had any issue yet):
sudo tune2fs -O has_journal -o journal_data_writeback /dev/sda1
- Another option I haven't yet explored is creating a RAMDisk, should be noticeably faster and as now we're going towards 16GB can be interesting if your VM does a lot of I/O.
- Disable Super key/Win key: Quite annoying and a problem if both the Host and Guest OS are Linux as one steals the keypress from the other. Afterwards I for example have it mapped to switching the keyboard layout.
- To remove undesired autoboot applications, you can check the boot list at /etc/xdg/autostart
- Sometimes (for example disabling Bluetooth) the Unity control panel just "stops working". Ubuntu dependencies seem to uninstall it, but bringing it back is easy: sudo apt-get install unity-control-center
- If with a Windows Host the Guest Linux runs extremely slow, this SuperUser.com instructions might help. In my specific case I was missing the proper Host Intel chipset drivers and VirtualBox was really slow.
- Encrypting the Home folder: After install, as at setup time you can do it. Careful as it will eat twice the HDD space (it decryps the home folder upon login, creating a copy) and hurts I/O.
- Or activating a /Private home encrypted subfolder: My favourite, way less taxing on I/O but with some symbolic links you can have a safe but comfortable folder structure.
- And how to disable encryption, just in case you change your mind or wish to change from /Home folder to /Private subfolder one