Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
open-vm-tools and VMWare Shared Folders for Ubuntu guests

(NB: adapted from this Ask Ubuntu thread -- tested to work with Ubuntu 16 LTS branches and Ubuntu 17.10)

Unlike using VMWare Tools to enable Linux guest capabilities, the open-vm-tools package doesn't auto-mount shared VMWare folders. This can be frustrating in various ways, but there's an easy fix.

TL;DR

Install open-vm-tools and run:

sudo mount -t fuse.vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other

(Make sure /mnt/hgfs exists and is empty)

You can put configuration stanzas in /etc/fstab to facilitate this, and then mount /mnt/hgfs will work.

See the Setting up auto-mounting section for setting up auto-mounting instead.

Pre-work

Make sure open-vm-tools (and open-vm-tools-desktop if you're using a desktop environment) are installed, and that you've rebooted after their installation.

sudo apt update
sudo apt install open-vm-tools open-vm-tools-desktop

Make sure you have a /mnt/hgfs directory made and empty. If not:

sudo mkdir -p /mnt/hgfs

Mounting

To mount the filesystem, run:

sudo mount -t fuse.vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other

The shared folders will now be in subdirectories of /mnt/hgfs

Setting up auto-mounting

  1. Add the following line to /etc/fstab:

    .host:/	/mnt/hgfs	fuse.vmhgfs-fuse	noauto,allow_other	0	0
    

Do not use the auto keyword; vm-tools has to start completely before the mount will work

  1. Create or edit the script /etc/rc.local (as root), and add the line:

  mount /mnt/hgfs

  1. make sure rc.local is executable and owned by root:

    sudo chown root:root /etc/rc.local
    sudo chmod 0755 /etc/rc.local
    
  2. enable the rc.local service in systemd:

    sudo systemctl enable rc-local.service
    
  3. reboot

The rc.local script runs as the last step of startup, allowing the HGFS filesystem to mount after open-vm-tools services are running, which is required for successful operation.

Browse /mnt/hgfs at will.

#!/usr/bin/env bash
## this must be run as root!
## It should set up VMWare Shared folders on Ubuntu guests using open-vm-tools
rclocal="/etc/rc.local"
owner="root:root"
mountpoint="/mnt/hgfs"
## fail if we're not run as root
if [ "$EUID" != 0 ]
then
(>&2 echo "$0 must be run as root")
exit 127
fi
## set up FSTAB
mkdir -p $mountpoint
echo ".host:/ ${mountpoint} fuse.vmhgfs-fuse noauto,allow_other 0 0" >> /etc/fstab
## set up rc.local script
if ! [ -f "$rclocal" ]
then
echo '#!/bin/sh' > "$rclocal"
fi
echo "mount '$mountpoint'" >> "$rclocal"
chown $owner "$rclocal"
chmod 0755 "$rclocal"
## enable rc.local service
systemctl enable rc-local.service
systemctl start rc-local.service
## report and exit
(>&2 echo -e "set up and started $rclocal\nyou should be able to browse $mountpoint now and after reboots")
exit 0
@chartre

This comment has been minimized.

Copy link

@chartre chartre commented May 10, 2018

I tested your solution for auto-mounting with the option auto instead of noauto and it worked fine (Ubuntu 18.04). Can be considered as a valid solution or may cause problems in future?
BTW: congrats for good info.

@elar-systems

This comment has been minimized.

Copy link

@elar-systems elar-systems commented Jul 1, 2018

I did the same thing in fstab and used option "auto" instead of "noauto" and it worked fine (Ubuntu 18.04).
No need "rc.local" at all.

@johnsondnz

This comment has been minimized.

Copy link

@johnsondnz johnsondnz commented Jul 18, 2018

Tested with elementary-os (16.04 based) with "auto", and works fine.

@sunilkallur

This comment has been minimized.

Copy link

@sunilkallur sunilkallur commented Sep 11, 2018

I did the same in fstab i.e "auto" and it worked(Ubuntu 18.04.1 LTS) and VMware Workstation 14 Player.
Thanks a lot for sharing this info.

@rich-nahra

This comment has been minimized.

Copy link

@rich-nahra rich-nahra commented Apr 28, 2019

nice work. auto in /etc/fstab seem to work fine on ubuntu 19.04 / vmw workstation 15.03

@im007

This comment has been minimized.

Copy link

@im007 im007 commented Feb 4, 2020

Can confirm this also works on PopOS 19.10 & VMware Fusion 11.5.1 -- with the auto option instead of noauto

No need "rc.local" at all.

@darrenpmeyer

This comment has been minimized.

Copy link
Owner Author

@darrenpmeyer darrenpmeyer commented Mar 18, 2020

I tested your solution for auto-mounting with the option auto instead of noauto and it worked fine (Ubuntu 18.04). Can be considered as a valid solution or may cause problems in future?

I haven't tested with Ubuntu 18.04; I can't validate. It's good news that they seem to have fixed the issue that required the rc.local workaround, but I don't know what the issue was so I can't comment about how safe it is to switch to using auto. It seems easy enough to fix either way, but for now I know that noauto + an rc.local script always works.

@kfreund

This comment has been minimized.

Copy link

@kfreund kfreund commented Feb 5, 2021

You're probably better off using autofs rather than putting an entry in fstab. As the author pointed out, bad things can happen if the mount cannot happen at the proper point in the boot process and you have an entry in fstab that for whatever reason can't mount, blowing the boot process out of the water. With autofs, the mount doesn't occur until you actually try to stat below the mount point.

https://www.kernel.org/doc/html/latest/filesystems/autofs.html

  1. Install autofs through your package manager
  2. Create a mount point for autofs:
    sudo mkdir /mnt/autofs
  3. Create a file (as root):
    /etc/auto.master.d/hgfs.autofs
    with the contents:
    /mnt/autofs /etc/auto.mnt
  4. Create a file (as root):
    /etc/auto.mnt
    with the contents (assuming you didn't rename "Macintosh HD" in OS X):
    hgfs -fstype=fuse.vmhgfs-fuse,allow_other .host:/Macintosh\ HD
  5. enable autofs to start at boot, restart the service, and reload the autofs configs we just made:
    sudo systemctl enable autofs
    sudo systemctl restart autofs
    sudo systemctl reload autofs
  6. Navigate to your new automount, which will be your root OS X file system:
    cd /mnt/autofs/hgfs # fuse file system will mount on this command
  7. If you're really ambitious, you could:
    sudo ln -s /mnt/autofs/hgfs /mnt
    cd /mnt/hgfs # fuse file system will mount on this command
@keithrbennett

This comment has been minimized.

Copy link

@keithrbennett keithrbennett commented Apr 18, 2021

Confirmed, in (Kubuntu) Ubuntu 20.04, I only had to add the following line to /etc/fstab, then reboot:

.host:/ /mnt/hgfs fuse.vmhgfs-fuse auto,allow_other 0 0

No other steps were necessary for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment