Linux · Server · VirtualBox

VirtualBox Shared Folders with Ubuntu Server Guest


Updated on 13/March/2014: Corrected the use of the incorrect /media/cdrom path. Please note that the screenshots date from 2010 and are probably out of date.

Shared folders is a nifty way that VirtualBox allows guest operating system to access files stored on your host system. I find it very convenient to share my host’s download directory with my guest servers. So that way I do not need to type out long, sometimes cryptic URLs for software downloads packages I might want to install onto my guest systems.

In this example I will be creating a shared folder within VirtualBox that will link my c:\users\ben\downloads directory with one on the Linux box.
cd
Now let’s start;

Within VirtualBox, select the guest machine you wish to contain the shared folder.

Press the Settings button.

  1. In the Settings dialog, press Shared Folders tab.
  2. Click the Add Shared Folder button.
  3. In the popup dialog, select the directory you want to share with the guest machine. In my case I will be choosing the directory c:\users\ben\downloads.
  4. Give the share a simple, but descriptive name.
  5. I would suggest selecting the Read-only checkbox. This will mean the guest operating system will not be able to modify any files or directories on within the shared folder.

Start your guest machine and login as normal.

Select Devices, CD/DVD Devices, VBoxGuestAdditions.iso.

We will now mount the VirtualBox Guest Additions.iso CD
sudo mount /dev/cdrom /media/cdrom
If successful you should receive a message about the block device being mounted and that it is read-only.

We now need to install some software packages that are required by the VBoxGuestAdditions.iso but that are not installed by Ubuntu Server as default.
sudo apt-get install build-essential linux-headers-`uname –r`
I needed around 26.9 MB of downloads though your mileage might vary.

Once complete we run the Guest Additions install script.
For 32bit users: sudo /media/cdrom/VBoxLinuxAddition-x86.run
For 64bit users: sudo /media/cdrom/VBoxLinuxAddition-amd64.run

The installation should be an automated process and if everything runs okay you should receive messages informing you that the Guest Addition, folder support, OpenGL, non-kernal Guest Additions have been built. You should also receive an error message saying the Window System drivers have failed to install, which is fine because our guest machine is not running X-Windows.

Now I recommend rebooting the guest machine and re-logging in.
sudo reboot

For the final part of this process we need to mount our shared folder. But firstly we need to create a directory within the guest that we can mount the shared folder to. I recommend placing it in the /mnt directory, but you can place it anywhere and give it any name.

sudo mkdir /mnt/host-downloads

Now we just need to mount the shared folder to our newly created directory using the following command.

sudo mount –t vboxsf {host shared folder name} {guest mount directory }

So in my example I would do the following, please remember that Linux is case sensitive.

sudo mount –t vboxsf Downloads /mnt/host-downloads

Then I should be able to

cd /mnt/host-downloads
ls -sh

Now you can easy copy over Internet downloads onto your guest operating system.

cp {files} {guest home directory}

So I could do the following to copy the 125MB Railo install package to my guest machine.
cp railo-3.1.2.001-pl0-linux-installer.bin /home/ben

19 thoughts on “VirtualBox Shared Folders with Ubuntu Server Guest

  1. We now need to install some software packages that are required by the VBoxGuestAdditions.iso but that are not installed by Ubuntu Server as default.
    sudo apt-get install build-essentual linux-headers-`uname –r`
    I needed around 26.9 MB of downloads though your mileage might vary.

    spelling error “essentual” should be “essential”, otherwise thanks for posting.

  2. Thanks for the post – it was very helpful. I wanted to post an additional option to have the folder mounted at startup.
    Simply putting an entry in fstab didn’t work for me, as ubuntu spit out some error on restart. However, working on the theory that this mechanism was trying too soon to use the vboxsf driver, I put it as a startup script at runlevel 2 and it worked. Here’s how:
    1) Make file ‘/etc/init.d/mount-vboxsf’ with the contents
    “mount.vboxsf -o uid=1000 /home//”
    where uid=1000 should be replaced with the userid of the user who will use the share (for multiuser, you may need to do gid=something), which can be found at or near the end of /etc/passwd
    2) $ sudo chmod u+x /etc/init.d/mount.vboxsf
    3) $ cd /etc/rc2.d
    $ sudo ln -s /etc/init.d/mount-vboxsf S99mount-vboxsf
    What this does is to tell ubuntu to run the script /etc/init.d/mount-vboxsf with priority 99 (low priority, runs later) when entering runlevel 2, which is the default runlevel for debian/ubuntu.
    This was ubuntu 10.10 running in virtualbox 4.0.6 on mac os x 10.5.8
    John

  3. Question… how do you make this mount permanent so you don’t have to mount it every time after rebooting?

    1. Disregard.

      It was like really late when I posted this. And I didn’t change my timezone on the board so no… it wasn’t 7:43 am. =)

      Looking at the previous post #6 … I got my answer. Thanks John Smith.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s