libguestfs / virt-v2v

Virt-v2v converts guests from foreign hypervisors to run on KVM
GNU General Public License v2.0
90 stars 34 forks source link

Error when converting ovf2.0 ova file #18

Open Starrah opened 1 year ago

Starrah commented 1 year ago

I want to convert an ovf2.0 ova file to libvirt format so that I can use it in virt-manager. However, when I try to use the following command:

virt-v2v -i ova xxx.ova # xxx.ova is the filename

However, it seems like virt-v2v cannot understand the content of the .mf file in the ova file. The output is: (Some information has been replaced with xxx)

virt-v2v: virt-v2v 1.44.2 (x86_64)
libvirt version: 8.0.0
[   0.0] Opening the source -i ova ubuntu22.04-NetworkCourse-v0.1.ova
qemu-img info json:'{ "file": { "driver": "raw", "offset": 512, "size": 512, "file": { "filename": "/tmp/v2vqemuimgtst0b3733.img" } } }' >/dev/null
qemu-img supports "offset" and "size" in json URLs: true
libguestfs: trace: set_verbose true
libguestfs: trace: set_verbose = 0
libguestfs: trace: get_backend
libguestfs: trace: get_backend = "direct"
tar -tf 'xxx.ova'
tar -xf 'xxx.ova' -C '/var/tmp/ova.0bDvEc' 'ubuntu22.ovf' 'ubuntu22.mf'
libguestfs: trace: set_verbose true
libguestfs: trace: set_verbose = 0
libguestfs: trace: get_backend
libguestfs: trace: get_backend = "direct"
ova: orig_ova = xxx, top_dir = /var/tmp/ova.0bDvEc, ova_type = TarOptimized xxx
ova: processing manifest file /var/tmp/ova.0bDvEc/ubuntu22.mf
libguestfs: trace: close
libguestfs: closing guestfs handle 0x56393e07d3f0 (state 0)
libguestfs: trace: close
libguestfs: closing guestfs handle 0x56393e097710 (state 0)
virt-v2v: warning: unable to parse line from manifest file: "SHA256 
(ubuntu22-disk001.vmdk) = 
f99d291dc42a96f6f07a6df9d4f44xxxxxxecd20d913d61e609b68dcf779"
virt-v2v: warning: unable to parse line from manifest file: "SHA256 
(ubuntu22.ovf) = 
1aeb4c15217a0a92e3e08492551xxxxxx361a609976269c90b45c39164"
virt-v2v: warning: could not parse ovf:Name from OVF document
    source name: xxx
hypervisor type: vmware
       VM genid: 
         memory: 1099511627776 (bytes)
       nr vCPUs: 1
     CPU vendor: 
      CPU model: 
   CPU topology: 
   CPU features: 
       firmware: bios
        display: 
          video: 
          sound: 
disks:

removable media:

NICs:

virt-v2v: error: source has no hard disks!
rm -rf '/var/tmp/ova.0bDvEc'
rm -rf '/var/tmp/null.i3cg6v'
rwmjones commented 1 year ago

The problem is: virt-v2v: error: source has no hard disks!

What's the OVA file? Where does it come from?

rwmjones commented 1 year ago

And in particular, what's in the *.ovf file inside the ova?

Starrah commented 1 year ago

The .ova file is a OVF2.0 file. Its contains three files: image The content in the ubuntu22.ovf file is:

