hyperreal.coffee

Mount qcow2 image

Enable NBD on the host.

1sudo modprobe nbd max_part=8

Connect qcow2 image as a network block device.

1sudo qemu-nbd --connect=/dev/nbd0 /path/to/image.qcow2

Find the VM’s partitions.

1sudo fdisk /dev/nbd0 -l

Mount the partition from the VM.

1sudo mount /dev/nbd0p3 /mnt/point

To unmount:

1sudo umount /mnt/point
2sudo qemu-nbd --disconnect /dev/nbd0
3sudo rmmod nbd

Resize qcow2 image

Install guestfs-tools (required for virt-resize command).

1sudo dnf install -y guestfs-tools
2sudo apt install -y guestfs-tools libguestfs-tools

To resize qcow2 images, you’ll have to create a new qcow2 image with the size you want, then use virt-resize on the old qcow2 image to the new one.

You’ll need to know the root partition within the old qcow2 image.

Create a new qcow2 image with the size you want.

1qemu-img create -f qcow2 -o preallocation=metadata newdisk.qcow2 100G

Now resize the old one to the new one.

1virt-resize --expand /dev/vda3 olddisk.qcow2 newdisk.qcow2

Once you boot into the new qcow2 image, you’ll probably have to adjust the size of the logical volume if it has LVM.

1sudo lvresize -l +100%FREE /dev/mapper/sysvg-root

Then resize the XFS root partition within the logical volume.

1sudo xfs_growfs /dev/mapper/sysvg-root

Reply to this post by email ↪