Tuesday, April 3, 2012

Coherence-like Linux Integration with Parallels Desktop (or any other VM system)

Here's a nifty trick you can use to integrate your Linux virtual machine with OSX's windowing system:

First ensure that you've installed ssh on your Linux virtual and that you have sshd running.  On Ubuntu, it's as easy as typing this command from a terminal window:
sudo apt-get install ssh
Once you have ssh installed, you will want to figure out the IP address of your Linux guest virtual.  I've configured my Linux instance's network to use NAT.  If you're running Ubuntu, you can simply type this command from a terminal window:
ifconfig eth0 | grep "inet addr" | awk '{print $2}'
I've found that in Parallels, even though my virtual guest is configured to get it's IP address from a DHCP server, it always get's the same IP address when I run it in NAT mode.  You may want to consider changing your Linux guest configuration from DHCP to static if you find that your IP address is always changing.


Once you have your guest computer's IP address in hand, you will want to add it to the /etc/hosts file on your Mac.  You will need to have admin privileges when editing it.  I edit mine using vim from a OSX terminal window.
sudo vi /etc/hosts
You will want to add an entry at the bottom of your /etc/hosts file for your Linux guest.  Name it whatever you'd like.
 Once you've done that, you should be able to ssh into your Linux guest from an OSX terminal window using the hostname you provided in the hosts file:
ssh steve@linux
If this is working, you're in good shape.  You may want to consider using key-based authentication so that you're not constantly being prompted for a password.

Now we're getting to the interesting part.  You can use ssh's X11 tunneling capability to run X11 apps on your Linux guest, but have the output directed to your Mac using either X11.app or XQuartz.app.  X11.app comes with OSX Lion and below.  If you're considering Mountain Lion, you'll need to download XQuartz.app and install it yourself.

To use the X11 tunneling, you simply need to ssh into your Linux guest with the "-Y" option:
ssh -Y steve@linux
Once you're logged into the Linux guest, ensure that your DISPLAY environment variable is set to:  localhost:10.0.
echo $DISPLAY
If it is, you're all set.  Just try to run an X11 app from your Linux bash prompt:
xeyes
libreoffice --calc
firefox
sudo synaptic 

Your Mac should pop-up a new window with the app you specified:


Pretty cool huh?


No comments:

Post a Comment