What is the procedure for mounting a VirtualBox shared folder in Linux?

I tried variations of the following mount command but I keep getting protocol error or other mount errors.

sudo mount -t vboxsf share /home/toto

closed as off-topic by Michael Hampton May 11 '15 at 1:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow." – Michael Hampton
If this question can be reworded to fit the rules in the help center, please edit the question.

locked by Michael Hampton May 11 '15 at 1:37

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

  • Is this a question? Please rephrase it so that it becomes a question, post your own answer to it, and I'll be more than glad to remove the downvote. – icedwater Mar 12 '14 at 4:26
  • 1
    Edited to conform to Q&A standards. – BSalita Mar 12 '14 at 4:52
  • pls update question what you tried and what error you getting – vinay hunachyal Mar 12 '14 at 4:56
  • Edited to show non-working command. A common error is protocol error as stated in question. – BSalita Mar 12 '14 at 5:05
  • I am getting this error any solution to this "mount: unknown filesystem type 'vboxsf'" – sandip divekar Nov 20 '14 at 6:24

Ok this was a little confusing for me but I finally realized what was happening. So I decided to give my 2 cents in hopes that it will be more clear for others and if I forget sometime in the future : ).

I was not using the name of the share I created in the VM, instead I used share or vb_share when the name of my share was wd so this had me confused for a minute.

First add your share directory in the VM Box: enter image description here

Whatever you name your share here will be the name you will need to use when mounting in the vm guest OS. i.e. I named mine "wd" for my western digital passport drive.

Next on the the guset OS make a directory to use for your mount preferably in your home directory.

mkdir share

Next open the terminal and copy and paste the following or type it in. You can enable shared clipboard under Device-> Shared Clipboard-> Bidirectional

sudo mount -t vboxsf wd ~/share/

You should now be able to copy files between OS's using the folder "share" in your home directory.

Hope this Helps!

  • 4
    Works great! Thanks :) – stormwild Sep 28 '14 at 6:25
  • 2
    + 1 This should have been the accepted answer, works perfectly. – Nate Nov 22 '14 at 19:56
  • 1
    I spent a few hours to understand, how can I get files from the Guest. It turned out that "sharename" (from official VBox documentation) in the "mount" command - is a just NAME specified in the virtual box Shared Folders at the first column. Great job, you're my hero. – zen11625 Dec 5 '14 at 9:23
  • .. Thanks Man, That saved my shared files ;) – Zouhair Elamrani Abou Elassad Dec 15 '14 at 12:19
  • 2
    great answer, +1 for the screenshot... This mounts the share as root however i believe. See [the docs] (forums.virtualbox.org/viewtopic.php?t=15868) on how to mount it as your current user eg: sudo mount -t vboxsf -o rw,uid=1000,gid=1000 share ~/host – timbrown Jan 6 '15 at 7:24
up vote 28 down vote accepted

For VirtualBox with a Linux guest, these are the steps to mount a shared folder:

  1. Use the VirtualBox host's application, VirtualBox Manager, to specify host folders to share.

  2. Make sure VirtualBox Guest Additions are installed in the VirtualBox guest.

  3. In the Linux guest, the mount command should show a line that the share was mounted. This is indicated by type vboxsf. The issue becomes that the mount point may not be where desired, and the permissions are root only. The default mount location is in /media/sf_.

  4. 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.

  5. You can change where the folder is mounted by using the VBoxControl command. The command is installed when Guest Additions is installed. May require reboot. For example, to change the mount point from /media/sf_... to /home/toto/sf_... use the following command to set the VirtualBox shared folder guestproperty:

sudo VBoxControl guestproperty set /VirtualBox/GuestAdd/SharedFolders/MountDir /home/toto/

To confirm the change, use get:

sudo VBoxControl guestproperty get /VirtualBox/GuestAdd/SharedFolders/MountDir

References:

VirtualBox's Shared Folder Info

VirtualBox's guestproperty info

  • This worked for me – LondonRob Apr 14 '14 at 9:50
  • 4
    New problem, with Vbox 4.3.10 the link is broken, check to verify (ls -l) /sbin/mount.vboxsf If that target does not exist the directory must be re-mapped: sudo ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions/mount.vboxsf /sbin/mount.vboxsf – ppostma1 Apr 22 '14 at 18:56
  • 4
    To add the user myuser to the group vboxsf you can use: sudo adduser myuser vboxsf – Vítor E. Silva Souza Jul 2 '14 at 17:13
  • VirtualBox 4.3.14 fixes Guest Additions install issues for RHEL 7 and CentOS 7. Install Guest Additions using: if-not-true-then-false.com/2010/… – BSalita Jul 22 '14 at 10:34
  • I am on VirtualBox 4.3.20 on Windows 8.1. I have Ubuntu installed in the VM. I can't see type vboxsf when running the mount command even though I have the guest stuff installed! please help – J86 Jan 29 '15 at 12:19

When encountering:

mount: Protocol error

after trying to share folders in VirtualBox, eg:

$ sudo mount -o uid=1000,gid=1000 -t vboxsf D_DRIVE ~/host

this finally worked for me:

$ sudo apt-get install virtualbox-guest-dkms

(My setup: Windows 7 host, guests: Ubuntu 12.04,13.10,14.04; currently running VBox 4.3.10 r93012)

Install virtual box additions on the guest os. Then shutdown the guest OS. Open the guestos settings in virtual box. Then add a shared folder and save the settings. Then start the guest os and for ubuntu issue the below command. It adds the current user to the vboxsf group.

sudo adduser $USER vboxsf

