6

In DMESG I see:

[sdb] Attached SCSI removable disk

  1. How does Linux decide what is removable and not removable?
  2. Is there a way I can look up if a device is "removable" or not other than the log, for example somehwere in /sys or /proc?
8

All block devices have a removable attribute, among other block device attributes. These attributes can be read from userland in sysfs at /sys/block/DEVICE/ATTRIBUTE, e.g. /sys/block/sdb/removable.

You can query this attribute from a udev rule, with ATTR{removable}=="0" or ATTR{removable}=="1".

Note that removable (the device keeps existing but may have no media) isn't the same thing as hotpluggable (the device can come and go). For example, CD drives are removable but often not hotpluggable. USB flash drives are both, but hard disks in external enclosures are typically hotpluggable but not removable.

If you want to find out the nitty-gritty of when a device is considered removable, you'll have to dig into the kernel source. Search for removable — there aren't too many spurious hits. For SCSI devices, the removable bit is read from the device in scsi_add_lun with a SCSI INQUIRY command.

2

With a little effort I found the answer to my second question:

cat /sys/block/sda/removable

  • Also considering just using fstatfs and checking the fs type – Kyle Brandt Apr 22 '14 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.