I added new disk to my running Linux virtual machine.
Is it possible to add a SCSI/SATA device explicitly, or to re-scan an entire SCSI/SATA host bus without rebooting a running Linux?
I added new disk to my running Linux virtual machine.
Is it possible to add a SCSI/SATA device explicitly, or to re-scan an entire SCSI/SATA host bus without rebooting a running Linux?
Yes, it is possible. There are some methods to do it:
Add a single device
echo "scsi add-single-device <Host> <Bus> <Target> <Lun>" > /proc/scsi/scsi
In my case, I added the only SCSI/SATA disk on Host=8, so the command is
echo "scsi add-single-device 8 0 0 0" > /proc/scsi/scsi
Rescan SCSI/SATA Host Bus
If there were more than one disks added to your system, you can scan all devices on explicit SCSI/SATA Host
echo "- - -" > /sys/class/scsi_host/hostHOSTNUM/scan
I.e. if the disk was added to Host=8, the command is
echo "- - -" > /sys/class/scsi_host/host8/scan
Rescan all SCSI/SATA Hosts
Generally, if you don't know a host number of added disk, you can scan the whole SCSI hosts on your machine.
Get a list of SCSI/SATA hosts:
Use lsscsi to get a list of hosts: lsscsi -H
Use sysfs to get a list of hosts: ls -d /sys/class/scsi_host/host*
.
Rescan given host: echo "- - -" > /sys/class/scsi_host/hostX/scan
Simple full scan automation script
#/bin/bash
# ReScan all SCSI/SATA Hosts
for SHOST in /sys/class/scsi_host/host*; do
echo -n "Scanning ${SHOST##*/}..."
echo "- - -" > ${SHOST}/scan
echo Done
done
Sources were used in this answer: