Determinig removable devices in shell scripts?

Oliver Fromme olli at lurza.secnetix.de
Wed Sep 8 12:32:26 UTC 2010


Alexander Leidinger wrote:
 > is there an easy way to determine in a shell script if a device  
 > (da/ada) is removable (USB memory stick, eSATA connection)? I was  
 > thinking more or less about something like "sysctl kern.disks".

USB devices are easy, just check if the da(4) device is
connected to umass.  I think camcontrol will tell you.
Same with FireWire devices via sbp(4).

eSATA might be more difficult.

Finally, there are cases where it's pretty much impossible
to detect.  I've got a hot-swap frame for P-ATA hard drives
which I use for backups, using atacontrol(8) attach/detach/
reinit, so it's basically a removable device.  But it's
completely transparent to the OS, i.e. there is no way to
determine if a certain ad(4) device is located in such a
swappable frame or not.

Well ...  if the device was not present during boot (see
/var/run/dmesg.boot), then it is obviously removable, but
the reverse isn't true since a removable device might be
already present during boot, so that's not a complete
solution to the problem.

Best regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd

One Unix to rule them all, One Resolver to find them,
One IP to bring them all and in the zone to bind them.


More information about the freebsd-geom mailing list