Re-scan the SCSI bus in Linux after hot-swapping a drive

Servers with hot swappable drive bays are always handy. However, things can turn ugly if the SCSI controller doesn't like a new drive when it is inserted. You may end up with these errors in your dmesg output:

kernel: sdb : READ CAPACITY failed.
kernel: sdb : status=0, message=00, host=4, driver=00 
kernel: sdb : sense not available. 
kernel: sdb: Write Protect is off
kernel: sdb: Mode Sense: 00 00 00 00
kernel: sdb: asking for cache data failed
kernel: sdb: assuming drive cache: write through
kernel:  sdb:<6>sd 1:0:0:0: SCSI error: return code = 0x00040000
kernel: end_request: I/O error, dev sdb, sector 0
kernel: Buffer I/O error on device sdb, logical block 0
kernel: sd 1:0:0:0: SCSI error: return code = 0x00040000
kernel: end_request: I/O error, dev sdb, sector 0
kernel: Buffer I/O error on device sdb, logical block 0
kernel: sd 1:0:0:0: SCSI error: return code = 0x00040000
kernel: end_request: I/O error, dev sdb, sector 0

The errors show that the SCSI bus is having issues bringing the new drive online, and it won't be seen by the OS until the SCSI controller is pleased. You can force the controller to re-scan the drives attached to it, and this should correct the problem:

cd /sys/class/scsi_host/hostX
echo "- - - " > scan

Replace the X with the proper controller number of your SCSI controller. If you're not sure which controller is which, try running:

# cat /sys/class/scsi_host/host0/proc_name
sata_nv

Credit for this find goes to Tony Dolan

Printed from: http://rackerhacker.com/2009/04/23/re-scan-the-scsi-bus-in-linux-after-hot-swapping-a-drive/ .
© Major Hayden 2012.

5 Comments   »

  • Phil Dufault says:

    # cat /sys/class/scsi_host/host0/proc_name
    scsi_host, not scsi_hosts :)

    Great read, I have this problem occasionally.

  • major says:

    Thanks for catching the typo, Phil!

  • SCSI 68 PIN says:

    Thank you so much for the info now days its really hard to find useful informaitons thank you again

  • Thank you very much for all the useful informaiont I am sure every one like me can gain lot of knowledge..

  • Matt says:

    A better way to find out the correct host controller:
    # udevadm info -a -p /sys/class/scsi_generic/sg0
    where sg0 is the device node of which you'd like to know the corresponding SCSI controller - down that tree you will find hostX mentioned as part of the device path.
    And thanks for the rescanning tip, it saved my day.

RSS feed for comments on this post

Leave a Reply

 

  • Welcome! I started this blog as a way to give back to all of the other system administrators who have taught me something in the past. Writing these posts brings me a lot of enjoyment and I hope you find the information useful. If you spot something that's incorrect or confusing, please write a comment and let me know. Drop me a line if there's something you want to know more about and I'll do my best to write a post on the topic.
    -- Major Hayden

    Flattr this