In Linux KVM we use sparse file format called qcow
and qcow2
for disk images.
Sometimes we need to mount a qcow2 disk images of a guest devices on to your host server.
We need to do this to salvage a file, reset password of root user, or troubleshoot a faulty disk image.
We can use this dcumentation to do mount a Linux KVM guest qcow2 disk.
1. Dynamically load the NDB driver to Linux kernel
modprobe nbd max_part=8
2. Attach the QCOW2 file as network block device
qemu-nbd --connect=/dev/nbd0 /var/lib/libvirt/images/cda_vm01/cda_vm01_deb11_amd64_hd0.qcow2
3. Probing the partitions inside the newly added Block device using fdisk
fdisk /dev/nbd0 -l
4. Create a empty directory for mounting the required volumes from new Block device
mkdir -vp /mnt/virtual/cda_vm01/
5. Mounting the partition from the newly added Block device
mount /dev/nbd0p1 /mnt/virtual/cda_vm01/
6. Unmounting partition and disconnecting the block device
umount /mnt/virtual/cda_vm01/
qemu-nbd --disconnect /dev/nbd0
rmmod nbd
Done!!!