macOS VM Guest Installation: from qemu-kvm to virt-install

Issues related to applications and software problems
Post Reply
techana
Posts: 5
Joined: 2018/09/14 07:39:43

macOS VM Guest Installation: from qemu-kvm to virt-install

Post by techana » 2018/09/14 08:05:45

Here is the command I use to successfully run macOS on KVM:

Code: Select all

sudo /usr/libexec/qemu-kvm \
    -machine q35,accel=kvm \
    -m 4096 \
    -cpu Penryn -smp 4,cores=2 \
    -bios ./osx-kvm-2/share/qemu/bios-mac.bin \
    -kernel /var/lib/libvirt/images/enoch_rev2902_boot \
    -usb -device usb-kbd -device usb-tablet \
    -netdev user,id=usr0 -device e1000,netdev=usr0,id=vnet0 \
    -device ide-drive,bus=ide.0,drive=MacDVD \
    -drive id=MacDVD,if=none,snapshot=on,file=/var/lib/kimchi/isos/Install_macOS_10.12.5_Sierra.iso \
    -device ide-drive,bus=ide.2,drive=MacHDD \
    -drive id=MacHDD,if=none,file=./mac_hdd.img
With the above command, the boot kernel recognizes the disks and shows them in the boot options menu:
Image

I wanted to install the guest permanently in KVM as a domain. I tried to translate the above command as follows:

Code: Select all

sudo virt-install --virt-type=kvm \
 --name macOSSierra \
 --machine q35 --virt-type kvm \
 --memory 4096 \
 --cpu Penryn --vcpus sockets=2,cores=4,threads=2 \
 --disk size=32 \
 --disk /var/lib/kimchi/isos/Install_macOS_10.12.5_Sierra.iso,device=cdrom,perms=ro \
 --boot kernel=/var/lib/libvirt/images/enoch_rev2902_boot,cdrom \
 --input tablet,bus=usb \
 --input keyboard,bus=usb \
 --network network=default,model=e1000
The installed domain runs, but the boot kernel cannot see the disks, so it shows an empty menu:
Image

Any idea what went wrong with the virt-install command?

Thank you.
Last edited by techana on 2018/09/16 13:50:01, edited 1 time in total.

hunter86_bg
Posts: 2019
Joined: 2015/02/17 15:14:33
Location: Bulgaria
Contact:

Re: Translating qemu-kvm Command into virt-install One?

Post by hunter86_bg » 2018/09/14 19:05:59

Try to define in virt-install that the storage is IDE, as most probably it tries with SATA (this is just a guess).

techana
Posts: 5
Joined: 2018/09/14 07:39:43

Re: Translating qemu-kvm Command into virt-install One?

Post by techana » 2018/09/16 13:38:33

Finally, I was able to add a macOS as a domain into qemu-kvm in centOS. Instead of using "virt-install", I created an XML definition and imported it. Here I post the XML for anyone who may need it:

Code: Select all

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <name>OSX_KVM</name>
  <title>OSX-KVM</title>
  <description># echo 1 &gt; /sys/module/kvm/parameters/ignore_msrs</description>
  <memory unit='KiB'>4194304</memory>
  <currentMemory unit='KiB'>4194304</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <os>
    <type arch='x86_64' machine='pc-q35-rhel7.5.0'>hvm</type>
    <kernel>/var/lib/libvirt/images/enoch_rev2902_boot</kernel>
  </os>
  <features>
    <acpi/>
    <kvm>
      <hidden state='on'/>
    </kvm>
  </features>
  <cpu mode='custom' match='exact'>
    <model fallback='allow'>Penryn</model>
  </cpu>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/home/mans/workarea/macosx_kvm/mac_hdd.img'/>
      <target dev='sda' bus='sata'/>
      <boot order='1'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <interface type='network'>
      <source network='default'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x02' function='0x0'/>
    </interface>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='vnc' port='5900' autoport='no' listen='127.0.0.1' keymap='en-us'>
      <listen type='address' address='127.0.0.1'/>
    </graphics>
    <video>
      <model type='qxl' vram='16384' heads='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
    </video>
    <memballoon model='none'/>
  </devices>
  <qemu:commandline>
    <qemu:arg value='-usb'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='usb-tablet,bus=usb-bus.0'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='usb-kbd,bus=usb-bus.0'/>
  </qemu:commandline>
