My main productivity tool is a MacBook, but I develop and deploy software for Linux (64-bit Ubuntu GNU/Linux to be exact). With the release of the free and open source VirtualBox 1.2, I can now run a 64-bit guest OS on my Mac, so I now have everything needed to develop 64-bit Linux applications comfortably on my Mac. In my situation, I want to use Mac OS X as the host of my development environment. My source code lives on my Mac volume -- local Mac OS X tools work well with it. TextMate works, svn, and Time Machine for backup, and so on. For much of what I do, that suffices. But our deployment platform is 64-bit Ubuntu Linux. I want to do some compiling, debugging, unit testing, etc. under an environment that is as close to production as possible.
By default this OS sits behind a NAT -- it can see the network, but the "outside net", including the host mac, can't connect to internal service. To fix that, from the Mac OS X terminal do this:
$ VBoxManage setextradata "Ubuntu64" \ "VBoxInternal/Devices/e1000/0/LUN#0/Config/guestssh/Protocol" TCP $ VBoxManage setextradata "Ubuntu64" \ "VBoxInternal/Devices/e1000/0/LUN#0/Config/guestssh/HostPort" 2222 $ VBoxManage setextradata "Ubuntu64" \ "VBoxInternal/Devices/e1000/0/LUN#0/Config/guestssh/GuestPort" 22
This forwards the mac's localhost interface, port 2222 to the VM's SSH service. This assumes you called your VM "Ubuntu64" and that it's configured to use the "e1000" network interface, which is the default. Also, let's assume that the Mac OS X user is called "macuser"; Linux user is "linuxuser".
Check you settings with:
$ VBoxManage getextradata "Ubuntu64" enumerate
Now restart the VM instance, and then ssh into the VM.
$ ssh -p 2222 linuxuser@localhost
(I put this in a Mac OS-side shell script, and also add a variety of port-forwarding commands to connect to Linux hosted services -- that's left as an exercise for the reader).
From my Linux VM (accessed from the ssh session in the Mac Terminal) I mount my work environment with sshsf. First install sshfs, and add the user to the fuse group. For my needs, I also want the linux "root" user to access the sshfs-mounted file system. SSH needs to be enabled on the Mac OS side for this to work. To do this, turn on "Remote Login" under the "Sharing" panel in the Mac OX X System Preferences application. Then ssh into the linux VM:
$ ssh -p 2222 linuxuser@localhost
(enter your password, and now you're in the Linux VM)
$ sudo apt-get install sshfs $ sudo addgroup linuxuser fuse
Log out and log back in at this point to enable the group membership. Then edit /etc/fuse.conf and uncomment "user_allow_other".
Now we map the Mac OS "work" directory into Linux. From Linux:
$ sshfs macuser@10.0.2.2:/Users/macuser/work /home/linuxuser/work -o uid=1000 -o gid=1000 -o allow_root
this assumes that "linuxuser" has UID/GID's of 1000, which is typical for the first user on Ubuntu. Note also that "10.0.2.2" is the address of the Mac OS interface on the other side of the VM's NAT. I put this in a Linux-side shell script, and run it automatically on login.
From this point, changes to "~/work" on either side effect the same files. Editing on the Mac in TextMate is speedy, and "make" on Linux works as expected and produces amd64 binaries.
- Q: Why not just have the source files live in the Linux VM, and then mount them into the Mac OS file system via NFS, SMB, SSHFS or something? A: I used to do this, but I want my files to live in Mac OS -- that's where I generally "live", and all of my tools like TextMate, TimeMachine, etc. run there. Also, I'm more leery about having my important files live inside a virtual disk.
- Q: Why not use svn, git, or rsync, etc. to push changes between environments? A: That can work, but then changes have to be explicitly checked in or at least pushed / pulled between environments. I don't want to track this (or bother other with my check-ins). I also want to be able to edit the same files under either os (e.g. a quick vi under Linux), and not have to think about what changed where.


When did it come to this? My Mac told me this morning that I was almost out of disk space. Entourage quit, telling me to not bother opening it until more space is available. This is just crazy. Since when is 55GB not enough?