How to access/retrieve guest data from host system in kvm?

Earlier it was bit difficult to access data from guest image as it required serious attention on the process. But today it is much much easier using ‘guestmount’ binary. Thanks to libguestfs & fuse. Below snip from my Fedora system will prove my words..

[root@humbles-lap /]# which guestmount
/usr/bin/guestmount
[root@humbles-lap /]# rpm -qf /usr/bin/guestmount
libguestfs-mount-1.8.13-1.fc14.x86_64

I picked below guest and its image for experiment..

[root@humbles-lap /]# cat /etc/libvirt/qemu/rhel5.4-x86_64-kvm.xml |grep -A 2 disk

disk type=’file’ device=’disk’
driver name=’qemu’ type=’raw’
source file=’/misc/guest-images/rhel5.4-x86_64-kvm.img’

disk
disk type=’file’ device=’disk’
driver name=’qemu’ type=’raw’
source file=’/var/lib/libvirt/images/rhel5.4-x86_64-kvm-3.img’

disk
controller type=’ide’ index=’0′
address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x01′ function=’0x1′

now “mnt” is an empty mount point .

[root@humbles-lap /]# mount|grep mnt

[root@humbles-lap /]# guestmount -a /misc/guest-images/rhel5.4-x86_64-kvm.img -i –ro /mnt

[root@humbles-lap /]# mount |grep mnt
guestmount on /mnt type fuse.guestmount (rw,nosuid,nodev)

Now mnt has guest data..

[root@humbles-lap /]# cd /mnt/
[root@humbles-lap mnt]# ls
bench boot client_config_update.py etc lib lost+found misc net proc sbin srv tftpboot usr
bin client-config-overrides.txt dev home lib64 media mnt opt root selinux sys tmp var

[root@humbles-lap mnt]# cat boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
# initrd /initrd-version.img
#boot=/dev/hda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux Server (2.6.18-164.11.1.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-164.11.1.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /initrd-2.6.18-164.11.1.el5.img
title Red Hat Enterprise Linux Server (2.6.18-128.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-128.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /initrd-2.6.18-128.el5.img
[root@humbles-lap mnt]#

To unmount use below command..

[root@humbles-lap /]# fusermount -u /mnt/
[root@humbles-lap /]# mount |grep mnt
[root@humbles-lap /]#

Thats it. How-ever go for man guestmount for more details..