This shows you the differences between two versions of the page.
| linux:kvmqemu:expanddisk [2023/02/12 17:05] – created olaf | linux:kvmqemu:expanddisk [2023/11/05 13:41] (current) – Added LVM extension olaf | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | +===== 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: | ||
| + | <code bash> | ||
| + | qemu-img resize virtual_disk.qcow2 +10G | ||
| + | </ | ||
| + | |||
| + | Load the network block device driver into the kernel and attach the disk to the host | ||
| + | <code bash> | ||
| + | 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 | ||
| + | <code bash> | ||
| + | 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: | ||
| + | <code bash> | ||
| + | qemu-img resize virtual_disk.qcow2 +10G | ||
| + | </ | ||
| + | |||
| + | Start the VM and login. \\ | ||
| + | As root or sudo: | ||
| + | |||
| + | <code bash> | ||
| + | lsblk | ||
| + | </ | ||
| + | < | ||
| + | NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT | ||
| + | sr0 11:0 1 1024M 0 rom | ||
| + | vda | ||
| + | ├─vda1 | ||
| + | ├─vda2 | ||
| + | └─vda3 | ||
| + | ├─rhel_rhel8-root 253:0 0 | ||
| + | ├─rhel_rhel8-swap 253:1 0 | ||
| + | └─rhel_rhel8-home 253:2 0 24.4G 0 lvm /home | ||
| + | </ | ||
| + | This shows the LVM partitions are on device vda, partition 3 (vda3)\\ | ||
| + | |||
| + | <code bash> | ||
| + | pvs | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | PV | ||
| + | / | ||
| + | </ | ||
| + | The virtual device is ''/ | ||
| + | |||
| + | Claim the free disk space for partition 3 | ||
| + | <code bash> | ||
| + | growpart /dev/vda 3 | ||
| + | pvresize /dev/vda3 | ||
| + | </ | ||
| + | ... and finally claim the available space for the root partition: | ||
| + | <code bash> | ||
| + | lvextend -r -l +100%FREE / | ||
| + | </ | ||
| + | |||
| + | Check if all went well: | ||
| + | |||
| + | <code bash> | ||
| + | lsblk | ||
| + | </ | ||
| + | < | ||
| + | NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT | ||
| + | sr0 11:0 1 1024M 0 rom | ||
| + | vda | ||
| + | ├─vda1 | ||
| + | ├─vda2 | ||
| + | └─vda3 | ||
| + | ├─rhel_rhel8-root 253:0 0 | ||
| + | ├─rhel_rhel8-swap 253:1 0 | ||
| + | └─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: | ||
| + | |||
| + | Done. | ||
| + | |||