macOS-Simple-KVM icon indicating copy to clipboard operation
macOS-Simple-KVM copied to clipboard

Support usermode qemu session and make simpler add macOS to GNOME Boxes

Open kowalski7cc opened this issue 5 years ago • 14 comments
trafficstars

Updated scripts to make easier to generate domain template and add them to usermode qemu, adding support for GNOME Boxes, fixing also input using USB Tablet. Uses vga video to allow resolution selection from macOS settings. fixes #149

kowalski7cc avatar May 03 '20 20:05 kowalski7cc

This should be now fool proof!

kowalski7cc avatar May 03 '20 21:05 kowalski7cc

Thanks for this PR. I got it running on my Debian with minor changes (see inline comments/above). Note that I'm not affiliated with this project.

yan-foto avatar May 29 '20 12:05 yan-foto

I was thinking that would be interesting using Jinja templates with Python to generate the virtual machine domain.xml

kowalski7cc avatar Jul 08 '20 08:07 kowalski7cc

I tested it and the generating part seem to be fine:

❯ ./make.sh -i
How much RAM? [2]: 4
template.xml has been generated in /home/user/VMs/macOS-Simple-KVM
Creating direcories /home/user/.config/libvirt/qemu/firmware and /home/user/.local/share/gnome-boxes/images
Creating system disk /home/user/.local/share/gnome-boxes/images/macOS.qcow2 of size
How much storage? [60G]: 80
Formatting '/home/user/.local/share/gnome-boxes/images/macOS.qcow2', fmt=qcow2 size=80 cluster_size=65536 lazy_refcounts=off refcount_bits=16
Coping BaseSystem.img and ESP.qcow2 in /home/user/.local/share/gnome-boxes/images
Coping OVMF_CODE.fd in /home/user/.config/libvirt/qemu/firmware/
Coping OVMF_CODE.fd in /home/user/.config/libvirt/qemu/nvram/
Copy template.xml to /home/user/.config/libvirt/qemu
Domain macOS-Simple-KVM defined from /home/user/.config/libvirt/qemu/macOS-Simple-KVM.xml

But when I try to start it in Boxes, I'm getting this error:

Failed to start "macOS" Troubleshooting Logs

The troubleshooting log looks like this:

Broker URL: qemu+unix:///session
Domain: macOS-Simple-KVM
UUID: 7b568a24-5e97-414e-a7ba-c00a65c07e3f
Persistent: yes
Cpu time: 0
Memory: 4194304 KiB
Max memory: 32459660 KiB
CPUs: 4
State: GVIR_DOMAIN_STATE_SHUTOFF

