Ubuntu – how can I force a mount -a to run after the system boots up

bootfstabmountnetworkingsamba

Media server running Ubuntu 16.04 and Kodi. Synology NAS in the next room contains all the media.

how can I get my fstab mounts working if they won't mount on bootup? — tried switching to username/password instead of .smbcredentials, no change.

Tried adding _netdev, no change.

I've tried fixing my /etc/fstab and it's just not working. I'm not sure what the problem is, but I cannot get my NAS folders to mount that way. Posted here, posted on ubuntuforums, no go (didn't get any answers in either one). Every time I reboot I have to ssh in to the box to get my media folders back.

So, I thought I'd take a different approach. I'm assuming there is some issue with my NAS or network that makes mounting at boot via fstab to not work. I don't know.

Since I know that my folders will mount with sudo mount -a, how can I run that command at boot time after everything else (network especially) is done?

Best Answer

One way to add your command at startup would be to add it as a cron job.

Add your command to the root cron by typing in the following line in a terminal window:

sudo crontab -e

then at the bottom of the cron add a line that reads like this:

@reboot /bin/mount -a

or if you want to add a delay of like 10 seconds to it:

@reboot /bin/bash -c 'sleep 10 && /bin/mount -a'

that should tell it to run the mount -a command as root at boot up time.

Or, you could add it to your system wide crontab by editing the following file:

/etc/crontab

and adding the following line:

@reboot root /bin/bash -c 'sleep 10 && /bin/mount -a'

Hope this helps!