Share Folders Between a Linux Host and Linux Virtual Machine on VirtualBox

June 3, 2009 by
Filed under: HowTo, linux 

VirtualBox is a great application for trying out different Linux distros without messing with your current build. In this post I'll show you how to share a folder between your Linux host and the guest virtual machine. This assumes you have already installed VirtualBox, created and installed your guest OS, and installed VirtualBox Guest Additions.

On you host machine, create a folder to share. I'll call mine vbox.

mkdir vbox

Start up your guest OS in VirtualBox. In the window for the running virtual machine, select Devices->Shared Folders... Click the icon to Add a New Shared Folder. Select the Folder Path drop-down and click Other. Navigate to your shared folder and click Choose.

VirtualBox Add Share

VirtualBox Add Share

Affiliate Link

Click OK twice. That was the easy part.

Go into your guest OS and open a terminal window.

Create a new directory where you'll mount the shared folder.

mkdir ~/share

Enter the id command and look at the output. You should see something like:

uid=1000(user) gid=1000(user) groups=4(adm),20(dialout),24(cdrom),46(plugdev),106(lpadmin),121(admin),122(sambashare),1000(user)

It's the uid and gid parts that are important. Now you will mount the shared folder from the host to the guest OS.  From a terminal in the guest OS:

sudo mount -t vboxsf -o uid=1000,gid=1000 vbox /home/user/share

Make sure to make the proper substitutions for uid and gid as well as the host and guest folder names (vbox and /home/user/share respectively).

You should now be able to share files between your guest and host.

Make the Mounted Share Permanent

You can make the shared folder mount automatically each time you start the virtual machine by making an entry in /etc/fstab. From the guest:

sudo gedit /etc/fstab

Add a line at the bottom that looks like this:

vbox /home/user/share vboxsf rw,uid=1000,gid=1000 0 0

Again, make the appropriate changes for your folder names and user/group ids.


10 Responses to “Share Folders Between a Linux Host and Linux Virtual Machine on VirtualBox”

  1. HCl1314 says:

    One question, everytime I restart my VM my shared folder is still here (without editing the fstab file so no linked) but I cannot remove it. If I go to devices -> shared folder -> remove share folder:

    Failed to remove the shared folder "blabla" (pointing to path_on_host) from the virtual machine VMname

    Please close all the programs in the guest OS that may be using this shared folder and try again

    Could not remove the shared folder 'blabla' (VERR_PERMISSION_DENIED)

    I hesitate a bit to just rm ~/share

    Some advice ?


  2. Peter Nosko says:

    Thanks for posting this. It is nearly working for me. I can't get the fstab entry to work (yes,I triple-checked the syntax). I even tried putting the mount command that works from my user command line in rc.local. It didn't work there either. Go figure.

    BTW, your website has bee intermittently offline for the past 30 mins, and no cache was available at cloudflare. Just in case you wanted to know. It took 3 attempts to post this reply.

  3. sam says:

    in terminal: sudo mount -t vboxsf *sharedfolder* *mountpoint* --> where *sharedfolder* is the name of the folder in VirtualBox settings (host OS) under "shared folders" and *mountpoint* is where you want to have files from host os on you guest os linux e.g. /home/sam/myfiles

  4. Suvojit says:

    I am getting an error /sbin/mount.vboxsf: mounting failed with the error: Protocol error

    • Linerd says:

      Are you running Ubuntu Lucid Beta as your guest OS? I had this problem with the Alpha3 release of Lucid. I think it has to do with Ubuntu removing HAL and replacing it with DeviceKit for hardware interaction.

      Make sure you're using the latest version of VirtualBox and the latest version of VirtualBox Guest Additions. Though I'm not sure if VirtualBox has fixed the issue yet.

    • Linerd says:

      I'm running the latest updates in Lucid and the shared folders are now working.

  5. FMG says:

    nothing easier as what you described, but what is with:

    share-folders linux-host & windows-virtual-machine virtualbox


  6. [...] Share Folders Between a Linux Host and Linux Virtual Machine on …By Linerd How to set up a shared folder between guest and host Linux machines with VirtualBox.Tux Tweaks - [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>