# HOWTO: Automounting local filesystems with autofs

## jsosic

Automounting devices with autofs

revision 1.12

1. What will I learn?

I think Subject is pretty clear  :Smile:  No NFS will be discussed here.

2. Why to choose autofs among ivman, gnome-volume-manager, submount and others? What are advantages and disadvantages of autofs?

PROS:1. autofs doesn't mount media after you insert it, but when you access mountpoint

2. autofs is capable of automatic umounting after configured time period of non usage of the mounted device

3. less dependencies than other automounters (lighter)

CONS:1. autofs is !not! userspace, but kernelbased

2. autofs is not inteligent, you must configure all new device before you use them

If you know some other +/- then please tell it and I'll expand the list  :Smile: 

Now first the short explanation of how autofs works: *Quote:*   

> When you instert cdrom into drive, nothing happens. Then you enter /media dir and type ls. Nothing appears. You type cd cdrom and TAADDDDAAA. Youre in /media/cdrom. Autofs created the dir and mounted device. Once you exit that dir, and stop using your drive, tray is still locked for timeout T, and after T seconds drive is unlocked and you can take out you compact disc.
> 
> Things can be made simplier by adding symbolic links and/or icons. Version 4.x has ghosting feature, that keeps directories exist even if device is not mounted, so you can see all configured devices by typing ls /media.

 

1. log on as root or su

2. re-configure, recompile and reboot your kernel

```
# cd /usr/src/linux

# make menuconfig
```

turn this on:

```
File systems --->

<*>  Kernel automounter version 4 support (also supports v3)
```

 Note that it doesn't matter if it's builtin or a module, do it how you prefer. If it's compiled as a module, it will be loaded automatically upon startup of autofs daemon, so you don't need to load it manually. After exiting menuconfig and saving new kernel config file, you should recompile it. If autofs is built into the kernel (<*>) then you can just run "make bzImage" and copy new image in /boot, and if it's selected as a module (<M>) then you don't need to recompile kernel image, but just modules ("make modules modules_install"). After doing this, don't forget to re-emerge additional kernel modules (like nforce-audio, sys-fs/fuse, lircd, fglrx.....) that you use.

3. fetch and compile autofs

```
# emerge net-fs/autofs
```

4. setup "/etc/autofs/auto.master"

```
/media   /etc/autofs/auto.media   --option1 --option2
```

 *Quote:*   

> 1. First option tells autofs under what directory devices will be mounted
> 
> 2. Second option tells autofs what configuration file to use for selected dir
> 
> 3. Third come the options that will be passed to automounter. --timeout=1 means that any device configured in auto.media file will be umounted after 1s of inactivity. --ghost can be added too, and some other opts.
> ...

 

5. setup "/etc/autofs/auto.media"

```
cdrom      -fstype=iso9660,ro,nosuid,nodev   :/dev/cdroms/cdrom1

cdrw      -fstype=iso9660,ro,nosuid,nodev   :/dev/cdroms/cdrom0

camera      -fstype=vfat,rw,uid=0,gid=100,fmask=0117,dmask=0007,nosuid,nodev:/dev/sda1
```

 *Quote:*   

> 1. First option tells autofs what is the name of dir to mount device. Dir will be placed under directory stated previously in auto.master (in this case: /media/cdrom).
> 
> 2. Second option configures fstype and various permisions what will be passed to mount. Also for vfat you must set various masks for user-vulgaris to be able to access it.
> 
> 3. Third place states device.
> ...

 

6. setup additional options in "/etc/conf.d/autofs"

```
daemonoptions='--timeout=1 --ghost'
```

 *Quote:*   

> This file is parsed during autofs daemon startup, and checked for daemonoptions. If you don't want ghosting on all your mountpoints, don't put it in dameonoptions but in auto.master file, third section.
> 
> NOTE: This kind of setting up options is Gentoo-specific. Other distros use other methods, and if you wish to have distro-unspecific setup, then all the options should be set like described in section 4. This also stands for other distro users.
> 
> NOTE 2: If you don't know, --ghost is pretty nice option. It request  that  directories  in  the  automount must be shown but not mounted until accesssed. This way you can eliminate the need of symlinks, and this makes life a lot easier 
> ...

 

7. start autofs daemon and add it to runlevel

```
# /etc/init.d/autofs start

# rc-update add autofs default
```

8. test automounter

Insert disc into cdrom and type $ cd /media/cdrom. Then, type $ cd .. and wait for timeout. If everything went ok, you can now unload tray of your cdrom drive. You passed the test, congratulations!

