Start autofs on boot

6,529

Add this to /etc/rc.local

Using any editor:

Graphical

gksu gedit /etc/rc.local

Command line

sudo -e /etc/rc.local 

add / edit the following:

#!/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.

service autofs start &

mount -a

exit 0

You could probably improve on that a bit, 4 60 second sleep are probably excessive, I would try one, and increase the number if needed.

Make it executable

sudo chmod u+x /etc/rc.local

Reboot and it should work. If not, try adding a sleep as per the bug report below.

See also Bug Report

Share:
6,529

Related videos on Youtube

Fake Name
Author by

Fake Name

Updated on September 18, 2022

Comments

  • Fake Name
    Fake Name almost 2 years

    I have autofs all setup, and it correctly mounts my shared directories.

    However, right now, I have to manually run sudo upstart autofs start after every boot, before the automounting actually works.

    I think in installed autofs manually through synaptic, though it has been a while. The computer in question is used as a lightweight server, and rarely gets restarted, so having to manually start a service isn't too big a deal, but my backups do not work until autofs is running, so I do worry.

    • Admin
      Admin over 12 years
      I can't help directly, but I can confirm that autofs from the repositories is definitely auto-started on login/startup and will mount anything it sees in /etc/auto.master automatically.
    • Admin
      Admin over 12 years
      @Scaine - Well, damn if I know what's going on, then. Maybe it was packaged into the xubuntu installation, and just not enabled until I set it up.
    • Admin
      Admin over 12 years
      I'd do a re-install of autofs through synaptic, but getting it working at all was an enormous pain, and I don't know if a re-install would clobber my config files. Frankly, considering how much of a complete PITA it was to get working, I really don't want to to touch autofs itself, for fear of breaking it.
    • Admin
      Admin over 12 years
      Anyone? This is still an issue for me....
    • Admin
      Admin over 12 years
      What do you want to do with autofs exactly? If I understand correctly, it's a tool to mount stuff. Can't you do just do that with a new line in /etc/fstab?
    • Admin
      Admin over 12 years
      @Exeleration-G - autofs automatically mounts shared directories on demand. It's better then just using mount because it does not hold connections to all your servers open all the time. It's a system service, so when you try to navigate to a directory a autofs manages, it mounts it for you. After the directory has been unused for a period of time, it unmounts it and closes the SMB (in this case) connection.
  • Fake Name
    Fake Name over 12 years
    I think the restarts may not be needed. All I have to do to get autofs to work normally is just issue a sudo service autofs start. The problem isn't that it's failing, it's that it is never starting. Anyways, I will try this when I get home from work later today.
  • Panther
    Panther over 12 years
    I agree, the start ... sleep ... restart ... sleep ... seems excessive, probably written in frustration, but probably after a shorter script fails. Give it a try and you can of course optimize it for your needs.
  • Panther
    Panther over 12 years
    Do you still need assistance ?
  • Fake Name
    Fake Name over 12 years
    Nope, that did it. I just put service autofs start in rc.local, without any sleep or repetitions. I still wonder how I installed autofs without it bing set up to start, though.
  • Panther
    Panther over 12 years
    Thank you for commenting back on the requirement for the sleep. I will revise my answer. As far as it not working out of the box, aye it is a bug. My guess would be autofs is running too soon, without waiting for some service to finish.