Virtual Machines as Mitochondria
15 Feb 2010
Here’s the idea: Use Linux virtual machines (VMs) hosted on Mac OS X for all types of one-off, console- or server-related tasks. That’s it. Depending on your background, that may be all you need to read. If you’re looking for tips, you’re done.

And this one even comes with a metaphor: Think of the VM like a mitochondrion; not necessarily the energy-producing-powerhouse, but the specialized-cell-that-evolved-to-live-in-another-cell aspect. If you lack the technical skill to implement this idea, I’m sorry but you’re also done. A lone article written by me in February 2010 isn’t the right venue to impart this skill. If you’re still here and you’d like to explore how far you can take this idea, and hear a one-sided argument for it, read on.
Let Linux be Linux
This is a setup I’ve been using for a long time. I tweak it when I think of ways to improve it, which happens a lot. It stems from questions like these:
- You need to run an NFS server. How would you do it?
- You need to cross-compile a whole stack of code. How quickly can you gather the tools?
I use Mac OS X as my everyday machine, but I’m painfully aware of how easy Linux can make these two tasks, and a slew of related ones. So I let Linux play to its strengths and just run them in a VM. I’m coming way late this argument:
Installing MySQL on Ubuntu (the NSFW way)
but Mark Pilgrim’s characteristically good article solidified my answer to the question, “How do you setup MySQL for local webapp development?” and it’s not, “Compile it from the source and run it on your Mac.” I like to apt-get install as much as anyone, but I’m willing to accept lock-in that Pilgirm will not. My setup is more in line with Alex Payne’s Rules for Computing Happiness:
http://al3x.net/2008/09/08/al3xs-rules-for-computing-happiness.html
i.e., “Do not use anything other than a Mac at home and Linux/BSD on the server.” (But see here to read how the tide is also turning for him.) The virtual machines I run all happen to be Ubuntu server, and I think of them as if I’m carrying along a few extra servers with my laptop. Because I run the server versions, I ssh into them and otherwise interact with them as if they were remote servers. They just have great ping times.
One parting shot at Linux: It’s come a long way since I used it as my everyday, desktop operating system. For example, I never had a Linux machine with reliably-working WiFi. So while this doesn’t cause current users as much grief, now it causes me and my VM no grief. The VM thinks it got its IP address from a very friendly DHCP server over eth0.
Keep the Mac clean
In a nutshell, anything that’s moderately server related, I put in a VM. For example, even though my Mac is capable and eager to serve files from my ~/Sites directory, I spin up an Ubuntu 8.04 machine running Apache to do that work. Yes, the same Apache project (and much of the codebase) that my Mac would have used. And that’s just for Apache, which ships with the Mac. I’ve stopped using Fink and MacPorts altogether, and that’s because you have to be ruthless about what you keep on your Mac. If it doesn’t install by dragging into the /Applications folder, there has to be a compelling reason to install it. I’ve been using Mac OS X since 10.0 in 2001. One of my favorite features is the User Migration Manager. Upgrades are painless. As Kottke observed, they’re painless almost to a fault. But with upgrade after upgrade, the footprint of software I carried with me in /sw (Fink) and /opt/local (MacPorts) became a burden. Worse than a burden, in fact, because system upgrades would render the software incompatible.
I have no loyalty to any of the VMs. Whenever I think I need a clean slate I grab the latest version of Ubuntu. I delete VMs at whim without grabbing any data from them. If something was important, it would have already been on my Mac or in the cloud. But despite my lack of loyalty, the insular nature of the VMs ensures that they will run fine no matter the host system.
Trade-offs
This system doesn’t optimize for:
- Cost. Mac OS X and VMware Fusion cost money. Using Mac OS X allows me to run other great, expensive software.
- Freedom. It’s important to me, but I don’t optimize for it.
- Disk space. My biggest regret about this system is that Time Machine chews up the virtual disk images. I read that CrashPlan is better in this regard, but I haven’t tried it.
- Performance. The Ubuntu server VMs I run require 256 MB of resident memory. If that’s significant, buy a new machine.
I try to optimize for:
- Flow. Even though “it’s all the same machine,” I find lots of situations where there’s a natural division of labor between the Mac frontend and Linux backend. The ability to focus on one or the other helps, and it helps the most when the VM is a local development mirror of a remote Linux production server. Need to edit your config file? You do it in the same place on the local VM as the real webserver.
- Security. The fewer services I run on my Mac, the better. The VMs are generally NAT’d from the rest of the network.
- Google-ability of problems. Forget for a moment that google-ability isn’t a word, and recognize a great disparity. Searching for “Ubuntu <name of some service or command line program or error message>” almost always leads to the right answer. There are just so many other people in the same boat. At the time of writing, the top hit for “mac os x nfs server” has screenshots full of pinstripes. (It’s a Tiger tutorial from 2005.)
Tools
Here are five things I’ve done to make interface between my Mac and Linux VMs even better:
- SSH keys. I shouldn’t even need to state this. If you don’t have these properly working, I’ve failed you in letting you read this far. You should be reading more introductory material.
- Prefer Bonjour over editing /etc/hosts. Run Avahi on the Linux VM. It’s sweet, and it saves you from having to note the VMs IP address.
- Matching user ids. This is a pain, and somewhat ridiculous, but just suck it up and make your UID in the VM the same as the one on your Mac. It will pay off when you install the…
- VMWare HGFS module to mount the Mac’s home directory. The Linux VM can read the Mac’s files directly with this module. I edit webpages in Coda on my Mac, and then have Apache in the VM serve them back to me.
- Expandrive to view Linux files. It’s rare that I need to grab a lot of files from the VM (I’ll use scp for small jobs), but when I do Expandrive handles the job well.
Specialization and trade
If you didn’t like the junior-high-biology-class metaphor from the opening, I’ll close with an economic one: Specialization and trade promote higher output and prosperity. Two countries can find ways to capitalize on each other’s strengths, so I challenge you to do the same with these UNIX offspring.
Exercises left to the reader
I’ve left out details of how to replicate my setup, partly because that information has a shelf-life of about five minutes. Also, this is an idea you should take and personalize. Maybe you’ll use Dropbox, rsync, sshfs, WebDAV, or git to move files around. Maybe you’ll try out the latest versions of the ejabberd or Prosody XMPP servers in a VM instead of littering your Mac with files. The ideas and the metaphors are more important than my details.