Scaning for SCSI/libata hard disks
Howto scan the SCSI/SATA bus for devices when a warm-swap is required.
Scanning for disks
To get host adapters to scan for new devices, 'echo "- - -"' to the scan file. The following command will cause all host adapters to scan their buses:
# for A in /sys/class/scsi_host/host[0-9]*/scan ; do cat ${A%/scan}/proc_name ; echo "- - -" > $A ; done
Note: If the driver for the host adapter doesn't support warm-swap, then the echo command will fail with the message 'write error: Operation not supported'. e.g. Linux 2.6.22 sata_mv driver.
Manually deleting disks
This script allows the 'warm' removal for SCSI disk by specifying their device name. Examples
scsi-delete /dev/sd[a-e] scsi-delete /dev/sda
The '-d' dry-run option shows which SCSI nodes would be deleted.
scsi-delete
#!/bin/sh set -e # # Parse switches # while [ "$1" != "${1##-}" ] ; do # loop over options case $1 in -v) VERBOSE=yes ;; -d) DRYRUN=yes ;; *) echo "Warning: Unknown option $1" exit 10; ;; esac shift done if [ $# -eq 0 ] ; then echo "Usage: $0 -v device ..." echo echo "Known SCSI devices are:" for DEVICE in /sys/bus/scsi/devices/* ; do NAME=`ls $DEVICE | grep '^block\:' | sed -e 's/block://'` echo " ${NAME}" done exit 1 fi while [ "$#" -gt 0 ] ; do # loop over options # Just use the filename part of the device path DEVICE_NAME="${1##*/}" [ -n "$VERBOSE" ] && echo "Attempting to delete SCSI device with $1 ($DEVICE_NAME)" # enumerate all SCSI devices for DEVICE in /sys/bus/scsi/devices/* ; do # get the block device name for the SCSI device (assumes one name only) NAME=`ls $DEVICE | grep '^block\:' | sed -e 's/block://'` [ -n "$VERBOSE" ] && echo " Checking SCSI device $DEVICE ($NAME)" # Check if the SCSI block device name matches the command line arg if [ "$DEVICE_NAME" = "$NAME" ] ; then [ -n "$VERBOSE" ] && echo " Checking SCSI device ${DEVICE} ($NAME)" # Delete the SCSI device echo "Deleting device $DEVICE (${NAME})" if [ -n "$DRYRUN" ] ; then echo " Dry run - device $DEVICE NOT deleted" else echo 1 > $DEVICE/delete fi fi done shift done