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?
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Kyle Brandt
  • 832
  • 11
  • 18

2 Answers2

9

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.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
2

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

cat /sys/block/sda/removable

Kyle Brandt
  • 832
  • 11
  • 18