Amd and UFS mounts

Christopher Sean Hilton chris at
Tue Nov 28 13:35:57 PST 2006

It's dim but I seem to remember that amd had no problems mounting a UFS
volume but it would never time it out. This may be the bug that Oliver
is referring to. 

This caused problems when using UFS on a USB stick since the drive would
never be dismounted so it was never safe to remove from the USB port.
I've just retested this and amd doesn't automatically time out a ufs
volume unless you ask it to by using the amq command. If I remember my
research correctly this is a feature, not a bug.

It's important to be able to get these volumes to unmount automatically.
The reason I researched this before was because I would continually
forget to unmount the usb stick before I suspended my computer. Before I
implemented this I was fscking my usb stick an average of twice a day.
After that I only had to fsck usb attached storage once every two weeks.
Although my current laptop won't suspend/resume cleanly I still find it
useful. The usb hub in the docking station triggers bugs in FreeBSD's
usb subsystem. Every once in a while the usb subsystem will hiccup.
Normally this isn't a problem but if a drive is plugged in and mounted
at the time of the hiccup then the drive won't detach properly and on
system shutdown you get a stuck buffer which causes a need for a
background fsck on the regular drives and a full fsck on the usb drive. 

I worked around the UFS mounts problem by using program mounts in amd.
>From time to time I am tempted to write a "How-To" on getting amd to
work with pendrives going all the way through using fdisk, disklabel,
and newfs to put a native FreeBSD filesystem on a USB stick or portable
hard drive but I always chicken out at the point where I'm telling the
user how to modify /etc/fstab for fear that if someone slips up with vi
they end up with an unusable FreeBSD install.

In any case here's how I'm using amd with my pendrives: I've
standardized on MSDOS FAT filesystems in <device>s1 and FreeBSD
filesystem in <device>s2. Amd handles the e partition on on the FreeBSD
slice. So the first usb drive will usually be device: /dev/da0. Under my
system the MS-DOS slice on that drive will be /dev/da0s1 and can be
accessed by any user via the amd by doing: 

     ls -l /amd/msdos0

On a successful mount the user gets a symlink listing. The user can
unmount the command by doing:

     amq -u /amd/msdos0

This will only work if there are no processes accessing the drive. If
the user forgets amd does this automatically after 30 seconds. The
utility FreeBSD partition, /amd/da0s2e is available as /amd/ufs0 and
works the same as the msdos partition.


***** Startup Options ***** 

I run amd with a conf file because on some machines I use it as a means
of nfs mounting my home directories.

$ grep amd /etc/rc.conf
## amd
amd_enable="YES"                # Run amd service with $amd_flags (or NO).
amd_flags="-F /etc/amd.conf"

***** Amd Configuration options *****

Nothing really special here.

$ cat /etc/amd.conf
[ global ]
    browsable_dirs =                        no
    map_type =                              file
    mount_type =                            nfs
    search_path =                           /etc
    auto_dir =                              /.amd
    cache_duration =                        30
    log_file =                              syslog:daemon
    log_options =                           info
    print_pid =                             yes
    pid_file =                              /var/run/
    restart_mounts =                        yes
    selectors_in_defaults =                 no

[ /amd ]
    map_name =                              /etc/

***** Map files *****

Here's how amd maps a directory to a filesystem.

$ cat /etc/
# $FreeBSD: src/etc/,v 1.9 2002/05/15 22:24:29 obrien Exp $

## /defaults       type:=host;fs:=${autodir}/${rhost}/host;rhost:=${key}
## *                       opts:=rw,grpid,resvport,vers=3,proto=udp,nosuid,nodev

## To use:
## mkdir -p /amd /.amd /.amd/cdrom /.amd/disk0 /.amd/disk1
## chmod 755 /.amd/*
## chmod 555 /.amd /amd

## Hotpluggable disks: Firewire, USB, etc. All the work gets done by
## setting up the appropriate entry in /etc/fstab. Ex. My firewire
## enclosures appear as { da0, and da1 } my convention is to put the
## msdos filesystem, if any, in slice 1 and the hotpluggable FreeBSD
## filesystem, if any, in partition e of slice 2.  The system expects
## that the hotpluggable freebsd filesystem will have all "autorun"
## scripts. So, the first firewire drive needs the following entries
## in /etc/fstab:
## /dev/da0s1   /.amd/msdos0    msdos   rw,noauto 0 0
## /dev/da0s2e  /.amd/ufs0      ufs rw,nosuid,nodev,noauto 0 0

msdos0          type:=program;fs:=${autodir}/${key};\
                        mount:="/sbin/mount mount ${fs}";\
                        unmount:="/sbin/umount umount ${fs}"

ufs0            type:=program;fs:=${autodir}/${key};\
                        mount:="/sbin/mount mount ${fs}";\
                        unmount:="/sbin/umount umount ${fs}"

***** Fstab entrys *****

Careful here. If you want to be really paranoid here add noexec to the mount flags.

/dev/acd0               /.amd/cdrom     cd9660  ro,noauto                       0    0

/dev/da0s1              /.amd/msdos0    msdos   rw,longnames,noauto             0    0
/dev/da0s2e             /.amd/ufs0      ufs     rw,nosuid,nodev,noauto          0    0

More information about the freebsd-stable mailing list