我正在使用 Oracle Linux 7.6,它是基于 RHEL 7.6 的发行版。以下测试在 RHEL 7.6 或其他基于 RHEL 7.6 的发行版上应该是相同的。
我在 Windows 10 上的 VMware Workstation 中运行 Oracle Linux 7.6 服务器。我要做的是在不重新启动 Linux 服务器的情况下将磁盘添加到 Linux 来宾虚拟机。我四处搜索并找到了这个页面:https ://rahsupport.wordpress.com/2017/08/10/vmware-add-disk-to-linux-without-rebooting-the-vm/ 。基本上,它的作用是:
- 将磁盘从 VMware Workstation 添加到 Linux VM
- 去
/sys/class/scsi_host/
- 跑
echo '- - -' > host1/scan
- 然后运行
fdisk -l
,就可以看到新添加的磁盘了
我在我的环境中对其进行了测试。有三个这样的主机目录,每个目录中都有一个scan
文件:
root:[/sys/class/scsi_host]# ls -la
total 0
drwxr-xr-x. 2 root root 0 Aug 24 22:49 .
drwxr-xr-x. 54 root root 0 Aug 24 22:49 ..
lrwxrwxrwx. 1 root root 0 Aug 24 22:49 host0 -> ../../devices/pci0000:00/0000:00:07.1/ata1/host0/scsi_host/host0
lrwxrwxrwx. 1 root root 0 Aug 24 22:49 host1 -> ../../devices/pci0000:00/0000:00:07.1/ata2/host1/scsi_host/host1
lrwxrwxrwx. 1 root root 0 Aug 24 22:49 host2 -> ../../devices/pci0000:00/0000:00:10.0/host2/scsi_host/host2
root:[/sys/class/scsi_host]#
root:[/sys/class/scsi_host]# ls -la */scan
--w-------. 1 root root 4096 Aug 24 22:50 host0/scan
--w-------. 1 root root 4096 Aug 24 22:50 host1/scan
--w-------. 1 root root 4096 Aug 24 22:50 host2/scan
root:[/sys/class/scsi_host]#
原来Linux服务器无法识别磁盘:
root:[/sys/class/scsi_host]# fdisk -l
Disk /dev/sda: 1099.5 GB, 1099511627776 bytes, 2147483648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d3e78
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 976895 487424 83 Linux
/dev/sda2 976896 2059401215 1029212160 83 Linux
/dev/sda3 2059401216 2101344255 20971520 83 Linux
/dev/sda4 2101344256 2147483647 23069696 5 Extended
/dev/sda5 2101348352 2143289343 20970496 83 Linux
/dev/sda6 2143291392 2147483647 2096128 82 Linux swap / Solaris
但是当我运行时echo '- - -' > host0/scan
,磁盘出现了:
root:[/sys/class/scsi_host]# echo '- - -' > host0/scan
root:[/sys/class/scsi_host]# fdisk -l
Disk /dev/sda: 1099.5 GB, 1099511627776 bytes, 2147483648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d3e78
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 976895 487424 83 Linux
/dev/sda2 976896 2059401215 1029212160 83 Linux
/dev/sda3 2059401216 2101344255 20971520 83 Linux
/dev/sda4 2101344256 2147483647 23069696 5 Extended
/dev/sda5 2101348352 2143289343 20970496 83 Linux
/dev/sda6 2143291392 2147483647 2096128 82 Linux swap / Solaris
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
root:[/sys/class/scsi_host]#
我将我的 Linux VM 恢复到其原始状态以再次测试。这次它表明这echo '- - -' > host1/scan
不起作用,但echo '- - -' > host2/scan
有效。
root:[/sys/class/scsi_host]# fdisk -l
Disk /dev/sda: 1099.5 GB, 1099511627776 bytes, 2147483648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d3e78
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 976895 487424 83 Linux
/dev/sda2 976896 2059401215 1029212160 83 Linux
/dev/sda3 2059401216 2101344255 20971520 83 Linux
/dev/sda4 2101344256 2147483647 23069696 5 Extended
/dev/sda5 2101348352 2143289343 20970496 83 Linux
/dev/sda6 2143291392 2147483647 2096128 82 Linux swap / Solaris
root:[/sys/class/scsi_host]# echo '- - -' > host1/scan
root:[/sys/class/scsi_host]# fdisk -l
Disk /dev/sda: 1099.5 GB, 1099511627776 bytes, 2147483648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d3e78
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 976895 487424 83 Linux
/dev/sda2 976896 2059401215 1029212160 83 Linux
/dev/sda3 2059401216 2101344255 20971520 83 Linux
/dev/sda4 2101344256 2147483647 23069696 5 Extended
/dev/sda5 2101348352 2143289343 20970496 83 Linux
/dev/sda6 2143291392 2147483647 2096128 82 Linux swap / Solaris
root:[/sys/class/scsi_host]# echo '- - -' > host2/scan
root:[/sys/class/scsi_host]# fdisk -l
Disk /dev/sda: 1099.5 GB, 1099511627776 bytes, 2147483648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d3e78
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 976895 487424 83 Linux
/dev/sda2 976896 2059401215 1029212160 83 Linux
/dev/sda3 2059401216 2101344255 20971520 83 Linux
/dev/sda4 2101344256 2147483647 23069696 5 Extended
/dev/sda5 2101348352 2143289343 20970496 83 Linux
/dev/sda6 2143291392 2147483647 2096128 82 Linux swap / Solaris
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
root:[/sys/class/scsi_host]#
我的问题是,这些主机目录是什么?为什么echo '- - -' > host0/scan
并且echo '- - -' > host2/scan
会让Linux服务器识别磁盘,但echo '- - -' > host1/scan
不能?
顺便说一句,我是 Linux 的新手,还在学习它。
不同的
host
目录对应不同的磁盘控制器。控制器映射到什么取决于所涉及的技术;AHCI SATA 主机每个端口有一个主机,NVMe 每个控制器使用一个主机,等等。具体情况取决于您的 VM 设置。基本上这意味着您应该重新扫描所有主机。