ESXI添加硬盘并免重启扩展Linux虚拟机LVM

手动在vCenter中将要扩充空间的Linux虚拟机添加一块50G的硬盘,过程略。

接下来是在Linux中操作步骤:

1、  查看SCSI总线:

[root@c11-mysql-n02 ~]# ls/sys/class/scsi_host/

host0  host1 host2

2、  重新扫描SCSI总线并添加SCSI设备到系统

[root@c11-mysql-n02 ~]# echo"- - -" > /sys/class/scsi_host/host0/scan

[root@c11-mysql-n02 ~]# echo"- - -" > /sys/class/scsi_host/host1/scan

[root@c11-mysql-n02 ~]# echo"- - -" > /sys/class/scsi_host/host2/scan

3、  确认磁盘已添加:

[root@c11-mysql-n02 ~]# fdisk –l

Disk /dev/sdc: 53.7 GB, 53687091200bytes

****

4、  格式化磁盘:

[root@c11-mysql-n02 ~]#fdisk  /dev/sdc

依次输入:n          #新建分区

p         #主分区

1                    #分区ID,这里是/dev/sdc1

回车2   #将所有空间分配

t输入8e   #设置分区格式为lvm8e

                     w#保存修改

[root@c11-mysql-n02 ~]# fdisk –l

   DeviceBoot     Start        End      BlocksId  System

/dev/sdc1         16527    52428096   8eLinux LVM

5、  将修改更新到系统(避免重启,使用partprobe命令):

[root@c11-mysql-n02 ~]#partprobe /dev/sdc1    #如未有此命令,则使用yum –y install parted

6、  确认当前需要扩展的VG

[root@c11-mysql-n02 ~]#vgdisplay或者vgs

--- Volume group ---

VG Name datavg

*

*

VG Size 100.00 GiB

*

*

8、使用/dev/sdc1创建PV

        [root@c11-mysql-n02 ~]# pvcreate /dev/sdc1

Writingphysical volume data to disk "/dev/sdc1"

Physicalvolume "/dev/sdc1" successfully created

9、使用新建的PV扩展VG(这里是datavg):

        [root@c11-mysql-n02 ~]# vgextend datavg /dev/sdc1

        Volume group "datavg" successfully extended

10、确定扩展后VG中可用的PE,以扩展LV

        [root@c11-mysql-n02 ~]# vgdisplay datavg

        Free  PE / Size       12799 / 50.00 GiB

11、使用free PE空间扩展LV

        [root@c11-mysql-n02 ~]#lvdisplay              #查看要扩展的LV

        --- Logical volume ---

LVPath               /dev/datavg/datalv

***

[root@c11-mysql-n02~]# lvextend -l +12799 /dev/datavg/datalv

Extendinglogical volume datalv to 149.99 GiB

Logical volumedatalv successfully resized

12、在线扩展文件系统:

        [root@c11-mysql-n02 ~]# resize2fs /dev/datavg/datalv

resize2fs1.41.12 (17-May-2010)

Filesystem at/dev/datavg/datalv is mounted on /data; on-line resizing required

old desc_blocks= 7, new_desc_blocks = 10

Performing anon-line resize of /dev/datavg/datalv to 39319552 (4k) blocks.

The filesystemon /dev/datavg/datalv is now 39319552 blocks long.

13、查看空间是否扩充生效:

[root@c11-mysql-n02~]# df -h

Filesystem           Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root

                        35G  5.1G   28G16% /

tmpfs                1.9G   76K1.9G   1% /dev/shm

/dev/sda1            485M   37M423M   8% /boot

/dev/mapper/datavg-datalv

                          148G   94G   47G67%/data