Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Mar 2009 18:43:04 +0100
From:      Roland Smith <rsmith@xs4all.nl>
To:        Peter Steele <psteele@maxiscale.com>
Cc:        questions@freebsd.org
Subject:   Re: How to auto-detect a USB drive?
Message-ID:  <20090311174304.GA67007@slackbox.xs4all.nl>
In-Reply-To: <20138265.681236784246466.JavaMail.HALO$@halo>
References:  <21664605.661236783895798.JavaMail.HALO$@halo> <20138265.681236784246466.JavaMail.HALO$@halo>

next in thread | previous in thread | raw e-mail | index | archive | help

--BXVAT5kNtrzKuDFl
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Mar 11, 2009 at 08:10:46AM -0700, Peter Steele wrote:
> >My question to you would be: What exactly do you mean by=20
> >"automatically detect"? The drive *is* automatically detected.=20
> >Should it be mounted afterwards?=20
>=20
> Yeah, I guess my wording was a little vague. I know that the system
> automatically detects when a USB drive is inserted, and creates the
> appropriate entries under /dev. I want to follow this up with having
> the drive automatically mounted, and I'll then examine the USB drive
> for specific files I expect to be present, and possible run something
> that's installed on the disk, then unmount the disk. We want to use
> this approach to deploy our software on large clusters of machines
> that may not have an IP identity.

The easiest way (I think) is to use devd, in combination with a USB
drive that has a unique label.

Say you have a USB drive formatted with a UFS filesystem. You use
'tunefs -L' to give this drive a unique label,
e.g. 'FOO'. Then you can put the following in /etc/devd.conf

notify 1000 {
        match   "system"                "DEVFS";
        match   "subsystem"             "CDEV";
        match   "cdev"                  "/dev/ufs/FOO";
        action  "sh /usr/local/sbin/autorun /dev/ufs/FOO &";
};

Where the script /usr/local/sbin/autorun would contain the required actions
(mount, check, run, umount, beep).

The reason for using a labeled device is that you might not want to run
the script on any old USB drive! If you want to use a FAT formatted
drive you should use /dev/msdosfs/FOO for the path.

Last week I submitted a patch to get this system and subsystem
documented in the manual page of devd.conf. It should be in CURRENT now,
and will be MFC'd to STABLE in a week or so.

Roland
--=20
R.F.Smith                                   http://www.xs4all.nl/~rsmith/
[plain text _non-HTML_ PGP/GnuPG encrypted/signed email much appreciated]
pgp: 1A2B 477F 9970 BA3C 2914  B7CE 1277 EFB0 C321 A725 (KeyID: C321A725)

--BXVAT5kNtrzKuDFl
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (FreeBSD)

iEYEARECAAYFAkm3+CgACgkQEnfvsMMhpyWe8gCeNYpK/Q6l20TwbolEMRt1gC2q
87oAn0vaaNoxWKCtIJo3SXUWWEATTCdf
=a9G5
-----END PGP SIGNATURE-----

--BXVAT5kNtrzKuDFl--



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