我使用的是 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 虚拟机
- 去
/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 还很陌生,仍在学习中。
答案1
不同的host
目录对应不同的磁盘控制器。控制器映射到什么取决于所涉及的技术; AHCI SATA 主机每个端口一台主机,NVMe 每个控制器使用一台主机,等等。具体情况取决于您的虚拟机设置。
基本上这意味着您应该重新扫描所有主机。