2

I am using Ubuntu 14.04 on a VM using VirtualBox. As I often have to do development for work in both windows and linux, I have a shared development directory. The issue is that even with auto mount selected for the VM in the virtualbox manager, it is not automatically mounted upon startup.

I can mount it perfectly fine once I log in with the following command:

sudo mount -t vboxsf src /home/patrick/src

This is simple enough to do but seems pointless to me. Any ideas on how to get this to auto mount on startup/login?

4

I just had a similar thing in KVM with a shared folder as 9p file system.

The solution if you can't use an /etc/fstab entry is to edit the guest OS' /etc/rc.local and insert your personal mount command (without sudo!) before the exit 0 line.

The file would then normally look like 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.

mount -t vboxsf src /home/patrick/src

exit 0

Make sure you edit the file as root (e.g. with sudo nano or gksudo gedit).

  • Awesome thanks, this works like a charm! No more copy paste that command every time I restart – Patrick Schaefer Feb 2 '16 at 18:46
  • Another comment, this doesn't seem to work immediately on log-in. When I checked after rebooting this morning it wasn't there but was after about 1 minute. So the script must not run right away or runs slow on a VM. It does work eventually though. – Patrick Schaefer Feb 3 '16 at 17:54
1

@ByteCommander +1 is very clean solution but network was not available when the user want to mount the shared folder while booting guest system so add sleep 10 before mount command. "NodeJs" is my host shared folder and "/var/www/html" is mount point.

#!/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.
sleep 20
mount -t vboxsf NodeJs /var/www/html
exit 0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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