28

I have a QEMU virtual machine that uses a qcow2 disk image.

How can I mount its filesystem without powering on the virtual machine?

ændrük
  • 75,636
  • 74
  • 233
  • 365

4 Answers4

27

A quick google search turns up the qemu-nbd program, mentioned here. It is part of the qemu-kvm package, so you'll have to install KVM if you aren't using that already. Not sure about any direct GNOME/KDE solutions, if that is what you were looking for. Here is an example for using it:

sudo modprobe nbd
sudo qemu-nbd -c /dev/nbd0 --read-only /path/to/image.qcow2
udisksctl mount -b /dev/nbd0p1
Mihai Capotă
  • 2,158
  • 1
  • 20
  • 23
Tim Yates
  • 411
  • 4
  • 4
  • 3
    Looks like `qemu-nbd` is the best way to go, as long as I remember to `modprobe nbd` first. `qemu-nbd` fails *silently* if this module has not been loaded! – ændrük Sep 24 '10 at 16:03
  • That's unfortunate. You should be able to add `nbd` to `/etc/modules`, anyway. – Tim Yates Sep 24 '10 at 16:54
  • 1
    I wrote a little tool to wrap this up: https://github.com/JonathonReinhart/qcow2-explore – Jonathon Reinhart Nov 23 '16 at 01:49
  • `qemu-nbd` is part of the [`qemu-utils`](https://packages.ubuntu.com/bionic/qemu-utils) package, so no need to install KVM – myrdd Jan 10 '20 at 14:39
  • I must appreciate this very nice, yet simple and powerful answer. It helped me to resolve my issue in a couple of minutes. Thank you Tim Yates. – ivo Feb 11 '21 at 19:35
4

There's also libguestfs, but it's not yet available from official repositories1. There are binaries in libguestfs.org though.

sendmoreinfo
  • 224
  • 4
  • 7
  • 2
    While libguestfs looks really nice, but is heavyweight. It has a ton of dependencies (It recommends up to **55** dependencies, and installs an entire `supermin` appliance. – Stefan Lasiewski Mar 04 '13 at 05:53
-1

xmount can make the disk images of some VMs look like a raw disk (which can then be partitioned with losetup, and the partitions mounted). I don't know if it supports qcow2, however.

Gilles 'SO- stop being evil'
  • 59,745
  • 16
  • 131
  • 158
  • 1
    The [xmount manual](http://manpages.ubuntu.com/manpages/lucid/man1/xmount.1.html) states that only EWF and raw disk images can be used. – ændrük Sep 21 '10 at 02:21
-2

you can directly mount as a normal mount like this

mount /dev/sdb1 /mount-point

But if u have n number of device mean you want again mount it to another directory for that you can follow this one:

Mounting a partition from raw image is pretty simple:

losetup /dev/loop0 image.img
kpartx -a /dev/loop0
mount /dev/mapper/loop0p1 /mnt/image
Premkumar
  • 351
  • 2
  • 11