I discovered that when a VM has an ISO attached via CD-ROM, libguestfs
fails to read its partition table and therefore fails to perform basic
operations on a VM, e.g. listing a directory or editing a file:

# virsh domblklist rocky9-vm
Target Source
---------------------------------------------------------------------------
 sda   /vz/vmprivate/e827caad-b9e4-4858-b3dc-53ae6b8a5145/harddisk.hdd
 sdb   /vzt/images/Rocky-9.3-x86_64-minimal.iso

# virt-ls -d rocky9-vm /
libguestfs: error: inspect_os: sgdisk: Invalid partition data!

# virt-edit -d rocky9-vm /etc/fstab
libguestfs: error: inspect_os: sgdisk: Invalid partition data!


Even virt-inspector can't give us proper output on an ISO9660 image:

# virt-inspector /vzt/images/Rocky-9.3-x86_64-minimal.iso
libguestfs: error: inspect_os: sgdisk: Invalid partition data!
virt-inspector: no operating system could be detected inside this disk
image.
...


First I found a 3 years old topic where you suggested that sgdisk itself
might be too old:
https://listman.redhat.com/archives/libguestfs/2021-March/025939.html.
However this doesn't seem to be it in this case:
I've compiled the latest version from
https://sourceforge.net/projects/gptfdisk -- no luck as well.  Seems
that sgdisk isn't capable of recognizing ISO9660 images.

Then I noticed 2 things:

1. libguestfs appliance is being created (with backend=libvirt) with ISO
attached as device='disk' (not 'cdrom'):

>     <disk type='file' device='disk'>                                          
>   
>       <driver name='qemu' type='qcow2' cache='unsafe'/>                       
>   
>       <source file='/tmp/libguestfsD7IHvF/overlay2.qcow2' index='2'/>         
>   
>       <backingStore type='file' index='5'>                                    
>   
>         <format type='raw'/>                                                  
>                                                                               
>    
>         <source file='/vzt/images/Rocky-9.3-x86_64-minimal.iso'/>             
>      
>         <backingStore/>                                                       
>      
>       </backingStore>                                                         
>      
>       <target dev='sdb' bus='scsi'/>                                          
>   
>       <alias name='scsi0-0-1-0'/>                                             
>   
>       <address type='drive' controller='0' bus='0' target='1' unit='0'/>      
>   
>     </disk>

That forces this disk to be supplied with "scsi-hd" driver in use, which
in turn leads to the device being visible inside the guest as a regular
SCSI hdd /dev/sdb.  Shouldn't we, for instance, make sure that for such
images device='cdrom' and "scsi-cd" driver are being used?  In this case
the guest will see it as /dev/sr0, and I suspect srX devices are being
skipped by guestfs_inspect_os.

2. When trying to perform the same operation via guestfish, everything
appears to be working:

# guestfish -a /vzt/images/Rocky-9.3-x86_64-minimal.iso -m /dev/sda ls /
>/dev/null && echo $?
0

File edit works as well.  From debug output I see that sgdisk isn't
being invoked at all.  That means there's a code path for the same
operations where sgdisk can be omitted.  Maybe we should follow that
same code path when invoking other tools like virt-ls or virt-edit?


Overall, what would be an appropriate fix in your opinion?  We should at
least make sure that working with domains (with the "-d" option) works
no matter what.

Andrey
_______________________________________________
Libguestfs mailing list -- guestfs@lists.libguestfs.org
To unsubscribe send an email to guestfs-le...@lists.libguestfs.org

Reply via email to