Scan / detect new LUN s and SCSI disks on Linux

Posted by rich1983 on Wed, 29 Dec 2021 07:29:54 +0100

Disks in a Linux server can be divided into local disks and LUNs (logical unit number), the local disk is the local disk of the physical server or the local virtual disk of the virtual machine, and the LUN is the logical unit number, which is a logical object, so it is often called Logical Device. It is a logical disk shared by remote centralized storage to the server through optical communication, optical fiber and host HBA card, but it seems to be different from the local disk What's the difference? The access speed is not as fast as the local disk. In the past, it has solved the problems of insufficient local disk space and the need to share disks of many hosts, such as ORACLE RAC cluster.

There is a scenario where a new LUN is marked on the storage side or a virtual disk is expanded. How can I scan / detect new LUNs and SCSI disks on Linux? If there is no service for the new host, the system can be restarted to identify the newly added equipment. However, in most cases, this service runs on the host. We prefer online operation to maintain business continuity.

This can be done in three ways, scanning each scsi host device or running rescan scsi bus SH script to detect new disks.

After scanning, you can find them with different IDS in the / dev/disk / directory.

[root@irora01 ~]# ll /dev/disk/
total 0
drwxr-xr-x 2 root root 2480 Sep  2 03:00 by-id
drwxr-xr-x 2 root root 1980 Sep  2 03:00 by-path
drwxr-xr-x 2 root root  260 Sep  2 03:00 by-uuid

You can also find new disks by using the following command

fdisk -l
lsscsi
lsblk

There is usually link redundancy for LUNs, so 4 or 8 LUNs can be seen on the same disk on the host. Generally, it needs to be aggregated by multipath software. Multipath software can be used together with storage to provide storage access in the form of active standby or load. There are many multipath software. Manufacturers have their own multipath software, and the common one is multipath. For multipath, we usually need to customize the aggregated disk alias. Use the multipath -ll command to view the multipath.

[root@irora34 ~]# multipath -ll
mpath06 (363c9d56100e06a30f694115300000092) dm-10 HUAWEI,XSG1
size=100G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=1 status=active
| `- 7:0:0:6  sdh  8:112  active ready running
|-+- policy='round-robin 0' prio=1 status=enabled
| `- 7:0:1:6  sdae 65:224 active ready running
|-+- policy='round-robin 0' prio=1 status=enabled
| `- 8:0:0:6  sdbb 67:80  active ready running
`-+- policy='round-robin 0' prio=1 status=enabled
  `- 8:0:1:6  sdby 68:192 active ready running
mpath23 (363c9d56100e06a30f69487c7000000a3) dm-22 HUAWEI,XSG1
size=400G features='0' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=1 status=active
| `- 7:0:0:23 sdy  65:128 active ready running
|-+- policy='round-robin 0' prio=1 status=enabled
| `- 7:0:1:23 sdav 66:240 active ready running
|-+- policy='round-robin 0' prio=1 status=enabled
| `- 8:0:0:23 sdbs 68:96  active ready running
`-+- policy='round-robin 0' prio=1 status=enabled
  `- 8:0:1:23 sdcp 69:208 active ready running

Sweep disk

Method 1

Method 1: how to scan new LUN s and SCSI disks on Linux using / sys class files
sysfs file system is a pseudo file system, which provides an interface for kernel data structure.

The files under sysfs provide information about devices, kernel modules, file systems, and other kernel components.

The sysfs file system is usually mounted in / sys. Usually, it is mounted automatically by the system.

You can use the echo command to scan each SCSI host device as follows:

# echo "- - -" > /sys/class/scsi_host/host[n]/scan

When you run the rescan all commands above, the three dashes (- – -) refer to the wildcard options. These values are as follows:

# echo "c t l" > /sys/class/scsi_host/host[n]/scan

here:

  • c: Channels on HbAS

  • t: SCSI target ID

  • l: LUN ID

  • n: HBA number

Run the command ls -l /sys/class/scsi_host to find all host bus numbers in the system:

[root@irora34 ~]# ls -l /sys/class/scsi_host
total 0
lrwxrwxrwx 1 root root 0 Sep  2 03:00 host0 -> ../../devices/pci0000:00/0000:00:03.2/0000:03:00.0/host0/scsi_host/host0
lrwxrwxrwx 1 root root 0 Sep  2 03:00 host1 -> ../../devices/pci0000:00/0000:00:1f.2/host1/scsi_host/host1
lrwxrwxrwx 1 root root 0 Sep  2 03:00 host2 -> ../../devices/pci0000:00/0000:00:1f.2/host2/scsi_host/host2
lrwxrwxrwx 1 root root 0 Sep  2 03:00 host3 -> ../../devices/pci0000:00/0000:00:1f.2/host3/scsi_host/host3
lrwxrwxrwx 1 root root 0 Sep  2 03:00 host4 -> ../../devices/pci0000:00/0000:00:1f.2/host4/scsi_host/host4
lrwxrwxrwx 1 root root 0 Sep  2 03:00 host5 -> ../../devices/pci0000:00/0000:00:1f.2/host5/scsi_host/host5
lrwxrwxrwx 1 root root 0 Sep  2 03:00 host6 -> ../../devices/pci0000:00/0000:00:1f.2/host6/scsi_host/host6
lrwxrwxrwx 1 root root 0 Sep  2 03:00 host7 -> ../../devices/pci0000:40/0000:40:03.2/0000:45:00.0/host7/scsi_host/host7
lrwxrwxrwx 1 root root 0 Sep  2 03:00 host8 -> ../../devices/pci0000:40/0000:40:03.2/0000:45:00.1/host8/scsi_host/host8

View FC channels

[root@irora34 ~]# ls -l /sys/class/fc_host/
total 0
lrwxrwxrwx 1 root root 0 Sep  2 03:00 host7 -> ../../devices/pci0000:40/0000:40:03.2/0000:45:00.0/host7/fc_host/host7
lrwxrwxrwx 1 root root 0 Sep  2 03:00 host8 -> ../../devices/pci0000:40/0000:40:03.2/0000:45:00.1/host8/fc_host/host8

After obtaining the host bus number, run the following command to discover the new disk:

# echo "- - -" > /sys/class/scsi_host/host0/scan
# echo "- - -" > /sys/class/scsi_host/host1/scan
# echo "- - -" > /sys/class/scsi_host/host2/scan

If you only scan LUN s, you only need to scan host7 and host8. Of course, it may be different on different hosts. You should operate according to the actual situation.

In addition, you can use the for loop to scan all with one command without too many problems.

# for host in ls /sys/class/scsi_host/;do echo "- - -" >/sys/class/scsi_host/${host}/scan; done

Method 2

Method 2: how to use rescan SCSI bus The SH script scans for new LUN s and SCSI disks on Linux
Make sure you have SG3 installed_ Utils package to use this script. Otherwise, run the following command to install it.

For RHEL/CentOS 6/7 systems, use the yum command to install sg3_utils.

# yum install -y sg3_utils

For RHEL/CentOS 8 and Fedora systems, use the dnf command to install sg3_utils.

# dnf install -y sg3_utils

Now you can use rescan SCSI bus SH script rescan LUN s.

# ./rescan-scsi-bus.sh

Method 3

This performs a loop initialization protocol (LIP), then scans the interconnect and updates the SCSI layer to reflect the devices on the current bus. Lip is essentially a bus reset, which will lead to the addition and removal of devices. This procedure is required to configure a new SCSI target on a fibre channel interconnect. Remember, this issue_lip is an asynchronous operation. This command may be completed before the entire scan is completed. You must monitor / var/log/messages to determine when to complete. The lpfc and qla2xxx drivers support issue_lip. For more information about the API features supported by each driver in Red Hat Enterprise Linux, see Table 1.1, "fibre channel API functions".

echo "1" > /sys/class/fc_host/host[n]/issue_lip
echo "1" > /sys/class/fc_host/host[n]/issue_lip

The above command essentially initializes the HAB card port. You can see the relevant information in messages

Dec 28 00:13:15 orarac01 kernel: lpfc 0000:45:00.0: 0:1305 Link Down Event x4 received Data: x4 x20 x110 x0 x0
Dec 28 00:13:15 orarac01 kernel: lpfc 0000:45:00.0: 0:1303 Link Up Event x5 received Data: x5 x0 x20 x0 x0 x0 0
Dec 28 00:13:46 orarac01 kernel: rport-7:0-13: blocked FC remote port time out: removing rport
Dec 28 00:15:14 orarac01 kernel: lpfc 0000:45:00.1: 1:1305 Link Down Event x4 received Data: x4 x20 x110 x0 x0
Dec 28 00:15:14 orarac01 kernel: lpfc 0000:45:00.1: 1:1303 Link Up Event x5 received Data: x5 x0 x20 x0 x0 x0 0
Dec 28 00:15:46 orarac01 kernel: rport-8:0-13: blocked FC remote port time out: removing rport

For more information about technology previews, see https://access.redhat.com/support/offerings/techpreview/ .

Topics: Linux Storage