Domain config:
------------------------------------------------------------
<domain xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0" type="kvm">
  <name>macOS-Simple-KVM</name>
  <uuid>7b568a24-5e97-414e-a7ba-c00a65c07e3f</uuid>
  <title>macOS</title>
  <memory unit="KiB">4194304</memory>
  <currentMemory unit="KiB">4194304</currentMemory>
  <vcpu placement="static">4</vcpu>
  <os>
    <type arch="x86_64" machine="pc-q35-4.2">hvm</type>
    <loader readonly="yes" type="pflash">/home/user/.config/libvirt/qemu/firmware/OVMF_CODE.fd</loader>
    <nvram>/home/user/.config/libvirt/qemu/nvram/OVMF_VARS-1024x768.fd</nvram>
    <boot dev="hd"/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <vmport state="off"/>
  </features>
  <cpu mode="custom" match="exact" check="none">
    <model fallback="forbid">qemu64</model>
    <topology sockets="1" cores="4" threads="1"/>
  </cpu>
  <clock offset="utc">
    <timer name="rtc" tickpolicy="catchup"/>
    <timer name="pit" tickpolicy="delay"/>
    <timer name="hpet" present="no"/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <pm>
    <suspend-to-mem enabled="no"/>
    <suspend-to-disk enabled="no"/>
  </pm>
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type="file" device="disk">
      <driver name="qemu" type="qcow2" cache="writeback" io="threads"/>
      <source file="/home/user/.local/share/gnome-boxes/images/ESP.qcow2"/>
      <target dev="sda" bus="sata"/>
      <address type="drive" controller="0" bus="0" target="0" unit="0"/>
    </disk>
    <disk type="file" device="disk">
      <driver name="qemu" type="qcow2" cache="writeback" io="threads"/>
      <source file="/home/user/.local/share/gnome-boxes/images/macOS.qcow2"/>
      <target dev="sdb" bus="sata"/>
      <address type="drive" controller="0" bus="0" target="0" unit="1"/>
    </disk>
    <disk type="file" device="disk">
      <driver name="qemu" type="raw"/>
      <source file="/home/user/.local/share/gnome-boxes/images/BaseSystem.img"/>
      <target dev="sdc" bus="sata"/>
      <address type="drive" controller="0" bus="0" target="0" unit="2"/>
    </disk>
    <controller type="usb" index="0" model="ich9-ehci1">
      <address type="pci" domain="0x0000" bus="0x00" slot="0x1d" function="0x7"/>
    </controller>
    <controller type="usb" index="0" model="ich9-uhci1">
      <master startport="0"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x1d" function="0x0" multifunction="on"/>
    </controller>
    <controller type="usb" index="0" model="ich9-uhci2">
      <master startport="2"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x1d" function="0x1"/>
    </controller>
    <controller type="usb" index="0" model="ich9-uhci3">
      <master startport="4"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x1d" function="0x2"/>
    </controller>
    <controller type="sata" index="0">
      <address type="pci" domain="0x0000" bus="0x00" slot="0x1f" function="0x2"/>
    </controller>
    <controller type="pci" index="0" model="pcie-root"/>
    <interface type="user">
      <mac address="AB:CD:EF:00:11:22"/>
      <model type="e1000-82545em"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x02" function="0x0"/>
    </interface>
    <serial type="pty">
      <target type="isa-serial" port="0">
        <model name="isa-serial"/>
      </target>
    </serial>
    <console type="pty">
      <target type="serial" port="0"/>
    </console>
    <input type="tablet" bus="usb">
      <address type="usb" bus="0" port="1"/>
    </input>
    <input type="keyboard" bus="usb">
      <address type="usb" bus="0" port="2"/>
    </input>
    <input type="mouse" bus="ps2"/>
    <input type="keyboard" bus="ps2"/>
    <graphics type="spice">
      <listen type="none"/>
      <image compression="off"/>
      <gl enable="no"/>
    </graphics>
    <sound model="ich9">
      <address type="pci" domain="0x0000" bus="0x00" slot="0x1b" function="0x0"/>
    </sound>
    <video>
      <model type="vga" vram="131072" heads="1" primary="yes">
        <acceleration accel3d="no"/>
      </model>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x01" function="0x0"/>
    </video>
    <redirdev bus="usb" type="spicevmc">
      <address type="usb" bus="0" port="3"/>
    </redirdev>
    <redirdev bus="usb" type="spicevmc">
      <address type="usb" bus="0" port="4"/>
    </redirdev>
    <memballoon model="none"/>
  </devices>
  <seclabel type="dynamic" model="selinux" relabel="yes"/>
  <qemu:commandline>
    <qemu:arg value="-cpu"/>
    <qemu:arg value="Penryn,kvm=on,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,vmx=on,+pcid,+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check"/>
    <qemu:arg value="-device"/>
    <qemu:arg value="isa-applesmc,osk=ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"/>
    <qemu:arg value="-smbios"/>
    <qemu:arg value="type=2"/>
  </qemu:commandline>
</domain>
------------------------------------------------------------

Any advice?

alexanderadam avatar Aug 16 '20 11:08 alexanderadam

@alexanderadam the log you pasted does not give a lot of context. You should also have a QEMU log right after the domain.xml dump. Maybe that log can give you a bit more info to debug the problem.

apiraino avatar Aug 16 '20 12:08 apiraino

@alexanderadam the log you pasted does not give a lot of context.

I was wondering about that as well.

You should also have a QEMU log right after the domain.xml dump. Maybe that log can give you a bit more info to debug the problem.

But there isn't anything after it. I used the Copy on Clipboard functionality to copy the log. Also you can see from the screenshot that the scroll bar is already on the bottom of the log.

Screenshot from 2020-08-16 14-57-03

Can I increase verbosity or is there any other place for a "full" log?

alexanderadam avatar Aug 16 '20 13:08 alexanderadam

