PDA

View Full Version : how to determine USB drive?



sluge
25th May 2012, 06:17 AM
Hello!
Is any way to 100% determine that some of sda, sdb, sdc, etc is a USB key, USB hard drive, memory card's reader or other USB device using shell commands?

hadrons123
25th May 2012, 06:23 AM
dmesg output shall give an idea.

satanselbow
25th May 2012, 09:47 AM
Give all your filesystems / USB sticks labels and you won't lose track of what is what :D


sudo blkid

would also spew some useful info in addition to the dmesg command above ;)

pjfg
25th May 2012, 10:33 AM
lsscsi gives nice readable output:

$ lsscsi
[0:0:0:0] disk ATA Hitachi HDP72505 GM4O /dev/sda
[1:0:0:0] cd/dvd Optiarc DVD RW AD-7241S 1.03 /dev/sr0
[2:0:0:0] disk ATA Hitachi HDP72505 GM4O /dev/sdb
[3:0:0:0] disk ATA OCZ-AGILITY3 2.15 /dev/sdc
[8:0:0:0] disk Generic USB SD Reader 1.00 /dev/sdd
[8:0:0:1] disk Generic USB CF Reader 1.01 /dev/sde
[8:0:0:2] disk Generic USB SM Reader 1.02 /dev/sdf
[8:0:0:3] disk Generic USB MS Reader 1.03 /dev/sdg

It is even more clear which bus the storage device is on if you you the -v flag.

If you don't already have just install with "yum install lsscsi"

DBelton
25th May 2012, 12:58 PM
actually, if you use lsscsi, the regular output (as shown above) doesn't tell you is it is usb or not. What you see is what happens to be pulled from the drive itself in the 2 fields.



[root@tower20 ~]# lsscsi
[2:0:0:0] disk ATA ST3500630AS 3.AA /dev/sda
[2:0:1:0] disk ATA WDC WD2001FASS-0 05.0 /dev/sdb
[3:0:0:0] cd/dvd TSSTcorp CDW/DVD TS-H493A CD07 /dev/sr0
[4:0:0:0] disk Seagate BlackArmorDAS35 412D /dev/sdc
[5:0:0:0] disk PNY USB 2.0 FD 8192 /dev/sdd



But, if you use lsscsi --transport (or lsscsi -t) then it will tell you if it is USB and even what USB bus and port it is on.




[root@tower20 ~]# lsscsi -t
[2:0:0:0] disk ata: /dev/sda
[2:0:1:0] disk ata: /dev/sdb
[3:0:0:0] cd/dvd ata: /dev/sr0
[4:0:0:0] disk usb: 1-4:1.0 /dev/sdc
[5:0:0:0] disk usb: 1-6:1.0 /dev/sdd



You could read that in and test that third field to see if it is equal to usb

pjfg
25th May 2012, 01:38 PM
actually, if you use lsscsi, the regular output (as shown above) doesn't tell you is it is usb or not. What you see is what happens to be pulled from the drive itself in the 2 fields.



[root@tower20 ~]# lsscsi
[2:0:0:0] disk ATA ST3500630AS 3.AA /dev/sda
[2:0:1:0] disk ATA WDC WD2001FASS-0 05.0 /dev/sdb
[3:0:0:0] cd/dvd TSSTcorp CDW/DVD TS-H493A CD07 /dev/sr0
[4:0:0:0] disk Seagate BlackArmorDAS35 412D /dev/sdc
[5:0:0:0] disk PNY USB 2.0 FD 8192 /dev/sdd



But, if you use lsscsi --transport (or lsscsi -t) then it will tell you if it is USB and even what USB bus and port it is on.




[root@tower20 ~]# lsscsi -t
[2:0:0:0] disk ata: /dev/sda
[2:0:1:0] disk ata: /dev/sdb
[3:0:0:0] cd/dvd ata: /dev/sr0
[4:0:0:0] disk usb: 1-4:1.0 /dev/sdc
[5:0:0:0] disk usb: 1-6:1.0 /dev/sdd



You could read that in and test that third field to see if it is equal to usb

Or use the -v flag like I said. It outputs the bus to which the device is attached from /sys ;)

sea
25th May 2012, 03:00 PM
Another nice command is: lsblk

[simon@l670 ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 298,1G 0 disk
├─sda1 8:1 0 400M 0 part
├─sda2 8:2 0 99,7G 0 part
├─sda3 8:3 0 125G 0 part /home
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 31,4G 0 part /
├─sda6 8:6 0 768M 0 part [SWAP]
└─sda7 8:7 0 15,9G 0 part
sr0 11:0 1 1024M 0 rom