Mounting QEmu qcow2 Image using NBD

For some reason, I had to mount a QEmu qcow2 image in the host system. I googled around and found some post on the qemu-dev list. Also, the QEmu FAQ answers whether one can mount any QEmu image, but it’s not very verbose. So I went and tried and voila: It works 🙂

muelli@xbox:~$ qemu-nbd --read-only --partition=1  --snapshot  winxp.img &
muelli@xbox:~$ sudo nbd-client localhost 1024 /dev/nbd0
Negotiation: ..size = 31447206KB
bs=1024, sz=31447206
muelli@xbox:~$ sudo mount /dev/nbd0 -oloop  ~/empty/
muelli@xbox:~$ ls -l /home/muelli/empty/
total 1744981
-rwxrwxrwx 1 root root         0 2009-03-13 18:35 AUTOEXEC.BAT
-rwxrwxrwx 1 root root      4952 2008-04-14 09:00 bootfont.bin
-rwxrwxrwx 1 root root       207 2009-03-13 18:27 boot.ini
-rwxrwxrwx 1 root root         0 2009-03-13 18:35 CONFIG.SYS
drwxrwxrwx 1 root root      4096 2009-03-13 19:17 Dokumente und Einstellungen
drwxrwxrwx 1 root root         0 2009-03-13 22:02 Driver
-rwxrwxrwx 1 root root 536399872 2009-04-04 14:37 hiberfil.sys
-rwxrwxrwx 1 root root         0 2009-03-13 18:35 IO.SYS
-rwxrwxrwx 1 root root         0 2009-03-13 18:35 MSDOS.SYS
drwxrwxrwx 1 root root      4096 2009-03-13 22:29 nlite
-rwxrwxrwx 1 root root     47564 2008-04-14 09:00 NTDETECT.COM
-rwxrwxrwx 1 root root    251712 2008-04-14 09:00 ntldr
-rwxrwxrwx 1 root root 805306368 2009-04-04 14:37 pagefile.sys
drwxrwxrwx 1 root root         0 2009-03-13 19:03 Postinstall
drwxrwxrwx 1 root root      4096 2009-03-13 20:59 Programme
drwxrwxrwx 1 root root      4096 2009-03-13 19:06 System Volume Information
drwxrwxrwx 1 root root     32768 2009-04-04 14:40 WINXP

It uses a technology I’ve never heard of: Network Block Device (NBD). Now I’m a bit smarter. And I hope you can make use of this information 🙂

5 thoughts on “Mounting QEmu qcow2 Image using NBD”

  1. Hi,

    I am a newbie to nbd. I found this site while I was searching for a method to mount qcow image. I tried what you posted here but it didn’t work. When I issued the nbd-client cmd, it never returned after printing out Negotiation: . Am I supposed to run a nbd server?

    Thanks in advance,

  2. Yes, you are supposed to run the nbd server. But that’s qemu-nbd’s job. So make sure that runs properly. If you provide the commands you issue, we might be able to debug this issue.

    1. Thanks for your quick reply.

      I did exactly what you suggested above except that I installed nbd-client beforehand:

      $ sudo apt-get install nbd-client
      $ qemu-nbd –read-only –partition=1 –snapshot xp_he_sp2_QCOW2.img &
      [1]+ Exit 1 qemu-nbd –read-only –partition=1 –snapshot xp_he_sp2_QCOW2.img
      $ sudo nbd-client localhost 1024 /dev/nbd1

      And it is there…

      How can I tell if the server is running properly?

      Thanks again,

      1. hm. you see, it qemu-nbd exists with the code 1, so it does not run. You might want to try –verbose to get a hint as to whats going wrong. But I imagine that the –snapshot is not necessary for you, so just try running without that argument.

        1. I tried –verbose without –snapshot, but it doesn’t say anything but exit 1.
          man qemu-nbd does not give any useful info for this.

          I will continue surfing the web on this issue.

Leave a Reply

Your email address will not be published. Required fields are marked *

Creative Commons Attribution-ShareAlike 3.0 Unported
This work by Muelli is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported.