Skip to content

Instantly share code, notes, and snippets.

@darrenpmeyer
Last active April 10, 2024 19:18
Show Gist options
  • Save darrenpmeyer/b69242a45197901f17bfe06e78f4dee3 to your computer and use it in GitHub Desktop.
Save darrenpmeyer/b69242a45197901f17bfe06e78f4dee3 to your computer and use it in GitHub Desktop.
open-vm-tools and VMWare Shared Folders for Ubuntu guests

(NB: adapted from this Ask Ubuntu thread -- tested to work on Ubuntu 16.04 LTS through Ubuntu 22.04 LTS (Jammy).

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

Add the following line to /etc/fstab:

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

Update: based on extensive testing, the auto keyword seems to work fine. Prior versions suggested noauto. If you have trouble with auto, change to noauto and see below

If using the noauto keyword, but you want automount

  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
## USAGE setup-hgfs-automount-ubuntu.sh [noauto]
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
if [ "$1" == "noauto" ]
then
echo ".host:/ ${mountpoint} fuse.vmhgfs-fuse nauto,allow_other 0 0" >> /etc/fstab
else
echo ".host:/ ${mountpoint} fuse.vmhgfs-fuse auto,allow_other 0 0" >> /etc/fstab
echo "You may now `mount ${mountpoint}`; it will also be auto-mounted on next boot"
exit 0
# if using the `auto` keyword, no rc.local setup is required, and we're done here.
fi
## 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
@jrep41
Copy link

jrep41 commented May 19, 2022

Thank you!!!

@ppilotto
Copy link

ppilotto commented Jun 7, 2022

Worked for me too. Thank you

@Linhuihang
Copy link

It works! Thank you!!

@slhck
Copy link

slhck commented Sep 9, 2022

@kfreund I followed your steps precisely but it didn't load the shared folders.

root@debian:/home/debian# cat /etc/auto.master.d/hgfs.autofs 
/mnt/autofs /etc/auto.mnt
root@debian:/home/debian# cat /etc/auto.mnt
hgfs -fstype=fuse.vmhgfs-fuse,allow_other,uid=1000 .host:/
root@debian:/home/debian# automount -f -v
Starting automounter version 5.1.8, master map /etc/auto.master
using kernel protocol version 5.05
lookup_nss_read_master: reading master file /etc/auto.master
do_init: parse(sun): init gathered global options: (null)
lookup_read_master: lookup(file): read entry +dir:/etc/auto.master.d
lookup_nss_read_master: reading master dir /etc/auto.master.d
lookup_read_master: lookup(dir): scandir: /etc/auto.master.d
include_file: lookup(dir): include: /etc/auto.master.d/hgfs.autofs
lookup_nss_read_master: reading master file /etc/auto.master.d/hgfs.autofs
do_init: parse(sun): init gathered global options: (null)
lookup_read_master: lookup(file): read entry /mnt/autofs
lookup_read_master: lookup(file): read entry +auto.master
lookup_nss_read_master: reading master files auto.master
do_init: parse(sun): init gathered global options: (null)
master_do_mount: mounting /mnt/autofs
automount_path_to_fifo: fifo name /var/run/autofs.fifo-mnt-autofs
lookup_nss_read_map: reading map file /etc/auto.mnt
do_init: parse(sun): init gathered global options: (null)
mounted indirect on /mnt/autofs with timeout 300, freq 75 seconds
st_ready: st_ready(): state = 0 path /mnt/autofs

Any idea?

This works:

root@debian:/home/debian# vmhgfs-fuse .host:/ /mnt/hgfs/ -o allow_other -o uid=1000
root@debian:/home/debian# ls /mnt/hgfs/
Desktop

But it is not a solution for putting into the /etc/fstab file if shared folders have not been enabled yet.

@lypanov
Copy link

lypanov commented Mar 6, 2023

Thank you.

@MattDMo
Copy link

MattDMo commented Jul 27, 2023

@BillHargen's solution worked for me perfectly - I had upgraded open-vm-tools and open-vm-tools-desktop and even rebooted, but no dice. Deselecting and then selecting the "Enable Shared Folders" checkbox in the VM's settings window under "Sharing" got my shares to mount using

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

@MadMartian
Copy link

Doesn't work on Ubuntu 22.04, attempting to mount crashes with a segmentation fault.

@gmikhaile
Copy link

Thank you!

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