Introduction
The SCSI (Small Computer System Interface) is a protocol used to communicate with storage devices such as hard drives, tape drives, and CD/DVD drives. SCSI is used in many enterprise-level servers and storage systems. However, sometimes when adding or removing SCSI devices, the system might not recognize them. This can happen due to various reasons such as an incorrect cable connection or a malfunctioning SCSI device.
In this guide, we will show you how to rescan the SCSI bus to detect new or removed SCSI devices in Linux. We will be using the echo command to trigger a SCSI bus rescan, which will make the system re-scan the SCSI bus and add or remove the SCSI devices accordingly.
Step 1: Check the Current SCSI Devices
Before rescanning the SCSI bus, we need to check the current SCSI devices on the system. We can use the lsblk command to display the current SCSI devices. Open your terminal and run the following command:
lsblk
This will display the current block devices on the system, including SCSI devices.
Step 2: Rescan the SCSI Bus
To rescan the SCSI bus, we need to send a command to the kernel to re-scan the SCSI host bus adapters. We can do this by using the echo command and writing to the /sys/class/scsi_host/hostX/scan file, where hostX is the name of the SCSI host adapter.
To rescan all SCSI host adapters, we can use the following command:
echo "- - -" > /sys/class/scsi_host/hostX/scan
Replace hostX with the appropriate SCSI host adapter name. If you have multiple SCSI host adapters, you need to run this command for each one of them.
Alternatively, you can use the following command to rescan all SCSI host adapters at once:
echo "- - -" > /sys/class/scsi_host/*/scan
This command will rescan all SCSI host adapters on the system.
Step 3: Verify the Rescan Results
After running the command to rescan the SCSI bus, we need to verify the results. We can again use the lsblk command to check the current block devices, including SCSI devices.
lsblk
This should display the newly added or removed SCSI devices on the system.
Commands Mentioned:
- lsblk – List all available block devices on the system, including SCSI devices.
- echo – Write a specified string to a file or standard output. In this case, we are writing “- – -” to the SCSI host adapter scan file to trigger a SCSI bus rescan.
Conclusion
In this guide, we have shown you how to rescan the SCSI bus to detect new or removed SCSI devices on Linux. By using the echo command to write to the SCSI host adapter scan file, we have triggered a SCSI bus rescan, which made the system re-scan the SCSI bus and add or remove the SCSI devices accordingly. We also verified the rescan results using the lsblk command. This can be helpful in situations where a SCSI device is not recognized by the system or when a new SCSI device is added to the system.