Skip to content

Instantly share code, notes, and snippets.

@sar
Created August 19, 2020 03:01
Show Gist options
  • Save sar/240918744fe512b070205737015e7371 to your computer and use it in GitHub Desktop.
Save sar/240918744fe512b070205737015e7371 to your computer and use it in GitHub Desktop.
Resize Qemu KVM with contained root LVM

Resize qcow2 image attached to KVM and internal LVM root vg, lv

Obtain root access with sudo -i before running the following commands.

Resize KVM qcow2 image

Online resize is not supported, it is recommended to clone the image before proceeding. To allocate additional blocks to an image that does not pre-allocate space, run the following command.

$ qemu-img resize <<image_name>> +128G

Create Allocation Partition

To consume the remaining space, it is recommended to create a secondary linux filesystem based partition.

$ fdisk /dev/vda
# > p (print)
# > m (manfile)
# > n
# ... follow on screen instructions to select start and end blocks
# > t (change partition type)
# > select and set to 8e
# > w (write changes)

Create Physical Volume

$ pvcreate /dev/vda4
$ pvdisplay

Resize Volume Group

Volume groups are containers that can spread across partitions. To resize the primary group and consume the additional physical volume, run the command:

$ vgdisplay
$ vgextend /dev/fedora_localhost-live /dev/vda4
$ vgdisplay
# > New Size Shown

Resize Logical Volume

Finally, resize the logical volume with mapping of root file system to /. Online resize will occur, it's recommended to restart your computer for ionode optimization.

$ lvresize --resizefs -l +100%FREE /dev/mapper/fedora_localhost--live-root

👋 Leave a comment if you found this gist helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment