Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm using iscsi-initiator-utils successfully to use some iscsi devices on CentOS 5, and I have some symlinks created by udev in /dev/disk:

# ls -l /dev/disk/by-path/ip-* /dev/disk/by-id/scsi-*
lrwxrwxrwx 1 root root 9 Sep 29 15:41 /dev/disk/by-id/scsi-14f504e46494c45006779706e4d772d746d36582d6869556e -> ../../sdb
lrwxrwxrwx 1 root root 9 Sep 29 15:41 /dev/disk/by-path/ip-192.168.20.149:3260-iscsi-iqn.2006-01.com.openfiler:tsn.0a16ba8cb6c9-lun-0 -> ../../sdb

I know that the by-path one is the IQN of the device, and I presume that the by-id one is a SCSI device identifier.

I would like to know how to get these values myself from e.g. /dev/sdb. scsi_id -g /dev/sdb returns nothing.

(I know I could map symlinks back and scrap the IDs from the filenames, but that would be redundant: udev is getting those IDs from somewhere, and I'd like to know where).

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Try udevinfo command

Also man 7 udev

Example:

[root@centos ~]# udevinfo -q all -n /dev/sda1 | grep 'ID_FS_UUID=' | awk -F'='  '{print $2}'
358c8298-3889-4982-8831-817a18ae4e67

[root@centos ~]# ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Dec  1 12:47 358c8298-3889-4982-8831-817a18ae4e67 -> ../../sda1
[root@centos ~]# readlink -e /dev/disk/by-uuid/358c8298-3889-4982-8831-817a18ae4e67 
/dev/sda1

Another one is blkid, which has integration with udev to show uuid

[root@centos ~]# blkid 
/dev/mapper/VolGroup00-LogVol01: TYPE="swap" 
/dev/mapper/VolGroup00-LogVol00: UUID="7951711f-0564-46a5-8e1c-427eff4b4115" TYPE="ext3" 
/dev/sda1: LABEL="/boot" UUID="358c8298-3889-4982-8831-817a18ae4e67" TYPE="ext3" 
/dev/hdc: LABEL="VBOXADDITIONS_4.1.2_73507" TYPE="iso9660" 
/dev/VolGroup00/LogVol00: UUID="7951711f-0564-46a5-8e1c-427eff4b4115" TYPE="ext3" 
/dev/VolGroup00/LogVol01: TYPE="swap" 
share|improve this answer
    
udev creates the device files, symlinks on the fly based on the rules defined /etc/udev/rules.d. UIDs are generated by udev something like uuidgen and that takes name, count of name characters, size, physical attributes and other geometric parameters into consideration for generating the UIDs. –  Nikhil Mulley Dec 1 '11 at 8:28

udev listens for uevents generated by the kernel. You would need to build something to listen for them to get this information in the same manner as udev. Here is some example code and discussion about doing that:

http://lwn.net/Articles/242046/

More information about how udev gets the info:

http://en.wikipedia.org/wiki/Udev#Operation

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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