Finding attributes of mounted SD card

10

3

My SD card is automounted fine as /dev/sdb:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  1024M  0 rom  
sda      8:0    0    80G  0 disk 
├─sda1   8:1    0    78G  0 part /
├─sda2   8:2    0     1K  0 part 
└─sda5   8:5    0     2G  0 part [SWAP]
sr1     11:1    1  1024M  0 rom  
sdb      8:16   1   7.4G  0 disk 
├─sdb1   8:17   1    56M  0 part /media/boot
└─sdb2   8:18   1   2.7G  0 part /media/af599925-1134-4b6e-8883-fb6a99cd58f1

In dmesg:

[ 1206.970596] sd 3:0:0:0: [sdb] Attached SCSI removable disk

I would like to know a few attributes - serial #, manufacturer id, etc. that I thought would be in /sys/class. I have searched /sys/class/scsi_disk/3:0:0:0/ without any luck.

Where would I find this information? I am using the latest version of Arch-linux.

Charles Pehlivanian

Posted 2014-01-04T01:55:35.230

Reputation: 235

Answers

11

The proper way to do this, in Arch Linux but by now in all systems which use udev, is the command:

  sudo udevadm info -a -n /dev/sdb

in your case.

Edit:

A reply to your comment: I believe you are mistaken. The class is a view of a device which is independent of the low-level implementation details. The classic example is a disk. You may of course have a SCSI disk or an ATA disk, but, at the class level, they are the same thing. The idea of the class is to allow users to build userspace code which is independent of how they are connected to the network, how they work, which device driver they use, and so on. In a way, the class is the highest level of abstraction available as a model for devices.

Thus you are wrong in searching for such details as your SD card vendor (which, by the way, should be in /sys/class/mmc_host, if anything at all) within /sys/class.

MariusMatutiae

Posted 2014-01-04T01:55:35.230

Reputation: 41 321

@CharlesPehlivanian: You can get to that detailed information via /sys/class; see @Robert's answer. It may just not be the best way. However, on some systems (e.g. Android), udevadm isn't available. – LarsH – 2015-10-23T17:51:59.320

1Ok, this gives all that information. But - I though /sys/class was supposed to be a way do navigate /dev without all the device-specific (set by udev) hieracrchy? Am I wrong about that? – Charles Pehlivanian – 2014-01-05T21:27:14.033

@CharlesPehlianian See the Edit to my answer – MariusMatutiae – 2014-01-05T22:13:12.793

Ok - I was under the wrong impression then. Thanks! – Charles Pehlivanian – 2014-01-07T01:11:44.843

6

The exact layout is driver dependent, but try searching /sys for some MMC (SD) specific keywords. Below is from an ARM-based embedded system:

$ find /sys -name "oemid"
/sys/class/mmc_host/mmc0/mmc0:aaaa/oemid
$ find /sys -name "cid"
/sys/class/mmc_host/mmc0/mmc0:aaaa/cid
$ find /sys -name "csd"
/sys/class/mmc_host/mmc0/mmc0:aaaa/csd

Bunnie's blog entry on SD card shenanigans is a good place to start back-tracking what those ID numbers mean.

Robert Calhoun

Posted 2014-01-04T01:55:35.230

Reputation: 273

Great. In my case, with this answer, I could find most SD and MMC device attributes. cid, csd, scr, date, fwrev, hwrev, manfid, name, oemid, serial... – agfe2 – 2018-08-28T08:28:02.950

2

I don't use Arch Linux, but "usb-devices" lists the details of all USB devices the system knows about, and included the following for a USB key I plugged in:

T:  Bus=03 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#=  5 Spd=480 MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=0781 ProdID=5567 Rev=01.26
S:  Manufacturer=SanDisk
S:  Product=Cruzer Blade
S:  SerialNumber=4C532000060624123092
C:  #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=200mA
I:  If#= 0 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage

davidgo

Posted 2014-01-04T01:55:35.230

Reputation: 49 152

1Thanks, this gives me what I was asking for, but I'd like to understand /sys/class a little better so I'd like an answer based on that. – Charles Pehlivanian – 2014-01-04T03:16:04.723

1

Looking at /sys/class/scsi_disk I discovered that (on my system) that these are symkinks to actual disks. Indeed when I do an "ls -la /sys/class/scsi_disk/ it shows a symlink for 8:0:0:0 to ../../devices/pci0000:00/0000:00:1c.4/0000:09:00.0/usb3/3-2/3-2.3/3-2.3:1.0/host8/target8:0:0/8:0:0:0/scsi_disk/8:0:0:0

If I then shift in to :/sys/devices/pci0000:00/0000:00:1c.4/0000:09:00.0/usb3/3-2/3-2.3/3-2.3:1.0/host8/target8:0:0/8:0:0:0 It has a number of files which I suspect are of interest to you including -

model = model of the drive
vendor = the drive vendor

Also of interest might be parsing /proc/scsi -

/proc/scsi/scsi          contains the description of each device and associated host
                         as scsi8 which lets me derive the "8" in the next bit.

/proc/scsi/usb-storage/8 contains the Vendor, Product and serial number

davidgo

Posted 2014-01-04T01:55:35.230

Reputation: 49 152

When do ls on your /sys/devices/... directory, as you indicate, I get a symlink back to /sys/class/scsi_disk/8:0:0:0, which is where my question began. I don't see any files for model, vendor, only FUA, device, allow_restart, etc. I have searched these with no luck. – Charles Pehlivanian – 2014-01-05T21:32:39.573