87

I have Ubuntu 10 as the guest OS on a Windows 7 machine. I have been trying to setup shares through VirtualBox, but nothing is working. First, I create the share in VirtualBox and point it to a Windows folder. Then I try to mount the drive in Linux, but I keep getting

/sbin/mount.vboxsf: mounting failed with the error: Protocol error

I have read so many solutions to this, but none seem to work. I have tried:

  • Using the mount.vboxsf syntax
  • Reinstalling VBox additions
  • Rebooting
  • Enabling and trying as root account

I made a share called "Test" in VBox Shared folders. Then I made a directory in ubuntu named "test2". Then I tried to execute this command:

sudo mount -t vboxsf Test /mnt/test2

Any other ideas?

Zanna
  • 70,465
skaz
  • 1,343
  • 2
    i tried all the answers and after installing dkms error persisted. But the solution to me was to just restart ubuntu and mount again. It worked. – void Apr 13 '20 at 13:34

11 Answers11

96

In order to use shared folder functionality few prerequisites need to be met:

  • Make sure that Guest Additions are properly installed on the guest OS.
  • Users in a guest Ubuntu must be in the group vboxsf to be able to access shares.
  • Define a directory on the host that will be used in the virtual machine using the settings dialogue of Virtual Box.

Depending on host or guest OS the following may also be needed:

  • Do not share personal folders like /home/username or My Documents
  • Avoid special characters or empty spaces in the path to the shared folder, especially if the host or VM is a Windows machine
  • Use different names for share and mountpoint
  • Create a mountpoint on the guest OS (best in your HOME directory).

Testing shared folders functionality can be done by creating a shared directory on the host (e.g. C:\myshare), define this as a shared folder for your guest system in Virtual Box settings (e.g. share), create a mount point in your guest os (e.g. mkdir /home/username/host) and mount this in the guest OS with the command:

sudo mount -t vboxsf -o uid=1000,gid=1000 share /home/username/host

where the option -o makes sure that you will have access to the mount (that will otherwise be owned by root).

For further information on shared folders see also the Virtual Box User Manual.

Files or directories can also be shared over the network by using Samba on the host and the guest.

