Smokes your problems, coughs fresh air.

Growing a qcow2 image file

First, convert it to raw:

qemu-img convert system.qcow2 -O raw system.raw

Then use DD to append a zero all the way at the end of the new file. It will automatically create a hole in the file:

# Make sure the seek value is bigger than the file size, otherwise it would put a zero somewhere in the middle of the file.
dd if=/dev/zero of=temp.raw bs=1 count=1 seek=100G

Then resize the partition. I did that by binding the image to a loop device:

losetup /dev/loop0 system.raw

Then you can use fdisk on /dev/loop0 to alter the partition table. parted didn’t want to resize my file sytem because it had a journal (argh…) so I just used fdisk and made sure that the start of the partition was the same.

Then you detach the loop device and attach the partition:

losetup -d /dev/loop0
# 32256 is 63*512. 63 is the start sector, which fdisk can tell you (with the u option)
losetup -o 32256 /dev/loop0 system.raw

Then I used resize2fs on /dev/loop0 and detached it again.

2 Comments

  1. halfgaar

    Hmm. even though the partition mounted fine, it doesn’t boot because of corruption errors…

  2. halfgaar

    I received this by e-mail from Richard, not sure why through e-mail?:

    Hi,

    I have had the same problem, I use this :
    Context : qcow2 file with two partitions type 8e (LVM)

    Stop the VM

    $ qemu-img resize trafalgar.qcow2 +5G

    Start the VM with SystemRescueCD for delete / recreate the partion with fdisk, then stopped the VM.

    $ fdisk -l /dev/sda
    d
    n
    t
    8e
    w
    q

    Start the VM normally, for grow physical volume.

    pvresize /dev/sda2

    Richard

© 2024 BigSmoke

Theme by Anders NorenUp ↑