kpartx tool, covered by this section, to mount the guest file system as a loop device which can then be accessed.
kpartx command creates device maps from partition tables. Each guest storage image has a partition table embedded in the file.
# yum install kpartx
guest1.img.
# kpartx -l /var/lib/libvirt/images/guest1.img
loop0p1 : 0 409600 /dev/loop0 63
loop0p2 : 0 10064717 /dev/loop0 409663
guest1 is a Linux guest. The first partition is the boot partition and the second partition is an EXT3 containing the root partition.
/dev/mapper/.
# kpartx -a /var/lib/libvirt/images/guest1.img# ls /dev/mapper/ loop0p1 loop0p2
loopXpY.
/mnt/guest1 for mounting the partition.
# mkdir /mnt/guest1
# mount /dev/mapper/loop0p1 /mnt/guest1 -o loop,ro
/mnt/guest1 directory. Read or copy the files.
# umount /mnt/guest1
# kpartx -d /var/lib/libvirt/images/guest1.imgguest1.img to the recognized devices in the /dev/mapper/ directory.
# kpartx -a /var/lib/libvirt/images/guest1.imgvgscan command to find the new volume groups.
# vgscan Reading all physical volumes . This may take a while... Found volume group "VolGroup00" using metadata type lvm2
VolGroup00 by default) with the vgchange -ay command.
# vgchange -ay VolGroup00 2 logical volumes in volume group VolGroup00 now active.
lvs command to display information about the new volumes. The volume names (the LV column) are required to mount the volumes.
# lvs LV VG Attr Lsize Origin Snap% Move Log Copy% LogVol00 VolGroup00 -wi-a- 5.06G LogVol01 VolGroup00 -wi-a- 800.00M
/dev/VolGroup00/LogVol00 in the /mnt/guestboot/ directory.
# mount /dev/VolGroup00/LogVol00 /mnt/guestboot
/mnt/guestboot directory. Read or copy the files.
# umount /mnt/guestboot
VolGroup00
# vgchange -an VolGroup00# kpartx -d /var/lib/libvirt/images/guest1.img