Ask Your Question

startup script to mount share in fedora 25

asked 2017-05-13 15:19:23 -0500

tataprase gravatar image

updated 2017-05-14 04:56:25 -0500


I am trying to figure out this for few days, spent hours with google and tried bunch of solutions, so would appreciate any help.

Description: Running Fedora 25 as VirtualBox guest VM, with VBox guest additions installed. In a host machine, within VirtualBox I have shared drive that is visible in guest, and I can mount it in guest Fedora 25 when I trigger command in terminal:

**sudo mount -t vboxsf share /home/username/Desktop/mount_point/**

What I am not able to do is to put this in a script and make automatize the process at startup.

What I tried so far: I use Autostart - System Settings to trigger script at startup and this always fails.

So far I understood that mounting of Vbox shared drive must be done with sudo privileges so my script looks like:

sudo mount -t vboxsf share /home/username/Desktop/mount_point/**

and fails.

Script file was set as "Is Executable"

Tried autostartup Pre-KDE-startup option.

Script file located in /home/username/Documents/ and later I tried switching to location within root folder,

Changed permissions on the scirpt file to include permissions for current user to rwx and still failing.

I included specific user/group to command like:

**sudo mount -t vboxsf -o uid=username,gid=username data /home/username/Desktop/mount_point/**

and failed

I tried to send password to sudo by adding echo password | before sudo and , do I need to tell, failed.

Also tried editing fstab to include entry to mount share, and this also failed (suppose fstab execution is being done before system get virtualbox shared drive), tried setting script as startup service to run once - no luck.

So, I am out of idea, and would highly appreciate any advice. Thanks in advance.

edit retag flag offensive close merge delete


You can try allowing regular users to mount your partition: Edit /etc/sudoers end add this line: %users ALL=/sbin/mount -t vboxsf-o uid=username,gid=username data /home/username/Desktop/mount_point

You can also disable the password only for you:

yourusername ALL=(ALL) NOPASSWD:ALL

man sudoers for more options

fcomida gravatar imagefcomida ( 2017-05-13 20:25:19 -0500 )edit

I have a better idea: put your command in /etc/rc.d/rc.local and run: sudo systemctl enable rc-local, sudo systemctl start rc-local hoping it runs after vbox share appears. Another possibility: write a systemd unit-file yourself using dependency rules for running your service at the very end, adding something like: "" and "". Good luck.

fcomida gravatar imagefcomida ( 2017-05-13 20:44:01 -0500 )edit

You don't need to start rc-local as it only runs at boot. Also, as it's run as root, you don't need to use sudo.

sideburns gravatar imagesideburns ( 2017-05-13 21:55:56 -0500 )edit

2 Answers

Sort by » oldest newest most voted

answered 2017-05-14 05:47:26 -0500

tataprase gravatar image

@fcomida @sideburns Thanks a lot. This worked.

I did not need to edit sudoers file, placing the code to /etc/rc.d/rc.local did the job. Also it was not necessary to enable rc.local, just creating the file and setting appropriate permissions was sufficient:

touch /etc/rc.d/rc.local
chmod 777 /etc/rc.d/rc.local

@genodeftest Thanks for suggestion. I already tried placing line to /etc/fstab (mentioned in my question) but it did not work. I assumed that might be fstab execution time is before system gets vbox shared drive.

Also, for someone else that might be walking same path, I failed to notice that when running:

sudo mount -t vboxsf share /home/username/Desktop/mount_point/

mounting of share is being completed, but in read-only mode, as it was done by root. That is why option with uid or gid needed to be added, so command that worked for me was:

mount -t vboxsf -o uid=1000 data /home/username/Desktop/Host/

(uid=1000 provided there is only one user on the system, other wise put username)

edit flag offensive delete link more


Please please please do not set chmod 777 on any directory ever. This is highly insecure because any non-privileged user can write into that directory and can – potentially – execute stuff like bootkits. chmod 555 or chmod 755 is enough.

genodeftest gravatar imagegenodeftest ( 2017-05-15 04:47:48 -0500 )edit

@genodeftest Thank you for advice, I appreciate and will never, ever hit 777 to any directory. However, 777 was shot at rc.local file, not directory (which also is I believe over-permissive). Changed to 755 and now it looks like:

-rwxr-xr-x. 1 root root 72 May 14 11:26 /etc/rc.d/rc.local

Question regarding this: if it was 555, there would be no w for owner and script would be executable for anyone but no one would be able to write/change? Thanks. Newbie in Linux/Fedora world (but like it)

tataprase gravatar imagetataprase ( 2017-05-15 15:41:35 -0500 )edit

answered 2017-05-14 04:49:24 -0500

genodeftest gravatar image

You could add the file to your /etc/fstab. See man fstab for the file format. Please backup this file before changing it. This is the intended place where stuff like "mount disk on boot" should be.

If that does not work, you could use a systemd unit, as fcomida and sideburns suggested above. You don't need to make dangerous changes to sudo by editing /etc/sudoers or disabling your password.

edit flag offensive delete link more


He already tried with /etc/fstab without success. The problem is that fstab is designed for real devices, available at the early stage of booting. In his case "mount disk on boot" doesn't apply since there is no disk (or share) yet.

fcomida gravatar imagefcomida ( 2017-05-14 10:44:39 -0500 )edit

You can add it to the fstab with noauto option so the device is skipped during boot, but you can mount it later just by using mount "mountpoint" and if you add option users all users can mount it, so it should work as a autostart script.

vtrefny gravatar imagevtrefny ( 2017-05-14 11:03:16 -0500 )edit

@vtrefny: Thanks, that's a good improvement.

@fcomida: I'd still prefer /etc/fstab, because that is the cleaner solution.

genodeftest gravatar imagegenodeftest ( 2017-05-15 04:50:34 -0500 )edit

@genodeftest Agreed, fstab with with noauto option and an autostart script is the way to go.

fcomida gravatar imagefcomida ( 2017-05-15 07:00:24 -0500 )edit

@vtrefny and others, Thank you, I already implemented /etc/rc.d/rc.local command and it is working fine but am willing to switch to suggested /etc/fstab noauto solution. So, noauto will postpone mounting which can later be done by less privileged user (will set to be automatic). Do I also need to set user option with /etc/fstab to enable specific user?

tataprase gravatar imagetataprase ( 2017-05-15 15:57:57 -0500 )edit

Question Tools

1 follower


Asked: 2017-05-13 15:19:23 -0500

Seen: 845 times

Last updated: May 14 '17