qcow2 images are not flat files, see qemu-img(1). KVM ships with qemu-nbd, which lets you use the NBD protocol to share the disk image on the network.
First, for partition nbd partition support you need to be running kernel 2.6.26 (commit, changelog) or greater. For ubuntu users, that means it’s time to upgrade to intrepid ibex. Load the nbd module with:
sudo modprobe nbd max_part=8
If you leave off the max_part attribute, partitions are not supported and you’ll be able to access the disk, but not have device nodes for any of the partitions. Running
sudo qemu-nbd root.qcow2
will bind to all interfaces (0.0.0.0) and share the disk on the default port (1024). It’s important to note that the nbd kernel module produces /dev/nbd0 while the nbd-client man page recommends /dev/nb0 in it’s examples. The error message isn’t so clear, see lp:290076.
# nbd-client localhost 1024 /dev/nb0
Error: Can not open NBD: No such file or directory
This can all be reduced in steps using the ‘–connect’ option of qemu-nbd, like this:
sudo qemu-nbd --connect=/dev/nbd0 root.qcow2
At which point you can view the disk partitions:
sudo fdisk /dev/nbd0
or mount a disk, such as
mount /dev/nbd0p1 /mnt
Pingback: Marco Gabriel
Pingback: Usefull: Mounting KVM qcow2 qemu disk images « StoiloBlog: everyday administration adventures
If you’re running ubuntu, install nbd-client before issuing above commands.
This worked for me on karmic RC: http://tjworld.net/wiki/Linux/MountQemuQcowImages
# nbd-client localhost 1024 /dev/nb0
Error: Can not open NBD: No such file or directory
-> sudo nbd-client localhost 1024 /dev/nbd0
while work. the error in nbd-client come from it need some privilege
using real nbd-client on remote computer work with qemu-nbd aswell ofc.
Thanks for this very informative post! Just wanted to leave a note that on my Ubuntu 8.10 machine, I had to use kvm-nbd instead of qemu-nbd. I assume this is because we only have kvm packages installed, and I suspect that other will experience the same thing.
Pingback: qcow2 Disk Image mounten
It works for me on Ubuntu LTS 10.4! Thanks.
thanks for this, it proved helpful during my migration of a bunch of xen machines from an old to a new server.
I fixed up the wikipedia entry for qcow, combining it with qcow2, and drew on your blog for reference.
p.s. http://en.wikipedia.org/wiki/Qcow
Great!
It worked for me in debian squeeze with an vmdk image.
I ran partprobe /dev/nbd0 after qemu-nbd, then
I was able to mount “mount /dev/nbd0p1 /mnt”
Thanks for this. It helped a lot when I was hectically server swapping!
This has helped and worked on Ubuntu LTS 10.4! Thanks. but still needing a few tips. Dont know what I would do without posts like this. thanks for sharing
Pingback: qcow2 Disk Image mounten « Der Konsum