Mapping ATA to Device Name

source: http://superuser.com/questions/617192/mapping-ata-device-number-to-logical-device-name/938620#938620
source: http://www.phuket-data-wizards.com/blog/2011/07/16/matching-linux-ata-numbers-to-the-device-names/comment-page-1/#comment-164108

First Get the ata # (maybe its from some error message that you see in dmesg)

The ata # is the unique_id with scsi_host

So ata # 5 is unique_id 5

Now we have to find out how ata # (or unique_id) maps to a scsi_host host number.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
grep . /sys/class/scsi_host/host*/unique_id
grep . /sys/class/scsi_host/host*/unique_id
grep . /sys/class/scsi_host/host*/unique_id

NOTE: the above command reads every unique_id file in all /sys/class/scsi_host/host* files and outputs it, for nice output.

Here is the ouput which shows the mapping between host number and unique_id:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/sys/class/scsi_host/host0/unique_id:1
/sys/class/scsi_host/host1/unique_id:2
/sys/class/scsi_host/host2/unique_id:3
/sys/class/scsi_host/host3/unique_id:4
/sys/class/scsi_host/host4/unique_id:5
/sys/class/scsi_host/host5/unique_id:6
/sys/class/scsi_host/host6/unique_id:0
/sys/class/scsi_host/host0/unique_id:1 /sys/class/scsi_host/host1/unique_id:2 /sys/class/scsi_host/host2/unique_id:3 /sys/class/scsi_host/host3/unique_id:4 /sys/class/scsi_host/host4/unique_id:5 /sys/class/scsi_host/host5/unique_id:6 /sys/class/scsi_host/host6/unique_id:0
/sys/class/scsi_host/host0/unique_id:1
/sys/class/scsi_host/host1/unique_id:2
/sys/class/scsi_host/host2/unique_id:3
/sys/class/scsi_host/host3/unique_id:4
/sys/class/scsi_host/host4/unique_id:5
/sys/class/scsi_host/host5/unique_id:6
/sys/class/scsi_host/host6/unique_id:0

So ata # 5 which is unique_id 5 is host # 4.

Mapping SCSI HOST to Device Name

So now to find out what host # 4 drive device name we run this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
ls -l /sys/block
ls -l /sys/block
ls -l /sys/block

