How to access proxmox disk image file on host?
Recently I could not connect to my proxmox virtual machine on which I had some important files for my project. In this tutorial I will show how to easily mount a disk from a proxmox virtual machine and access its data.
- Find your .qcow2 disk image file which you would like to mount. They are located usually under
/var/lib/vz/images
folder.
sudo ls /var/lib/vz/images/*
/var/lib/vz/images/100:
vm-100-disk-0.qcow2 vm-100-disk-1.qcow2
/var/lib/vz/images/101:
vm-101-disk-0.qcow2 vm-101-disk-1.qcow2
/var/lib/vz/images/106:
vm-106-disk-0.qcow2 vm-106-disk-1.qcow2>)
- Ensure that nbd module is loaded into kernel.
The nbd kernel module stands for Network Block Device. It allows you to treat a file like a .qcow2 disk image as if it was a local disk represented by block devices like /dev/nbd*
.
sudo modprobe nbd max_part=8
- Use qemu-nbd to attach the .qcow2 disk image to an NBD device.
qemu-nbd is a tool from the QEMU suite that allows disk images (such as .qcow2 files) to be attached to the host’s NBD system, making them accessible as block devices like in this example /dev/nbd0
.
qemu-nbd --connect=/dev/nbd0 /var/lib/vz/images/100/vm-100-disk-0.qcow2
- Identify partitions on the disk.
fdisk -l /dev/nbd0
Device Start End Sectors Size Type
/dev/nbd0p1 2048 1050623 1048576 512M EFI System
/dev/nbd0p2 1050624 65107967 64057344 30.5G Linux filesystem
/dev/nbd0p3 65107968 67106815 1998848 976M Linux swap
- Mount the partition in which you are interested in. In my case it was
/dev/nbd0p2
.
mkdir -p /mnt/data
mount /dev/nbd0p2 /mnt/data
- You can now navigate to
/mnt/data
to access the files on the .qcow2 disk.
cd /mnt/data
- After accessing the data, unmount the partition and disconnect the NBD device.
umount /mnt/data
qemu-nbd --disconnect /dev/nbd0
That's all! As you see it's so easy to access .qcow2 disk images from a host. Hope that helped you!
Thanks for reading! Read other posts?