Total Pageviews

Monday, March 28, 2011

VMware Fusion + Ubuntu + Shared Folders

For you crazies out there trying to circumvent lockouts... you may have endeavored to create a development environment utilizing multiple technologies to facilitate your need. Case in point:


This setup allows me to run various programs on my local system when I'm not on campus. However, the tiny gotchas in setting up the environment have serious bite! The setup involves VMware Fusion on a Mac running an Ubuntu installation in a virtual machine and sharing folders between the host operating system (OS X) and the guest (Ubuntu).  My Ubuntu installation is actually augmented as a Debathena station.

This post will only cover getting around the problems encountered when sharing folders between the Mac and the Ubuntu Virtual Machine running concurrently.  More specifically, making sure that it can be seen from the guest and streamlining to mitigate against the risk of system updates breaking the shared folders functionality. Creating the whole environment from scratch might be the topic of another post. Anyway, I found a mechanism so that shared folders work, but it does require a manual operation whenever the virtual machine is launched.

The problem revolves around VMware Tools. VMware tools provides extra features that allow for a more seamless operation between the host and guest operating systems such that the line splitting the two is blurred. This includes copy/paste functionality, shared folders, and more. However, installing VMware tools is quite a process.  There are a few ways to do it:
  1. using the open-vm-tools package provided by Ubuntu
  2. using packages.vmware.com from VMware itself
  3. manually via the VMware host you are running
Of these three, method 2 will allow you to utilize the standard package manager operations provided by the Ubuntu operating system to manage updates. And that... is priceless. When I first created this development environment, I went with option 3. Everything worked beautifully, although I had to use the 32-bit 10.04 Lucid version of Ubuntu instead of the 64-bit 10.10 version after hitting several road bumps. Then at some future date, I had to install a slew of updates...  this is when vmware tools got broken and, more specifically, shared folders.

Go with option 2....

Installation via Option 2


The following sites provide pretty good instruction on how to get vmware tools installed:
Unfortunately, it will take some back and forth between the two guides to fully complete the installation as the former is missing some steps mentioned in the latter. Here is my abridged version (actual command line commands will be in bold italics):
  1. (optional) if vmware tools is already installed via option 3, it must be uninstalled:
    1. sudo vmware-uninstall-tools.pl 
  2. create a directory to store some keys (doesn't matter where)
  3. navigate to that directory
  4. wget http://packages.vmware.com/tools/keys/VMWARE-PACKAGING-GPG-DSA-KEY.pub
  5. wget http://packages.vmware.com/tools/keys/VMWARE-PACKAGING-GPG-RSA-KEY.pub
  6. wget http://packages.vmware.com/tools/VMWARE-PACKAGING-GPG-KEY.pub
  7. sudo apt-key add *KEY.pub
  8. cd /etc/apt/sources.list.d
  9. sudo emacs -nw vmware-tools.list
  10. add the following line to that file followed by a newline:
    1. deb http://packages.vmware.com/tools/esx/4.1latest/ubuntu lucid main restricted
  11. ctrl+x ctrl+s (saves the file)
  12. ctrl+x ctrl+c (exits emacs)
  13. sudo apt-get update
  14. sudo apt-get install vmware-open-vm-tools-kmod-source
  15. sudo module-assistant prepare
  16. sudo module-assistant build vmware-open-vm-tools-kmod-source
  17. sudo module-assistant install vmware-open-vm-tools-kmod
  18. sudo apt-get install vmware-open-vm-tools
There is a chance that step 14 will generate an error in the vain of, "I don't know what file you are talking about...."  If this happens, something likely went wrong in steps 9-12.  Make sure there is a new line at the end of the file.

At some point during those steps, a reboot or two will likely be required. 

Installation Verification


After all these steps, it is wise to verify the installation.  According to the VMware documentation, this can be done by running the following command:
  • /etc/init.d/vmware-tools status
In this status, you want to verify that "vmware-guestd" is running (for ESX releases prior to 4.1) or "vmtoolsd" is running (for ESX releases 4.1 and later).  The documentation also says to check that certain kernel modules are running using the /sbin/lsmod command. See page 29 under "Verify VMware Tools installation" in the documentation for more details.

Verifying Shared Folders


If you desire to share folders on your OS X side with the Ubuntu guest, a few extra steps will be required.  
  1. On the VMware Fusion menu bar, select "Virtual Machine"
  2. Click on "Shared Folders"
  3. If a shared folder hasn't yet been created, select "Add a Shared Folder"
    1. When completed return to the "Virtual Machine > Shared Folders" menu option 
  4. Select "Open Shared Folders Settings..." and verify your desired settings
Now that a shared folder is verified to exist on the VMware Fusion software, check that it can be seen within the Ubuntu guest (it likely won't):
  1. Open a terminal window
  2. ls /mnt/hgfs/
If your shared folder does not get listed, it means Ubuntu cannot see it.  Return to the VMware Fusion menu bar and do the following:
  1. Select "Virtual Machine > Shared Folders > Turn Shared Folders Off"
  2. Select "Virtual Machine > Shared Folders > Turn Shared Folders On"
That's right, simply toggle shared folders off and on. Return to the terminal window on the Ubuntu guest and run the same command again:  
  • ls /mnt/hgfs/
This time, your shared folder should get listed.  And off you go.  

You should now be able to ensure vmware tools is always updated via Ubuntu's package manager. However, every time the Ubuntu guest is relaunched, the shared folders toggling trick will need to be executed to ensure the guest can see the shared folders.

Run along now, hope this helps!