guestfish

Latest response

I'm trying to figure out the proper way to use guestfish in host down scenario. Say, we have a RHEV VM that won't boot and the possible fix is to modify a config file (i.e. lvm.conf). How do I go about using guetfish to mount that file system so I can make a change to the configuration files? Basically, I want to know how to use guestfish in RHEV similar to using a rescue disk.

In the past, I tried by activating the VM's logical volume, then mounting it with guestfish. Doing this actually caused more issues that I was never able to resolve. Unfortunately, it was long enough ago, that I don't remember the exact issues.
Thank you,

Responses

Hi Douglas,

It is more easy as you might think ... all you need to do is : sudo yum install libguestfs-tools
Here are some examples how to use the tools (the virtual guest system gets mounted automatically) :

Show the content of the /etc/fstab file of the guest system ->
sudo virt-cat -d domain-name (e.g.redhat-server) /etc/fstab

Copy a file from the host /home directory into the /home directory of the guest system ->
sudo virt-copy-in -d domain-name (e.g.redhat-server) /home/user/file /home/user

Copy a file from the guest /home directory into the /home directory of the host system ->
sudo virt-copy-out -d domain-name (e.g.redhat-server) /home/user/file /home/user

Delete a file from the /home directory of the guest system ->
sudo virt-customize -d domain-name (e.g.redhat-server) --delete /home/user/file

Edit the content of the /etc/fstab file of the guest system ->
sudo virt-edit -d domain-name (e.g.redhat-server) /etc/fstab

Show the content of the /etc directory of the guest system ->
sudo virt-ls -d domain-name (e.g.redhat-server) /etc

It is recommended to execute all of these virt-* commands when the virtual machine is not running !
Hope the information is useful for you, learn more about libguestfs-tools on the libguestfs.org website. :)

Regards,
Christian

So, my guest VM is currently off line, so when I run 'virsh list --all' on the hypervisor host, I don't see the VM in the list. So, when I run the commands you suggest I get an error like following. Any ideas as to how I can see the domain when it's powered off? Thanks,

libguestfs: error: no libvirt domain called 'RHEL7_tmpl': Domain not found: no domain with matching name 'RHEL7_tmpl'

Hi Douglas,

When the virtual machines are properly created and configured, the domains should be shown.
You have to execute virsh list --all with root privileges though - example and proof :

$ virsh list --all
 Id    Name                           State
----------------------------------------------------

$ sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     centos-server                  shut off
 -     fedora-server                  shut off
 -     redhat-beta-1                  shut off
 -     redhat-beta-2                  shut off
 -     redhat-server                  shut off

$ sudo virt-cat -d redhat-server /etc/fstab

#
# /etc/fstab
# Created by anaconda on Sat Aug  5 15:08:16 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=33EE-B80C                  /boot/efi  vfat   umask=0077,shortname=winnt 0 0
UUID=8e897966-fa62-4558-89bd-3267563cc8bf  swap       swap   defaults        0 0
UUID=dcb98465-2dd8-47b9-b456-30980cc3c088  /          ext4   defaults        1 1

Regards,
Christian

Thank you for the response.

I'm on the hypervisor as root and only get VMs that are running. I'm also trying to get a listing using vdsm-client but so far, it too only shows VMs that are running.

[root@rhvhost1 ~]# virsh list --all

Id Name State

3 server1 running

Hi Douglas,

Unfortunately I have no idea why, both should be listed, the running and the shutoff ones - look here :

$ sudo virsh start redhat-server
Domain redhat-server started

$ sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 2     redhat-server                  running
 -     centos-server                  shut off
 -     fedora-server                  shut off
 -     redhat-beta-1                  shut off
 -     redhat-beta-2                  shut off  

The only reason I can imagine is, that your virtual machine is damaged or in 'unsafe' or unusable state.

Regards,
Christian

I wonder if it has to do with the permissions of the user authenticating when accessing the virsh info. The user is set in /etc/ovirt-hosted-engine/virsh_auth.conf

Probably not. I noticed that "virsh --readonly list --all" only displayed VM's that are running on the hypervisor on which the command is issued. Then I read https://access.redhat.com/discussions/672423

"When VDSM is managing a node libvirt is set to allow readonly mode (eg virsh --readonly list) any commands that require write access are locked down."

Is VDSM managing your VM's?

Hi Siem,

I checked the command you've provided and in my case the "powered off" virtual machines are listed :

$ sudo virsh --readonly list --all
 Id    Name                           State
----------------------------------------------------
 -     centos-server                  shut off
 -     fedora-server                  shut off
 -     redhat-beta-1                  shut off
 -     redhat-beta-2                  shut off
 -     redhat-server                  shut off  

Regards,
Christian

My VM's are managed bij VDSM. Are yours too?

No Siem,

I'm not managing the virtual machines with VDSM, so is this only valid when managing with VDSM ?

Regards,
Christian

According to https://access.redhat.com/discussions/672423

"When VDSM is managing a node libvirt is set to allow readonly mode (eg virsh --readonly list) any commands that require write access are locked down."

Hi Siem,

Maybe I'm a little bit confused now, but does the virsh list -all command indeed require write access ?

Regards,
Christian

I cannot think of anything written to the VM's by "virsh list --all". I just observe that adding the "--readonly" option does produce output and not the error message mentioned by Douglas.

I wonder if this has to do with the fact that this environment is RHEV 4.1 and our hypervisors are not full RHEL 7 OSs, but the small footprint of the RHEV hypervisor. I have KVM running at home, and virsh list --all works fine, but this is not just KVM.

Hi Douglas,

Yes - this is most probably the cause and might be the right explanation ... quote from Dan Yasny :

"Since RHEV hosts are managed by VDSM, that in turn uses some parts of the libvirt functionality, you should be using VDSM's command line tool, vdsClient. virsh will not be able to power a VM on anyway, because the hosts do not hold VM XML definitions."

Regards,
Christian

We run RHV 4.0 and hypervisors with full RHEL 7.3 OS and observe the same as you did.

Hi Douglas,

Can you start any other VM ? If yes, then there is possibly something wrong with this very special VM. Also, I'm starting to wonder what this special virsh problem has to do with your original question ... :)

Regards,
Christian

In order to access a VM with the virt commands, it needs to be "seen".

Hi Siem,

That is true - so I think there is something wrong with the configuration of the VM generally or with the domain name of the VM which Douglas is talking about. Means, when he cannot list or start this very VM, then he of course cannot access the VM with the libguestfs-tools. That's why I asked him if he can start any other VM. If he can't, it is more likely that the problem is the virtualization setup. :)

Regards,
Christian

I can't see any VMs that are powered off. I'm just using the one as a test, but there are several on this cluster that are powered off, yet only the ones powered on are visible. I'm guessing it has to do with what Siem was saying. I'm currently going over the link he provided to see if something there will help

Christian, Here's how virsh not working ties into the original post: all the commands you listed in your original reply include "-d domain-name", and since the VM is down, those commands won't work since libvirt doesn't see the shutdown VM. That being said, I haven't tried using those commands to access the disks associated with the powered off VM -- I'm assuming it is possible. The only issue I see, we're not using disk images, we're using pre-allocated disks which, if I understand correctly, are actually logical volumes.

-- example libguestfs: error: no libvirt domain called 'RHEL7_tmpl': Domain not found: no domain with matching name 'RHEL7_tmpl'

Hi Douglas,

Thanks for clarification. As you told us in one of your responses above a few minutes ago, you are working with RHEV in this case and at home the virsh list --all command works fine. So, I suggest that you use a virtual machine guest on your host system at home to check out the libguestfs-tools there. :)

Regards,
Christian

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.