</domain>
Then:

Code: Select all

sudo virsh define macos_vm.xml
Of course, one needs to create "mac_hdd.img" first using:

Code: Select all

qemu-img create -f qcow2 mac_hdd.img 64G
Then install macOS in that image using the "/usr/libexec/qemu-kvm" command in the original post.

Also, sometime qemu-kvm refuses executing "<qemu:commandline>" portion. In this case, edit the domain using:

Code: Select all

sudo virsh edit OSX_KVM
Then ensure the first line reads exactly as:

Code: Select all

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
EDIT: where recognition is due, this project helped me a lot: https://github.com/kholia/OSX-KVM

letran
Posts: 2
Joined: 2019/01/07 03:18:38

Re: macOS VM Guest Installation: from qemu-kvm to virt-install

Post by letran » 2019/01/07 03:24:44

please help me.
I use your file html to create a VM and started, but VM don't have interface network
this is my file html.

Code: Select all

<domain type='kvm' id='87' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <name>OSX_KVM</name>
  <uuid>6b13d768-baca-445e-a841-e1df9ae48179</uuid>
  <title>OSX-KVM</title>
  <description># echo 1 &gt; /sys/module/kvm/parameters/ignore_msrs</description>
  <memory unit='KiB'>4194304</memory>
  <currentMemory unit='KiB'>4194304</currentMemory>
  <vcpu placement='static'>4</vcpu>
  <resource>
    <partition>/machine</partition>
  </resource>
  <os>
    <type arch='x86_64' machine='pc-q35-rhel7.3.0'>hvm</type>
    <kernel>/var/kvm/ISO/OSX-KVM/enoch_rev2902_boot</kernel>
  </os>
  <features>
    <acpi/>
    <kvm>
      <hidden state='on'/>
    </kvm>
  </features>
  <cpu mode='custom' match='exact' check='full'>
    <model fallback='forbid'>Penryn</model>
    <feature policy='require' name='vme'/>
    <feature policy='require' name='x2apic'/>
    <feature policy='require' name='hypervisor'/>
  </cpu>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/data/mac_hdd.img'/>
      <backingStore/>
      <target dev='sda' bus='sata'/>
      <boot order='1'/>
      <alias name='sata0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw' cache='none'/>
      <source file='/data/usb-test.img'/>
      <backingStore/>
      <target dev='sdb' bus='usb'/>
      <alias name='usb-disk1'/>
      <address type='usb' bus='0' port='1'/>
    </disk>
    <controller type='usb' index='0' model='nec-xhci'>
      <alias name='usb'/>
      <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
    </controller>
    <controller type='sata' index='0'>
      <alias name='ide'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pcie-root'>
      <alias name='pcie.0'/>
    </controller>
    <controller type='pci' index='1' model='dmi-to-pci-bridge'>
      <model name='i82801b11-bridge'/>
      <alias name='pci.1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x1e' function='0x0'/>
    </controller>
    <controller type='pci' index='2' model='pci-bridge'>
      <model name='pci-bridge'/>
      <target chassisNr='2'/>
      <alias name='pci.2'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    </controller>
    <controller type='pci' index='3' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='3' port='0x10'/>
      <alias name='pci.3'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0' multifunction='on'/>
    </controller>
    <controller type='pci' index='4' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='4' port='0x11'/>
      <alias name='pci.4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x1'/>
    </controller>
    <interface type='bridge'>
      <mac address='52:54:00:c7:ca:5c'/>
      <source network='localbr' bridge='localbr'/>
      <virtualport type='openvswitch'>
        <parameters interfaceid='0e2db0f2-6637-478e-bb2b-fc15890c2e00'/>
      </virtualport>
      <target dev='vnet4'/>
      <model type='e1000'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x02' function='0x0'/>
    </interface>
    <input type='mouse' bus='ps2'>
      <alias name='input0'/>
    </input>
    <input type='keyboard' bus='ps2'>
      <alias name='input1'/>
    </input>
    <graphics type='vnc' port='5903' autoport='yes' listen='0.0.0.0' keymap='en-us'>
      <listen type='address' address='0.0.0.0'/>
    </graphics>
    <video>
      <model type='qxl' ram='65536' vram='16384' vgamem='16384' heads='1' primary='yes'/>
      <alias name='video0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
    </video>
    <memballoon model='none'/>
  </devices>
  <seclabel type='none' model='none'/>
  <seclabel type='dynamic' model='dac' relabel='yes'>
    <label>+107:+107</label>
    <imagelabel>+107:+107</imagelabel>
  </seclabel>
  <qemu:commandline>
    <qemu:arg value='-usb'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='usb-tablet,bus=usb-bus.0'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='usb-kbd,bus=usb-bus.0'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='ide-drive,bus=ide.1,drive=MacDVD'/>
    <qemu:arg value='-drive'/>
    <qemu:arg value='id=MacDVD,if=none,snapshot=on,file=/var/kvm/ISO/Install_macOS_10.12.4_Sierra.iso'/>
  </qemu:commandline>
