Sharing files with a linux guest on VirtualBox

One of my friends recently installed Ubuntu on a VirtualBox, and he had a really tough time sharing files between the Ubuntu guest and the Windows 7 host machine. In this article I will describe the two most common ways to share files between the host and a *nix guest os inside VirtualBox.

Some information in this article assumes you are fimilar with working on a linux command line. Even if you have not used the linux commandline before, fear not, as you can copy and run the commands without any modification on a Ubuntu guest machine. For other versions of linux, you might be required to make a few changes to the commands (mentioned wherever possible)

Let’s get started. Assuming you have already performed the following steps before we can enable file sharing between the host and guest machine.

1. Create a virutal machine for Ubuntu in VirtualBox.
2. Install Ubuntu (its free!)
3. From the machine settings, enable Network adapter (either bridged or host only adapter, host-only is recommended) and shared folders.
4. Login once onto the Ubuntu GUI with your userid and password.
5. Install Guest Additions on the Ubuntu machine from the VirtualBox GUI and restart the machine once.

Now we are ready to start sharing files between our host and guest os.

Sharing files over the Network

  • Right click the Network Icon on the top right corner of desktop and select ‘Edit  connections’.
  • Double click the ‘auto eth0’ entry and select the ‘IPv4 ettings’ tab on the dialog that just opened.
  • Depending on whether you selected briged network or host-only adapter for the virtual machine setting, configure the network. I usually prefer host-only network as it keeps the machine secure and the data transfer is pretty fast, not to mention hassle free configuration.
  • Once the network is configured, Open network browser using the Menu ‘Places -> Network’ on the top left of screen.

You should see ‘Windows Network’ as a folder in the explorer pane. Double click it and you should also see your host machine name displayed. Inside it you will see your folders listed that you shared over the network. Please note that you might be required to enter a valid Windows machine userid/password when you access the folder.

Configuring and using Shared Folders

  • In VirtualBox GUI, open virtual machine settings and select ‘shared folders’ tab.
  • Click the plus sign icon. In the dialog, enter the path to the folder on your host machine which you want to share, and also give it a name. For this example, I will name it ‘Shared’. Uncheck ‘Auto-mount’ option and check ‘Make Permanent’ option. This will make sure when the virtual machine restarts, the folder will still be accessible inside the machine.
  • Back to the virtual machine, if you are comfortable with text file editing in linux, add the following line to /etc/fstab file (you might need to use sudo)
    Shared /media/sf_Shared vboxsf defaults,rw,uid=1000,gid=1000 0 0
  • Alternatively, open a new Terminal from the Applications -> Acessories menu on top left of screen and run the following command inside the terminal.
echo "Shared /media/sf_Shared vboxsf defaults,rw,uid=1000,gid=1000 0 0" | sudo tee -a /etc/fstab

This will have the same effect as if you edited the file as described above.

  • Now run the following command inside the Terminal
sudo mount -a

If all went well, you can now use the shared folder inside your virtual machine. Open Places -> Computer from the top left menu. Open FileSystem and then double click the ‘media’ folder. You should see a folder called ‘sf_Shared’. This is the folder you just shared from your host machine. If you get ‘access denied’ error, you will need to do a bit extra to access the folder, which is also described at the end of this article.

Troubleshooting folder access problems

In some cases (usually when Ubuntu has more than one user accounts), you will get access denied errors when you try to access a shared folder. To fix this problem, try the following:
Open a Terminal window and type the command ‘id’ (without the quotes). The output will be something like this

uid=1005(samnan) gid=1005(samnan) groups………..

Note the uid and gid number from the command output. Now instead of the original command we used to enable shared folder inside the virutal machine terminal, type the following command, replacing <<uid>> and <<gid>> with the numbers you just picked from the ‘id’ command output.

echo "Shared /media/sf_Shared vboxsf defaults,rw,uid=<<uid>>,gid=<<gid>> 0 0" | sudo tee -a /etc/fstab

Follow the rest of the steps as usual and you should be able to access the folder without any problems.

  • Tweets that mention Sharing files with a linux guest on VirtualBox | Kaizen —

    […] This post was mentioned on Twitter by Ovais Tariq, Umair Jabbar. Umair Jabbar said: Sharing files with a linux guest on VirtualBox | Kaizen via @umairr […]

  • Frank Cheung

    or you can just use dropbox… it takes a bit of time to sync initially, but then you then get immediate access to useful scripts, favourite wallpapers, various dot and configuration files (e.g. bash env/aliases addendums, chrome speed dial setup), source code, etc. depending on what you choose to store in dropbox.

  • Sam

    Frank, dropbox is good, but if you have to share large/many files, especially when your machine is having trouble connecting to the internet, then only the above methods will work. I hope that clears the situation.

  • Sam

    Dropbox is good, but when you have large data/many files to share, especially if your machine is having trouble connecting to internet, then the above two methods work flawlessly. I hope this clears the confusion.

  • Maroc Freelance

    do you know a method to make the guest and the host use the same partition ?!

  • Sam

    Actually no, because virtualbox does not allow that option. However, there are additional softwares that can be used to perform this trick, however, that requires another post :)

  • best food mixers

    Guests wear windows 7 best price uk this parallel development over apple’s implemented et in some small embedded systems the speed on third party device drivers attempt cracked delivered, launching a unix-based file system amongst aka wow.

  • Maher

    Thanks so much for all the info… I had a problem “could not enter folder” when I checked “Auto mount”, though I could enter it as a root user.

  • Maher

     My problem was solved simply by the command: : sudo usermod -a -G vboxsf <>, as detailed in just needed to add my account to the group vboxsf, that is allowed to access the shared folders.