Takkat
  • 142,284
  • 4
    I believe I have met all of these requirements but am still getting the error. Is there a way that I can diagnose what the problem is? – skaz Mar 15 '11 at 12:24
  • 1
    Not to the string literal level, but my share is C:\test instead of C:\myshare, it is defined in VBox 4.0.4. I have made a folder in /home/[myusername]/test2 and a folder in /mnt/test2 and run the command exactly on these two folders and both return the same error. – skaz Mar 15 '11 at 13:56
  • 1
    Thanks for your help! I didn't realize that the words "test" and "Test2" would be considered as using the same name. This solved the problem! – skaz Mar 15 '11 at 15:46
  • My problem was with the name apparently. It started after I applied an update. Now solved by changing the mounted name to something other than the actual name. – Aditya M P Mar 15 '13 at 09:03
  • everything is good and done. but i need to mount the the shared folder every time I login..ANY ADVICE – abh-kirrack Apr 27 '13 at 09:58
  • @abh-kirrack: for a permanent solution see: http://askubuntu.com/questions/52328/mount-virtualbox-sharedfolder-in-ubuntu-vm-on-boot – Takkat Apr 27 '13 at 11:22
  • It might be worth noting that share should be the shared folder's name defined in the setting dialogue on VirtualBox (I found some trusted answers in other questions suggest to use a full path of the shared folder's on the host). – IsaacS Jun 08 '14 at 23:02
  • 2
    For 'share' I'd foolishly used sf_[sharename], since I could see it was being mounted under /media/ with that name and assumed it would need the ubuntu-local name and not VBox's own name. However, I removed the 'sf_' prefix and this solved the problem. – Astravagrant Dec 29 '15 at 18:13
  • To avoid the error, if have to rename the share first before mounting it (via menu item of the guest window). Any ideas why? – Christian Schulzendorff May 31 '18 at 21:15
  • @ChristianSchulzendorff: hard to say generally - it may be a name conflict from sharename and mountpoint – Takkat Jun 01 '18 at 06:07
  • 1 upvote for adding uid and gid. This solved it for me. – ArchLinuxTux Jun 21 '18 at 12:12
  • Can you elaborate on 'Do not share personal folders like /home/username or My Documents'? Is that your own (quite reasonable) advice, or an actual restriction? If it's a restriction, how does VirtualBox determine blacklisted directories? Does it just reject $HOME, or is this a setting somewhere? – Michael Scheper Aug 07 '18 at 16:08
  • Also, please define 'special characters'. I don't believe Linux restricts characters in filenames at all (you can even include a slash in a filename by escaping it out), so is this a real restriction when the host and guest are both Linux boxen? [Citation needed] – Michael Scheper Aug 07 '18 at 16:10
  • 1
    @MichaelScheper these are recommendations only - if it works for you, all is fine. – Takkat Aug 08 '18 at 07:09
  • I tried to edit the answer to make it clear they're just your recommendations, but it seems the reviewer didn't understand that those points aren't actually 'needed' for it to work, but rather your own (quite reasonable) recommendations. Oh well. – Michael Scheper Aug 13 '18 at 17:31
  • @MichaelScheper: I did not make up these recommendations, they are not "mine" and I prefer to not claim they are. Unfortunately your edit made this wrong impression. – Takkat Aug 13 '18 at 19:22
  • Okay, fair enough; I misunderstood your previous comment—mea culpa. But then, I suggest you expand on the recommendations, or cite their source. I just did some websearching about sharing home directories in VirtualBox, and while I see well founded concerns about security, and about different versions of applications working on the same data, I haven't found anything suggesting it could cause this error. My concern is that readers may waste time 'fixing' things that have nothing to do with the error in the question, and that it may be incorrect to say they 'depend on the host or guest OS'. – Michael Scheper Aug 14 '18 at 16:29
  • @MichaelScheper: as always I did give a reference to my source in the answer, you may not have seen it. In the troubleshoot guide (click link on prerequisites) from the official Virtual Box forum it is stated: You're sharing a personal folder like your Home Folder (Linux), or My Documents (Windows) on the Host. - I am sorry for the time you had wasted, did you manage to get it working in the meantime? The last sentence of my answer actually is my own recommendation: use a network share for consistent results through all VMs - at least that is how I share my documents. – Takkat Aug 14 '18 at 18:36
  • Hi. Sorry to drag this out; you clearly are open to the point I've been trying to make, and I appreciate it. I actually did follow that link, and while it does say the short notation for the home folder is not allowed (~ in POSIX), and it suggests sharing a subdirectory of My Documents as a troubleshooting exercise, I don't see where it says those directories can't be shared at all. I actually have shared home folders myself, e.g. /home/myuser, without issue. I did solve my issue (embarrassingly https://askubuntu.com/a/1063266/135088); I just question this is the best answer for others. – Michael Scheper Aug 15 '18 at 15:52
  • Thanks, I was using the same name for share and mountpoint, that was the problem. But is is weird, I don't understand why we cannot use the same name... By the way, it worked for me in read-only mode even if my user was not in a vboxsf group. – baptx Aug 27 '19 at 12:05
17

I also met this trouble. I found that the shared folder were already mounted at /media/sf_share.

I tried to delete /media/sf_share, but I couldn't.

So I deleted shared folder "share" in my home directory.

$ rm -r ~/share

And then switch to root user with the following way:

$ sudo -i

Create softlink/shortcut to the /media/sf_share folder that owns by root user modify the ownership of softlink with chown command. Exit from root user to normal user

# ln -s /media/sf_share /home/username/share
# chown username.username /home/username/share
# exit
logout

$ chmod 777 ~/share

You can see the files in Windows through the shared folder. And username must be a member of group vboxsf.

  • Thanks ! you were right... already mounted in /media/sf_sharename – Laurent Oct 21 '17 at 13:46
  • 1
    Using CentOS 7, and I also found that my directory is mounted at media/sf_sharename. Creating a symlink to that directory would seem to be a possible option, but this is quite different from the advertised/documented procedure on the VirtualBox site. There must be a proper resolution to this!?!? – cartbeforehorse Sep 15 '18 at 17:57
12

Here is what worked for me without any problem

I figured it out that, actually my user name was not in vboxsf group. Following two commands will help to get the group info:

grep "vboxsf" /etc/group    
grep "saurav" /etc/group

So I added saurav (me) to the vboxsf group using following command:

sudo usermod -a -G vboxsf saurav 

Then restarted the virtualbox and then.. Jumped from my placed.. :D :D Everything worked fine without any problem.

Please comment if any one still having any problem..

Saurav Kumar
  • 14,916
2

I also struggled a lot with the mounting, and tried everything I come up with in the interwebz but I finally found a very weird workaround to solve it! My guest is Ubuntu 13 and my host is Windows 7.

Change to the media folder and from there type user@os:/media$ sudo mount -t vboxsf share /home/username/folder