NOTE: /sys/block has all of the block devices you have symlinks to their final path.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop0 -> ../devices/virtual/block/loop0
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop1 -> ../devices/virtual/block/loop1
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop2 -> ../devices/virtual/block/loop2
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop3 -> ../devices/virtual/block/loop3
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop4 -> ../devices/virtual/block/loop4
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop5 -> ../devices/virtual/block/loop5
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop6 -> ../devices/virtual/block/loop6
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop7 -> ../devices/virtual/block/loop7
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 md0 -> ../devices/virtual/block/md0
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 md1 -> ../devices/virtual/block/md1
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 md2 -> ../devices/virtual/block/md2
lrwxrwxrwx 1 root root 0 2015-07-08 15:45 sda -> ../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
lrwxrwxrwx 1 root root 0 2015-07-08 15:45 sdb -> ../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sdb
lrwxrwxrwx 1 root root 0 2015-07-08 15:45 sdc -> ../devices/pci0000:00/0000:00:1f.2/host4/target4:0:0/4:0:0:0/block/sdc
lrwxrwxrwx 1 root root 0 2015-07-08 15:45 sdd -> ../devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host6/target6:0:0/6:0:0:0/block/sdd
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop0 -> ../devices/virtual/block/loop0 lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop1 -> ../devices/virtual/block/loop1 lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop2 -> ../devices/virtual/block/loop2 lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop3 -> ../devices/virtual/block/loop3 lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop4 -> ../devices/virtual/block/loop4 lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop5 -> ../devices/virtual/block/loop5 lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop6 -> ../devices/virtual/block/loop6 lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop7 -> ../devices/virtual/block/loop7 lrwxrwxrwx 1 root root 0 2015-07-09 15:01 md0 -> ../devices/virtual/block/md0 lrwxrwxrwx 1 root root 0 2015-07-09 15:01 md1 -> ../devices/virtual/block/md1 lrwxrwxrwx 1 root root 0 2015-07-09 15:01 md2 -> ../devices/virtual/block/md2 lrwxrwxrwx 1 root root 0 2015-07-08 15:45 sda -> ../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda lrwxrwxrwx 1 root root 0 2015-07-08 15:45 sdb -> ../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sdb lrwxrwxrwx 1 root root 0 2015-07-08 15:45 sdc -> ../devices/pci0000:00/0000:00:1f.2/host4/target4:0:0/4:0:0:0/block/sdc lrwxrwxrwx 1 root root 0 2015-07-08 15:45 sdd -> ../devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host6/target6:0:0/6:0:0:0/block/sdd
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop0 -> ../devices/virtual/block/loop0
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop1 -> ../devices/virtual/block/loop1
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop2 -> ../devices/virtual/block/loop2
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop3 -> ../devices/virtual/block/loop3
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop4 -> ../devices/virtual/block/loop4
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop5 -> ../devices/virtual/block/loop5
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop6 -> ../devices/virtual/block/loop6
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 loop7 -> ../devices/virtual/block/loop7
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 md0 -> ../devices/virtual/block/md0
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 md1 -> ../devices/virtual/block/md1
lrwxrwxrwx 1 root root 0 2015-07-09 15:01 md2 -> ../devices/virtual/block/md2
lrwxrwxrwx 1 root root 0 2015-07-08 15:45 sda -> ../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
lrwxrwxrwx 1 root root 0 2015-07-08 15:45 sdb -> ../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sdb
lrwxrwxrwx 1 root root 0 2015-07-08 15:45 sdc -> ../devices/pci0000:00/0000:00:1f.2/host4/target4:0:0/4:0:0:0/block/sdc
lrwxrwxrwx 1 root root 0 2015-07-08 15:45 sdd -> ../devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:1.0/host6/target6:0:0/6:0:0:0/block/sdd

So for me host #4 is sdc.

So to summarize ata #5 is unique_id # 5 is host # 4 which is /dev/sdc.

OR ata #5 is /dev/sdc

COOL COMMAND: ata=3; ls -l /sys/block/sd* | grep $(grep ^$ata$ /sys/class/scsi_host/host*/unique_id | awk -F’/’ ‘{print $5}’)

REVERSE: device name to ata name

We can now go in reverse (using above output):

so /dev/sdb is host # 1

host # 1 is unique_id # 2

And unique_id #2 is ata 2

So /dev/sdb is ata #2

BONUS – 12 drives example – ATA to DEVICE &HOST to DEVICE maps

Here is a unit with 12 drives. It appears some drives dont need to have “ata” they can be just attached to the “scsi” drives. So some drives go from “ata”->”scsi” and some just go straight thru “scsi”.

