How to Identify Physical Hard Drives by ATA Port (ata1.00/ata12.00) Using Serial Numbers in Linux


2 views

When managing multiple drives in a Linux system, you might encounter SMART errors reported against ATA ports like ata1.00 or ata12.00. The challenge is correlating these abstract identifiers with physical drives in your machine.

The most reliable method is extracting serial numbers through these commands:


# Method 1: Using smartctl
sudo smartctl -i /dev/sdX | grep -i serial

# Method 2: Checking sysfs entries
cat /sys/block/sdX/device/serial

Create a complete mapping with this script:


#!/bin/bash
for ata in /sys/class/ata_port/*; do
    port=$(basename $ata)
    for link in $ata/ata*/../../../../host*/target*/*/block/*; do
        [ -e "$link" ] || continue
        dev=$(basename $link)
        serial=$(cat $link/device/serial)
        echo "$port -> /dev/$dev (Serial: $serial)"
    done
done

For more detailed device information:


udevadm info --query=all --name=/dev/sdX | grep -E 'ID_SERIAL|ID_ATA'

Let's say you have this error in /var/log/syslog:

kernel: [12345.67890] ata12.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x0

Run this diagnostic sequence:


# Find which /dev/sdX corresponds to ata12
ls -l /sys/block/sd*/device | grep ata12

# Then check the serial
smartctl -i /dev/sdc | grep Serial

For servers, create a persistent mapping file:


#!/bin/bash
rm -f /root/drive_map.txt
for dev in /dev/sd*[^0-9]; do
    serial=$(smartctl -i $dev | awk '/Serial Number:/ {print $3}')
    echo "$(basename $dev) -> $serial" >> /root/drive_map.txt
done




In Linux systems, ATA drives are typically labeled as ataX.00 where X represents the controller/channel number. This numbering doesn't directly correlate with physical drive bays or ports, making physical identification challenging when dealing with multiple drives.

The most reliable way to match ATA devices to physical drives is through their serial numbers. Here's how to extract this information:

sudo smartctl -i /dev/sdX | grep -i "serial number"

For a comprehensive scan of all ATA devices:

for drive in /dev/sd*[a-z]; do
    echo "Checking $drive:"
    sudo smartctl -i $drive | grep -i "serial number"
done

To specifically identify ata1.00 and ata12.00, we can query them directly through their device paths:

# For ata1.00
sudo smartctl -i /dev/disk/by-path/*ata1.00* | grep -i "serial"

# For ata12.00  
sudo smartctl -i /dev/disk/by-path/*ata12.00* | grep -i "serial"

The udevadm command provides another way to inspect device properties:

udevadm info --query=all --name=/dev/sdX | grep -i "ata\|serial"

Or to find all ATA devices with their serials:

ls -l /dev/disk/by-id/ | grep ata

When you have SMART errors reported for specific ATA devices, here's a complete diagnostic workflow:

# First identify which /dev/sdX corresponds to ata1.00
ATA1_DEVICE=$(readlink -f /dev/disk/by-path/*ata1.00*)

# Then run detailed SMART tests
sudo smartctl -a $ATA1_DEVICE

# Repeat for ata12.00
ATA12_DEVICE=$(readlink -f /dev/disk/by-path/*ata12.00*)
sudo smartctl -a $ATA12_DEVICE

For future reference, generate a complete drive mapping:

#!/bin/bash
for ata in /dev/disk/by-path/*ata*; do
    device=$(readlink -f $ata)
    serial=$(sudo smartctl -i $device | grep -i "serial" | awk '{print $3}')
    echo "ATA Path: $(basename $ata) | Device: $(basename $device) | Serial: $serial"
done