Wednesday, May 12, 2010

Mount qemu harddisk image in host system

Recently I got to copy a lot of files from a qemu guest, and I think using network is too slow, so I googled for solutions to mount qemu image in host system (when guest is shutdown). And it turns out that only raw images are supported, therefore the first step is to convert the image format:

qemu-img convert –f qcow2 origin.qcow –O raw temp.raw

Then I fount in archlinux wiki that I should mount with –loop,offset=32256 option, but I fail to figure out where 32256 comes. Luckily I remenbered how I delt with dd images. Just get the offset with fdisk:

fdisk –u –l temp.raw

Then I have the sector size (512 in my case) and the offset (2048, start sector of my partation), so the offset should be 512*2048=1048576. (btw, you can calculate with bc: echo ‘512*2048’ | bc)

mount –t ext4 –o loop,offset=1048576 temp.raw /mnt/some-path

That’s it :)

No comments:

Post a Comment