–
KVM虚拟机扩容
只要是虚拟机使用了LVM分区均可实现KVM虚拟机在线热扩容根目录操作
KVM LVM在线热扩容根目录
查看虚机信息
1、查看vg和lvs信息 [root@jira_t_4_239 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom vda 252:0 0 60G 0 disk ├─vda1 252:1 0 1G 0 part /boot └─vda2 252:2 0 59G 0 part ├─cl-root 253:0 0 55G 0 lvm / └─cl-swap 253:1 0 3.9G 0 lvm [SWAP] [root@jira_t_4_239 ~]# vgs VG #PV #LV #SN Attr VSize VFree cl 1 2 0 wz--n- 59.00g 76.00m [root@jira_t_4_239 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root cl -wi-ao---- 55.05g swap cl -wi-ao---- 3.88g
宿主机操作
切换到宿主机镜像文件目录,创建一个和原来虚拟机名字不同的磁盘文件
2、查看原镜像文件 [root@kvm_online_dc2_4_32 ~]# ll -h /var/lib/libvirt/images/jira_t_4_239.qcow2 -rw-r--r--. 1 qemu qemu 1.1G 10月 14 10:36 /var/lib/libvirt/images/jira_t_4_239.qcow2 3、新建磁盘镜像文件 [root@kvm_online_dc2_4_32 ~]# qemu-img create -f qcow2 /var/lib/libvirt/images/jira_t_4_239_disk.qcow2 200g Formatting '/var/lib/libvirt/images/jira_t_4_239_disk.qcow2', fmt=qcow2 size=214748364800 encryption=off cluster_size=65536 lazy_refcounts=off 4、添加虚拟机磁盘 [root@kvm_online_dc2_4_32 ~]# virsh attach-disk jira_t_4_239 /var/lib/libvirt/images/jira_t_4_239_disk.qcow2 vdb --live --config --cache=none --subdriver=qcow2 成功附加磁盘
虚拟机操作
5、登录虚拟机查看分区信息,发现vdb已经添加 [root@jira_t_4_239 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom vda 252:0 0 60G 0 disk ├─vda1 252:1 0 1G 0 part /boot └─vda2 252:2 0 59G 0 part ├─cl-root 253:0 0 55G 0 lvm / └─cl-swap 253:1 0 3.9G 0 lvm [SWAP] vdb 252:16 0 200G 0 disk 6、将/dev/vdb创建为pv物理卷 [root@jira_t_4_239 ~]# pvcreate /dev/vdb Physical volume "/dev/vdb" successfully created. 7、查看vg名字 [root@jira_t_4_239 ~]# vgdisplay --- Volume group --- VG Name cl System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 59.00 GiB PE Size 4.00 MiB Total PE 15103 Alloc PE / Size 15084 / 58.92 GiB Free PE / Size 19 / 76.00 MiB VG UUID VMMVD0-tHBe-6g8u-XHw7-hlgF-mhBe-MsNLrA 8、扩容VG 将/dev/sdb的PV空间扩展到VG卷组:VolGroup [root@jira_t_4_239 ~]# vgextend cl /dev/vdb Volume group "cl" successfully extended 9、发现vg已经扩展了 [root@jira_t_4_239 ~]# vgdisplay --- Volume group --- VG Name cl System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 7 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 258.99 GiB PE Size 4.00 MiB Total PE 66302 Alloc PE / Size 15084 / 58.92 GiB Free PE / Size 51218 / 200.07 GiB VG UUID VMMVD0-tHBe-6g8u-XHw7-hlgF-mhBe-MsNLrA 10、查看lv大小,/dev/cl/root大小为55g [root@jira_t_4_239 ~]# lvdisplay --- Logical volume --- LV Path /dev/cl/swap LV Name swap VG Name cl LV UUID XlKviV-bJXW-2RLT-Wv7j-dzxn-Uitk-UGXgtr LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-05-16 08:35:28 +0800 LV Status available # open 2 LV Size 3.88 GiB Current LE 992 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/cl/root LV Name root VG Name cl LV UUID yi4Ea5-TCm2-06Zj-zPYQ-cptb-0JXc-MoCcWu LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-05-16 08:35:29 +0800 LV Status available # open 1 LV Size 55.05 GiB Current LE 14092 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 11、扩展cl-root的lv的大小 [root@jira_t_4_239 ~]# lvextend -L +190G /dev/mapper/cl-root Size of logical volume cl/root changed from 55.44 GiB (14192 extents) to 245.44 GiB (62832 extents). Logical volume cl/root successfully resized. 12、发现cl-root的lv已经扩展到245g [root@jira_t_4_239 ~]# lvdisplay --- Logical volume --- LV Path /dev/cl/swap LV Name swap VG Name cl LV UUID XlKviV-bJXW-2RLT-Wv7j-dzxn-Uitk-UGXgtr LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-05-16 08:35:28 +0800 LV Status available # open 2 LV Size 3.88 GiB Current LE 992 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/cl/root LV Name root VG Name cl LV UUID yi4Ea5-TCm2-06Zj-zPYQ-cptb-0JXc-MoCcWu LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-05-16 08:35:29 +0800 LV Status available # open 1 LV Size 245.44 GiB Current LE 62832 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0
文件系统扩展
13、文件系统扩容 [root@jira_t_4_239 ~]# df -hT 文件系统 类型 容量 已用 可用 已用% 挂载点 /dev/mapper/cl-root xfs 56G 2.2G 53G 4% / devtmpfs devtmpfs 5.1G 0 5.1G 0% /dev tmpfs tmpfs 5.1G 0 5.1G 0% /dev/shm tmpfs tmpfs 5.1G 8.4M 5.1G 1% /run tmpfs tmpfs 5.1G 0 5.1G 0% /sys/fs/cgroup /dev/vda1 xfs 1014M 139M 876M 14% /boot tmpfs tmpfs 840M 0 840M 0% /run/user/0 如果是其他文件系统,使用resize2fs [root@jira_t_4_239 ~]# xfs_growfs /dev/mapper/cl-root meta-data=/dev/mapper/cl-root isize=512 agcount=6, agsize=2427136 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=14430208, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=4740, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 14430208 to 64339968 [root@jira_t_4_239 ~]# df -hT 文件系统 类型 容量 已用 可用 已用% 挂载点 /dev/mapper/cl-root xfs 246G 2.2G 244G 1% / devtmpfs devtmpfs 5.1G 0 5.1G 0% /dev tmpfs tmpfs 5.1G 0 5.1G 0% /dev/shm tmpfs tmpfs 5.1G 8.4M 5.1G 1% /run tmpfs tmpfs 5.1G 0 5.1G 0% /sys/fs/cgroup /dev/vda1 xfs 1014M 139M 876M 14% /boot tmpfs tmpfs 840M 0 840M 0% /run/user/0
上面的操作都是文件系统级别的操作,不用将挂载放到开机启动中等操作,虚机重启也生效
扩容总结
一.对虚拟磁盘进行扩容 使用工具virt-resize将镜像vmdisk.qcow2从10GB扩容为20GB,需要安装libguestfs-tools和guestfish 1.新建20GB的镜像 qemu-img create -f qcow2 vmdisk-20G.qcow2 20G 2.磁盘分区扩充 virt-resize --expand /dev/vda3 vmdisk.qcow2 vmdisk-20G.qcow2 二. vg,lv和文件系统扩容 1. 修改虚拟机xml,让其从新磁盘vmdisk-20G.qcow2启动 2. 进入虚拟机 3. vgdisplay 查看,vg已经自动扩容 4. lvs查看,lv需要扩容 #lvextend -L +10G /dev/redosbe_bogon/root 5. df -Th发现根分区没有变,文件系统也需要扩容 xfs文件系统,使用xfs_growfs扩容 #xfs_growfs /dev/mapper/redosbe_bogon-root 如果是其他文件系统,使用resize2fs 6. 查看根分区大小,扩容成功
–
–
–
评论前必须登录!
注册