如何在不重启 Linux 的情况下检测连接的新硬盘

解决方案

在下面的路径中,我们可以找到指向 Linux 机器上配置的 iSCSI 设备的主机符号链接列表

# ls -l /sys/class/scsi_host/
total 0
lrwxrwxrwx 1 root root 0 Jun 14 05:08 host0 -> ../../devices/pci0000:00/0000:00:07.1/host0/scsi_host/host0
lrwxrwxrwx 1 root root 0 Jun 14 05:08 host1 -> ../../devices/pci0000:00/0000:00:07.1/host1/scsi_host/host1
lrwxrwxrwx 1 root root 0 Jun 14 05:08 host10 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:05.0/host10/scsi_host/host10
lrwxrwxrwx 1 root root 0 Jun 14 05:08 host2 -> ../../devices/pci0000:00/0000:00:10.0/host2/scsi_host/host2
lrwxrwxrwx 1 root root 0 Jun 14 05:08 host3 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:05.0/host3/scsi_host/host3
lrwxrwxrwx 1 root root 0 Jun 14 05:08 host4 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:05.0/host4/scsi_host/host4
lrwxrwxrwx 1 root root 0 Jun 14 05:08 host5 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:05.0/host5/scsi_host/host5
lrwxrwxrwx 1 root root 0 Jun 14 05:08 host6 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:05.0/host6/scsi_host/host6
lrwxrwxrwx 1 root root 0 Jun 14 05:08 host7 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:05.0/host7/scsi_host/host7
lrwxrwxrwx 1 root root 0 Jun 14 05:08 host8 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:05.0/host8/scsi_host/host8
lrwxrwxrwx 1 root root 0 Jun 14 05:08 host9 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:05.0/host9/scsi_host/host9

但是要检测连接的新硬盘驱动器,
我们需要首先获取使用的主机总线编号,我们可以使用以下命令获取

# grep mpt /sys/class/scsi_host/host?/proc_name

你应该得到如下输出

/sys/class/scsi_host/host2/proc_name:mptspi

因此,如我们所见, host2 是我们需要重置存储缓冲区值的相关字段。
运行以下命令

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

这里的“-”定义了存储在 host*/scan 中的三个值,例如:通道号、SCSI 目标 ID 和 LUN 值。
我们只是用通配符替换这些值,以便它可以检测添加到 Linux 机器上的新更改。
此过程将添加 LUN,但不会删除它们。

完成后验证我们是否可以看到新的硬盘驱动器,在我的情况下它工作得很好,如下所示

# fdisk -l
Disk /dev/sdb: 3221 MB, 3221225472 bytes
 255 heads, 63 sectors/track, 391 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes
 Sector size (logical/physical): 512 bytes/512 bytes
 I/O size (minimum/optimal): 512 bytes/512 bytes
 Disk identifier: 0x00000000

如何检测新硬盘

在这里假设我们已将一个新硬盘添加到在任何虚拟环境中运行的 Linux 操作系统,
我这里使用的是VMware workstation。

添加新硬盘后,除非我们重新启动客户机操作系统,否则通常不会反映出来。

但是,如果我们无法重新启动来宾 Linux 操作系统怎么办?

日期:2020-06-02 22:18:29 来源:oir作者:oir