遲早咱們會遇到虛擬機的大小不夠用的狀況。此時能夠用virt-resize命令從新分配虛擬機大小。假設咱們的虛擬機vm-gitlab6須要擴充到40G。那麼首先關閉虛擬機,而後備份虛擬機文件。
git
如下操做都在下面的虛機目錄下進行:ubuntu
/var/lib/libvirt/images/vm-gitlab6/ubuntu-kvm/ gitlab
$ sudo apt-get install libguestfs-tools get
$ sudo virsh shutdown vm-gitlab6
it
$ 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 sed
$ 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%tools
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