Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I have Ubuntu installed in Virtualbox. I want to mount my VirtualBox shared folder in Ubuntu automatically when I log in Ubuntu. I put the following line in my ~./bashrc and ~/.bash_profile:

sudo mount -t vboxsf windows_share /media/windows_share

where windows_share is the name I created with Virtualbox. But everytime I start my Ubuntu, it asks me for passwd since it needs sudo. Is there anyway to automatically mount Windows share without entering password every time I log in?

share|improve this question

3 Answers 3

up vote 36 down vote accepted

To always mount a Virtual Box "shared folder" on booting an Ubuntu guest we have two options. It is up to personal preference which option works best in our setting.

1. Mount with fstab

To mount a shared folder using the vboxsf filesystem provided with Guest Additions we first need to make sure prerequisites are met. Then we may put the following line in our etc/fstab file:

<name_of_share>   /path/to/mountpoint   vboxsf   <options>  0   0

Replace name_of_share and /path/to/mountpoint with your individual setup (the directory for the mountpoint has to be created first). See the manpage for mount for mount <options>. One possibility is to mount with defaults, or to give specific mount options (e.g. rw, suid, exec, auto, users).

On some systems the vboxsf kernel module is not yet loaded at the time fstab is read on boot. It may then help to append the vboxsf kernel module to /etc/modules.

2. Mount with Virtual Box "automatic mounting":

In recent releases of Virtual Box we can also automatically mount shared folders on creation:

enter image description here

After a reboot of the guest this shared folder will be mounted to the guest directory /media/<username>/sf_<name_of_share> accessible to all users who had been made member of the group vboxsf.

share|improve this answer
How do you change the mount directory and mount prefix? Do you run some terminal commands in the HOST OS or the GUEST OS? –  CMCDragonkai Jan 18 '14 at 12:12
This feature requires that the "virtualbox-guest-utils" service has started, and on Ubuntu 14.04 this service starts later than the filesystems are mounted. This is the reason for "device not found" error when mounting the shares through fstab –  kolypto May 13 '14 at 14:58
@kolypto, that's a good observation. Any idea of how to reorder their loading order? –  garromark May 17 '14 at 2:35
@garromark, my only idea is to create an upstart script, which is quite simple. Another option is to put the same fstab entry, but add "noauto" so you just mount it manually. –  kolypto May 19 '14 at 21:56
@kolypto, thanks for getting back to me. I actually found two competing solutions, only one of which worked for me: Option 1) (Worked for me), is, as you said, to put noauto in the fstab options and then to later mount typically in a startup script (such as .profile), Option 2) the main issue being that vboxsf isn't loaded prior to fstab running, append vboxsf to the file /etc/modules, asking the kernal to load the module prior to fstab being run. Maybe this will help someone else. –  garromark May 20 '14 at 22:11

I do it of a very similar mode at was proposed above but these script create the required and mount or unmount the shared folder with the following script:

# Mount automatically even shared folder on startup and unmount it at shutdown.
# VirtualBox (c) 2015 by Oracle Systems Inc.

# Check user privileges.
if [[ $EUID -ne 0 ]]; then
    echo -e "This script must run at ROOT user!" \
        "\nPlease, use 'sudo', 'visudo' or any other to run it."
    exit 1

# Check paramas from caller.
if [[ $# -eq 0 ]]; then
    echo -e "Auto-Mount selected shared folder of VirtualBox machine." \
        "\nUsage:" \
        "\n    VBoxShared <drive_one> <drive_two> <...>"
    exit 2

declare EVENT=          # This set the ACTION: -m OR -u
declare -a DRIVES=()

# Processing each param:
for arg in "$@"; do
    case "$arg" in
            if [[ -z ${EVENT} ]]; then
                exit 318        # parameters at conflict!

            if [[ -z ${EVENT} ]]; then
                exit 318        # parameters at conflict!

            DRIVES=("${DRIVES[@]}" "${arg}")
unset arg

[[ -z ${EVENT} ]] && exit 1             # ERROR: No se ha establecido la acción a realizar.
[[ "${#DRIVES[@]}" -gt 0 ]] || exit 1   # ERROR: No se han indicado las unidades a manejar.

# Process each shared folder stored on '${DRIVES}' array
for drive in "${DRIVES[@]}"; do

    case "${EVENT}" in
            [[ -d ${DEST} ]] || (mkdir ${DEST} && chown root:vboxsf ${DEST} && chmod 770 ${DEST})
            mount -t vboxsf ${drive} ${DEST}

            if [[ `df --output=target | grep "${DEST}"` > /dev/null ]]; then
                umount -f ${DEST}
                rm -rf "${DEST}"
    unset DEST
unset drive

unset EVENT
unset DRIVES
exit 0

Save it as /opt/.scripts/

Make sure that this can be runned. On shell type:

sudo chmod a+x /opt/.scripts/

Now, we add a line that run this script on rc.local:

sudo nano /etc/rc.local

and we add these line before last line (exit 0):

. /opt/.scripts/ --mount <SharedFolder1> [<SharedFolder2> <SharedFolder3> ...]

Save (CtrlO) and close it (CtrlX)

At this point, we mount automatically all shared folder listed on <SharedFolder> at startup.

For unmount it, we only need type:

sudo nano /etc/rc6.d/


. /opt/.scripts/VBoxShared --umount <SharedFolder1> [<SharedFolder2> <SharedFolder3> ...]

exit 0

Save (CtrlO) and close (CtrlX)

sudo chmod a+x /etc/rc6.d/

And that's all!

share|improve this answer
  1. Edit /etc/rc.local

    sudo -H gedit /etc/rc.local
  2. Before exit 0 type:

    mount.vboxsf windows_share /media/windows_share vboxsf
  3. Save

  4. (Optional) Create a shortcut to the desktop or home folder:

    ln -s /media/windows_share /home/freddy/Desktop

In order to boot without errors like pressing S to skip mount or press M to manually repair you may have to delete your entry in fstab

share|improve this answer
This is the ONLY way I have found to work, tried RC.Local with the regular mount command, tried FSTAB, tried Crontab w/ script. Huge Thanks!! –  FreeSoftwareServers Sep 5 at 9:17
This worked for me too (opposed to the accepted answer, not quite sure why). So a big thank you from me! :) –  Daniel Lisik Sep 26 at 0:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.