Convert your disk file from raw to qcow2

Use Virtual machines, such as within KVM, then you may be running raw disk images.

Converting them to Qcow2 will give you some advantages, such as the ability to snapshot your VM. Here we will show you how to:

  •     Check your disk file's format to see if it is raw or qcow2
  •     Convert your disk file from raw to qcow2

Check Your Format

You can test your disk file with the following command:

qemu-img info [disk filename] 

If it is a raw image format, you should get output similar to below:

image: images.programster.org.img 
file format: raw 
virtual size: 30G (32217432064 bytes) 
disk size: 30G 

If it is a qcow2 image format, then it will output something similar to:

image: images.programster.org.qcow2 
file format: qcow2 
virtual size: 30G (32217432064 bytes) 
disk size: 4.8G 
cluster_size: 65536 
Format specific information: 
    compat: 1.1
    lazy refcounts: false

 

Convert Raw To Qcow2

Simply enter the following command:

qemu-img convert -p -f raw -O qcow2 [input filename] [output filename] 

After the operation completes, you may wish to delete the original input file. You will need to update any configs that utilize the new image, such as through sudo virsh edit [VM ID] for KVM. E.g. change the type from raw to qcow2 and update the path.

 

  • The convert option tells qemu-img that we want to copy an existing image file to a new image file.
  • The -p option tells the qemu-img tool that I want to know about the progress of the copy operation.
  • The -f option specifies the format of the original input file.
  • The [input filename] parameter is the disk name of the input file.
  • The -O option specifies the format that we want to use for the output file.
  • The [output filename] parameter is the disk name of the output

 

Credits|Credits

Leave a Reply

Your email address will not be published. Required fields are marked *