Linux – detect specific device is USB / SATA apart from dmesg output

commandlinuxsatausb

Suppose in a linux machine you have both SATA and USB devices present, and if they are all detected properly, how do you know whether a specific device(sda1/ sdb1) is USB device OR SATA device.
Note: devices needs to be manually mounted.
Note: dmesg is cleared already. we cannot use /var/log/messages as that too is cleared.

Question is : Is there other way, say from /proc or any other command by which we know that the specific device(sda1/sdb1) is SATA OR USB ?

Thanks!

Best Answer

You can get that information from /sys virtual file system.

Run find /sys -name \*sd[ab]\*. Some of the lines from my station are:

/sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1:1.0/host69/target69:0:0/69:0:0:0/block/sdb
/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda

There is "usb" in the line with sdb, there's none in the line with sda, so the USB drive is sdb.

Another piece of information that you can get is from

cat /sys/class/block/sda/removable
cat /sys/class/block/sdb/removable

files. If file's contents is 0, then the device isn't removable, so it cannot be an external USB drive. Some SATA drives report themselves as removable, so it may not be definitive.