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?

  • 1
    Consider editing /etc/fstab as in usual (non-VirtualBox) environment. Look at this wiki https://wiki.archlinux.org/index.php/fstab, or here a question http://askubuntu.com/questions/154180/how-to-mount-a-new-drive-on-startup. – Abdillah Feb 02 '16 at 16:58
  • Also see: https://askubuntu.com/questions/252853/how-to-mount-a-virtualbox-shared-folder-at-startup and https://askubuntu.com/questions/30396/error-mounting-virtualbox-shared-folders-in-an-ubuntu-guest – Takkat Feb 02 '16 at 18:54

2 Answers2

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).

Byte Commander
  • 107,489
  • Awesome thanks, this works like a charm! No more copy paste that command every time I restart – Patrick Schaefer Feb 02 '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 03 '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