<?xml version="1.0"?>
<Envelope ovf:version="2.0" xml:lang="en-US" xmlns="http://schemas.dmtf.org/ovf/envelope/2" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/2" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:vbox="http://www.virtualbox.org/ovf/machine" xmlns:epasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_EthernetPortAllocationSettingData.xsd" xmlns:sasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_StorageAllocationSettingData.xsd">
  <References>
    <File ovf:id="file1" ovf:href="ubuntu22-disk001.vmdk"/>
  </References>
  <DiskSection>
    <Info>List of the virtual disks used in the package</Info>
    <Disk ovf:capacity="53687091200" ovf:diskId="vmdisk1" ovf:fileRef="file1" ovf:format="http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized" vbox:uuid="48f77291-3c6a-47c9-87ce-89ca6f6563d7"/>
  </DiskSection>
  <NetworkSection>
    <Info>Logical networks used in the package</Info>
    <Network ovf:name="NAT">
      <Description>Logical network used by this appliance.</Description>
    </Network>
  </NetworkSection>
  <VirtualSystem ovf:id="ubuntu22.04-xxx">
    <Info>A virtual machine</Info>
    <OperatingSystemSection ovf:id="94">
      <Info>The kind of installed guest operating system</Info>
      <Description>Ubuntu_64</Description>
      <vbox:OSType ovf:required="false">Ubuntu_64</vbox:OSType>
    </OperatingSystemSection>
    <VirtualHardwareSection>
      <Info>Virtual hardware requirements for a virtual machine</Info>
      <System>
        <vssd:ElementName>Virtual Hardware Family</vssd:ElementName>
        <vssd:InstanceID>0</vssd:InstanceID>
        <vssd:VirtualSystemIdentifier>ubuntu22.04-xxx</vssd:VirtualSystemIdentifier>
        <vssd:VirtualSystemType>virtualbox-2.2</vssd:VirtualSystemType>
      </System>
      <Item>
        <rasd:Caption>4 virtual CPU</rasd:Caption>
        <rasd:Description>Number of virtual CPUs</rasd:Description>
        <rasd:InstanceID>1</rasd:InstanceID>
        <rasd:ResourceType>3</rasd:ResourceType>
        <rasd:VirtualQuantity>4</rasd:VirtualQuantity>
      </Item>
      <Item>
        <rasd:AllocationUnits>MegaBytes</rasd:AllocationUnits>
        <rasd:Caption>4096 MB of memory</rasd:Caption>
        <rasd:Description>Memory Size</rasd:Description>
        <rasd:InstanceID>2</rasd:InstanceID>
        <rasd:ResourceType>4</rasd:ResourceType>
        <rasd:VirtualQuantity>4096</rasd:VirtualQuantity>
      </Item>
      <Item>
        <rasd:Address>0</rasd:Address>
        <rasd:Caption>ideController0</rasd:Caption>
        <rasd:Description>IDE Controller</rasd:Description>
        <rasd:InstanceID>3</rasd:InstanceID>
        <rasd:ResourceSubType>PIIX4</rasd:ResourceSubType>
        <rasd:ResourceType>5</rasd:ResourceType>
      </Item>
      <Item>
        <rasd:Address>1</rasd:Address>
        <rasd:Caption>ideController1</rasd:Caption>
        <rasd:Description>IDE Controller</rasd:Description>
        <rasd:InstanceID>4</rasd:InstanceID>
        <rasd:ResourceSubType>PIIX4</rasd:ResourceSubType>
        <rasd:ResourceType>5</rasd:ResourceType>
      </Item>
      <Item>
        <rasd:Address>0</rasd:Address>
        <rasd:Caption>sataController0</rasd:Caption>
        <rasd:Description>SATA Controller</rasd:Description>
        <rasd:InstanceID>5</rasd:InstanceID>
        <rasd:ResourceSubType>AHCI</rasd:ResourceSubType>
        <rasd:ResourceType>20</rasd:ResourceType>
      </Item>
      <Item>
        <rasd:Address>0</rasd:Address>
        <rasd:Caption>usb</rasd:Caption>
        <rasd:Description>USB Controller</rasd:Description>
        <rasd:InstanceID>6</rasd:InstanceID>
        <rasd:ResourceType>23</rasd:ResourceType>
      </Item>
      <Item>
        <rasd:AddressOnParent>3</rasd:AddressOnParent>
        <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation>
        <rasd:Caption>sound</rasd:Caption>
        <rasd:Description>Sound Card</rasd:Description>
        <rasd:InstanceID>7</rasd:InstanceID>
        <rasd:ResourceSubType>ensoniq1371</rasd:ResourceSubType>
        <rasd:ResourceType>35</rasd:ResourceType>
      </Item>
      <StorageItem>
        <sasd:AddressOnParent>0</sasd:AddressOnParent>
        <sasd:Caption>disk1</sasd:Caption>
        <sasd:Description>Disk Image</sasd:Description>
        <sasd:HostResource>/disk/vmdisk1</sasd:HostResource>
        <sasd:InstanceID>8</sasd:InstanceID>
        <sasd:Parent>5</sasd:Parent>
        <sasd:ResourceType>17</sasd:ResourceType>
      </StorageItem>
      <EthernetPortItem>
        <epasd:AutomaticAllocation>true</epasd:AutomaticAllocation>
        <epasd:Caption>Ethernet adapter on 'NAT'</epasd:Caption>
        <epasd:Connection>NAT</epasd:Connection>
        <epasd:InstanceID>9</epasd:InstanceID>
        <epasd:ResourceSubType>E1000</epasd:ResourceSubType>
        <epasd:ResourceType>10</epasd:ResourceType>
      </EthernetPortItem>
    </VirtualHardwareSection>
    <vbox:Machine ovf:required="false" version="1.19-windows" uuid="{657399bb-aff7-4c30-b0aa-297771b1e189}" name="ubuntu22.04-xxx" OSType="Ubuntu_64" snapshotFolder="Snapshots" lastStateChange="2022-11-14T13:03:15Z">
      <ovf:Info>Complete VirtualBox machine configuration in VirtualBox format</ovf:Info>
      <ExtraData>
        <ExtraDataItem name="GUI/AutoresizeGuest" value="false"/>
        <ExtraDataItem name="GUI/LastNormalWindowPosition" value="0,23,1280,730,max"/>
        <ExtraDataItem name="GUI/LastScaleWindowPosition" value="320,136,640,480"/>
        <ExtraDataItem name="GUI/ScaleFactor" value="1.75"/>
      </ExtraData>
      <Hardware>
        <CPU count="4">
          <PAE enabled="false"/>
          <LongMode enabled="true"/>
          <X2APIC enabled="true"/>
          <HardwareVirtExLargePages enabled="true"/>
        </CPU>
        <Memory RAMSize="4096"/>
        <Firmware type="EFI"/>
        <HID Pointing="USBTablet"/>
        <Display controller="VMSVGA" VRAMSize="16"/>
        <BIOS>
          <IOAPIC enabled="true"/>
          <SmbiosUuidLittleEndian enabled="true"/>
        </BIOS>
        <USB>
          <Controllers>
            <Controller name="OHCI" type="OHCI"/>
            <Controller name="EHCI" type="EHCI"/>
          </Controllers>
        </USB>
        <Network>
          <Adapter slot="0" enabled="true" MACAddress="0800273E698E" type="82540EM">
            <NAT/>
          </Adapter>
        </Network>
        <AudioAdapter codec="AD1980" useDefault="true" driver="WAS" enabled="true" enabledOut="true"/>
        <RTC localOrUTC="UTC"/>
        <Clipboard mode="Bidirectional"/>
        <GuestProperties>
          <GuestProperty name="/VirtualBox/GuestAdd/HostVerLastChecked" value="7.0.2" timestamp="1668421692272633100" flags=""/>
          <GuestProperty name="/VirtualBox/GuestAdd/Revision" value="154219" timestamp="1668421668932147700" flags=""/>
          <GuestProperty name="/VirtualBox/GuestAdd/Version" value="7.0.2" timestamp="1668421668931169202" flags=""/>
          <GuestProperty name="/VirtualBox/GuestAdd/VersionExt" value="7.0.2" timestamp="1668421668931169203" flags=""/>
          <GuestProperty name="/VirtualBox/GuestInfo/OS/Product" value="Linux" timestamp="1668421668930196300" flags=""/>
          <GuestProperty name="/VirtualBox/GuestInfo/OS/Release" value="5.15.0-52-generic" timestamp="1668421668930196301" flags=""/>
          <GuestProperty name="/VirtualBox/GuestInfo/OS/ServicePack" value="" timestamp="1668421668931169201" flags=""/>
          <GuestProperty name="/VirtualBox/GuestInfo/OS/Version" value="#58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022" timestamp="1668421668931169200" flags=""/>
          <GuestProperty name="/VirtualBox/HostInfo/GUI/LanguageID" value="zh_CN" timestamp="1668430121257655300" flags="RDONLYGUEST"/>
        </GuestProperties>
        <StorageControllers>
          <StorageController name="IDE" type="PIIX4" PortCount="2" useHostIOCache="true" Bootable="true">
            <AttachedDevice passthrough="false" type="DVD" hotpluggable="false" port="1" device="0"/>
          </StorageController>
          <StorageController name="SATA" type="AHCI" PortCount="1" useHostIOCache="false" Bootable="true" IDE0MasterEmulationPort="0" IDE0SlaveEmulationPort="1" IDE1MasterEmulationPort="2" IDE1SlaveEmulationPort="3">
            <AttachedDevice type="HardDisk" hotpluggable="false" port="0" device="0">
              <Image uuid="{48f77291-3c6a-47c9-87ce-89ca6f6563d7}"/>
            </AttachedDevice>
          </StorageController>
        </StorageControllers>
      </Hardware>
    </vbox:Machine>
  </VirtualSystem>
