Search This Blog

Thursday, July 18, 2013

VMware Fusion - Permissions on Shared Folders on Ubuntu

VMware Fusion provides a nice functionality of sharing folder from host (Mac OSX) to guest (Ubuntu). But then, it seems they are more focused on windows guests, because they screwup on file permissions of shared folders.

"ls -al /mnt/hgfs" will show 501 dialout as user and group, which is sure to cause permission issues on linux guest.

Update: Found a more persistent alternative
1. sudo vim /etc/vmware-tools/services.sh
2. Search for 'vmhgfs_mnt="/mnt/hgfs"'. After this line add: 'vmuser=${VMWARE_MNT_USER:-root}'
3. Then search for 'vmware_exec_selinux "mount -t vmhgfs .host:/ $vmhgfs_mnt"' and replace it with following section:
   uid=`id --user $vmuser`
   gid=`id --group $vmuser`
   vmware_exec_selinux "mount -t vmhgfs .host:/ $vmhgfs_mnt -o uid=$uid,gid=$gid"
4. sudo vim /etc/init/vmware-tools.conf
Before the "pre-start" and "post-stop" lines add:
env VMWARE_MNT_USER=[The guest user you want]
5. sudo reboot

NOTE: This will have to be redone when you update/ reinstall vmware-tools

To fix this:
ssh to your ubuntu.
run command "id". Make note of uid and gid.
"sudo vim /etc/mtab"
look for line ".host:/ /mnt/hgfs vmhgfs rw,ttl=1 0 0"
Duplicate the line and change it to ".host:/ /mnt/hgfs vmhgfs rw,ttl=1,uid=1000,gid=1000 0 0"
"sudo umount /mnt/hgfs"
"sudo mount /mnt/hgfs"

Now do a "ls -al /mnt/hgfs" to verify if correct username and group are shown.

Ideally, vmware fusion should be making this as transparent as possible. But then again, they don't care because they still don't have a real competition. Once, we do some real competitors, maybe then might start worrying about such minor but key items.

Currently, I spend more time trying to get it working than actually working on a VM. I am desperately looking for a better alternative.

This seems like a pretty neat fix. On the sharing screen, VMWare could add a simple textbox for user name and next time vmware tools are installed, use this value while generating the vmware-tools.conf file.

Not sure when VMWare will take note of such minor issues.

6 comments:

Anonymous said...

Hello Viraj,

I found your post trying to google a solution to my problem. I am trying to mount my VM shares so that they are owned by root. I simplified your script to one line:

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

And just forced the uid and gid to 0 for root. Sure enough when I do a long list of the directory, those mounted folders are now owned by root.

However, if I try running a "chown" command, I still get an "Operation not permitted" error. I read somewhere about "root squash" which may prevent true root ownership. However, I have not been able to find out how to turn that off. Any ideas?

I use my VM as my web development environment. My only user is root and I'm not concerned about security. I just want it to work.

Any help you can give would be appreciated.

Thanks,
Rob

V'Raj Kanwade said...

Hi Rob,

I too faced this issue, but since the above works for me, haven't gone into the details yet.

Will update if I find something.

Wayne said...

Blows my mind and wasted 4 hours. I am in awe that shared folder functionality is so poor for vmware. guess I have to learn how to use vagrant after all....

Wayne said...

what a load of shite. I never even imagined that vmware could'nt interpret file permissions between the two. I dont even see the point of having shared folers. Well this is the stubbed toe i need to head to vagrant.

waste of an evening thanks emc2
the best is when the top four articles while searching are 8 year old posts from vmware forums.

grrrr

Kelby said...

Thanks for the great fix! One addition if you are offended by world-writable files, as was the case on my Linux guest:

Add a file mask and directory mask to the -o options, e.g.

fmask=0022,dmask=0022

Note that this is the setting for 755, since VMWare has to be obtuse and thus requires the opposite of the permissions you want.

rangdrol said...

To avoid modifying VMWare scripts, you can unmount and remount the VMware folder with the proper permissions.

For me on Ubuntu, I added the following single line to /etc/fstab (where I mount as user and group 1000):

.host:/ /mnt/hgfs vmhgfs rw,uid=1000,gid=1000

To unmount and remount the drive, you can issue the following commands:

sudo umount /mnt/hgfs
sudo mount /mnt/hgfs


Thanks and regards,
-alec