Laurent Vivier wrote:
Hi,
this patch allows to mount qemu disk images on the host.
It is based on the Network Block Device protocol and allows qemu-img to
become an NBD server (Yes, Anthony, userspace block device is the right
way to do that... :-P ).
FYI, I've been maintaining qemu-nbd out of tree for a while now.
http://hg.codemonkey.ws/qemu-nbd
It also includes some nice features like read-only mount and exposing an
individual partition.
Regards,
Anthony Liguori
Once you've applied the attached patch to Qemu and build the binaries,
you can use it like that:
# ./qemu-img server -d 1234 etch.qcow2
This starts an NBD server on port 1234. This server will expose
the disk image etch.qcow2. "-d" means it will be daemonize and will run
in background.
Then you need to connect the block device to the server:
# nbd-client localhost 1234 /dev/nbd0
Negotiation: ..size = 4194304KB
bs=1024, sz=4194304
This will link etch.qcow2 to /dev/nbd0.
Then to see partitions, you can use kpartx, as explained Daniel, or my
patched loop modules (I can send an updated and bug free version).
...
# kpartx -a /dev/nbd0
...
or
...
# rmmod loop
# insmod drivers/block/loop.ko max_part=64
# losetup -f /dev/nbd0
...
# mount /dev/loop0p1 /mnt
# ls /mnt
bench cdrom etc initrd.img media proc selinux tmp vmlinuz
bin clients home lib mnt root srv usr
boot dev initrd lost+found opt sbin sys var
# cd
# umount /mnt
# losetup -d /dev/loop0
# nbd-client -d /dev/nbd0
TODO: security/host client checking, device lock...
As usual all comments are welcome,
have fun,
Laurent