autofs
Contents
About
Quite some pages to read
Installation
1 aptitude install autofs
Global Options
Global options of the init-script /etc/init.d/autofs are stored in
/etc/default/autofs
1 #
2 # Init system options
3 #
4 # If the kernel supports using the autofs miscellanous device
5 # and you wish to use it you must set this configuration option
6 # to "yes" otherwise it will not be used.
7 #
8 USE_MISC_DEVICE="yes"
9 #
10 # Use OPTIONS to add automount(8) command line options that
11 # will be used when the daemon is started.
12 #
13 #OPTIONS=""
14 #
15
During initial configuration set the logging to verbose in
/etc/autofs.conf
1 logging = verbose
Remove it when you are finished.
Master File
/etc/auto.master
1 #
2 # Sample auto.master file
3 # This is a 'master' automounter map and it has the following format:
4 # mount-point [map-type[,format]:]map [options]
5 # For details of the format look at auto.master(5).
6 #
7 #/misc /etc/auto.misc
8 #
9 # NOTE: mounts done from a hosts map will be mounted with the
10 # "nosuid" and "nodev" options unless the "suid" and "dev"
11 # options are explicitly given.
12 #
13 #/net -hosts
14 #
15 # Include /etc/auto.master.d/*.autofs
16 # The included files must conform to the format of this file.
17 #
18 +dir:/etc/auto.master.d
19 #
20 # Include central master map if it can be found using
21 # nsswitch sources.
22 #
23 # Note that if there are entries for /net or /misc (as
24 # above) in the included master map any keys that are the
25 # same will not be seen as the first read key seen takes
26 # precedence.
27 #
28 +auto.master
Configuration directory
So we add a configuration directories, cause this style of config is great for templating.
1 sudo mkdir /etc/auto.master.d /etc/autofs
Configuration files located in
/etc/auto.master.d must have suffix .autofs to be included
ls -l /etc/auto.master.d/*.autofs/etc/autofs can have arbitrary names
SMB
Direct mount
Create mount directory
1 mkdir /media/quasar/music
/etc/auto.master.d/smb.autofs
/etc/autofs/smb_direct
NFS
See filesystems/nfs for some generic information.
Indirect mount
Lets define a map for nfs /etc/auto.master.d/nfs.autofs
Create a directory that will later contain the autofs configuration files and copy a template file to the location defined in our map file.
Lets edit our configuration /etc/autofs/nfs
1 #
2 # This is an automounter map and it has the following format
3 # key [ -mount-options-separated-by-comma ] location
4 # Details may be found in the autofs(5) manpage
5
6 #cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
7
8 # the following entries are samples to pique your imagination
9 #linux -ro,soft,intr ftp.example.org:/pub/linux
10 #boot -fstype=ext2 :/dev/hda1
11 #floppy -fstype=auto :/dev/fd0
12 #floppy -fstype=ext2 :/dev/fd0
13 #e2floppy -fstype=ext2 :/dev/fd0
14 #jaz -fstype=ext2 :/dev/sdc1
15 #removable -fstype=ext2 :/dev/hdd
16
17 ### Lets use wildcards and substitution
18 * imp-xu4:/media/ceph/&
I don't think you need to create the directories to be used as wildcards. But could be a good idea if you don't remember.
1 # systemctl restart autofs.service
2 # mount |grep /srv/nfs
3 /etc/autofs/nfs on /srv/nfs type autofs (rw,relatime,fd=7,pgrp=31093,timeout=300,minproto=5,maxproto=5,indirect)
4 root@infinitas /srv/nfs # ll
5 insgesamt 0
6 root@infinitas /srv/nfs # ls space
7 anime
8 root@infinitas /srv/nfs # ll
9 drwxr-xr-x 1 phoenix phoenix 26 Apr 24 18:13 space
10 # mount |grep /srv/nfs
11 /etc/autofs/nfs on /srv/nfs type autofs (rw,relatime,fd=7,pgrp=31093,timeout=300,minproto=5,maxproto=5,indirect)
12 imp-xu4:/media/ceph/space on /srv/nfs/space type nfs4 (rw,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.182.240,local_lock=none,addr=192.168.182.11)
Wow, Awesome, Great!!! Thanks for this amazing tool!
Direct mount
/etc/auto.master.d/nfs.autofs
1 /- /etc/autofs/nfs_direct
/etc/autofs/nfs_direct
SSH
Prepare Pubkey Authentication
- Create an unencrypted ecdsa-keypair and copy it to the remote machine.
- Please make sure your rootfs is encrypted to ensure this key can't be stolen easily.
Test it to add hostkey to /root/.ssh/known_hosts
Create directory sshfs
1 mkdir /srv/sshfs/imp-xu4
/etc/auto-master.d/sshfs.autofs
/etc/autofs/sshfs
1 #
2 # This is an automounter map and it has the following format
3 # key [ -mount-options-separated-by-comma ] location
4 # Details may be found in the autofs(5) manpage
5
6 imp-xu4 -fstype=fuse,rw,nodev,nonempty,noatime,allow_other,max_read=65536 :sshfs\#phoenix@imp-xu4\:
7 ### With
8 #imp-xu4 -fstype=fuse,rw,nodev,nonempty,noatime,allow_other,max_read=65536,IdentityFile=/root/.ssh/id_ecdsa :sshfs\#phoenix@imp-xu4\:
9
For options that should be passed to ssh see man ssh_config
Unmount
Write a little alias to simplify umounting:
1 echo "alias autoumount='kill -USR1 $(pidof automount)'" >> /etc/zsh/zshrc.local
autofs reload fails
TLDR: Path to kill must be fixed in systemd-unit.
Error:
1 root@infinitas ~log # systemctl reload autofs.service
2 Job for autofs.service failed because the control process exited with error code. See "systemctl status autofs.service" and "journalctl -xe" for details.
3 ### Syslog contains
4 Apr 25 00:36:18 infinitas systemd[1]: Reloading Automounts filesystems on demand.
5 Apr 25 00:36:18 infinitas systemd[13690]: autofs.service: Failed at step EXEC spawning /usr/bin/kill: No such file or directory
6 Apr 25 00:36:18 infinitas systemd[1]: autofs.service: Control process exited, code=exited status=203
7 Apr 25 00:36:18 infinitas systemd[1]: Reload failed for Automounts filesystems on demand.
Find kill:
1 root@infinitas ~log # which kill
2 kill: shell built-in command
3 root@infinitas ~log # ll /bin/kill
4 -rwxr-xr-x 1 root root 26704 May 31 2018 /bin/kill
5 root@infinitas ~log # locate autofs.service
6 /etc/systemd/system/multi-user.target.wants/autofs.service
7 /lib/systemd/system/autofs.service
8 /var/lib/systemd/deb-systemd-helper-enabled/autofs.service.dsh-also
9 /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/autofs.service
Fix it! /lib/systemd/system/autofs.service
1 [Unit]
2 Description=Automounts filesystems on demand
3 After=network.target ypbind.service sssd.service network-online.target
4 Wants=network-online.target
5
6 [Service]
7 Type=forking
8 PIDFile=/var/run/autofs.pid
9 EnvironmentFile=-/etc/default/autofs
10 ExecStart=/usr/sbin/automount $OPTIONS --pid-file /var/run/autofs.pid
11 ### Change path to /bin/kill
12 ExecReload=/bin/kill -HUP $MAINPID
13 TimeoutSec=180
14
15 [Install]
16 WantedBy=multi-user.target
Retry and Check:
1 root@infinitas ~log # systemctl reload autofs.service
2 Warning: autofs.service changed on disk. Run 'systemctl daemon-reload' to reload units.
3 Job for autofs.service failed because the control process exited with error code. See "systemctl status autofs.service" and "journalctl -xe" for details.
4 root@infinitas ~log # systemctl daemon-reload
5 root@infinitas ~log # systemctl reload autofs.service
6