Volker Raschek
Volker Raschek

Reputation: 609

How to create vm with libvirt-go package - get boot error

I would like to create a new centos 7 vm with kickstart option over the golang library libvirt-go.

To create the new vm I need a XML-Config which I generate over the libvirt-go-xml package.

Here is my function to generate a domain struct which I parse later into a XML-Dom.

func defineDomain(domainName string, vcpu *libvirtxml.DomainVCPU, disks []libvirtxml.DomainDisk, interfaces []libvirtxml.DomainInterface, memory *libvirtxml.DomainMemory) *libvirtxml.Domain {
  domainId := 10

  domain := &libvirtxml.Domain{
    XMLName: xml.Name{
      Space: "Hello",
      Local: "World",
    },
    Type:        "kvm",
    ID:          &domainId,
    Name:        domainName,
    UUID:        uuid.Must(uuid.NewV4()).String(),
    Title:       domainName,
    Description: domainName,
    Metadata: &libvirtxml.DomainMetadata{
      XML: "",
    },
    Memory: memory,
    VCPU:   vcpu,
    OS: &libvirtxml.DomainOS{
      BootDevices: []libvirtxml.DomainBootDevice{
        libvirtxml.DomainBootDevice{
          Dev: "hd",
        },
      },
      Kernel:  "",
      Initrd:  "/home/markus/workspace/worker-management/centos/kvm-centos.ks",
      Cmdline: "ks=file:/home/markus/workspace/worker-management/centos/kvm-centos.ks method=http://repo02.agfa.be/CentOS/7/os/x86_64/",
      Type: &libvirtxml.DomainOSType{
        Arch: "x86_64",
        Type: "hvm",
      },
    },
    OnCrash:    "restart",
    OnPoweroff: "destroy",
    OnReboot:   "restart",
    Devices: &libvirtxml.DomainDeviceList{
      Emulator:   "/usr/bin/kvm-spice",
      Disks:      disks,
      Interfaces: interfaces,
      Graphics: []libvirtxml.DomainGraphic{
        libvirtxml.DomainGraphic{
          VNC: &libvirtxml.DomainGraphicVNC{
            AutoPort: "yes",
            Listen:   "127.0.0.1",
            Keymap:   "de",
            Listeners: []libvirtxml.DomainGraphicListener{
              libvirtxml.DomainGraphicListener{
                Address: &libvirtxml.DomainGraphicListenerAddress{
                  Address: "127.0.0.1",
                },
              },
            },
          },
        },
      },
    },
  }

  return domain

}

When I want to create the new vm with my XML-Dom, I get the following error. 2018/09/25 08:12:45 virError(Code=1, Domain=10, Message='internal error: process exited while connecting to monitor: 2018-09-25T06:12:45.683418Z qemu-system-x86_64: -append only allowed with -kernel option')

I defined an empty string as Kernel option, because I don't know what to show off.

Upvotes: 1

Views: 1247

Answers (1)

Michael Hampton
Michael Hampton

Reputation: 9980

You've provided a wrong Initrd:

      Initrd:  "/home/markus/workspace/worker-management/centos/kvm-centos.ks",

This is not an initrd, but your kickstart file (which you correctly specified in Cmdline.

Specifying Kernel and Initrd is not recommended. This is intended for booting a VM from a kernel which is outside the VM instance itself. In almost all circumstances, you do not want this.

Instead, this should also be the empty string, the same as Kernel. The VM will then boot from the virtual boot media (hard drive, ISO image, etc.) that you will provide.

Upvotes: 1

Related Questions