Determinig removable devices in shell scripts?

Alexander Motin mav at FreeBSD.org
Tue Sep 7 18:13:31 UTC 2010


Hi.

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".

There is two kinds of removability - removable media and removable device.

For removable media: SCSI/ATAPI disks (da) report different device types
for fixed disks (HDD) and removable (ZIP, FDD, card readers, ...). It
can be found via `camcontrol inquiry daX`. I haven't heard about ATA
(non-ATAPI) disks with removable media, though specifications last time
include dedicated fields for media serial number, which may mean
removable media.

For removable devices: I believe it is controller of even more -
platform dependent. For USB it probably may be assumed by default, for
others it depends. All I have seen - AHCI controller have two bits per
port defining different kind of removability. You may see them during
verbose boot. But BIOS vendors often not bothering to fill them
correctly even if some ports wired to external connectors. To get
information about controller, you may try `camcontrol negotiate ada0 -v`.

-- 
Alexander Motin


More information about the freebsd-geom mailing list