Howto: Mount a QCOW2 Image

How to mount a QCOW2 image

Step 1

Login as root on the UCS host where the image can be accessed

Step 2

Enable network block device (NBD) on the Host

modprobe nbd max_part=8

Step 3

Connect the QCOW2 as network block device

qemu-nbd --connect=/dev/nbd0 /var/lib/vz/images/100/vm-100-disk-1.qcow2

Step 4

Find the Virtual Machine partitions

root@ucskvm:~# fdisk -l /dev/nbd0                                 
Disk /dev/nbd0: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000c820f

Device      Boot Start      End  Sectors Size Id Type
/dev/nbd0p1 *       63 41929649 41929587  20G 83 Linux

Step 5

Activate the partition device nodes
partx -a /dev/nbd0

Step 6

Mount the partition from the VM

mount /dev/nbd0p1 /mnt/somepoint/

Step 7

After you are done, unmount and disconnect


umount /mnt/somepoint/
qemu-nbd --disconnect /dev/nbd0
rmmod nbd
1 Like
Mastodon