Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

In VirtualBox, what is the best way to share a directory between an OS X host and Ubuntu guest?

  • Host: Mac OS X 10.7.3
  • Guest: Ubuntu 12.04
  • Guest has a shared directory mounted via VirtualBox settings with Access=Full and Auto-Mount=Yes.

The problem with this setup is illustrated below. In my shared directory, I can't change the permissions at all (not a permissions denied error, but they just don't take effect).

Ubuntu 12.04 (guest):

% ls -l
total 0
-rwxrwx--- 1 root vboxsf 0 Apr 17 21:56 1
-rwxrwx--- 1 root vboxsf 0 Apr 17 21:56 10
-rwxrwx--- 1 root vboxsf 0 Apr 17 21:56 2
-rwxrwx--- 1 root vboxsf 0 Apr 17 21:56 3
-rwxrwx--- 1 root vboxsf 0 Apr 17 21:56 4
-rwxrwx--- 1 root vboxsf 0 Apr 17 21:56 5
-rwxrwx--- 1 root vboxsf 0 Apr 17 21:56 6
-rwxrwx--- 1 root vboxsf 0 Apr 17 21:56 7
-rwxrwx--- 1 root vboxsf 0 Apr 17 21:56 8
-rwxrwx--- 1 root vboxsf 0 Apr 17 21:56 9

Mac OS X 10.7.3 (host):

$ ls -l
total 0
-rw-r--r--  1 <my-mac-user>  staff  0 Apr 17 21:56 1
-rw-r--r--  1 <my-mac-user>  staff  0 Apr 17 21:56 10
-rw-r--r--  1 <my-mac-user>  staff  0 Apr 17 21:56 2
-rw-r--r--  1 <my-mac-user>  staff  0 Apr 17 21:56 3
-rw-r--r--  1 <my-mac-user>  staff  0 Apr 17 21:56 4
-rw-r--r--  1 <my-mac-user>  staff  0 Apr 17 21:56 5
-rw-r--r--  1 <my-mac-user>  staff  0 Apr 17 21:56 6
-rw-r--r--  1 <my-mac-user>  staff  0 Apr 17 21:56 7
-rw-r--r--  1 <my-mac-user>  staff  0 Apr 17 21:56 8
-rw-r--r--  1 <my-mac-user>  staff  0 Apr 17 21:56 9

If I chmod on the guest, nothing changes:

% chmod +x 1 | ls -l 1 # guest
-rwxrwx--- 1 root vboxsf 0 Apr 17 21:56 1

If I chmod on the host, it changes on the host but not on the guest:

$ chmod +x 1 | ls -l 1 # host
-rwxrwx--x  1 <my-mac-user>  staff  0 Apr 17 21:56 1

% ls -l 1 # guest
-rwxrwx--- 1 root vboxsf 0 Apr 17 21:56 1
share|improve this question
    
Ah, I figured it out, but I can't post the answer for another 8 hours (not enough points). The solution is to do sudo mount.vboxsf -o umask=002,gid=1000,uid=1000 src /media/sf_src, where the umask is the value of umask of the user, uid and gid are from id <user>, src is the name of the VBox share, and /meida/sf_src is the desired mount point. –  jmdeldin Apr 18 '12 at 4:56
add comment

1 Answer 1

up vote 8 down vote accepted

I've figured it out!

To reproduce:

  1. Shutdown the VM, add shared folders in VBox's settings (Permanent=Yes, Auto-Mount=No)
  2. Start the VM
  3. From a terminal, run umask && id as the normal user to get something like this:

    002 # this is your umask

    uid=1000(luser) gid=1000(luser) groups=1000(luser),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),109(lpadmin),124(sambashare),125(vboxsf)

  4. sudo mkdir -p /media/sf_src # src is the shared directory

To mount the src directory as a test:

sudo mount.vboxsf -o umask=002,gid=1000,uid=1000 src /media/sf_src 
                           |   |        |        |   |-> where to mount
                           |   |        |        |       the file
                           |   |        |        |-> name of the shared dir
                           |   |        |            (in VBox settings)
                           |   |        |
                           \   |        /
                        from the `id` command

To automatically mount it on login, edit /etc/fstab and add the following:

src /media/sf_src vboxsf umask=002,gid=1000,uid=1000
share|improve this answer
    
This is EXACTLY what I was looking for! I ended up creating a shared user group for apache2 and my users that have access to the mounted folder. serverfault.com/questions/6895/… –  thesmart May 29 '12 at 2:15
    
Thanks! Note that I had big problems until I discovered that /sbin/mount.vboxsf was a dangling symlink! Erasing it and then ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions/mount.vboxsf /sbin/mount.vboxsf solved the problem! The guest additions install probably wasn't able to symlink it. I spent far too much time figuring this out! –  csl May 1 at 14:00
    
... now the only problem seems to be that vboxsf doesn't handle symlinks! As in, you can't create symlinks in the shared folder from the VM! (At least on OSX, VirtualBox 4.3.10 –  csl May 1 at 14:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.