You should use libguestfs live with libvirt because it takes the pain out of it.
However if for some reason you don’t want to use libvirt, here is how to use it directly. Note normally you should use libvirt and you do not need to do any of this!
(1) Your guest needs to have
guestfsd -r installed and running. [Normally you just install
libguestfs-live-service which does everything necessary]
(2) You need to start up qemu (the guest) with these special options, or the equivalent. [Normally you just set this up through libvirt]
-chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -chardev socket,id=charchannel0,path=/tmp/socket,server,nowait -device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=org.libguestfs.channel.0
(3) Start guestfish and use the
attach-method command to point to the socket. [Normally using ‘-d Guest –live’ does all this automatically for you by getting the necessary information out of libvirt]
$ guestfish ><fs> attach-method unix:/tmp/socket ><fs> run ><fs> ll / [use libguestfs command as normal here]