In Abiquo environments, it’s common for the Cloud Admin to have permissions to access every VM on the platform. However, sometimes it’s not easy to get into these systems.
Imagine you have a virtual machine that has lost connectivity, VNC is unavaliable, it’s corrupted or you don’t know the login and password to get some important file.

libguestfs can help us to get into our virtual machines with some very easy steps.


First of all, keep in mind that the VM should be powered off if you want to make any changes in the filesystem, otherwise everything could end in disaster:

“Using guestfish in read/write mode on live virtual machines can be dangerous, potentially causing disk corruption. Use the –ro (read-only) option to use guestfish safely if the disk image or virtual machine might be live.”

Log in to the CentOS 6 machine and let’s get started:

Install EPEL6 repository:
[code light=”true”] rpm -Uvh
[/code] Install required packages (yes! we have support for Windows too):
[code light=”true”] yum install -y guestfish sshfs libguestfs-winsupport
[/code] Mount hypervisor’s datastore locally with sshfs. For example, for a Abiquo KVM/Xen node:
[code light=”true”] mkdir virt && sshfs root@ virt
[/code] If it is an ESX or ESXi node, the guest machine should be shut down as the hypervisor prevents access otherwise.
Start guestfish shell with the image of the virtual machine you want to inspect:
[code light=”true”] guestfish -a virt/ABQ_25ac9957-7970-4fca-9f9d-caef3fa092ab
[/code] Run or launch guestfish and list the filesystems (the run command can take a while to finish):
[code light=”true”] ><fs> run
><fs> list-filesystems
/dev/vda1: ext4
/dev/vg/lv_root: ext4
/dev/vg/lv_swap: swap
[/code] We can guess that the root filesystem should be located at /dev/vg/lv_root
Mount this device:
[code light=”true”] ><fs> mount /dev/vg/lv_root /
[/code] And now we can read (and write if you are running guestfish in rw mode) the filesystem:
[code light=”true”] ><fs> cat /etc/redhat-release
Fedora release 17 (Beefy Miracle)

><fs> vi /etc/passwd
><fs> exit
[/code] Let’s try with a running Windows guest now:
[code light=”true”] [root@localhost ~]# guestfish –ro -a virt/ABQ_795525bf-b1e7-4287-aef2-81262de6779b
Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.

Type: ‘help’ for help on commands
‘man’ to read the manual
‘quit’ to quit the shell

><fs> run
><fs> list-filesystems
/dev/vda1: ntfs
/dev/vda2: ntfs
><fs> mount /dev/vda1 /
><fs> ls /
System Volume Information
[/code] Now we can get some other OS information:
[code light=”true”] ><fs> inspect-os
><fs> inspect-get-arch /dev/vda2
><fs> inspect-get-product-name /dev/vda2
Windows Server 2008 R2 Enterprise

Don’t forget to unmount sshfs after you’re done:
[code light=”true”] ><fs> exit
[root@localhost ~]# fusermount -u virt/