29

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

5 Answers 5

29

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.

2
  • 3
    you may use lsblk -S instead of ls /dev/sd*
    – karlsebal
    Commented Sep 5, 2019 at 11:02
  • of 16 disks this helped me raise the discovered disk count from 13 to 15 ^^
    – xeruf
    Commented Dec 22, 2022 at 16:15
25

This worked for me to refresh all devices: (As an easier to run command)

echo "- - -" | tee /sys/class/scsi_host/host*/scan

The three dashes act as wildcards to rescan everything: channel, SCSI target ID, and LUN.

3
  • 3
    This one worked like a charm! I had added a disk via VMWare and linux instance did not see it until running this command.
    – Michael
    Commented Oct 6, 2021 at 16:59
  • 3
    @jak0lantash Best solution IMO. On Debian/Ubuntu, use sudo tee instead of tee.
    – SebMa
    Commented Sep 13, 2022 at 8:46
  • 1
    Didn't work for me. (kernel 5.4.0-173-generic on Ubuntu). What worked was echo - - - | sudo tee /sys/class/scsi_device/*/device/rescan. Commented Mar 15 at 17:32
18

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

7
  • 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 ?
    – Sensei
    Commented Nov 14, 2017 at 7:36
  • Use below command echo 1 >>/sys/class/scsi_device/device/rescan Commented Nov 14, 2017 at 7:54
  • For scanning exsisting hd need to use above command which i mentioned Commented Nov 14, 2017 at 7:55
  • 4
    What is the significance of "- - -"? Why this particular string? Commented Jun 9, 2022 at 11:43
  • 1
    The three dashes act as wildcards to rescan everything: channel, SCSI target ID, and LUN.
    – Hem
    Commented Mar 22, 2023 at 18:41
5

How about this :

To scan for new disks :

echo "- - -" | sudo tee /sys/class/scsi_host/host*/scan >/dev/null

To rescan existing disks :

echo 1 | sudo tee /sys/class/block/sd?/device/rescan >/dev/null
3

You can also try to run

partprobe

This command checks for changes in the partition table and notifies the OS about it.

1
  • We use this too, working.
    – K-attila-
    Commented Jun 19, 2023 at 15:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .