Automatically mount a windows shared folder in VirtualBox

This article is based on my personal setup using Vista x64 as the host and running Ubuntu/Kubuntu in a virtual box. I have read a great many articles of people stating mixed results in editing fstab to auto mount their shared folder upon boot. Maybe my method isn't preferred and I am sure somebody out there who actively idles 20+ IRC channels on freenode 24/7 would disagree with me for the sake of being cynical. I don't care, this is what works for me.

As we have all read in the VirtualBox user manual you can quickly mount a shared folder (assuming this has been setup in VirtualBox FIRST) by creating a new folder under the media directory and then running the mount command. For me this would look like:

$ sudo mkdir /media/windows-share
$ sudo mount -t vboxsf Ed /media/windows-share

 

It goes without saying that running this mount command EVERY time you want to access you shared directories is a load of bull. Like others I have had mixed luck with fstab, but after reading deeply into some random forum post after digging through 50+ pages of Google search results I found where an individual stated that by inserting the mount command into /etc/rc.local is all that is needed. So lets do this.

$ cd /etc
# ALWAYS BACKUP A FILE BEFORE EDITING IT
$ sudo cp rc.local rc.local.backup

 

Open rc.local with the editor of your choice. You will probably see something similar to this:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0

 

Place the cursor above 'end 0' and hit ENTER a couple times to make some room. Add the mount command you have been using (leaving out sudo), and for the sake of being thorough leave a little comment about what you just added. My rc.local file.

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# mount the Windows shared folder
mount -t vboxsf Ed /media/windows-share

exit 0

 

Reboot and your windows-share should be mounted. 

 

- Ed