</Envelope>

The content of the ubuntu22.mf is:

SHA256 (ubuntu22-disk001.vmdk) = f99d291dc42a96f6f07a6df9d4f44fab453113decd20d913d61e609b68dcf779
SHA256 (ubuntu22.ovf) = 1aeb4c15217a0a92e3e08492551629f67646518361a609976269c90b45c39164
Starrah commented 1 year ago

I think the error maybe due to virt-v2v cannot understand the .mf file with SHA256? I think the key error, which causes final problem virt-v2v: error: source has no hard disks!, maybe actually these lines:

virt-v2v: warning: unable to parse line from manifest file: "SHA256 
(ubuntu22-disk001.vmdk) = 
f99d291dc42a96f6f07a6df9d4f44xxxxxxecd20d913d61e609b68dcf779"
virt-v2v: warning: unable to parse line from manifest file: "SHA256 
(ubuntu22.ovf) = 
1aeb4c15217a0a92e3e08492551xxxxxx361a609976269c90b45c39164"
virt-v2v: warning: could not parse ovf:Name from OVF document
rwmjones commented 1 year ago

The regexp used to parse the .mf file is: https://github.com/libguestfs/virt-v2v/blob/cfb7a97dae3c9b76ddef4d910ce5a81d5254d40b/input/OVA.ml#L268 It won't match the .mf file you have because of the extra spaces.

Although that is a bug, I don't think that is causing the problem here since we only use the .mf file for checksumming if it exists and we can understand it. The real problem seems to be something about how the files are stored in the ova file.

Anyway the more fundamental problem is since this is a virtualbox file we don't support importing from it in virt-v2v (check: https://libguestfs.org/virt-v2v-support.1.html) and you probably don't need to do use virt-v2v because the guest already has the right configuration. Just convert the vmdk file to a native format like raw or qcow2 using qemu-img convert.