Saturday, August 9, 2008

How to mount a kvm and qemu disk image file

It is an easy task to mount a kvm/qemu disk image. The magic is the offset=32256 parameter. However this magic only works on raw format disk image. If the image is in qcow or qcow2 format, you need to convert it to raw format.

# mount a raw qemu disk image 'disk.img' to /mnt
sudo mount -o loop,offset=32256 disk.img /mnt
This is an example of converting a qcow image to a raw image. Only do it if the image format is not raw.

# convert image format
qemu-img convert -f qcow disk.img -O raw disk.raw
If you are unsure about the image format, you may type this command to figure it out.

#use qemu-img info  to get the virtual disk format information

qemu-img info disk.img

image: disk.img
file format: raw
virtual size: 1.0G (1073741824 bytes)
disk size: 866M

No comments: