Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Sep 2004 11:51:15 -0400
From:      Christopher Sean Hilton <chris@vindaloo.com>
To:        freebsd-mobile@freebsd.org
Subject:   Re: How to get usbd to umount fle systems without crashing ?
Message-ID:  <20040914155115.GB13849@dantooine.vindaloo.com>
In-Reply-To: <20040914121643.GG4012@warning.this.domain.does.not-exist.de>
References:  <200409141058.i8EAwbSm001391@laps.jhs.private> <20040914121643.GG4012@warning.this.domain.does.not-exist.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Sep 14, 2004 at 02:16:43PM +0200, Hank Hampel wrote:
> Hi Julian!
> 
> On (040914), Julian Stacey wrote:
> > Can usbd automatically umount file systems ? How ?
> 
> I think your best option is to use amd (auto mount daemon) for this.
> 
> > I can automatically mount usb ram sticks from usbd (config below)
> > but I crash the system when I unplug, even if I use mount -r on attach.
> 
> This seems to be a logical result because after you detached the usb
> stick there is no device to umount!
> 

I'm recomposing this for the list since I sent the original just to
Hank and my mailer was misconfigured.

You want to use the automounter for this. The reason it's dying is
because FreeBSD is trying to write information (dirty buffers) back to
the filesystem after the device has disappeared. The correct sequence
for this would be umount the filesystem, then unplug the device. The
automounter (amd) will mount the filesystem "on demand" and unmount
after an inactivity timeout has expired. Here's the configuration that
I'm using on my laptop.

To start the automounter I use these settings in /etc/rc.conf

    ===== /etc/rc.conf

    ...

    portmap_enable="YES"            # Run the portmapper service (YES/NO).

    nfs_client_enable="YES"         # This host is an NFS client (or NO).

    amd_enable="YES"                # Run amd service with $amd_flags (or NO).
    amd_flags="-c 30 -l syslog /amd /etc/amd.map"

    ...

I'm not sure if the portmapper is relevent. The nfs client helps
because the amd acts as an nfs server. It presents a directory: /amd
and when you try to use an object within that directory it mounts the
appropriate volumn according to it's configuration and generates a
symlink. My automounter configuration is as follows:

    ===== /etc/amd.map

    # $FreeBSD: src/etc/amd.map,v 1.8 1999/09/13 17:09:07 peter Exp $
    #
    /defaults       type:=host;fs:=${autodir}/${rhost}/host;rhost:=${key}

    *               opts:=rw,grpid,resvport,vers=2,proto=tcp,nosuid,nodev,unmount

    ## Mount the cdrom when someone visits /amd/cdrom

    cdrom           type:=cdfs;fs:=${autodir}/${key};dev:=/dev/acd0c;addopts:=ro

    ## My keychain drive has msdos on slice 1 and FreeBSD on slice 2 partition a
    ## msdos0, usb0 are for the first mounted drive. msdos1, and usb1 are the 
    ## second mounted drive.

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

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

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

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

    ## The smart media for my camera comes in via a pcmcia card.

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

    ...

Finally I added mount points for the devices in /etc/fstab as
follows. This cleans up the configuration in /etc/amd.map
significantly:

    ===== /etc/fstab

    # See the fstab(5) manual page for important information on automatic mounts
    # of network filesystems before modifying this file.
    #
    # Device                Mountpoint      FStype  Options                         Dump    Pass#

    ...

    ## A little help for the automounter

    /dev/da0s1              /.amd_mnt/msdos0        msdos   rw,noauto               0       0
    /dev/da0s2a             /.amd_mnt/usb0          ufs     rw,noatime,noauto       0       0

    /dev/da1s1              /.amd_mnt/msdos1        msdos   rw,noauto               0       0
    /dev/da1s2a             /.amd_mnt/usb1          ufs     rw,noatime,noauto       0       0

    /dev/ad8s1              /.amd_mnt/photos        msdos   ro,noauto               0       0

It works pretty simply. If I try to get a file from /amd/usb0 the amd
will attempt to mount /dev/da0s2a and then generates a symlink from
/.amd_mnt/usb0 to /amd/usb0. Finally it tries to satisfy the request
for the file. If thirty seconds passes and I haven't used /amd/usb0 it
gets unmounted automatically. So, if I want to use my keychain drive
basically I plug it in and then do $ ls -l /amd/usb0


Hope that helps!
-- chris

Chris Hilton                                 chilton-at-vindaloo-dot-com
------------------------------------------------------------------------
                "All I was doing was trying to get home from work!"
                                                 -- Rosa Parks



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040914155115.GB13849>