早晚我们会遇到虚拟机的大小不够用的情况。此时可以用virt-resize命令重新分配虚拟机大小。假设我们的虚拟机vm-gitlab6需要扩充到40G。那么首先关闭虚拟机,然后备份虚拟机文件。
以下操作都在下面的虚机目录下进行:
/var/lib/libvirt/images/vm-gitlab6/ubuntu-kvm/
$ sudo apt-get install libguestfs-tools
$ sudo virsh shutdown vm-gitlab6
$ sudo cp /var/lib/libvirt/images/vm-gitlab6/ubuntu-kvm/vm-gitlab6-img1.qcow2 /var/lib/libvirt/images/vm-gitlab6/ubuntu-kvm/vm-gitlab6-img1-back.qcow2
$ sudo virt-df -h vm-gitlab6-img1.qcow2
W: kvm binary is deprecated, please use qemu-system-x86_64 instead
Filesystem Size Used Available Use%
vm-gitlab6-img1.qcow2:/dev/sda1 18G 1.1G 16G 6%
vm-gitlab6-img1-big.qcow2,给40G大小(瞬间结束,让人以为错误)
$ sudo qemu-img create -f qcow2 vm-gitlab6-img1-big.qcow2 40G
$ sudo virt-resize --expand /dev/sda1 vm-gitlab6-img1.qcow2 vm-gitlab6-img1-big.qcow2