On Thu, Aug 27, 2020 at 10:50:12AM +0300, Sam Eiderman wrote:
Hi,
I'm using libguestfs 1.42,
When I run the following python3 commands on a rhel7.8:
print(g.ls('/sys')) []
This lists the files in /sys in the filesystem, which in most disk images is likely to be an empty directory.
print(g.sh('ls /sys')) block bus class dev devices firmware fs hypervisor kernel module power
sh bind-mounts /sys from the appliance into the filesystem temporarily in order to make it possible to run some commands: https://github.com/libguestfs/libguestfs/blob/fce82fe55a2b64a1a7e494858aa272... However this /sys has nothing to do with /sys as it may appear in the guest when it is running. Libguestfs edits filesystems, it doesn't run the guest.
It seems that g.ls('/sys') is chrooted correctly. But g.sh('ls /sys') isn't.
I came across this behavior when I used g.command(['grub2-mkconfig', '-o', '....']) on rhel7.8 and it didn't produce the correct linuxefi/initrdefi entries in grub, since in rhel7.8 the uefi detection algorithm is checking in bash '[ -d /sys/firmware/efi ]'. https://src.fedoraproject.org/rpms/grub2/blob/71e0fb4ea646071ec86e4a65bb2424...
It's pretty unlikely that running grub can work. The libguestfs appliance is sufficiently different from how the guest boots that things like BIOS mappings are not related, and libguestfs doesn't use EFI at all. There's unfortunately no good way to run grub. syslinux/extlinux is the only option since it is designed to make modifications to offline filesystems, and grub is not. Rich.
I thought I could simply g.mkdir_p('/sys/firmware/efi') - but that created a fake dir in my chrooted environment, where grub2-mkconfig somehow was inspecting the real /sys as demonstrated in the above 'ls' example.
Any ideas on why sh jailbreaks the chroot? is /sys set through some environment variable?
Thanks!
_______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://www.redhat.com/mailman/listinfo/libguestfs
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v