Properly convert qcow2 to fill new disk

I got a new drive recently for the specific purpose of hosting my dev vm image. How can I convert my existing qcow2 file to fill the entire disk.

So far I have tried using the following command:

qemu-image -O raw dev.qcow2 /dev/nvme0n1

but unfortunately I get “no bootable image found” when trying to boot into the image on the new drive. I would also like to expand this image on the new drive to fill the entire volume but Gparted complains that this might mess up the filesystem.

I’m not too familiar with how filesystems work in linux so I’m not sure that this is the best way of going about things so I’m open to other suggestions on what the best practice is to do in this case.

You’ll probably need to update grub(or systemd) after you do the reimage. I have it on my list of homelab stuff to do the same with a VM I want to move to a different machine, but haven’t got around to it yet.

Gparted usually warns you when you resize a bootable partition, because changing the location of the first sector can make boot loaders angry. If you’re just extending a partition without moving where it starts on the disk, then you should be fine.

Yeah this is interesting. I see that it creates a grub image but what do I do with that?

Oh, maybe you haven’t converted it to raw yet?

qemu-image convert -O raw dev.qcow2 /dev/nvme0n1

Assuming /dev/nvme0n1 is the correct device!

Sorry, like I said I haven’t actually done this part myself yet. That qemu-image command looked correct to me at first, so I was thinking you might need to update the bootloader so it has correct UUIDs or something.

Oh I had convert in the command that I used in my terminal I just didn’t write it down here sorry

I guess to provide more information, I’ve tried pointing to the root drive and the two images that the conversion creates but I get no bootable fs for each one.

Ok I fixed it. It turns out when I was inspecting the drive through Gparted and it was asking me to fix the partition, if you hit ignore and boot directly to it using libvirt, it’s fine. Now I’m going to try and expand the partition.

Edit: Yep that worked.

1 Like

Funny thing, I did the exact same thing today :slight_smile:

But I took a detour via an .img-file and then dd’d the result to the physical disk, good to know there is a quicker way :+1:

This topic was automatically closed 273 days after the last reply. New replies are no longer allowed.