Soft-resetting SATA devices in Linux

Soft-resetting SATA devices in Linux

There are times when devices fail, or lock up.

In some of those cases it could be a SATA hard disk locking up (perhaps it is developing bad blocks, perhaps it just had a power failure due to a bad connector and got left in an undefined state).

Thankfully, Linux offers you vast control over the hardware.

To reset a SATA device, start by figuring out which logical port the drive is connected to:

readlink /sys/block/sdX
../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0

Notice the host1 in the returned line above. That’s the controller that needs rescanned.

Force disconnect the device:

echo 1 > /sys/block/sdX/device/delete

Trigger rescan:

echo "- - -" > /sys/class/scsi_host/host1/scan

This should do it. If the device is still alive, it should return to working condition.

You can monitor dmesg for status information.

4 Comments

  1. I did this to a working RAID member which had dropped to 3gbps due to errors, and it disappeared as /dev/sdd and came back as /dev/sdo! Mdadm failed out the drive, I re-added it to the array and now it’s rebuilding… [facepalm.gif] But hey, at least it did come back and it even came back in 6gbps mode!

    Weasel
    1. The kernel kind of remembers device IDs and will assign the next available one when new hardware pops up. Reaching all the way to sdo could be an indication that a device (or several) vanish intermittently, getting new IDs assigned on each reconnect. You might want to dig through the logs to see if sde,f,g…….n were ever assigned and whom to.

      Zed

Leave a Reply