Why can't I chown a VirtualBox shared folder?
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?
Solution 1:
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
.
Solution 2:
These are the steps I followed, to get my shared folder to behave as expected:
Shared Folder Setting
Host
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.