Virtualbox – Sharing Folders with the correct permissions
# Add current user to vboxsf group in Ubuntu guest OS sudo usermod -aG vboxsf $USER #You can access the share by making the user, or group id of 1000, a member of group vboxsf. #This is done by changing the vboxsf line in the /etc/group file. May require reboot. #File permission issues with shared folders under Virtual Box (Ubuntu Guest, Windows Host) # add the following lines to .bashrc mkdir -p ~/host/share sudo mount -t vboxsf -o uid=1000,gid=1000 share ~/host/share
Stuff which I tried but did not work
Adding mount to fstab
The issue here is that vboxsf is not yet loaded when /etc/fstab is loaded.
I added vboxsf to /etc/modules but still had no luck.
Adding mount to rc.local
# So to add ownership and automatically mount in virtualbox via vboxsf in Ubuntu # add to the /etc/rc.local file before the exit 0 line the command as follows: # mount -t vboxsf -o uid=1000,gid=1000/home/ /where/ever/you/want # add shared folder to destination mount point in /etc/rc.local just before "exit 0" if sudo grep -q "mount -t vboxsf -o uid=1000,gid=1000 share" /etc/rc.local; then echo "share mount already added" else echo "adding share mount"; # remove exit 0 sudo sed -i "s/exit 0//g" /etc/rc.local # add new lines with exit 0 sudo tee -a /etc/rc.local << EOF mkdir -p ~/host/share sudo mount -t vboxsf -o uid=1000,gid=1000 share ~/host/share exit 0 EOF fi
cronjob
sudo crontab -e # add the following line @reboot mount -t vboxsf -o uid=1000,gid=1000 share /home/a/host/share
Troubleshooting
1. Appending the line vboxsf to /etc/modules did not work for me
Command Notes
a@a:~$ sudo mount -t vboxsf -o uid=$UID,gid=$GID sharea /home/a/sharea gid= requires an argument (i.e. gid==) a@a:~$ sudo mount -t vboxsf -o uid=$UID,gid=1000 sharea /home/a/sharea /sbin/mount.vboxsf: mounting failed with the error: Protocol error a@a:~$ sudo mount -t vboxsf -o uid=$UID,gid=1000 sharea /home/a/sharea /sbin/mount.vboxsf: mounting failed with the error: Protocol error # reason: using a different folder name than the share directory configured in the Virtualbox a@a:~$ sudo mount -t vboxsf -o uid=$UID,gid=1000 vb-share-folder ~/host/share #ln -s /media/sf_{mount_name} to /var/www/mountpint #ln -s /media/sf_hosta to /home/a/host/a
References
1. http://mikefunk.com/2014/01/22/automounting-with-virtualbox/
2. http://askubuntu.com/questions/481559/how-to-automatically-mount-a-folder-and-change-ownership-from-root-in-virtualbox