ATA Errors

From GigaTux Wiki
Revision as of 13:05, 14 December 2012 by Cocodude (talk | contribs) (Created page with "You may notice errors in ''dmesg'' or ''/var/log/kern*'' which say that something is going wrong on something like ''ata4.0''. It is non-trivial to translate this to a device map...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

You may notice errors in dmesg or /var/log/kern* which say that something is going wrong on something like ata4.0. It is non-trivial to translate this to a device mapping like /dev/sda so code from this page helps determine what ata devices corresponds to what device:

 #!/bin/bash
 # note: inspired by Peter
 ls -l /sys/block/sd* \
 \
  | sed -e 's^.*-> \.\.^/sys^' \
        -e 's^/host[0-9]\{1,2\}/target^ ^' \
        -e 's^/[0-9]\{1,2\}\(:[0-9]\)\{3\}/block/^ ^' \
 \
  |  while read Path HostFull ID
     do
 
       # this nifty line will tokenize HostFull into named substrings ( = host numbers)
       IFS=: read HostMain HostMid HostSub <<< "$HostFull"
 
       if grep -q '/usb[0-9]*/' <<< $Path; then
         echo "(Device $ID is not an ATA device, but a USB device [e. g. a pen drive])"
       else
         echo $ID: ata$(cat $Path/host$HostMain/scsi_host/host$HostMain/unique_id).$HostMid$HostSub
       fi
 
      done