2

I'm constantly having to make SAN changes which means that I am also constantly having to rescan the scsi bus so that my various changes are reflected in the machines I've exported disks to.

I've been plauged for some time by various facets of re-scanning disks in Linux.

Not to give Microsoft Credit, but they have really simplified the process into a single command which does everything and a lot faster than their linux counterparts.

I've been using the rescan-scsi-bus.sh command for quite some time now. However, the rescan-scsi-bus.sh command usually needs to be ran several times depending on what changes were made. IE. If a path was removed, I need to run "rescan-scsi-bus.sh -f -a -r -m". However, this command will not scan the disks for re-mapped disks nor will it scan for resized disks. In order to get the same functionality out of rescan-scsi-bus.sh, I end up having to run the command multiple times in succession which can end up taking lots of time (With lots of disks, 5 minutes or so which is years longer than windows takes.) Example:

# If the disk was removed.. Even though we aren't syncing, rescan can still hang
# unless we remove the disks first.
rescan-scsi-bus.sh --nosync -f -a -r -m 
# Next, We scan for new disks.. Don't know why the last command can't do it at the same time..
rescan-scsi-bus.sh -a
# Look for remapped disks.
rescan-scsi-bus.sh --nosync -a -u
# Look for resized disks.. Once again.. We have to go through the entire list which can take a good O'l 1 minute.
rescan-scsi-bus.sh --nosync -a -s

The question is, is there a better policy to re-scanning disks rather than running a gambit of rescan-scsi-bus.sh commands?

The requirement here is a single command which removes disks and disk paths which have been removed, adds disks and paths which are new, updates drives which have been remapped somewhere else, picks up changes in drives that have new sizes and runs in a reasonable amount of time (0-30 seconds) on ANY linux distribution regardless of the amount of disks or level of IO load the system is under.

I could go back to echoing values into sysfs, but that kind of defeats the whole make it simple and have a single command which runs that does it all in a timely fashion.

Rusty Weber
  • 462
  • 7
  • 20

1 Answers1

1

You can use any of the below methods

iscsiadm -m session --rescan
iscsiadm -m session -r SID --rescan

When Adding disk

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

When expending existing disk

echo 1 > /sys/class/scsi_device/device/rescan
asktyagi
  • 2,401
  • 1
  • 5
  • 19
  • I know it's been a long time, but is there a way to run these commands on every device including FC. something like the following? echo "- - -" > /sys/class/scsi_host/*/scan; echo 1 > /sys/class/scsi_device/*/rescan; – Rusty Weber Sep 01 '21 at 17:45