+===== KVM / QEMU Extend a virtual disk ======
===== Extend a virtual disk with simple partition schema =====
With the VM shut down directly extend the disk image on the host:
qemu-img resize virtual_disk.qcow2 +10G
Load the network block device driver into the kernel and attach the disk to the host
modprobe nbd
qemu-nbd -c /dev/nbd0 virtual_disk.qcow2
Use a partition manager (gParted ...) to extend the partition
Disconnect the virtual disk from the host
qemu-nbd -d /dev/nbd0
Start the VM and check if all is ok
===== Extend a virtual disk with LVM partitions =====
With the VM shut down directly extend the disk image on the host:
qemu-img resize virtual_disk.qcow2 +10G
Start the VM and login. \\
As root or sudo:
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 252:0 0 260G 0 disk
├─vda1 252:1 0 600M 0 part /boot/efi
├─vda2 252:2 0 1G 0 part /boot
└─vda3 252:3 0 208.4G 0 part
├─rhel_rhel8-root 253:0 0 180G 0 lvm /
├─rhel_rhel8-swap 253:1 0 4G 0 lvm [SWAP]
└─rhel_rhel8-home 253:2 0 24.4G 0 lvm /home
This shows the LVM partitions are on device vda, partition 3 (vda3)\\
pvs
PV VG Fmt Attr PSize PFree
/dev/vda3 rhel_rhel8 lvm2 a-- 258.41g 0
The virtual device is ''/dev/vda3'' and the volume group is ''rhel_rehl8''
Claim the free disk space for partition 3
growpart /dev/vda 3
pvresize /dev/vda3
... and finally claim the available space for the root partition:
lvextend -r -l +100%FREE /dev/rhel_rhel8/root
Check if all went well:
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 252:0 0 260G 0 disk
├─vda1 252:1 0 600M 0 part /boot/efi
├─vda2 252:2 0 1G 0 part /boot
└─vda3 252:3 0 258.4G 0 part
├─rhel_rhel8-root 253:0 0 230G 0 lvm /
├─rhel_rhel8-swap 253:1 0 4G 0 lvm [SWAP]
└─rhel_rhel8-home 253:2 0 24.4G 0 lvm /home
vda3 grew from 208.4 GB to 258.4 GB and the space was added to rhel_rhel8-root: it grew from 180 GB to 230 GB.
Done.