How to detect new hard disk attached without rebooting?

109,116

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
Share:
109,116
Sensei
Author by

Sensei

Updated on September 18, 2022

Comments

  • Sensei
    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
    Sensei over 6 years
    As 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
    Praveen Kumar BS over 6 years
    Use below command echo 1 >>/sys/class/scsi_device/device/rescan
  • Praveen Kumar BS
    Praveen Kumar BS over 6 years
    For scanning exsisting hd need to use above command which i mentioned
  • Sensei
    Sensei over 6 years
    The 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
    karlsebal over 4 years
    you may use lsblk -S instead of ls /dev/sd*
  • Michael
    Michael over 2 years
    This one worked like a charm! I had added a disk via VMWare and linux instance did not see it until running this command.