這些“主機”目錄是什麼?
我正在使用 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 設置。基本上這意味著您應該重新掃描所有主機。