The top command here is useful and shows how each ata device is attached to what drives.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
####################################
### 12 drives in a ReadyNAS 4220 ###
####################################
ls -l /sys/block
# total 0
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop0 -> ../devices/virtual/block/loop0
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop1 -> ../devices/virtual/block/loop1
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop2 -> ../devices/virtual/block/loop2
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop3 -> ../devices/virtual/block/loop3
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop4 -> ../devices/virtual/block/loop4
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop5 -> ../devices/virtual/block/loop5
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop6 -> ../devices/virtual/block/loop6
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop7 -> ../devices/virtual/block/loop7
# lrwxrwxrwx 1 root root 0 Jun 30 08:09 md0 -> ../devices/virtual/block/md0
# lrwxrwxrwx 1 root root 0 Jun 30 09:09 md1 -> ../devices/virtual/block/md1
# lrwxrwxrwx 1 root root 0 Jun 30 08:09 md127 -> ../devices/virtual/block/md127
# lrwxrwxrwx 1 root root 0 Jun 30 08:10 sda -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:0/end_device-0:0/target0:0:0/0:0:0:0/block/sda
# lrwxrwxrwx 1 root root 0 Jun 30 08:10 sdb -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:1/end_device-0:1/target0:0:1/0:0:1:0/block/sdb
# lrwxrwxrwx 1 root root 0 Jun 30 08:11 sdc -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:2/end_device-0:2/target0:0:2/0:0:2:0/block/sdc
# lrwxrwxrwx 1 root root 0 Jun 30 08:11 sdd -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:3/end_device-0:3/target0:0:3/0:0:3:0/block/sdd
# lrwxrwxrwx 1 root root 0 Jun 30 09:09 sde -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:4/end_device-0:4/target0:0:4/0:0:4:0/block/sde
# lrwxrwxrwx 1 root root 0 Jun 30 08:11 sdf -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:5/end_device-0:5/target0:0:5/0:0:5:0/block/sdf
# lrwxrwxrwx 1 root root 0 Jun 30 08:09 sdg -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:6/end_device-0:6/target0:0:6/0:0:6:0/block/sdg
# lrwxrwxrwx 1 root root 0 Jun 30 08:10 sdh -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:7/end_device-0:7/target0:0:7/0:0:7:0/block/sdh
# lrwxrwxrwx 1 root root 0 Jun 30 08:09 sdi -> ../devices/pci0000:00/0000:00:1f.2/ata1/host1/target1:0:0/1:0:0:0/block/sdi
# lrwxrwxrwx 1 root root 0 Jun 30 08:10 sdj -> ../devices/pci0000:00/0000:00:1f.2/ata2/host2/target2:0:0/2:0:0:0/block/sdj
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 sdk -> ../devices/pci0000:00/0000:00:1f.2/ata3/host3/target3:0:0/3:0:0:0/block/sdk
# lrwxrwxrwx 1 root root 0 Jun 30 08:10 sdl -> ../devices/pci0000:00/0000:00:1c.0/0000:03:00.0/ata7/host7/target7:0:0/7:0:0:0/block/sdl
# lrwxrwxrwx 1 root root 0 Jun 30 08:10 sdm -> ../devices/pci0000:00/0000:00:1c.0/0000:03:00.0/ata8/host8/target8:0:0/8:0:0:0/block/sdm
##########################
### ATA to DEVICE NAME ###
##########################
for i in {0..100}; do echo -n "ata${i}: "; echo $(find /sys | grep "ata$i" | egrep -o "(sd|hd|sg)[a-z]+" | sort | uniq); echo; done | egrep "(sd|hd|sg)[a-z]+"
# OUTPUT:
# ata1: sdi
# ata2: sdj
# ata3: sdk
# ata7: sdl
# ata8: sdm
# NOTE: my command allows multiple devices for an ata device (im not sure if an ata device can control more than 1 device)
###########################
### HOST to DEVICE NAME ###
###########################
for i in {0..100}; do echo -n "host${i}: "; echo $(find /sys | grep "host$i" | egrep -o "(sd|hd|sg)[a-z]+" | sort | uniq); echo; done | egrep "(sd|hd|sg)[a-z]+"
# OUTPUT:
# host0: sda sdb sdc sdd sde sdf sdg sdh
# host1: sdi
# host2: sdj
# host3: sdk
# host7: sdl
# host8: sdm
# NOTE: my command obviously allows multiple devices for a scsi host device (as seen with host0)
#################################### ### 12 drives in a ReadyNAS 4220 ### #################################### ls -l /sys/block # total 0 # lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop0 -> ../devices/virtual/block/loop0 # lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop1 -> ../devices/virtual/block/loop1 # lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop2 -> ../devices/virtual/block/loop2 # lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop3 -> ../devices/virtual/block/loop3 # lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop4 -> ../devices/virtual/block/loop4 # lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop5 -> ../devices/virtual/block/loop5 # lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop6 -> ../devices/virtual/block/loop6 # lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop7 -> ../devices/virtual/block/loop7 # lrwxrwxrwx 1 root root 0 Jun 30 08:09 md0 -> ../devices/virtual/block/md0 # lrwxrwxrwx 1 root root 0 Jun 30 09:09 md1 -> ../devices/virtual/block/md1 # lrwxrwxrwx 1 root root 0 Jun 30 08:09 md127 -> ../devices/virtual/block/md127 # lrwxrwxrwx 1 root root 0 Jun 30 08:10 sda -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:0/end_device-0:0/target0:0:0/0:0:0:0/block/sda # lrwxrwxrwx 1 root root 0 Jun 30 08:10 sdb -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:1/end_device-0:1/target0:0:1/0:0:1:0/block/sdb # lrwxrwxrwx 1 root root 0 Jun 30 08:11 sdc -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:2/end_device-0:2/target0:0:2/0:0:2:0/block/sdc # lrwxrwxrwx 1 root root 0 Jun 30 08:11 sdd -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:3/end_device-0:3/target0:0:3/0:0:3:0/block/sdd # lrwxrwxrwx 1 root root 0 Jun 30 09:09 sde -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:4/end_device-0:4/target0:0:4/0:0:4:0/block/sde # lrwxrwxrwx 1 root root 0 Jun 30 08:11 sdf -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:5/end_device-0:5/target0:0:5/0:0:5:0/block/sdf # lrwxrwxrwx 1 root root 0 Jun 30 08:09 sdg -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:6/end_device-0:6/target0:0:6/0:0:6:0/block/sdg # lrwxrwxrwx 1 root root 0 Jun 30 08:10 sdh -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:7/end_device-0:7/target0:0:7/0:0:7:0/block/sdh # lrwxrwxrwx 1 root root 0 Jun 30 08:09 sdi -> ../devices/pci0000:00/0000:00:1f.2/ata1/host1/target1:0:0/1:0:0:0/block/sdi # lrwxrwxrwx 1 root root 0 Jun 30 08:10 sdj -> ../devices/pci0000:00/0000:00:1f.2/ata2/host2/target2:0:0/2:0:0:0/block/sdj # lrwxrwxrwx 1 root root 0 Jun 30 08:39 sdk -> ../devices/pci0000:00/0000:00:1f.2/ata3/host3/target3:0:0/3:0:0:0/block/sdk # lrwxrwxrwx 1 root root 0 Jun 30 08:10 sdl -> ../devices/pci0000:00/0000:00:1c.0/0000:03:00.0/ata7/host7/target7:0:0/7:0:0:0/block/sdl # lrwxrwxrwx 1 root root 0 Jun 30 08:10 sdm -> ../devices/pci0000:00/0000:00:1c.0/0000:03:00.0/ata8/host8/target8:0:0/8:0:0:0/block/sdm ########################## ### ATA to DEVICE NAME ### ########################## for i in {0..100}; do echo -n "ata${i}: "; echo $(find /sys | grep "ata$i" | egrep -o "(sd|hd|sg)[a-z]+" | sort | uniq); echo; done | egrep "(sd|hd|sg)[a-z]+" # OUTPUT: # ata1: sdi # ata2: sdj # ata3: sdk # ata7: sdl # ata8: sdm # NOTE: my command allows multiple devices for an ata device (im not sure if an ata device can control more than 1 device) ########################### ### HOST to DEVICE NAME ### ########################### for i in {0..100}; do echo -n "host${i}: "; echo $(find /sys | grep "host$i" | egrep -o "(sd|hd|sg)[a-z]+" | sort | uniq); echo; done | egrep "(sd|hd|sg)[a-z]+" # OUTPUT: # host0: sda sdb sdc sdd sde sdf sdg sdh # host1: sdi # host2: sdj # host3: sdk # host7: sdl # host8: sdm # NOTE: my command obviously allows multiple devices for a scsi host device (as seen with host0)
####################################
### 12 drives in a ReadyNAS 4220 ###
####################################