reboot the guest OS and navigate to /media/ to access the shared folder.

  • sudo adduser doesn't work for me I add to use "sudo usermod -a -G vboxsf myUser" and it works. Thank You – Alex Nov 10 '14 at 15:07
  • 1
    Yep, that's what was missing: sudo adduser $USER vboxsf Now it works :-) – TalL Nov 11 '14 at 9:27
  • this worked for me. – aks. Mar 6 '15 at 19:16

Inside a Linux or Mac OS X VirtualBox guest, once you have installed the VirtualBox Guest Additions, you can discover the available VirtualBox shared folders with following command :

sudo  VBoxControl  sharedfolder  list

If your home folder inside your guest contains folders having same name as VirtualBox shared folders, you can mount them automatically with following shell script :

#!/bin/sh
#-----------------------------------------------------------------------------
# Discover VirtualBox shared folders and mount them if it makes sense
#-----------------------------------------------------------------------------

if  !  type  VBoxControl  > /dev/null;  then
  echo  'VirtualBox Guest Additions NOT found'  > /dev/stderr
  exit 1
fi

MY_UID="$(id -u)"
MY_GID="$(id -g)"

( set -x;  sudo  VBoxControl  sharedfolder  list; )  |  \
grep      '^ *[0-9][0-9]* *- *'                      |  \
sed  -e 's/^ *[0-9][0-9]* *- *//'                    |  \
while  read  SHARED_FOLDER
do
  MOUNT_POINT="$HOME/$SHARED_FOLDER"
  if  [ -d "$MOUNT_POINT" ];  then
    MOUNTED="$(mount  |  grep  "$MOUNT_POINT")"
    if  [ "$MOUNTED" ];  then
      echo  "Already mounted :  $MOUNTED"
    else
      (
        set -x
        sudo  mount  -t vboxsf  -o "nosuid,uid=$MY_UID,gid=$MY_GID"  "$SHARED_FOLDER"  "$MOUNT_POINT"
      )
    fi
  fi
done

When you get the following error: /sbin/mount.vboxsf: mounting failed with the error: Protocol error

Unfortunately this means that you use the default share name or host's share directory name is the same as the mounted guest share name. In this case it is "share". Just create another share folder, i.e. "vb_share" and then just execute:

mount -t vboxsf vb_share /home/< user >/host

  • Install Vbox Additions (ISO file or download then)
  • Create a dir with whatever name in the two system ( mkdir share, for example )
  • connect with the "VBox shared folders" the share folder in the original sys
  • use the command to connect your folder:
    sudo mount -t vboxsf name_of_folder_linked ~/name_of_folder_guest/

Setup: VirtualBox 4.3.26, Win 7 SP1 host, Debian jessie 8.0 (stable) guest.

In VirtualBox Manager, select Shared Folders Settings... in the Devices drop-down menu.

In the resulting pop-up window, select Machine Folders in the Folders List and then click the "Add a New Shared Folder Definition" button (the blue folder with a green "+" sign icon to the right of the Folders List).

In the resulting Add Share pop-up form, click on the down-arrow button in the Folder Path field, and then select Other. A Browse For Folder pop-up window will appear.

(In my case, I had just added another hard drive to my workstation to be used for a dedicated share, already formatted for NTFS, with a volume name of "share", and mounted as "G:". So I clicked the arrow next to Computer, selected drive G: and then clicked the OK button.)

(In your case you should select whatever folder or drive you intend to share, then click the OK button.)

When you've made your selection and clicked the OK button, VirtualBox Manager will fill in the Folder Path and Folder Name fields of the Add Share form. Leave the Folder Path field alone, but you can change the Folder Name if you like -- just be sure to remember it for later.

Finish up the Add Share form by selecting the Make Permanent check box, but be sure to leave the Auto-mount check box cleared -- we're going to take care of mounting later. (And of course, if you want to make the folder or drive read-only, then go ahead and check the Read-only box.) Then click the OK button.

The newly-configured share should now appear as an entry under Machine Folders in the Folders List. Click the OK button.

In order to mount this share during boot (startup) we need to add a mount definition line to /etc/fstab in our Debian jessie guest installation. This edit needs to be done either as root or via sudo, for example:

sudo nano /etc/fstab

(I personally used vi, but because nano is the default editor on Debian jessie I specified it in the above example.)

To mount this share in my home directory, with its ownership and group set to my personal UID and GID, I added the following definition to /etc/fstab:

share /home/conib/share vboxsf comment=systemd.automount,uid=conib,gid=conib,noauto 0 0

(Note that there are no spaces around the "=", ".", or "," characters.)

An /etc/fstab definition is in the form

<Device> <Mount Point> <Type> <Options> <Dump> <Pass>

(Note that there should be whitespace -- space(s) and/or tab(s) -- between the fields of the definition, but no whitespace within a field.)

The "Device" field should be set to the Folder Name we specified via VirtualBox Manager Add Share. I had changed the default "G_DRIVE" to "share".

The "Mount Point" is a directory path spec that must already exist but should be empty. (That is, anything already present in that directory will be hidden by what you're mounting on top of it.) I had created a new, empty subdirectory named "share" in my home directory.

The "Type" is "vboxsf".

The "Options" (comment=systemd.automount,uid=conib,gid=conib,noauto) were the tricky bit, and took a bit of trouble to get working for this setup.

Set "Dump" to 0 unless you know you want it set to something else.

And since we don't want fsck checking this share, set "Pass" to 0 too.

When you've added the definition line to /etc/fstab, reboot your Debian guest and confirm that you can see the files and subfolders of your Share.

HTH.