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

Issues related to applications and software problems
Post Reply
techana
Posts: 2
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: 1315
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: 2
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

Post Reply