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

9,726

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!

Share:
9,726

Related videos on Youtube

jcollum
Author by

jcollum

Updated on September 18, 2022

Comments

  • jcollum
    jcollum over 1 year

    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?

  • jcollum
    jcollum almost 8 years
    _netdev - sorry, I forgot to mention that I tried that.
  • jcollum
    jcollum almost 8 years
    askubuntu.com/questions/335615/… -- had to add "root" before /bin/bash. Still doesn't work though. They mount fine with sudo mount but @reboot root /bin/bash -c 'sleep 10 && /sbin/mount -a' doesn't do anything. Is it the /sbin that's the problem? I got an error with /bin
  • jcollum
    jcollum almost 8 years
    Oh wait it worked but using sudo crontab -e seems to open the wrong crontab. I did sudo vi crontab and it worked
  • Terrance
    Terrance almost 8 years
    @jcollum That is interesting, but glad you got it working. =)
  • Terrance
    Terrance almost 8 years
    @jcollum I am going to add that to my answer here.