So you read about how much I love VirtualBox and you decided to give it a go. You downloaded and installed VirtualBox (3.1.2 at time of writing) on your Windows computer. Then you grabbed the latest .ISO of Ubuntu Linux (9.10) and walked through VirtualBox’s New Virtual Machine Wizard to create your very first virtual appliance. Or maybe you went the other route and started off with a Linux machine and created a Windows-based virtual appliance.
Either way, now you want to swap files between the two of them.
The first thing you have to do, in both cases, is install the VirtualBox Guest Additions from inside your new virtual machine. You install these from an .ISO that is installed with the VirtualBox application. Basically you have to mount that ISO as a CD/DVD. Thankfully, VirtualBox takes a little of the confusion out of the process by providing you with a shortcut in the Devices Menu on your already running virtual machine. The keyboard shortcut is Host+D (Right CTRL + D by default).
Installing the VirtualBox Guest Additions on Linux (Ubuntu)
After ignoring the useless (in my case) auto-run prompt, I opened up a terminal window (Applications -> Accessories -> Terminal). I changed directories to where the CD was mounted (/media/cdrom), and ran ls to see the contents of the directory. After identifying the appropriate version your virtual environment, go ahead an run it as root (or use sudo if available). On 64bit Ubuntu, it looks just like this (don’t type the dollar sign, it’s used to illustrate the beginning of the command):
$ cd /media/cdrom
$ sudo ./VBoxLinuxAdditions-amd64.run
The sudo command temporarily elevates your privileges so you can run the installer, and it will ask you to re-enter your password, so you know.
Get used to this process. Every time you update the kernel you are going to want to re-install the guest additions. Also, whenever you update the VirtualBox application itself, it’s a good idea to re-install them as well.
Installing VirtualBox Guest Additions on Windows
…is easy as pie. Shortly after you mount the guest additions .ISO, an auto-run prompt will likely appear and you can just follow the prompts to run the installer. If it doesn’t autoplay, browse the computer to the CD-ROM drive and double-click on VBoxWindowsAdditions.exe. That should sort out the appropriate version for your current operating system. If you are unsure about individual components, just say yes to everything. No harm, no foul.
Again, in case you missed it above, it is possible that future windows updates could break the guest additions, so if the guest machine acts goofy after a windows update just reinstall them. Also, plan on re-installing the guest additions everytime you update the main VirtualBox application on your host machine. It’s painless, so quit whining.
Now that you have the guest additions installed, lets practice sharing!
Sharing Files from a Windows Host to a Linux Guest
Zhiqi Tao posted on this topic, but let me attempt a little more detail. For this example we are going to assume you have a local directory called “C:\Downloads” that you want your Linux virtual machine to access.
On your still running virtual machine, go to the “Devices” menu and select “Shared Folders…”. From there you will be prompted with a “Shared Folders” window, and in that window you should see a blue folder with a green plus sign in the upper right. Click on it or press the Insert key to open an “Add Share” window. Use the drop-down for the “Folder Path” and select “Other” to browse to the directory you intend to share, or you can simply type it in. If you browsed to the directory, then it will auto-populate the “Name” field otherwise you will have to type that in as well. The name field is very important here, and you will want to pay special attention to case. Since we want this share to be available every time we start the virtual machine, and we want to be able to write to it from either system, leave “Read-only” unchecked, but make sure you check “Make Permanent”. See the example below:
Click “OK” to add the share and return to the “Shared Folders” window. Under “Machine Folders” you should now see an entry with the name and path you specified above, along with Full Access. Click okay to return to the virtual machine. We are going to navigate to your home folder and create a miniature directory structure to support this initial share as well as any future shares you decide to make. Then, we are going to add a mount command to /etc/fstab and to /etc/rc.local so that the share is automatically made available every time you start the virtual machine. Play along at home and remember, Linux is case sensitive!
$ cd ~
$ mkdir Shared
$ mkdir Shared/Downloads
You are going to need to know the full path to the new Downloads directory. It should be “/home/<USERNAME>/Shared/Downloads” where <USERNAME> is the login you created when you installed the system. To be sure, you can enter the following commands:
$ cd Shared/Downloads
$ pwd
Make note of the output of the pwd command (which stands for present working directory), and don’t forget about case sensitivity (you tired of me saying that yet?). Let’s continue.
$ sudo nano /etc/fstab
Add the following line below the existing entries using the space or tab key between elements. Remember to replace <USERNAME> with your login name, and if you have been using different directories then change those as well. It’s long, but please remember it should go on a single line!
Downloads /home/<USERNAME>/Shared/Downloads vboxsf rw,user,noauto,exec,utf8 0 0
The first element is the name of the share, and it must be an exact match for the “Name” in the list of “Shared Folders” (see the “Folder Name” in the “Add Share” example window above). Hit CTRL+O then Enter to write the file, then CTRL+X to exit nano. Now we have to edit another file in /etc/, but before we do that, we need to do some self-examination.
$ id
Make note of the uid and gid values, because we are going to need them. Mine were both 1000, and yours may very well be 1000 too.
$ sudo nano /etc/rc.local
Add the following line directly above the line that reads “exit 0″. Feel free to copy and paste, but remember to change your uid and gid values in addition to swapping out <USERNAME> with your actual login!
mount -t vboxsf -o uid=1000,gid=1000,dmode=755,fmode=644 Downloads /home/<USERNAME>/Shared/Downloads
Again, Hit CTRL+O then Enter to write the file, then CTRL+X to exit nano. Reboot the machine with the following:
$ sudo shutdown now -r
or
$ sudo reboot
When the machine comes back up, /home/<USERNAME>/Shared/Downloads on your guest will be the same as C:\Downloads on your host machine, and should be completely writable from either direction. Voila!
Sharing Files from a Linux Host to a Windows Guest
This is a much simpler process in comparison. First, you select “Shared Folders…” from the “Devices” menu, then press the insert key or click the folder with the green plus sign in the resulting “Shared Folders” window to bring up the “Add Share” dialogue. Use the “Folder Name” drop-down to select “Other” and browse to the folder you’d like to share.
Make note of the Folder Name that is auto-filled, or change it to something of your liking. Keep it simple, and one word. Then make sure “Read Only” is not checked, but check “Make Permanent”. See the example in the section above.
Then, in your Windows Host, open up explorer and from the menu bar choose “Tools -> Map Network Drive”. Choose a drive letter from the drop down, and for the folder type
\\vboxsvr\<FolderNameFromAddShareDialogue>
Obviously you want to replace <FolderNameFromAddShareDialogue> with the actual folder name from the add share dialogue. In our previous example, it was “Downloads”.
Make sure you check “Reconnect at logon” and click on the “Finish” button. There you go, you are all set, easy peasy. And really, this process works no matter what kind of host you are working with. Windows is just easy that way.
Hopefully you find this useful!

Pingback: Jason P. Brown » Building an Ubuntu Dev Platform: Step 2 – Install Ubuntu
thanks for this useful toturial!