欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

VMware虚拟机(Linux)如何找出系统中磁盘设备对应的硬盘

程序员文章站 2022-03-28 19:38:16
VMware虚拟机(Linux)中,我们的Linux服务器可能拥有多个磁盘(或者叫虚拟磁盘),如下所示,这个服务器的磁盘有硬盘1、硬盘2、…………硬盘10总共10块硬盘。 而Linux系统中,磁盘中对应的设备如下 [root@mylnx01 ~]# ls -lrt /dev/sd*brw-r----... ......

 

vmware虚拟机(linux)中,我们的linux服务器可能拥有多个磁盘(或者叫虚拟磁盘),如下所示,这个服务器的磁盘有硬盘1、硬盘2、…………硬盘10总共10块硬盘。

 

 

而linux系统中,磁盘中对应的设备如下

 

[root@mylnx01 ~]# ls -lrt /dev/sd*
brw-r----- 1 root disk 8,   0 apr 30 09:53 /dev/sda
brw-r----- 1 root disk 8,   3 apr 30 09:53 /dev/sda3
brw-r----- 1 root disk 8,   2 apr 30 09:53 /dev/sda2
brw-r----- 1 root disk 8,  21 apr 30 09:53 /dev/sdb5
brw-r----- 1 root disk 8,  18 apr 30 09:53 /dev/sdb2
brw-r----- 1 root disk 8,  17 apr 30 09:53 /dev/sdb1
brw-r----- 1 root disk 8,  16 apr 30 09:53 /dev/sdb
brw-r----- 1 root disk 8,  37 apr 30 09:53 /dev/sdc5
brw-r----- 1 root disk 8,  34 apr 30 09:53 /dev/sdc2
brw-r----- 1 root disk 8,  33 apr 30 09:53 /dev/sdc1
brw-r----- 1 root disk 8,  32 apr 30 09:53 /dev/sdc
brw-r----- 1 root disk 8,  64 apr 30 09:53 /dev/sde
brw-r----- 1 root disk 8,  49 apr 30 09:53 /dev/sdd1
brw-r----- 1 root disk 8,  48 apr 30 09:53 /dev/sdd
brw-r----- 1 root disk 8,  82 apr 30 09:53 /dev/sdf2
brw-r----- 1 root disk 8,  81 apr 30 09:53 /dev/sdf1
brw-r----- 1 root disk 8,  80 apr 30 09:53 /dev/sdf
brw-r----- 1 root disk 8,  69 apr 30 09:53 /dev/sde5
brw-r----- 1 root disk 8,  65 apr 30 09:53 /dev/sde1
brw-r----- 1 root disk 8, 113 apr 30 09:53 /dev/sdh1
brw-r----- 1 root disk 8, 112 apr 30 09:53 /dev/sdh
brw-r----- 1 root disk 8,  96 apr 30 09:53 /dev/sdg
brw-r----- 1 root disk 8,  85 apr 30 09:53 /dev/sdf5
brw-r----- 1 root disk 8, 129 apr 30 09:53 /dev/sdi1
brw-r----- 1 root disk 8, 128 apr 30 09:53 /dev/sdi
brw-r----- 1 root disk 8, 101 apr 30 09:53 /dev/sdg5
brw-r----- 1 root disk 8,  97 apr 30 09:53 /dev/sdg1
brw-r----- 1 root disk 8, 130 apr 30 09:53 /dev/sdi2
brw-r----- 1 root disk 8, 147 apr 30 09:53 /dev/sdj3
brw-r----- 1 root disk 8, 146 apr 30 09:53 /dev/sdj2
brw-r----- 1 root disk 8, 145 apr 30 09:53 /dev/sdj1
brw-r----- 1 root disk 8, 144 apr 30 09:53 /dev/sdj
brw-r----- 1 root disk 8, 152 apr 30 09:53 /dev/sdj8
brw-r----- 1 root disk 8, 151 apr 30 09:53 /dev/sdj7
brw-r----- 1 root disk 8, 150 apr 30 09:53 /dev/sdj6
brw-r----- 1 root disk 8, 149 apr 30 09:53 /dev/sdj5
brw-r----- 1 root disk 8, 148 apr 30 09:53 /dev/sdj4
brw-r----- 1 root disk 8, 153 apr 30 09:53 /dev/sdj9
brw-r----- 1 root disk 8,   1 apr 30 09:53 /dev/sda1

 

那么我们如何找出/dev/sdj对应vmware中的哪个磁盘呢? 相信很多同学可能想通过磁盘大小来判断,但是呢,这个通过磁盘大小不好判断或者判断不精准,主要有下面一些因素:

 

1:两边计算磁盘大小的方式不一样。看到的磁盘大小有点出入。

 

2:可能存在相同大小的磁盘,此时你怎么判断呢?

 

那么有没有通过某个标识来判断呢?根据scsi标准,每个scsi磁盘都有一个wwid,类似于网卡的mac地址,而且是独一无二。linux系统上/dev/disk/by-id目录包含每个scsi磁盘wwid访问路径。

 

