How to configure the Berkeley automounter (amd) for CDs and USB sticks

Discussion in 'all things UNIX' started by Gullible Jones, Jun 21, 2013.

Thread Status:
Not open for further replies.
  1. Gullible Jones

    Gullible Jones Registered Member

    Joined:
    May 16, 2013
    Posts:
    1,459
    Simply put, use a file like this. Put it in /etc/amd.vol, and make a map with it in /etc/amd.conf (see ' man amd.conf').

    Code:
    /defaults       opts:=rw,nodev,nosuid,noexec,noatime
    *               type:=pcfs;dev:=/dev/${key} \
                    type:=cdfs;addopts:=ro;dev:=/dev/${key}
    Translation:

    The first line is the default mount options for all devices that the file is responsible for mounting.

    In the second line, ${key} (i.e. the device you want to mount) gets substituted for the wild card '*'. It will try to mount the device as a "pcfs" (i.e. FAT) filesystem.

    The third line extends the second. This time it checks for "cdfs" (i.e. ISO9660, and hopefully UDF) volumes, and tries to mount them read-only.

    Upshot is that (if everything worked) you now have a directory, /vol, from which you can access volumes as soon as you insert them or plug them in. e.g. plug in a USB stick, 'ls /vol/sd0a' -> there are the stick's contents. Leave the filesystem untouched for a time, and it will unmount automatically.

    IMO this is useful on *BSD, where it presents a more flexible (and possibly more secure) alternative to the usermount sysctl.

    Caveats:

    - The browsable_dirs flag unfortunately doesn't work with wild cards, so your graphical file manager won't see the volume until you access it with ls, cd, etc.

    - Default unmount delay is very, very long. I recommend setting dismount_interval and cache_duration to 2 (seconds) for this purpose.

    - amd may hang, and require a kill -9 command or three, if amd.conf is misconfigured. Again, I recommend reading the man page on that file.

    amd is probably really useful for all kinds of stuff, this being the very least of it. Unfortunately the documentation is verbose and hard to interpret, which is why I've documented this. If I find anything that improves it I'll mention it here.

    (And yes, I am using NetBSD at the moment. Works much better than Linux on my used desktop.)
     
Loading...
Thread Status:
Not open for further replies.