9. make symbolic links and/or icons

NOTE: If you use automounter4, and have --ghost option enabled, than you can skip this step. I will leave it online for users of old, 3.x version wich didn't support ghosting.

Insert cd in cdrom, dvdrom, cdrw. Plug usb sticks, cameras, etc (you can do it one by one). Automount them (acces /media/cdrom trough xterm). Open new xterm window and type (as root):

```
# cd /mnt

# ln -s /media/cdrom cdrom

# ln -s /media/cdrw cdrw

# ln -s /media/camera camera

...etc...
```

Now you can unplug/eject devices, and if you want to make icons, point them to /mnt/cdrom, /mnt/cdrw, etc. Now, if you want to access cdrom drive, you don't need console at all. Yust point your file manager to /mnt/cdrom and cdrom will automatically mount. Set for example Digikam to use "USB mass storage" and as dir enter /mnt/camera. And you'll have almost a perfect automounter!

10. Adding new devices

If you at some point wish to add new device to your automounter, you can do that (described in steps 5. & 8.). But don't forget to restart autofs daemon after that, autofs won't notice the changes 'cause it picks up "auto.master" setup file when daemon starts, so if you change something, you've got to restart it again.

That's it!!!

What am I using?

- kernel 2.6.9-gentoo-r13

- autofs 3.1.7-r5

- kernel 2.6.10-gentoo-r6

- autofs 4.1.3

- autofs 4.1.3-r2

- autofs 4.1.3-r3

- autofs 4.1.3-r4

I recomend the latest version of autofs -> 4.1.3-r4. Also I've been running many versions of kernels back to 2.4.23 with no problems regarding autofs, so if you have problems, it's very unlikely that they're kernel based...

Disclaimer: All damage done to your system by following this howto is not my responsability, do this at your, and your risk only. This document can have errors too, so please correct me, nobody's perfect (excpet Seven of Nine). I tried to explain even smallest details but it's unlikely that everyone will understand everything. So, if you have any troubles using autofs or have any doubts with this howto, feel free to mail me. Live long and prosper \V/

Additional note:  If you're interested in using autofs with network filesystems (NFS) then read my other autofs document: HOWTO: Automounting network filesystems with autofs.Last edited by jsosic on Thu May 03, 2007 1:09 pm; edited 19 times in total

----------

## DrWoland

I don't see how this isn't more popular, this OWNS the utopia project.

----------

## DrWoland

Hmmm, doesn't seem to work with audio devices. What's the dillio?

----------

## PrakashP

This is nice, indeed. Does anybody know how to properly integrate it with kde? If I use a device, kde tries to mount it and then gives an error that it already has been mounted, but works otherwise...

If I use a symlink, then I can't change the icon, as kde wants to write into the symlink, whcih is the cd... Beside the icon issue, the symlink works as expected though.

Ahh, OK, I need to make a link to konqueror and with it start the folder. Here I can change icon and everything works as expected. Nice!  :Smile: 

Uhm, new problem:  How can I actually write to a floppy? DO I have to change permissions every time? (It seems I can't change user permissions?)

OK, I got it:

```

floppy          -fstype=auto,rw,nosuid,sync,user,gid=11,umask=002       :/dev/fd0

```

----------

## Jimmy Jazz

Hello,

i have some problems with autofs when i'm using the last 4.1.3-r2 version.

Please, read my post for more informations

https://forums.gentoo.org/viewtopic.php?t=277731&start=0&postdays=0&postorder=asc&highlight=

With autofs 3.1.7-r5, it works and i have the following messages:

```

Jan 12 15:44:21 [automount] starting automounter version 3.1.7, path = /media aptype = file, mapname = /etc/autofs/auto.media

Jan 12 15:44:21 [automount] using kernel protocol version 3

Jan 12 15:44:24 [automount] attempting to mount entry /media/cdrw

Jan 12 15:44:35 [automount] expired /media/cdrw

Jan 12 15:45:30 [automount] shutting down, path = /media

```

but autofs-4.1.3-r2 returns:

```

Jan 12 15:46:34 [automount] >> mount: périphérique spécial /dev/cdroms/cdrom1  n'existe pas

Jan 12 15:46:34 [automount] mount(generic): failed to mount /dev/cdroms/cdrom1  (type auto) on /media/cdrw

Jan 12 15:46:34 [automount] failed to mount /media/cdrw

Jan 12 15:46:34 [automount] >> mount: périphérique spécial /dev/cdroms/cdrom1  n'existe pas

Jan 12 15:46:34 [automount] mount(generic): failed to mount /dev/cdroms/cdrom1  (type auto) on /media/cdrw

Jan 12 15:46:34 [automount] failed to mount /media/cdrw

Jan 12 15:46:34 [automount] >> mount: périphérique spécial /dev/cdroms/cdrom1  n'existe pas

Jan 12 15:46:34 [automount] mount(generic): failed to mount /dev/cdroms/cdrom1  (type auto) on /media/cdrw

Jan 12 15:46:34 [automount] failed to mount /media/cdrw

```

Have you made this test with autofs 4.1.3-r2 version ?

Jj

----------

## DrWoland

 *Jimmy Jazz wrote:*   

> Hello,
> 
> i have some problems with autofs when i'm using the last 4.1.3-r2 version.
> 
> Please, read my post for more informations
> ...

 

I use 4.1.3-r2 and it works tres bien  :Smile: 

Edit: Are you trying to mount an audio CD? Cuz it seems like those can't really be mounted in the traditional sense.

----------

## Jimmy Jazz

No of course i don't try to mount an audio cd. I use zinf for that  :Wink: 

Strange that i cannot get it work ...  :Sad: 

Jj

----------

## PrakashP

New problem: I have a zip drive and disks formatted with ext2. So how to make it writable for the user? Here gid and umask don't work...

----------

## iwankoenig

I have the following error:

```

make bzImage

  SPLIT   include/linux/autoconf.h -> include/config/*

make[1]: `arch/i386/kernel/asm-offsets.s' is up to date.

  CHK     include/asm-i386/asm_offsets.h

  CHK     include/linux/compile.h

  CC      drivers/cdrom/cdrom.o

drivers/cdrom/cdrom.c: In function `cdrom_open':

drivers/cdrom/cdrom.c:899: error: too few arguments to function `open_for_data'

make[2]: *** [drivers/cdrom/cdrom.o] Error 1

make[1]: *** [drivers/cdrom] Error 2

make: *** [drivers] Error 2

```

What`s now?

----------

## DrWoland

 *iwankoenig wrote:*   

> I have the following error:
> 
> ```
> 
> make bzImage
> ...

 

Hmmm what kernel are you using?

----------

## iwankoenig

Linux v2.6.8.1

----------

## jsosic

 *PrakashKC wrote:*   

> This is nice, indeed. Does anybody know how to properly integrate it with kde?

 

That's pretty easy. I'm using KDE too. You have to remove your KDE icons and make a new one's. Also, icons should point to SYMLINKS!

I've added one to my K menu. Here are options:

Name: cdrom

Description:

Comment: Load & mount CD-ROM

Command: krusader --right /mnt/cdrom

Note that /mnt/cdrom points to /misc/cdrom  :Smile: 

Hope this helps...

----------

## PrakashP

Well, I found it out on my, own, as I wrote above.  :Wink:  I am now more interested on how to set permissions to ext2 on zip disk, so that user can access mount point.

----------

## iwankoenig

```
6. start autofs daemon and add it to runlevel

Code:

# /etc/init.d/autofs start

# rc-update add autofs default

7. test automounter

Insert disc into cdrom and type $ cd /misc/cdrom. Then, type $ cd .. and wait for timeout. If everything went ok, you can now unload tray of your cdrom drive. You passed the test, congratulations! 
```

Fine. But when i insert the disk into dvd-rom , so is the order /misc empty.

$ cd /misc/dvd

-bash: cd: /misc/dvd: No such file or directory

And what was with my kernel? I don`t know. But i have got the kernel-2.6.9. It works fine!

----------

## DeathAndTaxes

Between this thead and this link:

http://freespace.sourceforge.net/guidod/howto/autofs.html

I got this up and running very nicely.  I noticed cedega was unable to figure it out, but I just opened shells and cd'd into those directories to keep the drives mounted.  With this, the installers worked nicely and I got a few win32 games up and running.

Since supermount isn't really supported anymore, we're stuck with strange things like autofs (or other, stranger alternatives) to handle our CD mounting.  The good thing about autofs is it also provides a method for mounting remote shares...Using one app and one config file for all these things is definitely handy.

----------

## davecs

I'm impressed. I might try this when I get home. One little thing, if unmounting takes a long time (for example if I have written loads of data to a USB storage device) do I get a progress bar so that I know when to pull it out?

I assume it copes well with udev, as I have set up different devices for USB key, CF card and MP3 player etc.

----------

## DrWoland

 *davecs wrote:*   

> I'm impressed. I might try this when I get home. One little thing, if unmounting takes a long time (for example if I have written loads of data to a USB storage device) do I get a progress bar so that I know when to pull it out?
> 
> I assume it copes well with udev, as I have set up different devices for USB key, CF card and MP3 player etc.

 

Works perfectly with udev, I have a purely udev system.

----------

## jsosic

https://bugs.gentoo.org/show_bug.cgi?id=77077

Be aware...it's not my howto to blame but autofs package gentoo maintainer...

Hope he fixes this soon.

----------

## davecs

So far I've set up my DVD-RW to work. It would not unmount using v4.1.3-r2  of autofs so I followed the advice in other threads and used v4.1.3

To put a DVD shortcut on my desktop, dragging a copy of the link at /mnt/dvdrw was not a good idea, as /misc/dvdrw/ is not a writable directory and so I cannot change the default icon.

Instead I right-clicked on Desktop and selected Create New > File > Link to Location (URL). A dialogue box that comes up you type in /misc/dvdrw and make the Filename whatever you want to see under the icon I just typed "DVD". This produced a desktop icon which I could then right-click on to change the icon.

The sweet thing though is that I will be able to add menu items which will be all the more important in other desktop systems which don't have icons on the desktop, eg XFCE, IceWM etc. It certainly seems more elegant than the rather crude script used in XFCE.

Now to sort out my other removable devices ...

----------

## davecs

ORIGINAL POST BEFORE EDIT

 *Quote:*   

> It was all going so well until ...
> 
> I set up three devices. I have used UDEV to ensure that various USB devices seen by the computer as USB-SCSI storage devices got different /dev/ shortcuts. The /dev shortcuts in my /etc/autofs/auto.misc file all work.
> 
> auto.misc:
> ...

 

Solution? I reverted back to version 3.1.7-r5

As far as I can see, version 4 does not  work properly in any form, with or without the Gentoo patches. I could only have 3 devices in v4, and even then, if I clicked on the shortcut when there was no device (CD out of drawer, USB flash card not plugged in) I would get an empty Konqueror window. However, with version 3 I get an error message unless there is something plugged in, in which case it "just works".

Moral? As yet, don't bother with version 4 at all.

----------

## jsosic

I don't know about you but v4 works fine for me without genpatches. I have 5 devices configured:

```
$ cat /etc/autofs/auto.media 

# $Id: auto.misc,v 1.2 2002/10/27 05:21:15 bcowan Exp $

# This is an automounter map and it has the following format

# key [ -mount-options-separated-by-comma ] location

# Details may be found in the autofs(5) manpage

#

#boot      -fstype=ext2   :/dev/hda1

floppy      -fstype=auto,rw   :/dev/fd0

cdrom      -fstype=auto,ro,nosuid,nodev   :/dev/cdroms/cdrom1

cdrw      -fstype=auto,ro,nosuid,nodev   :/dev/cdroms/cdrom0

camera      -fstype=vfat,rw,uid=0,gid=100,fmask=0117,dmask=0007,nosuid,nodev:/dev/sda1

usbhdd1      -fstype=auto,rw,uid=0,gid=100,fmask=0117,dmask=0007,nosuid,nodev:/dev/sda1

```

----------

## Jimmy Jazz

jsosic,

which kernel module are you using autofs or autofs4 ?

Do you load it at boot time or is it part of the kernel ?

Jj

----------

## jsosic

Module is automounter v4 and it's built into kernel. I think it must be part of the kernel, not standalone module... I've read something about it... Correct me if wrong  :Wink: 

----------

## Jimmy Jazz

 *jsosic wrote:*   

> Module is automounter v4 and it's built into kernel. I think it must be part of the kernel, not standalone module... I've read something about it... Correct me if wrong 

 

That could be my problem, "autofs4" is declared as a module but i'm too lazy to compile the kernel again to check if automount will work again  :Wink: 

```

...

CONFIG_AUTOFS4_FS=m

...

```

```

#lsmod

Module                  Size  Used by

...

autofs4                16388  0 

...

```

Jj

----------

## davecs

Just to add that I used v4 compiled into kernel.

All I can say about which version works and which one does not, is that 3.1.7-r5 worked for me, and the v4 versions didn't. Maybe it depends on other aspects of the system, hardware etc.

If it doesn't work with all systems, then unless there is something basically wrong with that system, there's a  bug! But I'm glad that v4 works for others!

----------

## fezz

I followed everything up to the the reboot.

After reboot I tried to start autofs but got the following error:

# /etc/init.d/autofs start

 * Starting automounter...

 * No autofs support available

I have the automounter has been added to the kernel exactly as in the steps.

I am using 2.6.11-r9 version of the kernel.

any thoughts?

thanks.

----------

## jsosic

Have you copied your new kernel bzImage over the old one which is places in /boot dir? autofs must be turned on, either as a builtin kernel option <*>, or as a module <M>. You've messed up something with the kernel configuration, or you forgot some step.

----------

## random-feed

I am having a problem with autofs, and I could not find any threads, posts or any other documents discussing a similar situation, so here it is:

I use autofs to automount the cdrom drive on my home router, a PII 350Mhz box. I want to share the mounted device with samba. Mounting works fawlessly, and I am able to access the share. However, once accessed via smb:// , the device will NEVER unmount. I read about a bug with autofs unmounting, but this is not the case -- if I stop or restart samba, the cdrom gets unmounted, i have the --timeout=1 option, so this is very easy to diagnose. I am certain no other clients are hooked to the share.

So, my question is: is there a way to make samba leave the shared dir alone when no activity is present, so that it can be umounted?

PS: My first Linux was Gentoo, installed 2 months ago. I used XP before that, so please excuse my ignorance. I did a lot of reading, but it never seems to be enough  :Smile: 

-----------------

I got it - all it took was sharing the autofs mountpoint, not the dir of the mounted device. That was an easy one  :Smile: 

----------

## jsosic

That's more like a Samba question  :Sad:  I'm not familiar with it so I wouldn't know...

----------

## jsosic

I've been playing with NFS, so I'm thinking about changing sections 4 & 5 of this howto. Local filesystems description would stay the same, only that few more lines would be added, and a little bit more explanation for NFS volumes. Do you think that would be ok, or should I write completely new Howto for NFS?

----------

## kamikaze04

I like the howto as it is. It is clear and easy to understand. I would write a howto for non-local systems, and put a link from this howto.

But it is only my opinion....

----------

## kernelcowboy

I had automounter support for both versions v4 and v3 compiled into the kernel.  the "why"  isn't important.

automounting worked, but --ghost did not.

i was about to post to this forum and ask why --ghost isn't working.  when i thought, oh, may be i have v3 compiled in too.   i checked, and indeed I did.  I disabled v3, recompiled.  --ghost works fine now.

So, instead of writing to ask, I'm writting to hopefully help someone else out. 

cheers

----------

## Braempje

Thanks for the --ghost tip, autofs is so great   :Very Happy: 

----------

## kernelcowboy

I have finally set it all up; I think the HOWTO was awesome, and got me almost all the way there.  As a sanity check, here's what i did.  Comments?

I have a small lan in my home office.  I run gentoo on all my machines.  samba.   the desktop can mount a cd, floppy and usb mp3 mem stick.

i wanted to have permissions set for all users on my system.  i'm behind a NAT.  i'm assuming there's little threat, so i didn't need to lock it down too much.  here's what i did.  

/etc/autofs/auto.master

```

/mnt/network /etc/autofs/auto.network --timeout 60  --ghost

/mnt/removable /etc/autofs/auto.removable --timeout 2  --ghost

```

/etc/autofs/auto.network - wanted this to hold any mounts to things on the network.  mounts that can have a longer timeout

guest stopped the password from being asked.  man smbmount for all the options

```

tib             -fstype=smbfs,rw,fmask=770,dmask=770,gid=users,guest    ://tib/public

```

/etc/autofs/auto.removable - removable stuff needs to get unmounted fast, so i can yank them out.  but notice how the fmask and dmask is different for the network mount above and stick mount here.

```

stick           -fstype=auto,rw,fmask=007,dmask=007,gid=users,sync      :/dev/sdb1

cdrom           -fstype=iso9660,ro,sync,nodev,nosuid                    :/dev/cdrom

floppy          -fstype=auto,sync,nodev,nosuid                          :/dev/fd0

```

then, i sym linked to the ghosted directories (i know you don't have too with v4.) so i can get in easy from the home dir.

cheers

----------

## ^Tomahawk^

thanks a lot, works very well for me

2.6.14-gentoo-r2

autofs 4.1.3-r4

together with udev rules this really rocks   :Arrow:   :Twisted Evil: 

----------

## thoffmeyer

Great how-to!

----------

## jsosic

 *^Tomahawk^ wrote:*   

> together with udev rules this really rocks   

 

Do you think I should expand my how to with udev rules for devices? Cause I use autofs with udev too  :Smile: 

----------

