Shared folder problems with Virtualbox guests

Are you having problems getting shared folders to work correctly between the guest and host with VirtualBox? Think you have it sorted and then you get that annoying "blah blah: Protocol error"? Take a step back and consider the following.

Shared folder problems with Virtualbox guests

VirtualBox guests run in 'user space'.

Unlike a network share (ie NFS, CIFS/SMB) guest rights, roles and permissions as defined within the guest VM, have limited expression out side the guest on the host.

The shared folder must have the correct permissions on the host to be accessed, (read and/or write) by the VirtualBox hypervisor itself. For example if the VirtualBox is running as running as your username on the host, it will honour your rights as defined by the access controls on the host. Shared folder objects will be created, deleted, read and written as the user under which the VirtualBox is running on the host.

e.g. On the HOST

drwxrwxr-x 3 vboxusr vboxusr 4096 Feb  8 12:16 .
drwxr-xr-x 9 root    root    4096 Feb  6 22:18 ..
drwxr-xr-x 2 vboxusr vboxusr 4096 Feb  8 11:35 data
-rw-rw-r-- 1 vboxusr vboxusr    0 Feb  8 11:36 ffff
-rw-r--r-- 1 vboxusr vboxusr    0 Feb  8 11:29 foo
-rw-r--r-- 1 vboxusr vboxusr    0 Feb  8 12:16 gggg
-rw-rw-r-- 1 vboxusr vboxusr    0 Feb  8 11:46 hhhh

Guest additions

Within the guest, you will need guest additions are installed.

Prepare the guest

On a Linux guest, make sure that the mount point is owned by the group 'vboxsf', and is group writable. This needs to be done BEFORE mounting the shared folder. (An automount'ed folder mount point is created with these permissions within the /media directory, using these permissions for you.)

e.g. On the GUEST

drwxr-xr-x  5 root root   4096 Feb  8 00:17 .
drwxr-xr-x 23 root root   4096 Feb  6 10:01 ..
drwxr-xr-x  2 root root   4096 Feb  6 11:34 cdrom
drwxrwx---  2 root vboxsf 4096 Feb  6 12:07 nextcloud
drwxrwx---  2 root vboxsf 4096 Feb  6 11:37 sf_nextcloud

Make sure that the user accessing the shared folder is in the vboxsf group.

Mount the shared folder, mapping the host group and user, to a guest group and user:

root@nextcloud-01:~# mount -t vboxsf -o uid=33,gid=33,rw nextcloud /media/nextcloud
root@nextcloud-01:~# ls -al /media
total 20
drwxr-xr-x  5 root     root     4096 Feb  8 00:17 .
drwxr-xr-x 23 root     root     4096 Feb  6 10:01 ..
drwxr-xr-x  2 root     root     4096 Feb  6 11:34 cdrom
drwxrwxr-x  1 www-data www-data 4096 Feb  8 01:16 nextcloud
drwxrwx---  2 root     vboxsf   4096 Feb  6 11:37 sf_nextcloud
root@nextcloud-01:~# ls -al /media/nextcloud/
total 12
drwxrwxr-x 1 www-data www-data 4096 Feb  8 01:16 .
drwxr-xr-x 5 root     root     4096 Feb  8 00:17 ..
drwxr-xr-x 1 www-data www-data 4096 Feb  8 00:35 data
-rw-rw-r-- 1 www-data www-data    0 Feb  8 00:36 ffff
-rw-r--r-- 1 www-data www-data    0 Feb  8 00:29 foo
-rw-r--r-- 1 www-data www-data    0 Feb  8 01:16 gggg
-rw-rw-r-- 1 www-data www-data    0 Feb  8 00:46 hhhh

Testing

Objects within the directory will be created with the mount's (-o) options :

root@nextcloud-01:~# touch /media/nextcloud/data/foo
root@nextcloud-01:~# sudo -u www-data touch /media/nextcloud/data/bah
root@nextcloud-01:~# sudo -u nobody touch /media/nextcloud/data/tui
touch: cannot touch '/media/nextcloud/data/tui': Permission denied
ls -al /media/nextcloud/data/
total 8
drwxr-xr-x 1 www-data www-data 4096 Feb  8 02:37 .
drwxrwxr-x 1 www-data www-data 4096 Feb  8 01:16 ..
-rw-r--r-- 1 www-data www-data    0 Feb  8 02:37 bah
-rw-rw-r-- 1 www-data www-data    0 Feb  8 02:37 foo

... appearing on the host with the VirtualBox's permissions:

total 8
drwxr-xr-x 2 vboxusr vboxusr 4096 Feb  8 13:37 .
drwxrwxr-x 3 vboxusr vboxusr 4096 Feb  8 12:16 ..
-rw-r--r-- 1 vboxusr vboxusr    0 Feb  8 13:37 bah
-rw-rw-r-- 1 vboxusr vboxusr    0 Feb  8 13:37 foo

Goodbye

touch: cannot touch 'foo': Protocol error