Mounting RAW virtual machine images

So you got some virtual machines for the your development, tests. Need to extract some files, do a backup, without messing with the other messy OS?

For one thing there is some qemu fuse code patch (or so), floating around. However, the simple, robust and straight forward way is to simply loop-back mount the partition on a RAW file at the given offset. You can determine the offset with your favorite partition editor, or disktype. Once you know the sector offset you simply multiply it with 512 (usual sector size) as the offset like so:

mount -o loop,offset=$((123456* 512)) img.raw /mnt/tmp

Update: and for qcow et al images:

odprobe nbd
qemu-nbd -c /dev/nbd0 image.img
mount /dev/nbd0p2 /mnt

qemu-nbd –disconnect /dev/nbd0

One Response to “Mounting RAW virtual machine images”

  1. zod Says:

    another possibilty is to use kpartx which uses device-mapper to create entries for each partition

Leave a Reply

You must be logged in to post a comment.