菜鸟玩云计算之十二:KVM虚拟机更改大小


/var/lib/libvirt/images/vm-gitlab6/ubuntu-kvm/

$ 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%

$ 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 


Examining vm-gitlab6-img1.qcow2 ...
W: kvm binary is deprecated, please use qemu-system-x86_64 instead
**********

Summary of changes:

/dev/sda1: This partition will be resized from 18.6G to 32.5G.  The
    filesystem ext4 on /dev/sda1 will be expanded using the 'resize2fs'
    method.

/dev/sda2: This partition will be left alone.

**********
Setting up initial partition table on vm-gitlab6-img1-1.qcow2 ...
Copying /dev/sda1 ...
 100% ⟦▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓⟧ 00:00
Copying /dev/sda2 ...
 100% ⟦▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓⟧ 00:00
W: kvm binary is deprecated, please use qemu-system-x86_64 instead
Expanding /dev/sda1 using the 'resize2fs' method ...

Resize operation completed with no errors.  Before deleting the old
disk, carefully check that the resized disk boots and works correctly.

$ sudo virt-df -h vm-gitlab6-img1-big.qcow2

W: kvm binary is deprecated, please use qemu-system-x86_64 instead
Filesystem                                Size       Used  Available  Use%
vm-gitlab6-img1-big.qcow2:/dev/sda1          32G       1.1G        29G    4%

$ sudo rm vm-gitlab6-img1.qcow2

$ sudo mv vm-gitlab6-img1-big.qcow2 vm-gitlab6-img1.qcow2

$ sudo chmod 755 vm-gitlab6-img1.qcow2


$ sudo virsh start vm-gitlab6


$ ls -lh vm-gitlab6-img1-big.qcow2
10月  7 16:55

$ sudo qemu-img convert -O qcow2 vm-gitlab6-img1-big.qcow2 vm-gitlab6-img1-shrink.qcow2

$ ls -lh vm-gitlab6-img1-shrink.qcow2
10月  7 17:06

$ virt-df -h vm-gitlab6-img1-shrink.qcow2
W: kvm binary is deprecated, please use qemu-system-x86_64 instead
Filesystem                                Size       Used  Available  Use%
vm-gitlab6-img1-shrink.qcow2:/dev/sda1                       1.1G        29G    4%

最后用替换即可。
==============================================================


最后转回去qcow2:


相关内容

    暂无相关文章