Gnome Boxes is nothing but a nice frontend to QEMU and libvirt therefore you can try launching your KVM virtual machines by using (for example) virt-manager or (if you're comfortable with the command line) with virsh, they're both excellent tools.

With virsh I would first try the following (your output will be different):

$ virsh --connect qemu:///session

virsh # list --all
 Id   Name                         State
---------------------------------------------
 -    debian-11-testing-bullseye   shut off
 -    macOS-Simple-KVM             shut off
 -    ubuntu-20.04                 shut off
 -    win10                        shut off

virsh # start --domain macOS-Simple-KVM 
Domain macOS-Simple-KVM started

if instead you get an error, you can start investigating why.

hope this helps!

apiraino avatar Aug 16 '20 15:08 apiraino

Thank you for the hint @apiraino,

this showed the problem indeed:

virsh # start --domain macOS-Simple-KVM 
error: Failed to start domain macOS-Simple-KVM
error: unsupported configuration: Security driver model 'selinux' is not available

Therefore this is exactly the issue that was mentioned on this PR already.

So I removed the line <seclabel type="dynamic" model="selinux" relabel="yes" /> and tried to call ./make.sh -i again but it fails with error: operation failed: domain 'macOS-Simple-KVM' already exists. So I guess it would be great to have a -u, --update option at this point.

I deleted some files (i.e. /home/userconfig/libvirt/qemu/macOS-Simple-KVM.xml and /home/user/.local/share/gnome-boxes/images) but I'm still getting error: operation failed: domain 'macOS-Simple-KVM' already exists.

There also don't seem a proper delete/remove command so I tried other commands which are also leading to errors:

virsh # undefine macOS-Simple-KVM
error: Failed to undefine domain macOS-Simple-KVM
error: Requested operation is not valid: cannot undefine domain with nvram
virsh # destroy macOS-Simple-KVM
error: Failed to destroy domain macOS-Simple-KVM
error: Requested operation is not valid: domain is not running

But it works with

virsh # undefine --nvram macOS-Simple-KVM
Domain macOS-Simple-KVM has been undefined

I have to admit that the libvirt CLI and GUI responses aren't giving any hints.

Also it was not very clear to me whether I have to do 2a and 2b (because b follows after a)? Or whether this is exclusive? Because the basic.sh script seem to run another machine than Gnome Boxes.

alexanderadam avatar Aug 17 '20 09:08 alexanderadam

I agree, at the beginning the usage of these scripts is confusing. As you point out, basic.sh simply launches a QEMU virtual machine and that's all. You won't see this virtual machine anywhere in Gnome Boxes or any other libvirt frontend.

Gnome Boxes and virt-manager (frontend GUIs to libvirt) use the libvirt XML domain files to store information about your virtual machines (with virt-manager you also have a GUI to view and edit them). Gnome Boxes basically just executes them, it give you very limited tools to customize it. The make.sh script attempts to ease the creation of the XML file by using a template and populating it with your preferences.

Hope this clarifies a bit

apiraino avatar Aug 17 '20 10:08 apiraino

I agree, at the beginning the usage of these scripts is confusing.

The scripts are fine. It's the missing error message in the boxes UI and the missing hint to use --nvram in the error message error: Requested operation is not valid: cannot undefine domain with nvram that makes it difficult to debug. But it's no issue of macOS-Simple-KVM and rather a problem of libvirt / Boxes :wink:

Now I cannot create a Snapshot of the image within Boxes. Failed to create snapshot of macOS

This time there's no possibility to click for a log. ~~Any chance that you also have advice how to debug that?~~ EDIT: Nevermind. I'm sure it's related to this comment and therefore will be fixed when the comment is fixed.

alexanderadam avatar Aug 17 '20 10:08 alexanderadam

Yes, @apiraino i should make selinux line dynamic, I was thinking about using Jinja template for the XML domain

kowalski7cc avatar Aug 17 '20 21:08 kowalski7cc

Yes, @apiraino i should make selinux line dynamic, I was thinking about using Jinja template for the XML domain

I use templating engines (jinja, liquid, tera, ...) for some use cases and I like them but imo, in this case, adding a dependency for what in the end is just a couple of variable substitution, may not be worth.

I would first refine and test this PR, clear out all the comments and try to get it merged, this PR has already quite a bit of meat (smaller incremental patches have better chances)

apiraino avatar Aug 17 '20 23:08 apiraino

Works really great. Automatic detection/enabling of SELinux or not SELinux would be nice but even was no problem to remove the show stopping line in the XML file. :+1:

HenriWahl avatar May 16 '21 19:05 HenriWahl

Thanks so much for this! Just wanted to add that it worked great for me too. As a small note, it might be useful to mention for Fedora users that the libvirt package should be installed, out of the box Fedora comes with Boxes, but not this package (which comes with virsh).

After installing that I was successfully able to create and install a Catalina box. Big Sur wasn't working for me, but that seems to be an known issue with this repo judging by the several other PRs/Issues that mention this. I just thought I'd mention it as this PR has some specific changes for Big Sur in place too.

jibsaram avatar Feb 08 '22 03:02 jibsaram