Thursday, October 04, 2012

Fixing VMWare Fusion permissions for shares under Ubuntu guest

The default mount options for shared folders in VMWare fusion are less than ideal.  You may have run into an obscure issue such as PHP Parse error: syntax error, unexpected 'x' in /mnt/hgfs/… or other permission issues.  When listing a mounted folder directory, you will see the uid and gid as 501 and dialup (20), which is your mac user and staff group:

drwxr-xr-x 1 501      dialup    748 Oct  4 17:41 .
drwxr-xr-x 1 501      dialup    442 Sep 19 12:14 ..
drwxr-xr-x 1 501      dialup    510 Oct  4 17:41 application
drwxr-xr-x 1 501      dialup    136 Jun 24 21:19 cirt
drwxr-xr-x 1 501      dialup    272 Apr 11 22:03 classes3p

This can be resolved by fixing the VMWare Tools script which mounts the shares. Follow these steps:

  1. sudo vim /etc/vmware-tools/
  2. locate the vmware_mount_vmhgfs function
  3. Set the appropriate uid and gid.  We'll use 1000, as Ubuntu assigns these to the first user / group:
    -o uid=1000,gid=1000 to the mount command:

    vmware_exec_selinux "mount -t vmhgfs .host:/ $vmhgfs_mnt -o uid=1000,gid=1000"

  4. Save the file and reboot your VM


The alternative is to run the following sed command. It will modify the script in place, also creating a backup:

sed --in-place=.bak 's/vmware_exec_selinux "mount -t vmhgfs .host:\/ \$vmhgfs_mnt"/vmware_exec_selinux "mount -t vmhgfs .host:\/ \$vmhgfs_mnt -o uid=1000,gid=1000"/1' /etc/vmware-tools/


André R. said...

On wmvare fusion 5.0 with Debian 7.0 I had to change "/etc/init.d/vmware-tools" instead of "/etc/vmware-tools/" which does not exists.

But this did not fix the problem for me, still need to do "touch app/cache/*/*.php" on a Symfony2 application.

But I mapped the UID to my console account, did not try mapping it to www-data.

Stuart said...

@André, I ended up creating an NFS share via OS X and mounting this. Much faster and more reliable.