From owner-freebsd-questions@FreeBSD.ORG Wed Mar 11 18:09:27 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 88B30106564A for ; Wed, 11 Mar 2009 18:09:27 +0000 (UTC) (envelope-from jmc-freebsd2@milibyte.co.uk) Received: from relay.ptn-ipout02.plus.net (relay.ptn-ipout02.plus.net [212.159.7.36]) by mx1.freebsd.org (Postfix) with ESMTP id 238518FC19 for ; Wed, 11 Mar 2009 18:09:26 +0000 (UTC) (envelope-from jmc-freebsd2@milibyte.co.uk) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAFebt0nUnw6T/2dsb2JhbADRe4QNBg Received: from ptb-relay03.plus.net ([212.159.14.147]) by relay.ptn-ipout02.plus.net with ESMTP; 11 Mar 2009 18:09:25 +0000 Received: from [84.92.153.232] (helo=curlew.milibyte.co.uk) by ptb-relay03.plus.net with esmtp (Exim) id 1LhSrt-0005rI-I0; Wed, 11 Mar 2009 18:09:25 +0000 Received: by curlew.milibyte.co.uk with local (Exim 4.69) (envelope-from ) id 1LhSrt-000Nsy-5A; Wed, 11 Mar 2009 18:09:25 +0000 From: Mike Clarke To: freebsd-questions@freebsd.org Date: Wed, 11 Mar 2009 18:09:24 +0000 User-Agent: KMail/1.9.10 References: <20138265.681236784246466.JavaMail.HALO$@halo> In-Reply-To: <20138265.681236784246466.JavaMail.HALO$@halo> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200903111809.25108.jmc-freebsd2@milibyte.co.uk> X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: jmc-freebsd2@milibyte.co.uk X-SA-Exim-Scanned: No (on curlew.milibyte.co.uk); SAEximRunCond expanded to false X-Plusnet-Relay: cf5e5462054ea15ae109e11c370d1db7 Cc: Peter Steele Subject: Re: How to auto-detect a USB drive? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Mar 2009 18:09:27 -0000 On Wednesday 11 March 2009, Peter Steele wrote: > 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. I do something like this. Here's the rules I have in /usr/local/etc/devd.conf #----------------------------------------------------------------- # # Generic USB devices # attach 10 { match "device-name" "umass0"; action "sleep 2; /root/bin/usbstick_attach > /dev/console"; }; # # Cameras # attach 20 { match "device-name" "umass0"; match "vendor" "0x(07b4|04b0)"; action "/bin/sleep 2 && mount -t msdosfs /dev/da0s1 /camera && /root/bin/camcopy && umount /camera && echo ^G > /dev/console"; }; #----------------------------------------------------------------- For most USB storage devices /root/bin/usbstick_attach parses the output of `camcontrol devlist` looking for entries like (da*,pass*) or (pass*,da*) and then it sets the permissions on the device to 660 and, for convenience, creates a link called usbstick in the dev directory pointing to the real device. This way the I can always mount /dev/usbstick on one of my own subdirectories without having to determine what device was created. I could have made the script mount the USB stick but if I have to make the effort to mount it myself I might be more likely to remember to unmount it afterwards. The cameras are a special case since all I want to do is to check for new photos and copy them to my photo archive so if devd detects one of my cameras it mounts the camera with the higher priority "attach 20" rule which invokes /root/bin/camcopy to copy the photos before unmounting the camera and sounding the console bell to let me know I can unplug it. The scripts are a bit primitive and get totally confused if I insert more than one USB storage device at a time so would need some refinement for general use but work OK for me as the only user on this PC. -- Mike Clarke