[root@kerrydb ~]# ll /dev/disk/by-id/
total 0
lrwxrwxrwx. 1 root root  9 apr 11 09:25 ata-st500dm002-1bd142_z6ea17fp -> ../../sda
lrwxrwxrwx. 1 root root 10 apr 11 09:25 ata-st500dm002-1bd142_z6ea17fp-part1 -> ../../sda1
lrwxrwxrwx. 1 root root 10 apr 11 09:25 ata-st500dm002-1bd142_z6ea17fp-part2 -> ../../sda2
lrwxrwxrwx. 1 root root 10 apr 11 09:25 ata-st500dm002-1bd142_z6ea17fp-part3 -> ../../sda3
lrwxrwxrwx. 1 root root 10 mar 10 14:29 dm-name-centos-home -> ../../dm-2
lrwxrwxrwx. 1 root root 10 mar 10 14:29 dm-name-centos-root -> ../../dm-0
lrwxrwxrwx. 1 root root 10 mar 10 14:29 dm-name-centos-swap -> ../../dm-1
lrwxrwxrwx. 1 root root 10 mar 10 14:29 dm-uuid-lvm-ooll2ne7hvrlu1rwfzricmprezgxlzhq2gwvhfhzrdlwmrz3kukgnjjqskln2noy -> ../../dm-0
lrwxrwxrwx. 1 root root 10 mar 10 14:29 dm-uuid-lvm-ooll2ne7hvrlu1rwfzricmprezgxlzhqnaliutdrhqv42rqnw8jaimopdueps5b3 -> ../../dm-1
lrwxrwxrwx. 1 root root 10 mar 10 14:29 dm-uuid-lvm-ooll2ne7hvrlu1rwfzricmprezgxlzhqybfexsotcltjcv0ds9tkiwa1ivbwxnrk -> ../../dm-2
lrwxrwxrwx. 1 root root 10 apr 11 09:25 lvm-pv-uuid-fayn5y-ydir-cywu-1vdf-btz6-dkyt-tny8ee -> ../../sda3
lrwxrwxrwx. 1 root root  9 apr 11 09:25 wwn-0x5000c5007911cd0c -> ../../sda
lrwxrwxrwx. 1 root root 10 apr 11 09:25 wwn-0x5000c5007911cd0c-part1 -> ../../sda1
lrwxrwxrwx. 1 root root 10 apr 11 09:25 wwn-0x5000c5007911cd0c-part2 -> ../../sda2
lrwxrwxrwx. 1 root root 10 apr 11 09:25 wwn-0x5000c5007911cd0c-part3 -> ../../sda3

 

但是当前环境下,vmware虚拟机(linux)默认情况下没有开启这个选项。

 

# ll /dev/disk/by-id
ls: /dev/disk/by-id: no such file or directory
# cd /dev/disk
# ls -lrt
total 0
drwxr-xr-x 2 root root  60 may  3 19:35 by-uuid
drwxr-xr-x 2 root root  60 may  3 19:35 by-label
drwxr-xr-x 2 root root 640 may  3 19:35 by-path

 

而且在vmware vsphere client连上vmware控制台,你会发现这里没有提供硬盘的wwid信息,即使你在linux中找到设备的wwid信息,但是在vmware控制台也看不到对应的wwid信息,我们还可以通过计算机的scsi编号来判断,scsi 可适用于许多设备(包括随机存取设备,比如磁盘和像磁带这样的顺序存储设备),如下截图所示,磁盘有个显示是通过scsi控制器管理磁盘的,硬盘9对应的为scsi(0:11)

 

 

 

 

 

[root@mylnx01 ~]# ll /dev/disk/by-path | grep '0:11'
lrwxrwxrwx 1 root root  9 apr 30 09:53 pci-0000:00:10.0-scsi-0:0:11:0 -> ../../sdj
lrwxrwxrwx 1 root root 10 apr 30 09:53 pci-0000:00:10.0-scsi-0:0:11:0-part1 -> ../../sdj1
lrwxrwxrwx 1 root root 10 apr 30 09:53 pci-0000:00:10.0-scsi-0:0:11:0-part2 -> ../../sdj2
lrwxrwxrwx 1 root root 10 apr 30 09:53 pci-0000:00:10.0-scsi-0:0:11:0-part3 -> ../../sdj3
lrwxrwxrwx 1 root root 10 apr 30 09:53 pci-0000:00:10.0-scsi-0:0:11:0-part4 -> ../../sdj4
lrwxrwxrwx 1 root root 10 apr 30 09:53 pci-0000:00:10.0-scsi-0:0:11:0-part5 -> ../../sdj5
lrwxrwxrwx 1 root root 10 apr 30 09:53 pci-0000:00:10.0-scsi-0:0:11:0-part6 -> ../../sdj6
lrwxrwxrwx 1 root root 10 apr 30 09:53 pci-0000:00:10.0-scsi-0:0:11:0-part7 -> ../../sdj7
lrwxrwxrwx 1 root root 10 apr 30 09:53 pci-0000:00:10.0-scsi-0:0:11:0-part8 -> ../../sdj8
lrwxrwxrwx 1 root root 10 apr 30 09:53 pci-0000:00:10.0-scsi-0:0:11:0-part9 -> ../../sdj9
 
[root@mylnx01 ~]# ls -l /dev/sdj*
brw-r----- 1 root disk 8, 144 apr 30 09:53 /dev/sdj
brw-r----- 1 root disk 8, 145 apr 30 09:53 /dev/sdj1
brw-r----- 1 root disk 8, 146 apr 30 09:53 /dev/sdj2
brw-r----- 1 root disk 8, 147 apr 30 09:53 /dev/sdj3
brw-r----- 1 root disk 8, 148 apr 30 09:53 /dev/sdj4
brw-r----- 1 root disk 8, 149 apr 30 09:53 /dev/sdj5
brw-r----- 1 root disk 8, 150 apr 30 09:53 /dev/sdj6
brw-r----- 1 root disk 8, 151 apr 30 09:53 /dev/sdj7
brw-r----- 1 root disk 8, 152 apr 30 09:53 /dev/sdj8
brw-r----- 1 root disk 8, 153 apr 30 09:53 /dev/sdj9

 

如上所示,我们通过上面命令的输出信息就可以判断磁盘9对应linux下的/dev/sdj这个设备。