How to access img the image in KVM?

On the redhat website there are detailed instructionson how to mount img virtual machine image for kvm to access it, we offer a tool kpartx.

But when I type the command:

kpartx -a /path/to/guest.img

Absolutely nothing happens - the command output is empty, no device /dev/mapper/loop is not added. How to win?
March 12th 20 at 08:04
2 answers
March 12th 20 at 08:06
Solution
Solved the problem this way:
qemu-nbd -c /dev/nbd0 /path/to/guest.img
mount /dev/nbd0p1 /mnt
March 12th 20 at 08:08
But when I type the command:
kpartx -a /path/to/guest.img
Absolutely nothing happens - the command output is empty

Add-v to the command line kpartx to was not empty -- and show that output.
Same thing - empty - Lesly20 commented on March 12th 20 at 08:11
@Lesly20, I in cases where it is unclear what is happening, take a strace and got this. Making strace -e open,ioctl kpartx -a /path/to/guest.img? - Neha commented on March 12th 20 at 08:14
@Neha, Thank you, strace helped to understand that kpartx still added the device /dev/loop0
But here's what I noticed: fdisk-l /path/to/guest.img does not give partitions in the image. Respectively, and fdisk-l /dev/loop0, too. Therefore mounting fails with the error:
# mount /dev/loop0 /mnt/
mount: /dev/loop0 is write-protected, mounting read-only
mount: unknown filesystem type '(null)' - Lesly20 commented on March 12th 20 at 08:17
try to start with this
losetup /dev/loop0 /path/to/guest.img
kpartx -a /dev/loop0
...
- Santiago.Kohler commented on March 12th 20 at 08:20
fdisk-l /path/to/guest.img does not give partitions in the image

@Lesly20, and they are there? What type of image? - Neha commented on March 12th 20 at 08:23
@Neha, the image type is QEMU QCOW Image (v3)
In General I found a solution - have used qemu-nbd (with fdisk saw the partitions on /dev/nbd0):
qemu-nbd -c /dev/nbd0 /path/to/guest.img
mount /dev/nbd0p1 /mnt - Lesly20 commented on March 12th 20 at 08:26
image type QCOW QEMU

But with this, and we had to start. It's a QCOW format, kpartx can mount raw images. - Neha commented on March 12th 20 at 08:29
@Neha, Thanks, didn't know. The guide from redhat on this kind would not be said. - Lesly20 commented on March 12th 20 at 08:32

Find more questions by tags CentOSKVMVirtualizationSystem administrationLinux