vbox How do I mount Virtualbox "shared folders" automatically?

I'm running FreeBSD as guest in Virtualbox. My shared folder won't mount until I run this command:

# mount_vboxvfs -w sharedfolder /home/luc/sharedfolder

I want it to mount automatically at boot. Virtualbox has an "Auto-mount" option but it doesn't work.

I've tried these:

# echo 'mount_vboxvfs -w sharedfolder /home/luc/sharedfolder' >> /etc/rc.local

and
Code:
# echo 'mount_vboxvfs -w sharedfolder /home/luc/sharedfolder' >> /usr/local/etc/rc.d/mountvbox.sh
# chmod + /usr/local/etc/rc.d/mountvbox.sh
It still doesn't work. What is the correct way?
 
've tried these:

# echo 'mount_vboxvfs -w sharedfolder /home/luc/sharedfolder' >> /etc/rc.local
There seems to be a $PATH problem to /usr/local/sbin where the mount_vboxvfs executable is placed from /etc/rc.local. Set full path instead:
Code:
/usr/local/sbin/mount_vboxvfs -w sharedfolder /home/luc/sharedfolder

and

# echo 'mount_vboxvfs -w sharedfolder /home/luc/sharedfolder' >> /usr/local/etc/rc.d/mountvbox.sh
# chmod + /usr/local/etc/rc.d/mountvbox.sh
That won't work. rc(8) scripts require a specific rc.d style script structure. See EXAMPLES section of rc(8).

Example specific for the case:
Code:
#!/bin/sh
#
# PROVIDE: mountvbox
# BEFORE: LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name="mountvbox"
desc="Mount vbox shared folder on boot automatically"
rcvar="mountvbox_enable"
start_cmd="mountvbox_start"

: ${mountvbox_enable:=NO}

mountvbox_start()
{
    /usr/local/sbin/mount_vboxvfs -w sharedfolder /usr/home/luc/sharedfolder
}

load_rc_config $name
run_rc_command "$1"
Set file permissions: chmod 555 /usr/local/etc/rc.d/mountvbox and enable service in /etc/rc.conf: service mountvbox enable


Another method to mount the vbox shared folder automatically is from a cron job. As root crontab -e:
Code:
@reboot     mount_vboxvfs -w sharedfolder /usr/home/luc/sharedfolder
See crontab(1) and crontab(5) for details.
 
Hi,

edit /etc/fstab in FreeBSD guest:

Code:
sharedfolder   /usr/home/luc/sharedfolder    vboxvfs  rw,late  0  0

In VirtualBox Manager you have to add <path to>/sharefolder as a common folder, automount-setting and mount-point are not relevant, see attachment. But I think you've already done that.
Maybe you need to adjust permissions for <path to>/sharefolder on your host (e.g. 777).

Hope this helps.
 

Attachments

  • Bildschirmfoto_2023-02-22_13-12-58.png
    Bildschirmfoto_2023-02-22_13-12-58.png
    23.1 KB · Views: 79
Right, I have forgotten fstab.

But
sharedfolder /usr/home/luc/sharedfolder vboxvfs rw,late 0 0
needs some improvement:
Rich (BB code):
sharedfolder   /usr/home/luc/sharedfolder    vboxvfs  rw,late,failok,uid=<luc's user id>,gid=<luc's group id>  0     0
See id(1) for user and group id. "gid" is not absolutely necessary. "failok" in case something goes wrong with the mount, the boot process won't stop in single user mode.

The above fstab entry gives following permissions and user/group:
Code:
drwx-----  luc  luc  /usr/home/luc/sharedfolder

Without specifying "uid":
Code:
drwx-----  root  wheel  /usr/home/luc/sharedfolder
meaning user "luc" can't access the shared folder.

Btw, mount_vboxvfs from examples in post # 2 gives these permissions and user/group:
Code:
drwr-x-r-x  luc   luc  /usr/home/luc/sharedfolder
 
It still doesn't work. What is the correct way?
To make it simple, there's two places where the shared folder has to be specifiled:

1. In the VirtualBox management console, as pointed out in post #3.
2. Inside the VM, using the UNIX mount commands shown elsewhere in this thread.

Yes, it has to be specified in both places for the shared folder to work. Both guest and host have to be on the same page about that folder.
 
Back
Top