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

June 3, 2009 by Linerd
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

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:

id

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.

Comments

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

  1. [...] 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 - http://tuxtweaks.com/ [...]

  2. FMG says:

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

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

    ???

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

Leave a Reply