It has been possible for a while to use libguestfs to access a running guest by installing guestfsd in the guest.
Up until now the process required lots of manual configuration. However today (thanks to Dan and Lennart), the process is almost automatic.
You just have to install the new (Rawhide-only) libguestfs-live-service package inside the guest.
On the host, add the following clause to the guest’s XML:
<channel type='unix'> <source mode='bind' path='/var/lib/libvirt/qemu/$GUESTNAME.libguestfs' /> <target type='virtio' name='org.libguestfs.channel.0' /> </channel>
(Replace $GUESTNAME with the name of the guest. We will likely change virt-install to make the above automatic.)
Update: librarian points out that you need qemu ≥ 0.14, and you also need to change the machine type to pc-0.14
, otherwise virtio-serial sockets are not supported.
You can now connect using guestfish, eg:
# guestfish --live -d FedoraRawhidex64 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> lvs /dev/vg_fedorarawhidex64/lv_root /dev/vg_fedorarawhidex64/lv_swap ><fs> touch /tmp/foo
A word of warning: Trying to edit disk images which are in use by virtual machines is dangerous and will result in disk corruption. libguestfs live works quite differently — it talks to the daemon running inside the guest and the daemon makes the changes safely.
hi Mr. Rich, should we install libguestfs before we install libguestfs-live-service package.
thanks.
I don’t think you need to. If you need to install libguestfs explicitly, then that may be a bug.
thanks
hi Mr.Rich,
I create and manage VMs with qemu, qemu-kvm command.
I don`t use virt-manager or any libvirt`s tool.
I`ve been searching the host file system but I can`t find any guest`s xml file.
Should I use virt-manager ?
Thank you
We have a useful virt-tools list where you can get answers to all sorts of virt-related questions:
https://www.redhat.com/mailman/listinfo/virt-tools-list
thank you
Hello Rich,
I’m working on my Bachelor thesis and I would like to access to a running guest. I know that this post have been written many years ago but I even tried the solution. I installed a Rawhide version of Fedora but the libguestfs-live-service package seems to have been deleted. Is there another solution ?
Thank you
There are probably better ways to do it these days. For the filesystem you can just open it up (readonly of course). For the VM itself (ie. memory) have a look at libVMI or the other links here: https://wiki.xenproject.org/wiki/Virtual_Machine_Introspection
Hi, Mr.Rich
Now when I use the libguestfs in my project,I have a problem:
In my project, the micro service is run in the Kata container. And I hope the micro service can use libguestfs to finish the identification and operation of the filesystem in a disk file. But the kernel of Kata container that I am using now is lack of kernel modules like KVM, so creating the qemu appliance in the container is unable to achieve.
So I am thinking about making the guestfsd and our micro service run in the same container, instead of creating another qemu appliance in the container, so that micro service can communicate with guestfsd by using API that is supplied by libguestfs.
But I still don’t have a very clear clue or an achievable method to realize what I’m thinking about. What do you think of my thoughts and how can I do? I sincerely look forward to your reply.
Thanks,
Alex
You can supply an alternate kernel to libguestfs that has all the required modules. See: http://libguestfs.org/guestfs-faq.1.html#how-can-i-compile-and-install-libguestfs-if-my-distro-doesnt-have-new-enough-qemu-supermin-kernel
Hi, Rich,
Thanks for your reply.
I tried to use my kernel by set the environment variables like this:
export SUPERMIN_KERNEL_VERSION=4.19.90-vhulk2005.1.0.h124.eulerosv2r9.aarch64
export SUPERMIN_KERNEL=/tmp/kmods/boot/vmlinuz-4.19.36-vhulk1907.1.0.h453.eulerosv2r8.aarch64
export SUPERMIN_MODULES=/tmp/kmods/lib/modules/4.19.36-vhulk1907.1.0.h453.eulerosv2r8.aarch64
But I got a error when I run ‘libguestfs-test-tool’. The error description is:
qemu: linux kernel too old to load a ram disk.
What is the reason for this error? Do you have any idea about this?
Thanks.
Did you remove
/var/tmp/.guestfs-*
before each run? I can’t recall if supermin always fully rebuilds the initramfs. The error itself seems to mean that the initramfs is corrupted: https://git.qemu.org/?p=qemu.git;a=blob;f=hw/i386/x86.c;h=93f7371a569384caed29190440798f81668cd76e;hb=HEAD#l695