Configuring Autofs

Kyle Rankin

President of NBLUG

What is Autofs?

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.

So What?

Accessing a CD in Autofs

    Before Autofs:
  • put CD in CDROM
  • mount /mnt/cdrom
  • ls /mnt/cdrom
  • umount /mnt/cdrom
  • eject CD
    After Autofs:
  • put CD in CDROM
  • ls /mnt/cdrom
  • eject CD

Big Deal, <foo> does that too

I like Autofs because it's:

Installing Autofs

  1. Configure the kernel
  2. Install Autofs software
  3. Configure Autofs
  4. Script Autofs (optional)

Configure the kernel

Install Autofs software

Configure Autofs

  1. Create /etc/auto.master
  2. Create /etc/auto.* files
  3. Restart autofs
  4. Access a configured directory

Creating /etc/auto.master

# 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

Create /etc/auto.ejectable

# Format of file:
# mountpoint options device
cdrom	-fstype=iso9660,ro,sync,nodev,nosuid	:/dev/cdrom
floppy	-fstype=auto,sync,nodev,nosuid	:/dev/fd0

What this does

Log Output

(from command 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

Configure /etc/auto.master

# 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

Create /etc/auto.usb

# 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

Configure /etc/auto.master

# 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

Create /etc/auto.smb

# 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

Introduction to Lufs

Installing Lufs (briefly)

Configure auto.master

# 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

Configuring auto.ftpfs

Using auto.ftpfs

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

Writing Autofs scripts

What does an Autofs script do?

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.

My Autofs script--auto.smbbrowse

Testing auto.smbbrowse

(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$

Configure auto.master

# 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

auto.smbbrowse in action

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

Managing Autofs mountpoints

Use symlinks

Managing Autofs mountpoints (cont.)

Autofs problems

Questions?

This presentation is adapted from my tips page at http://www.greenfly.org/tips/autofs.html