Yeah, that's it. But I don't understand how come it only works if it's done from the media folder. If someone knows please kindly explain us below. Thanks.

P.s. Editing my /etc/rc.local to do the automounting at startup doesn't work for me.

  • 1
    /etc/rc.local will never work, since it's done before the network is up. – Braiam Jan 03 '14 at 18:01
  • 2
    Hi Braiam! Nice to know. Unfortunately I have read in countless of sites people recommend editing the /etc/rc.local for the automounting. Do you know what is the correct way to automount it on startup? Thanks. – BringBackCommodore64 Jan 04 '14 at 19:30
  • I am also finding it only works from /media. Very strange. I just added this to my .profile: pushd media && sudo mount /media/<theshare> && popd. – Matt Greer Apr 09 '18 at 16:21
2

Tried all the aforesaid and nothing worked for me. Lastly I created a new transient folder "Shared" with "Make Permanent" and "Auto Mount" enabled. And then I run the command

sudo mount -t vboxsf -o uid=1000,gid=1000 Shared /mnt/sharedvm

It worked for me. No error this time.

boardtc
  • 103
  • 5
Pankaj
  • 21
1

For me, the problem was that I was a goose, and I'd forgotten that I'd removed the entry from my Shared Folders list in VirtualBox (Machine→Settings→Shared Folders).

I'm just throwing this in here, in case anybody else is ever similarly mislead by 'Protocol error'.

:honk:

1

I tried a few answers and then saw void's comment saying he restarted the Linux guest OS and re-mounted.

Worked for me. :)

Eliah Kagan
  • 117,780
1

With VirtualBox 5.1.20 running on Windows 10, and Ubuntu 16.04 as the guest OS with GuestAdditions 5.1.20 installed, I couldn't mount the shared folders from the command line. The mount commands failed, with mentions of Protocol Error and sf_read_super_aux err=-22.

Eventually I found https://www.virtualbox.org/ticket/16670 "mount.vboxsf symlink broken". I followed one of the workarounds there, to correct the symlink for mount.vboxsf, and it all worked. My approach was to do:

mv /sbin/mount.vboxsf /sbin/mount.vboxsf-orig
ln -s /opt/VBoxGuestAdditions-5.1.20/lib/VBoxGuestAdditions/mount.vboxsf /sbin/mount.vboxsf

The commands need to be done by root. So, because it was Ubuntu, I added "sudo " at the beginning of each line to do the command as root. Other flavors of Linux have other ways of doing that.

As an aside, there was a similar symlink problem reported in virtualbox's Ticket #12879 "Can't mount shared folders with guest additions 4.3.10" in 2014, that was fixed the following month.

2017-04-27

  • @duncan: good point. The title of the ticket describes the problem, but I edited to show the solution I used. – J Cumming May 01 '17 at 19:24
  • The changelog for virtual box v5.1.22 at https://www.virtualbox.org/wiki/Changelog#v22 says that – J Cumming May 01 '17 at 19:27
  • The changelog for virtual box v5.1.22, released 2017-04-28, (https://www.virtualbox.org/wiki/Changelog#v22), says that this bug/ticket #16670 is fixed. I'm excited! – J Cumming May 01 '17 at 19:35
  • Not sure why this was downvoted, but it helped me with my problems using Vbox 5.122 – qodeninja Aug 01 '17 at 03:41
0

Personally I faced the same error message and the problem was related to the fact I did a typo related to the folder located on the host machine and which I set as a shared folder from within the virtual machine thanks to the guest additions.

So the right command is:

sudo mount -t vboxsf -o uid=$UID,gid=$(id -g) shared_folder_located_in_host_machine path_to_mounting_folder_inside_the_virtual_machine

This fixed the error message.

Billal Begueradj
  • 6,011
  • 11
  • 39
  • 56
0

For me it was the wrong version of guest-additions.

I moved my whole VM from one laptop (which ran VirtualBox 5.8/something) to another laptop with VirtualBox 6.0. Everything worked except the mounting of shared folder.

I just started VM, clicked on Devices -> Insert Guest additions CD image... and followed instructions. It cribbed a bit about presence of older version of guest additions, but then removed it and installed the new one on second attempt. Reboot and works.

Kashyap
  • 351
  • 3
  • 10
0

My shared folder was working and after rebooting my host, it wasn't.

By changing the name of the shared folder from Shared to Shared2 it worked.

config.vm.synced_folder "/Users/username/Dropbox/Shared", "/Shared2"

No idea on what happened and why nor how to fix. System with no global mutable state like Nix do have a point.

nicolas
  • 101
  • 1