28

I'm trying to recursively chown a VirtualBox shared folder, but I can't get it to work:

$ ls -lah
total 16K
drwxr-xr-x  4 root root   4.0K Aug  1  2012 .
drwxr-xr-x 23 root root   4.0K Jul 21  2012 ..
drwxrwx---  1 root vboxsf 4.0K May  4 17:02 sf_dev
drwxrwx---  1 root vboxsf 4.0K Sep  2 10:21 sf_dropbox
$ sudo chown -R pknight:pknight sf_dropbox && ls -lah
total 16K
drwxr-xr-x  4 root root   4.0K Aug  1  2012 .
drwxr-xr-x 23 root root   4.0K Jul 21  2012 ..
drwxrwx---  1 root vboxsf 4.0K May  4 17:02 sf_dev
drwxrwx---  1 root vboxsf 4.0K Sep  2 10:21 sf_dropbox

I'm aware that I could just add a user to the vboxsf group (as it has full permissions), but I don't want to give every user/daemon full permissions to all of my shared folders.

I'm running VirtualBox 4.2.x, with Windows 7 as the host and both Xubuntu and Debian as guests.

Is there any way for me to change the owner/group of my VirtualBox shared directory?

1
  • 1
    Note that the accepted answer doesn't answer the question, and it's that question that I need an answer to. Mar 22, 2016 at 17:58

3 Answers 3

32

The VirtualBox shared file system (vboxsf) doesn't support POSIX permissions per se; rather, they are "set" at mount time:

$ mount
...
dropbox on /media/sf_dropbox type vboxsf (gid=1001,rw)

The gid bit specifies the group that owns the directory; on my system, this happens to correspond with the vboxsf group.

You can alter the user and/or group ownership by remounting (must be done as root):

# mount -t vboxsf -o remount,gid=1000,uid=1000,rw dropbox /media/sf_dropbox

Replace 1000 with the desired user/group IDs, and dropbox with the name of the share (the part after sf_).

Note that this must be done after every reboot unless you edit /etc/fstab.

2
  • 1
    How to you edit fstab to do this?
    – TheSmose
    Nov 25, 2015 at 19:29
  • @TheSmose see askubuntu.com/questions/252853/… for details about how to do this in Ubuntu (and probably other Debian-based distros as well). In the <options> field you'll most likely want to put gid=1000,uid=1000,rw (replace the user/group IDs as appropriate).
    – nc4pk
    Nov 26, 2015 at 2:46
4

These are the steps I followed, to get my shared folder to behave as expected:

Shared Folder Setting

Host

Add Shared Folder

Add Shared Folder

Reboot the guest.

Allow soft links

VBoxManage setextradata <guest vm> VBoxInternal2/SharedFoldersEnableSymlinksCreate/<shared folder> 1


Guest

Update guest additions

Devices -> Insert Guest Editions CD Image

add all necessary users to the vboxsf group

sudo usermod -a -G vboxsf <username>

Change permissions

sudo chown -R <username>:<user group> /media/

Reboot the system.

Change ownership

sudo mount -t vboxsf -o gid=<username>,uid=<user group>,rw <share folder name> /media/sf_<share folder name>

This is the corresponding line in /etc/fstab:

data /media/sf_data vboxsf rw,nodev,relatime,iocharset=utf8,uid=982,gid=982 0 0

Note: I'm still unable to change ownership to a random user on the shared folder.

1

The vboxsf group has full access to the shared folder, so you should add your user to that group.

Note: you should set the option "Auto-mount" in VirtualBox shared folder settings.

Shared folder permissions:

drwxrwx--- 1 root vboxsf    0 feb  9 07:41 sf

Add your user to the vboxsf group:

usermod -aG vboxsf <youruser>

Reboot:

sudo reboot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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