kvm扩容硬盘
在宿主机上确认kvm4的磁盘镜像路径
virsh domblklist kvm4
先看一下目前磁盘镜像的大小
qemu-img info /var/lib/libvirt/images/kvm4.qcow2
停止虚拟机后,执行如下命令
qemu-img resize /var/lib/libvirt/images/kvm4.qcow2 +20G
增容后,再次查看磁盘镜像信息,如下,磁盘的virtual size已经从50G变成了70G
qemu-img info /var/lib/libvirt/images/kvm4.qcow2
情况二、虚拟机使用了逻辑卷,添加一个磁盘,然后扩容逻辑卷。
登录虚拟机
创建分区
fdisk /dev/vda
partprobe
vgdisplay
pvcreate /dev/vda3
vgextend centos /dev/vda3
lvdisplay
lvextend /dev/centos/root /dev/vda3
xfs_growfs /dev/mapper/centos-root
参考:
https://www.cnblogs.com/guarderming/p/15532573.html
https://www.cnblogs.com/gaoyanbing/p/16968273.html
QA:
[root@kubewps images]# qemu-img resize /var/lib/libvirt/images/node02.qcow2 -20G
qemu-img: Could not open '/var/lib/libvirt/images/node02.qcow2': qcow2: Image is corrupt; cannot be opened read/write
修复:
[root@kubewps images]# qemu-img check -r all /var/lib/libvirt/images/node02.qcow2
[root@kubewps images]# qemu-img resize /var/lib/libvirt/images/node02.qcow2 +20G
Image resized.