kvm virtual machine expands disk capacity

virt-resize extension

#shutdown kvm virtual machine
virsh shutdown testkvm2 #installation
tool
yum install -y libguestfs-tools #view
disk file location
virsh edit testkvm2 #view


disk partition information
virt-filesystems --partitions --long -a /var/lib /libvirt/images/testkvm2.qcow2 #Create


a new disk file
qemu-img create -f qcow2 /var/lib/libvirt/images/testkvm3.qcow2 10G #Expand


the root directory to mount the disk
virt-resize --expand /dev/ sda2 \
/var/lib/libvirt/images/testkvm2.qcow2 /var/lib/libvirt/images/testkvm3.qcow2 #Modify


disk configuration
virsh edit testkvm2 #Original
disk file #Modified disk


file #Start


virtual machine
virsh start testkvm2
# Log in to the virtual machine and check the hard disk
#The hard disk has been expanded to 10G, but it is not allocated to the root directory


#View vg volume group
vgdisplay
#It has been automatically added to the vg volume group, and then expand the lv logical volume. #View the


lv logical volume
lvdisplay #Expand


the lv logical volume group
lvextend -L +5G /dev/centos/root #Adjust


the file system size
xfs_growfs /dev/centos /root


#View file system #Disk
size has been adjusted


Add a new disk extension

to create a disk file
#qcow2 is the file type, test1-add1.qcow2 is the disk file, 5G is the size
qemu-img create -f qcow2 /var/lib/libvirt/ images/test1-add1.qcow2 5G

create disk XML file (note, do not have the same name as the existing file)

virsh attach-disk <virtual machine name> \
--source /var/lib/libvirt/images/test1-add2.qcow2 \
--target vdd \
--sourcetype file \ --type
disk \
--driver qemu \
--subdriver qcow2 \
--cache none \
--targetbus virtio \
--print-xml > /etc/libvirt/qemu/test2 -add.xml

Attach device from XML file

#--persistent persistent
virsh attach-device <virtual machine name> /etc/libvirt/qemu/test2-add.xml --persistent
detach disk device
detach XML configuration device
virsh detach-device <virtual machine name > /etc/libvirt/qemu/test2-add.xml --persistent
delete file
rm -f /etc/libvirt/qemu/test2-add.xml
rm -f /var/lib/libvirt/images/test1-add1.qcow2

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324500373&siteId=291194637