0

I have 500 GB (~475 GiB) SSD that I want to image with qcow2. I plan on following this example on moving the Windows installation to a Qemu/KVM VM. I shrunk the ~470 GiB bitlocker root partition to 115 GiB using dislocker and gparted. I then moved the 2000 MiB WinRE_DRV partition to the left, leaving no space with itself and the recently shrunk bitlocker partition. In the current situation, the first 116 GiB of the drive contains data, and the rest of it is unallocated space.

I want to image the beginning 116 GiB of data, and exclude the unallocated space to not waste space in the image. At first, I thought of using dd with bs=1M and count=116688, so only the data I want would be copied, and pipping that to qemu-img. However, I later learned that qemu-img doesn't support stdin. The suggested solution to that problem was to use nbdcopy, which doesn't work well for me because

The catch is unfortunately you have to know the size of the final qcow2 file before you start, although it's OK to use a larger size.

This wouldn't work well for me, because I'm going to use compression while making the image, which means that I won't know the final size beforehand. I could just choose a size as big as the uncompressed data (116 GiB) to guarantee it to fit in the image, however doing so would end up wasting space leading it to be an unfavorable solution.

I also tried reading the manpage for qemu-img, and there didn't seem to be any count= option for qemu-img convert, however there did seem to be one for qemu-img dd, which I think wouldn't be helpful in this case.

My original command:

dd bs=1M if=/dev/nvme0n1 count=116688 status=progress | qemu-img convert -p -f raw -O qcow2 -c -o compression_type=zstd,preallocation=off /media/user/drive/win11_image.qcow2
Giacomo1968
  • 58,727

0 Answers0