Friday, May 30, 2008

How to re-scan the SCSI bus on Linux

Note to self/Google, here's how to re-scan the SCSI bus on Linux:
echo "- - -" > /sys/class/scsi_host/host0/scan
Update: Tim Verhoeven has a more complete description of the re-scanning process.

4 comments:

Dylan said...

Very handy, THANKS!

Ben said...

Cool. I'm finding that I need to leave these "Dear Google. Please index how to do this thing." posts more and more as I go through my career. Thanks for the legwork. :)

gregswallow said...

I think they're called "senior moments." :) I'll thank you, too.

MoChaMan said...

I made a minor change to take out this error:

./rescan-scsi-bus.sh: line 262: return: : numeric argument required

Here is the patch diff for you :

# diff -urp rescan-scsi-bus.sh.0 rescan-scsi-bus.sh
--- rescan-scsi-bus.sh.0 2011-07-20 18:10:33.967834956 -0400
+++ rescan-scsi-bus.sh 2011-07-20 18:10:41.719834262 -0400
@@ -259,7 +259,7 @@ idlist ()
# Returns the list of existing LUNs
getluns ()
{
- if test ! -x /usr/bin/sg_luns; then return ""; fi
+ if test ! -x /usr/bin/sg_luns; then echo ""; return ; fi
sgdevice
if test -z "$SGDEV"; then return ""; fi
sg_luns -d /dev/$SGDEV | sed -n 's/.*lun=\(.*\)/\1/p'