23

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
Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Sensei
  • 333
  • 1
  • 2
  • 5

5 Answers5

27

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.

karlsebal
  • 795
  • 8
  • 20
user3787216
  • 371
  • 3
  • 2
17

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

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Praveen Kumar BS
  • 5,139
  • 2
  • 9
  • 14
  • 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 Nov 14 '17 at 07:36
  • Use below command echo 1 >>/sys/class/scsi_device/device/rescan – Praveen Kumar BS Nov 14 '17 at 07:54
  • For scanning exsisting hd need to use above command which i mentioned – Praveen Kumar BS Nov 14 '17 at 07:55
  • 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 ? – Sensei Nov 14 '17 at 08:13
  • 4
    What is the significance of "- - -"? Why this particular string? – Andrew Savinykh Jun 09 '22 at 11:43
  • 1
    The three dashes act as wildcards to rescan everything: channel, SCSI target ID, and LUN. – Hem Mar 22 '23 at 18:41
15

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.

Hem
  • 131
  • 4
jak0lantash
  • 151
  • 1
  • 3
  • 2
    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 Oct 06 '21 at 16:59
  • 3
    @jak0lantash Best solution IMO. On Debian/Ubuntu, use `sudo tee` instead of `tee`. – SebMa Sep 13 '22 at 08:46
1

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
SebMa
  • 1,941
  • 4
  • 22
  • 37
1

You can also try to run

partprobe

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

dr_
  • 28,763
  • 21
  • 89
  • 133