不关机给虚拟机在线加硬盘

作者: 魏延是反贼. 分类: Linux

很多时候我们我们可能会发现当前硬盘不够用了,需要紧急增加容量,但是lvm划分的已经没有剩余了,只有往里新加一块磁盘。那么对于EXSi如何快速的给虚拟机增加硬盘容量呢?

在ESXI的虚拟机设置面板add一块新硬盘,然后在操作系统里让它识别出来

export TMOUT=0
echo “- – -” >/sys/class/scsi_host/host0/scan

发现新硬盘
Apr 25 15:09:47 wgq-fcs-dbs01 kernel: ? Vendor: VMware? ?Model: Virtual disk ? ? ?Rev: 1.0
Apr 25 15:09:47 wgq-fcs-dbs01 kernel: ? Type: ?Direct-Access ? ? ? ? ? ? ?? ? ? ?ANSI SCSI revision: 02
Apr 25 15:09:47 wgq-fcs-dbs01 kernel: ?target0:0:1:Beginning Domain Validation
Apr 25 15:09:47 wgq-fcs-dbs01 kernel: ?target0:0:1:Domain Validation skipping write tests
Apr 25 15:09:47 wgq-fcs-dbs01 kernel: ?target0:0:1:Ending Domain Validation
Apr 25 15:09:47 wgq-fcs-dbs01 kernel: ?target0:0:1:FAST-40 WIDE SCSI 80.0 MB/s ST (25 ns, offset 127)
Apr 25 15:09:47 wgq-fcs-dbs01 kernel: SCSI device sdb:209715200 512-byte hdwr sectors (107374 MB)
Apr 25 15:09:47 wgq-fcs-dbs01 kernel: sdb: Write Protect isoff
Apr 25 15:09:47 wgq-fcs-dbs01 kernel: sdb: cache dataunavailable
Apr 25 15:09:47 wgq-fcs-dbs01 kernel: sdb: assuming drivecache: write through
Apr 25 15:09:47 wgq-fcs-dbs01 kernel: SCSI device sdb:209715200 512-byte hdwr sectors (107374 MB)
Apr 25 15:09:47 wgq-fcs-dbs01 kernel: sdb: Write Protect isoff
Apr 25 15:09:47 wgq-fcs-dbs01 kernel: sdb: cache dataunavailable
Apr 25 15:09:47 wgq-fcs-dbs01 kernel: sdb: assuming drivecache: write through
Apr 25 15:09:47 wgq-fcs-dbs01 kernel: ?sdb: unknownpartition table
Apr 25 15:09:47 wgq-fcs-dbs01 kernel: sd 0:0:1:0: Attachedscsi disk sdb
Apr 25 15:09:47 wgq-fcs-dbs01 kernel: sd 0:0:1:0: Attachedscsi generic sg1 type 0

查看新硬盘
fdisk -l

fdisk /dev/sdb
Command (m for help): new
Command action
e extended
p primary partition (1-4) p
Partition number (1-4): 1
First cylinder (1-512, default 1):
Last cylinder or +size or +sizeM or +sizeK (1-512,default 512):
Command (m for help): t
Partition’s system id: 8e
Command(m for help): w

3. 创建物理卷
pvcreate /dev/sdb1

4 将新建物理卷添加到卷组中
vgextend VolGroup00 /dev/sdb1

5. 扩展逻辑卷大小
vgdisplay
— Volume group —
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 309.84 GB
PE Size 32.00 MB
Total PE 9915
Alloc PE / Size 6716 / 209.88 GB
Free PE / Size 3199 / 99.97 GB

lvextend -l +3199 /dev/VolGroup00/LogVol00

6. 扩展文件系统大小
resize2fs -p /dev/VolGroup00/LogVol00

7. 查看配置完成后的磁盘空间大小
df -h

8. 查看卷组和逻辑卷状态
vgdisplay
lvdisplay

返回正文

您的留言是我最大的支持!