How to detect new hard disk attached without rebooting?
Solution 1
Below is the command that you need to run to scan the host devices so it will show the new hard disk connected.
echo "- - -" >> /sys/class/scsi_host/host_$i/scan
$i is the host number
Solution 2
As was mentioned above, you could scan all existing hosts with a one-liner:
for host in /sys/class/scsi_host/*; do echo "- - -" | sudo tee $host/scan; ls /dev/sd* ; done
and the result:
$ for host in /sys/class/scsi_host/*; do echo "- - -" | sudo tee $host/scan; ls /dev/sd* ; done
- - -
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1 /dev/sdc /dev/sdc1
- - -
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1 /dev/sdc /dev/sdc1
︙
- - -
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1 /dev/sdc /dev/sdc1
- - -
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1 /dev/sdc /dev/sdc1
- - -
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1 /dev/sdc /dev/sdc1 /dev/sdd /dev/sdd1
The last line shows us /dev/sdd
device was discovered.
Solution 3
This worked for me to refresh all devices: (As an easier to run command)
echo "- - -" | tee /sys/class/scsi_host/host*/scan
Sensei
Updated on September 18, 2022Comments
-
Sensei over 1 year
I'm having a little issue. I've a live system which run on RHEL 6.7 (VM) and have VMware 6.5 (which is not managed by our group) . The issue is, the other group tried to extend the capacity of an existing disk on a VM. After that, I ran a scan command to detect new disk as usual with
echo "- - -" > /sys/class/scsi_host/host0/scan
, but nothing happened. They added 40G on sdb disk which should be 100G and I saw that is changed on VM but not in Linux. So where is the problem ? As I said, this is a live system, so I don't want to reboot it.Here is the system :
# df -h /dev/mapper/itsmvg-bmclv 59G 47G 9.1G 84% /opt/bmc # lsblk sdb 8:16 0 60G 0 disk └─itsmvg-bmclv (dm-2) 253:2 0 60G 0 lvm /opt/bmc # vgs VG #PV #LV #SN Attr VSize VFree itsmvg 1 1 0 wz--n- 59.94g 0 # pwd /sys/class/scsi_host # ll lrwxrwxrwx 1 root root 0 Nov 13 16:18 host0 -> ../../devices/pci0000:00/0000:00:07.1/host0/scsi_host/host0 lrwxrwxrwx 1 root root 0 Nov 13 16:19 host1 -> ../../devices/pci0000:00/0000:00:07.1/host1/scsi_host/host1 lrwxrwxrwx 1 root root 0 Nov 13 16:19 host2 -> ../../devices/pci0000:00/0000:00:15.0/0000:03:00.0/host2/scsi_host/host2
-
Sensei over 6 yearsAs I said in the question, I already run echo "- - -" > /sys/class/scsi_host/host0/scan (and host1 & host2) . But nothing happend. What's wrong ?
-
Praveen Kumar BS over 6 yearsUse below command echo 1 >>/sys/class/scsi_device/device/rescan
-
Praveen Kumar BS over 6 yearsFor scanning exsisting hd need to use above command which i mentioned
-
Sensei over 6 yearsThe problem is solved. I don't know why but when they extend the existing disk on VM, linux didn't detect it with command i mentioned. But I just wanna try add new disk , not expand existing disk; it is fixed. So should I run echo “- - -“ >> /sys/class/scsi_host/host_$i/scan after expand disk ? and what is echo 1 >>/sys/class/scsi_device/device/rescan command do ?
-
karlsebal over 4 yearsyou may use
lsblk -S
instead ofls /dev/sd*
-
Michael over 2 yearsThis one worked like a charm! I had added a disk via VMWare and linux instance did not see it until running this command.