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.
- CentOS 6 machine
- libguestfs and guestfish
- ssh access to the hypervisor
- Name of the VM and path to the datastore
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.”
Save time and money with Abiquo by reducing management complexity, offer different network SLAs to your customers and improve usability.
Install EPEL6 repository:
rpm -Uvh http://mirror.bytemark.co.uk/fedora/epel/6/i386/epel-release-6-8.noarch.rpm
Install required packages (yes! we have support for Windows too):
yum install -y guestfish sshfs libguestfs-winsupport
Mount hypervisor’s datastore locally with sshfs. For example, for a Abiquo KVM/Xen node:
mkdir virt && sshfs firstname.lastname@example.org:/var/lib/virt virt
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:
guestfish -a virt/ABQ_25ac9957-7970-4fca-9f9d-caef3fa092ab
Run or launch guestfish and list the filesystems (the run command can take a while to finish):
><fs> run ><fs> list-filesystems /dev/vda1: ext4 /dev/vg/lv_root: ext4 /dev/vg/lv_swap: swap
We can guess that the root filesystem should be located at /dev/vg/lv_root
Mount this device:
><fs> mount /dev/vg/lv_root /
And now we can read (and write if you are running guestfish in rw mode) the filesystem:
><fs> cat /etc/redhat-release Fedora release 17 (Beefy Miracle) ><fs> vi /etc/passwd ><fs> exit
Let’s try with a running Windows guest now:
[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 / BOOTSECT.BAK Boot System Volume Information bootmgr
Now we can get some other OS information:
><fs> inspect-os /dev/vda2 ><fs> inspect-get-arch /dev/vda2 x86_64 ><fs> inspect-get-product-name /dev/vda2 Windows Server 2008 R2 Enterprise
Don’t forget to unmount sshfs after you’re done:
><fs> exit [root@localhost ~]# fusermount -u virt/