3
Storage
KosiehBarter edited this page 2026-04-18 22:14:05 +01:00

General

Caution

Do not mount virtual machine's storage while it is running. This will cause data corruption.

QCOW2 (native LibvirtD format)

How to mount it:

Step Command Reasons/Notes
1 modprobe nbd max_part=8 This loads Network Block Device kernel modules and defines maximum partitions to be 8. You can use your own number.
2 qemu-nbd --connect=/dev/nbd0 /path/to/your/image.qcow2 This 'probes the image with QEMU's tools. Essentially you are "mimicking" a network storage to mount it. The /dev/nbd0 is a "default", you can use your own, but recommending to keep the /dev/ path as a good practice.
3 fdisk -l /dev/nbd0 You can now "probe" and list the actual device, including it's partitions. Possibly create new ones.
4 mount /dev/nbd0p<number> /your/desired/mountpath This mounts the partition for writting.
5 umount /your/desired/mountpath && qemu-nbd --disconnect /dev/nbd0 When done, unmount it and disconnect it.
6 rmmod nbd For consistency, you can also unload the NBD mod.

Raw disk image

How to mount it:

Step Command Reasons/Notes
1 kpartx -av /path/to/your/raw.img First, you need to "mount" the image as loop, because of internal structure. This creates items under /dev/, named loopXpY.
2 mount /dev/loopXpY /your/desired/mountpath/ Mount it the standard way, append your mount options if needed.
3 umount /your/mounted/mountpath Unmount it, when done.
4 kpartx -dv /path/to/your/raw.img And release it completely for VM to use.