</domain>
Last edited by letran on 2019/01/08 03:07:21, edited 2 times in total.

letran
Posts: 2
Joined: 2019/01/07 03:18:38

Re: Translating qemu-kvm Command into virt-install One?

Post by letran » 2019/01/07 04:03:09

techana wrote:
2018/09/16 13:38:33
Finally, I was able to add a macOS as a domain into qemu-kvm in centOS. Instead of using "virt-install", I created an XML definition and imported it. Here I post the XML for anyone who may need it:

Code: Select all

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <name>OSX_KVM</name>
  <title>OSX-KVM</title>
  <description># echo 1 &gt; /sys/module/kvm/parameters/ignore_msrs</description>
  <memory unit='KiB'>4194304</memory>
  <currentMemory unit='KiB'>4194304</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <os>
    <type arch='x86_64' machine='pc-q35-rhel7.5.0'>hvm</type>
    <kernel>/var/lib/libvirt/images/enoch_rev2902_boot</kernel>
  </os>
  <features>
    <acpi/>
    <kvm>
      <hidden state='on'/>
    </kvm>
  </features>
  <cpu mode='custom' match='exact'>
    <model fallback='allow'>Penryn</model>
  </cpu>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/home/mans/workarea/macosx_kvm/mac_hdd.img'/>
      <target dev='sda' bus='sata'/>
      <boot order='1'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <interface type='network'>
      <source network='default'/>
      <model type='e1000'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x02' function='0x0'/>
    </interface>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='vnc' port='5900' autoport='no' listen='127.0.0.1' keymap='en-us'>
      <listen type='address' address='127.0.0.1'/>
    </graphics>
    <video>
      <model type='qxl' vram='16384' heads='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
    </video>
    <memballoon model='none'/>
  </devices>
  <qemu:commandline>
    <qemu:arg value='-usb'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='usb-tablet,bus=usb-bus.0'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='usb-kbd,bus=usb-bus.0'/>
  </qemu:commandline>
</domain>
Then:

Code: Select all

sudo virsh define macos_vm.xml
Of course, one needs to create "mac_hdd.img" first using:

Code: Select all

qemu-img create -f qcow2 mac_hdd.img 64G
Then install macOS in that image using the "/usr/libexec/qemu-kvm" command in the original post.

Also, sometime qemu-kvm refuses executing "<qemu:commandline>" portion. In this case, edit the domain using:

Code: Select all

sudo virsh edit OSX_KVM
Then ensure the first line reads exactly as:

Code: Select all

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
EDIT: where recognition is due, this project helped me a lot: https://github.com/kholia/OSX-KVM
I use your file html to create and started VM, but it's don't have interface network

Post Reply