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.
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/
For 64bit users: sudo /media/cdrom/

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- /home/ben

21 thoughts on “VirtualBox Shared Folders with Ubuntu Server Guest

  1. Thanks! Very helpful.

    I found a typo:

    For 32bit users: sudo /media/cdrom/
    For 64bit users: sudo /media/cdrom/

    Should be VBoxLinuxAdditions not VBoxLinuxAddition.

  2. Played with this again. Works like charm. 🙂 But there’s one thing.

    sudo /media/cdrom/

    Without -x86 or -amd64 part with new VBox.

    Cheers. 🙂

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s