Wednesday, December 14, 2011

howto mount qcow2 images

Sometimes you need a way to access a virtual machine without starting it. It might dosn't work anymore and there are still some important files on it or you are simple just to lazy to start, login and change/look whatever you want to change/look for.
In case of lvm it easy: There are "real" partitions on the volume so its dead simple to mount and access the guest harddisk. It's also simple with raw files which works with loop devices thus with losetup.
Another story are qcow2 files.
For them you need qemu-nbd which comes with app-emulation/qemu-kvm and a kernel modul called nbd which you will find under: "Device Drivers --> Block devices --> Network block device support". If you didn't compile it yet (as modul) compile it now.
Next you have to load the modul with following parameters:

modprobe nbd max_part=8

You have to set the max_part because the default is 0 and usually you have more than 1 partition on a guest system. After that you can mount the image with:

qemu-nbd -c /dev/nbd0 guest.img
mount /dev/nbd0p1 /mnt/guest

That's all. With qemu-nbd -d you can disconnect the image finally, though you have to unmount it first.

No comments:

Post a Comment

Post a Comment