Understanding the Meaning of “- – -” in Linux SCSI Host Rescan Command


2 views

When working with storage devices in Linux, particularly in enterprise environments or when dealing with hot-pluggable storage, the SCSI subsystem plays a crucial role. The command:

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

is frequently used to trigger a rescan of the SCSI bus, but the three hyphens often confuse developers unfamiliar with SCSI internals.

The three hyphens represent three distinct parameters passed to the scan operation:

echo "channel target lun" > /sys/class/scsi_host/hostX/scan

Where:

  • channel: The SCSI channel number (typically 0 for most configurations)
  • target: The SCSI target ID
  • lun: The Logical Unit Number

The hyphens act as wildcards in this context:

"- - -"  # Scan all channels, all targets, all LUNs
"0 - -"  # Scan channel 0, all targets, all LUNs
"0 1 -"  # Scan channel 0, target 1, all LUNs

This provides granular control over which devices to rescan when needed.

Here's how to use this in real-world scenarios:

# Rescan all hosts for new storage
for host in /sys/class/scsi_host/host*/scan; do
    echo "- - -" > $host
done

# Rescan specific target after adding a disk
echo "0 2 -" > /sys/class/scsi_host/host2/scan

# Script to wait for new LUN to appear
while [ ! -d /dev/disk/by-path/*-lun5 ]; do
    echo "- - 5" > /sys/class/scsi_host/host0/scan
    sleep 1
done

While the echo method works, other approaches exist:

# Using rescan-scsi-bus.sh (from sg3_utils package)
rescan-scsi-bus.sh -a

# Using sysfs directly
echo 1 > /sys/class/fc_host/host0/issue_lip

If rescan doesn't work:

  • Verify host number exists in /sys/class/scsi_host/
  • Check dmesg for SCSI errors
  • Ensure the storage controller supports hot-add
  • Try different combinations of channel/target/LUN

When working with storage devices in Linux, you might have encountered this curious command:

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

At first glance, those three dashes appear cryptic. Let's decode what they actually represent.

The three dashes correspond to three parameters in the SCSI rescan operation:

echo "channel target lun" > /sys/class/scsi_host/hostX/scan

Each dash acts as a wildcard that means "scan everything" for that particular dimension:

  • First dash: Scan all channels
  • Second dash: Scan all targets
  • Third dash: Scan all LUNs (Logical Unit Numbers)

Here are some variations showing how you can be more specific if needed:

# Scan only channel 0, all targets, all LUNs
echo "0 - -" > /sys/class/scsi_host/host0/scan

# Scan all channels, target 2, all LUNs
echo "- 2 -" > /sys/class/scsi_host/host0/scan

# Scan specific channel, target and LUN
echo "0 1 2" > /sys/class/scsi_host/host0/scan

Common scenarios include:

  • Hot-adding storage devices in virtual machines
  • Rescanning after SAN storage modifications
  • Troubleshooting disappeared disks

Under the hood, this triggers the scsi_scan.host_scan() function in the Linux kernel. The kernel parses these parameters to determine the scan scope:

static int scsi_scan_host_selected(struct Scsi_Host *shost,
                   unsigned int channel,
                   unsigned int id,
                   u64 lun,
                   enum scsi_scan_mode rescan)

When you use "- - -", it sets all parameters to SCAN_WILD_CARD (-1).

While the echo method works, there are other ways to achieve similar results:

# Using rescan-scsi-bus.sh script (from sg3_utils package)
rescan-scsi-bus.sh

# Using sysfs directly
ls /sys/class/scsi_host/ | while read host; do
    echo "- - -" > /sys/class/scsi_host/${host}/scan
done

If the rescan isn't working:

  • Verify you're using the correct host number
  • Check dmesg for SCSI errors
  • Ensure the device is actually connected
  • Try rescanning the specific SCSI bus if known

Remember that some storage arrays may require additional commands or have specific timing requirements for new LUNs to become visible.