2

I saw a similar thread on this, but doing the exact steps in that thread, does not work for me. I want to upload a Linux image (which is qcow2) after converting to VHD image, to Azure.

I converted the qcow2 image to raw:

qemu-img convert -f qcow2 -O raw myimage.qcow2 myimage.img

Next, my raw image is an exact multiple of 1M, so I don't need to resize it.

ls -l myimage.img
-rw-r--r-- 1 user1 user11 2313158656 Mar  5 00:18 myimage.img

<2313158656 is exact multiple of 1M>

Then I converted the raw to VHD on a Ubuntu VM which has qemu 2.6.1 installed, using the force option:

qemu-img convert -f raw -o subformat=fixed,force_size -O vpc myimage.img myimage.vhd

Now, the qemu-img seems to have added 512 bytes to the image, hence I still can't upload in Azure.

ls -l myimage.vhd
-rw-r--r-- 1 user1 user1 2313159168 Mar  5 00:39 myimage.vhd

Uploading this VM to azure gives this error:

The VHD for disk 'clid01b1a17d9ec0eb1-os-1488675181694' with blob https://vmxstorage.blob.core.windows.net/vhddisks/vFPC-20170216.vhd has an unsupported virtual size of 2206.4765625 MB. The size must be a whole number in (MBs).

How do I create a VM with the correct size of multiple of an MB?

Thanks Anjali

Thomas
  • 4,155
  • 5
  • 21
  • 28
Anjali
  • 21
  • 1

1 Answers1

1

Try rounding instead:

rawdisk="MyLinuxVM.raw"
vhddisk="MyLinuxVM.vhd"

MB=$((1024*1024))
size=$(qemu-img info -f raw --output json "$rawdisk" | \
       gawk 'match($0, /"virtual-size": ([0-9]+),/, val) {print val[1]}')

rounded_size=$((($size/$MB + 1)*$MB))
echo "Rounded Size = $rounded_size"

Resize to $rounded_size

qemu-img resize MyLinuxVM.raw $rounded_size

And finally convert

qemu-img convert -f raw -o subformat=fixed,force_size -O vpc MyLinuxVM.raw MyLinuxVM.vhd

Reference:

Information for Non-Endorsed Distributions

Bruno Faria
  • 3,804
  • 1
  • 11
  • 18