3.8. Converting a RHEL image to Azure disk image
Microsoft Azure supports the Azure disk image (.vhd) format. To convert the image, ensure that the image file starts at a position that is a multiple of 1 MB, and then convert the RHEL image from qcow2 to a fixed VHD format.
The following commands use qemu-img version 2.12.0.
Prerequisites
- You have completed the steps of preparing VM for Azure deployment.
Procedure
Convert the image from
qcow2torawformat.$ qemu-img convert -f qcow2 -O raw <image_example_name>.qcow2 <image_name>.rawEdit the
align.shshell script:$ vi align.sh #!/bin/bash MB=$((1024 * 1024)) size=$(qemu-img info -f raw --output json "$1" | gawk 'match($0, /"virtual-size": ([0-9]+),/, val) {print val[1]}') rounded_size=$((($size/$MB + 1) * $MB)) if [ $(($size % $MB)) -eq 0 ] then echo "Your image is already aligned. You do not need to resize." exit 1 fi echo "rounded size = $rounded_size" export rounded_sizeRun the script:
$ sh align.sh <image_example_name>.rawIf the Your image is already aligned. You do not need to resize. message displays:
Convert the file to a fixed
VHDformat:$ qemu-img convert -f raw -o subformat=fixed,force_size -O vpc <image_example_name>.raw <image_example_name>.vhdOnce converted, the
VHDfile is ready to upload to Azure.
If a value displays mean the
rawimage is not aligned:Resize the
rawfile by using the rounded value as displayed above:$ qemu-img resize -f raw <image_example_name>.raw +1GConvert the
rawimage file to aVHDformat.$ qemu-img convert -f raw -o subformat=fixed,force_size -O vpc <image_example_name>.raw <image_example_name>.vhdOnce converted, the
VHDfile is ready to upload to Azure.
Next steps
- You can now configure Azure resources for your RHEL image.