扩容前状态

只有一块60GB的磁盘

[root@RHEL6 ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes
64 heads, 32 sectors/track, 51200 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0002d5e5

Device Boot Start End Blocks Id System
/dev/sda1 * 2 501 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 502 51200 51915776 8e Linux LVM
Partition 2 does not end on cylinder boundary.

Disk /dev/mapper/vg_rhel6-lv_root: 49.0 GB, 48997859328 bytes
255 heads, 63 sectors/track, 5956 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


Disk /dev/mapper/vg_rhel6-lv_swap: 4160 MB, 4160749568 bytes
255 heads, 63 sectors/track, 505 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

增加磁盘

vSphere web client为虚拟机增加一个16G磁盘

VMware Linux虚拟机在线增加磁盘/磁盘扩容 _扫描磁盘

Linux自动扫描到新增磁盘

[root@RHEL6 ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes
64 heads, 32 sectors/track, 51200 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0002d5e5

Device Boot Start End Blocks Id System
/dev/sda1 * 2 501 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 502 51200 51915776 8e Linux LVM
Partition 2 does not end on cylinder boundary.

Disk /dev/mapper/vg_rhel6-lv_root: 49.0 GB, 48997859328 bytes
255 heads, 63 sectors/track, 5956 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


Disk /dev/mapper/vg_rhel6-lv_swap: 4160 MB, 4160749568 bytes
255 heads, 63 sectors/track, 505 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


Disk /dev/sdb: 17.2 GB, 17179869184 bytes
64 heads, 32 sectors/track, 16384 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

到虚拟机内部可以看到新增的磁盘,本初示例是“/dev/sdb”,你的环境命名编号可能会有不一样。

dmesg
#日志最后可以看到新增的磁盘sdb
vmw_pvscsi: msg type: 0x0 - MSG RING: 1/0 (5)
vmw_pvscsi: msg: device added at scsi0:1:0
scsi 2:0:1:0: Direct-Access VMware Virtual disk 2.0 PQ: 0 ANSI: 6
sd 2:0:1:0: Attached scsi generic sg2 type 0
sd 2:0:1:0: [sdb] 33554432 512-byte logical blocks: (17.1 GB/16.0 GiB)
sd 2:0:1:0: [sdb] Write Protect is off
sd 2:0:1:0: [sdb] Mode Sense: 3b 00 00 00
sd 2:0:1:0: [sdb] Write cache: disabled, read cache: disabled, doesn't support DPO or FUA
sdb: unknown partition table
sd 2:0:1:0: [sdb] Attached SCSI disk

将虚拟机磁盘扩容

16GB——>20GB

VMware Linux虚拟机在线增加磁盘/磁盘扩容 _扫描磁盘_02

扩容后,linux没有识别到新增容量

扫描驱动器

echo 1>/sys/class/block/sdd/device/rescan
dmesg
# 重新扫描磁盘后,dgesg日志显示sdb容量增长
sd 2:0:1:0: [sdb] 41943040 512-byte logical blocks: (21.4 GB/20.0 GiB)
sdb: detected capacity change from 17179869184 to 21474836480
[root@RHEL6 device]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes
64 heads, 32 sectors/track, 51200 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0002d5e5

Device Boot Start End Blocks Id System
/dev/sda1 * 2 501 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 502 51200 51915776 8e Linux LVM
Partition 2 does not end on cylinder boundary.

Disk /dev/mapper/vg_rhel6-lv_root: 49.0 GB, 48997859328 bytes
255 heads, 63 sectors/track, 5956 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


Disk /dev/mapper/vg_rhel6-lv_swap: 4160 MB, 4160749568 bytes
255 heads, 63 sectors/track, 505 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


Disk /dev/sdb: 21.5 GB, 21474836480 bytes
64 heads, 32 sectors/track, 20480 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

注意:网上还有方法是

echo "- - -" > /sys/class/scsi_host/hostX/scan

X:0,1,2,...

这个主要是对scsi控制器的扫描,主要用于扫描新增加的驱动器,如果新增了磁盘,但是OS层面没有发现,那么用这种方法适用。