Autofs is a kernel option which allows you to automatically mount filesystems when you access them, and automatically unmount them when you are done using them.
|
|
I like Autofs because it's:
apt-get install autofs
# Sample auto.master file # Format of this file: # mountpoint map options /var/autofs/ejectable /etc/auto.ejectable --timeout=5 /var/autofs/usb /etc/auto.usb --timeout=2 /var/autofs/smb /etc/auto.smb --timeout=60 /var/autofs/smbbrowse /etc/auto.smbbrowse --timeout=60,-nonstrict /var/autofs/ssh /usr/bin/auto.sshfs uid=1000,gid=1000,--timeout=30 /var/autofs/ftp /usr/bin/auto.ftpfs uid=1000,gid=1000,--timeout=30
# Format of file: # mountpoint options device cdrom -fstype=iso9660,ro,sync,nodev,nosuid :/dev/cdrom floppy -fstype=auto,sync,nodev,nosuid :/dev/fd0
/etc/init.d/autofs restart
ls /var/autofs/ejectable/
ls /var/autofs/ejectable/cdrom
ls /var/autofs/ejectable/cdrom
)automount[17237]: attempting to mount entry /var/autofs/ejectable/cdrom automount[3028]: lookup(file): looking up cdrom automount[3028]: mount(generic): calling mkdir_path /var/autofs/ejectable/cdrom automount[3028]: mount(generic): calling mount -t iso9660 -s -o ro,sync,nodev,nosuid /dev/cdrom /var/autofs/ejectable/cdrom automount[3044]: running expiration on path /var/autofs/ejectable/cdrom automount[3044]: expired /var/autofs/ejectable/cdrom
# Sample auto.master file # Format of this file: # mountpoint map options /var/autofs/ejectable /etc/auto.ejectable --timeout=5 /var/autofs/usb /etc/auto.usb --timeout=2 /var/autofs/smb /etc/auto.smb --timeout=60 /var/autofs/smbbrowse /etc/auto.smbbrowse --timeout=60,-nonstrict /var/autofs/ssh /usr/bin/auto.sshfs uid=1000,gid=1000,--timeout=30 /var/autofs/ftp /usr/bin/auto.ftpfs uid=1000,gid=1000,--timeout=30
# Format of file: # mountpoint options device sda -fstype=vfat,uid=1002,gid=1002,umask=002,noatime :/dev/sda1 sdb -fstype=vfat,uid=1002,gid=1002,umask=002,noatime :/dev/sdb1 sdc -fstype=vfat,uid=1002,gid=1002,umask=002,noatime :/dev/sdc1 sdd -fstype=vfat,uid=1002,gid=1002,umask=002,noatime :/dev/sdd1
# Sample auto.master file # Format of this file: # mountpoint map options /var/autofs/ejectable /etc/auto.ejectable --timeout=5 /var/autofs/usb /etc/auto.usb --timeout=2 /var/autofs/smb /etc/auto.smb --timeout=60 /var/autofs/smbbrowse /etc/auto.smbbrowse --timeout=60,-nonstrict /var/autofs/ssh /usr/bin/auto.sshfs uid=1000,gid=1000,--timeout=30 /var/autofs/ftp /usr/bin/auto.ftpfs uid=1000,gid=1000,--timeout=30
# Format of file: # mountpoint options device backup -fstype=smbfs,username=joey,password=god,uid=1000,gid=1000 ://gibson/backup html -fstype=smbfs,username=joey,password=god,uid=1000,gid=1000 ://gibson/html mp3 -fstype=smbfs,username=joey,password=god,uid=1000,gid=1000 ://gibson/mp3
# Sample auto.master file # Format of this file: # mountpoint map options /var/autofs/ejectable /etc/auto.ejectable --timeout=5 /var/autofs/usb /etc/auto.usb --timeout=2 /var/autofs/smb /etc/auto.smb --timeout=60 /var/autofs/smbbrowse /etc/auto.smbbrowse --timeout=60,-nonstrict # THESE LINES /var/autofs/ssh /usr/bin/auto.sshfs uid=1000,gid=1000,--timeout=30 /var/autofs/ftp /usr/bin/auto.ftpfs uid=1000,gid=1000,--timeout=30
clover:~# ls /var/autofs/ftp/ (no output) clover:~# ls /var/autofs/ftp/ftp.kernel.org/pub/linux/kernel/ COPYING README people testing v1.1 v2.0 v2.3 v2.6 CREDITS SillySounds ports uemacs v1.2 v2.1 v2.4 Historic crypto projects v1.0 v1.3 v2.2 v2.5 clover:~# ls /var/autofs/ftp/ ftp.kernel.org
Basically, Autofs scripts are passed directory names and output a configuration based on the directory name.
Could be as simple as a bash script that echoes a default configuration (but that's really no different from having a static config file) or as complicated as you want to make it.
(in this example, gibson happens to be an SMB server on the network)
greenfly@clover:~$ /etc/auto.smbbrowse gibson -fstype=smbfs,guest /mp3 //gibson/mp3 /print$ //gibson/print$
# Sample auto.master file # Format of this file: # mountpoint map options /var/autofs/ejectable /etc/auto.ejectable --timeout=5 /var/autofs/usb /etc/auto.usb --timeout=2 /var/autofs/smb /etc/auto.smb --timeout=60 # THIS LINE /var/autofs/smbbrowse /etc/auto.smbbrowse --timeout=60,-nonstrict /var/autofs/ssh /usr/bin/auto.sshfs uid=1000,gid=1000,--timeout=30 /var/autofs/ftp /usr/bin/auto.ftpfs uid=1000,gid=1000,--timeout=30
greenfly@clover:~$ ls /var/autofs/smbbrowse (no output) greenfly@clover:~$ ls /var/autofs/smbbrowse/gibson mp3 greenfly@clover:~$ ls /var/autofs/smbbrowse/gibson/mp3 311 nofx Reef Madness! offspring Surf Rider operation_ivy anti-flag pennywise ... nin various_artists
Use symlinks
/mnt/kernel -> /var/autofs/ftp/ftp.kernel.org/pub/linux/kernel
This presentation is adapted from my tips page at http://www.greenfly.org/tips/autofs.html