ls -l /sys/block
# total 0
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop0 -> ../devices/virtual/block/loop0
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop1 -> ../devices/virtual/block/loop1
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop2 -> ../devices/virtual/block/loop2
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop3 -> ../devices/virtual/block/loop3
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop4 -> ../devices/virtual/block/loop4
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop5 -> ../devices/virtual/block/loop5
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop6 -> ../devices/virtual/block/loop6
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 loop7 -> ../devices/virtual/block/loop7
# lrwxrwxrwx 1 root root 0 Jun 30 08:09 md0 -> ../devices/virtual/block/md0
# lrwxrwxrwx 1 root root 0 Jun 30 09:09 md1 -> ../devices/virtual/block/md1
# lrwxrwxrwx 1 root root 0 Jun 30 08:09 md127 -> ../devices/virtual/block/md127
# lrwxrwxrwx 1 root root 0 Jun 30 08:10 sda -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:0/end_device-0:0/target0:0:0/0:0:0:0/block/sda
# lrwxrwxrwx 1 root root 0 Jun 30 08:10 sdb -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:1/end_device-0:1/target0:0:1/0:0:1:0/block/sdb
# lrwxrwxrwx 1 root root 0 Jun 30 08:11 sdc -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:2/end_device-0:2/target0:0:2/0:0:2:0/block/sdc
# lrwxrwxrwx 1 root root 0 Jun 30 08:11 sdd -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:3/end_device-0:3/target0:0:3/0:0:3:0/block/sdd
# lrwxrwxrwx 1 root root 0 Jun 30 09:09 sde -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:4/end_device-0:4/target0:0:4/0:0:4:0/block/sde
# lrwxrwxrwx 1 root root 0 Jun 30 08:11 sdf -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:5/end_device-0:5/target0:0:5/0:0:5:0/block/sdf
# lrwxrwxrwx 1 root root 0 Jun 30 08:09 sdg -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:6/end_device-0:6/target0:0:6/0:0:6:0/block/sdg
# lrwxrwxrwx 1 root root 0 Jun 30 08:10 sdh -> ../devices/pci0000:00/0000:00:01.1/0000:02:00.0/host0/port-0:7/end_device-0:7/target0:0:7/0:0:7:0/block/sdh
# lrwxrwxrwx 1 root root 0 Jun 30 08:09 sdi -> ../devices/pci0000:00/0000:00:1f.2/ata1/host1/target1:0:0/1:0:0:0/block/sdi
# lrwxrwxrwx 1 root root 0 Jun 30 08:10 sdj -> ../devices/pci0000:00/0000:00:1f.2/ata2/host2/target2:0:0/2:0:0:0/block/sdj
# lrwxrwxrwx 1 root root 0 Jun 30 08:39 sdk -> ../devices/pci0000:00/0000:00:1f.2/ata3/host3/target3:0:0/3:0:0:0/block/sdk
# lrwxrwxrwx 1 root root 0 Jun 30 08:10 sdl -> ../devices/pci0000:00/0000:00:1c.0/0000:03:00.0/ata7/host7/target7:0:0/7:0:0:0/block/sdl
# lrwxrwxrwx 1 root root 0 Jun 30 08:10 sdm -> ../devices/pci0000:00/0000:00:1c.0/0000:03:00.0/ata8/host8/target8:0:0/8:0:0:0/block/sdm

##########################
### ATA to DEVICE NAME ###
##########################

for i in {0..100}; do echo -n "ata${i}: "; echo $(find /sys | grep "ata$i" | egrep -o "(sd|hd|sg)[a-z]+" | sort | uniq); echo; done | egrep "(sd|hd|sg)[a-z]+"

# OUTPUT:

# ata1: sdi
# ata2: sdj
# ata3: sdk
# ata7: sdl
# ata8: sdm

# NOTE: my command allows multiple devices for an ata device (im not sure if an ata device can control more than 1 device)

###########################
### HOST to DEVICE NAME ###
###########################

for i in {0..100}; do echo -n "host${i}: "; echo $(find /sys | grep "host$i" | egrep -o "(sd|hd|sg)[a-z]+" | sort | uniq); echo; done | egrep "(sd|hd|sg)[a-z]+"

# OUTPUT: 

# host0: sda sdb sdc sdd sde sdf sdg sdh
# host1: sdi
# host2: sdj
# host3: sdk
# host7: sdl
# host8: sdm

# NOTE: my command obviously allows multiple devices for a scsi host device (as seen with host0)

The end

One thought on “Mapping ATA or SCSI HOST to Device Name

  1. UPDATE: ata# and host# can both map to more than 1 drive. especially if port multipliers or SAS controllers are used in the system

Leave a Reply

Your email address will not be published. Required fields are marked *