天天看點

在阿裡雲上安裝黑蘋果(2):本地虛拟機方案研究和可行資源參考

本文關鍵字:虛拟機黑蘋果,osx kvm guest

在《在阿裡雲上安裝蘋果(1)》中我們講到實機上安裝黑蘋果是一件難事,但也不是不可能,因為有全套的clover方案和不斷豐富的kexts(kexts是EFI專屬驅動,不是OS用的),如果硬體有問題,比如CPU不支援osx特有的指令擴充(低标準CPU不能運作OSX,To run MacOS Mojave, you need a processor with support for sse4.1 and sse4.2 instructions),主機闆不支援UEFI,顯示卡不受osx支援。我們換了它們就是。而雲主機,比如阿裡雲,(1)我們除了不能控制它的硬體類型如CPU等,(2)還由于它是一種Qemu/kvm/virtio架構。是一種遠端host架構,我們沒有辦法控制host,充其量隻能在本地支援VT的實機上自建Qemu/kvm host/guest的虛拟機環境裡搗鼓測試,(3)雖然本地都是自己可以控制的全套host/guest虛拟機方案,但虛拟機本身也有它特殊的局限,它不同于實機,是沒有UEFI的(4)最後,還由于雲主機是虛拟機的一種局限類型和特殊類型,我們除了得不到它的UEFI控制隻能得到其guest之外,還要面對其僅支援從mbr+bios中啟動系統(5)不論是實體虛拟機,還是雲guest only虛拟機,我們都面對需內建virtio的事實。4,5關聯緊密。因為UEFI中的驅動跟OS中的驅動聯系緊密。

故在雲主機上安裝黑蘋果就更是一件難事了,每一個新出現的大問題。都有可能使我們的最終目的泡湯。—— 但好在市面上支援osx vm的現行虛拟化方案(使用clover或不使用clover方案的黑蘋果,甚至白蘋果)也不少,如un-locker+vmware也可以,parallesdesk也可以是最好用的(它是白蘋果),qemu/kvm下面的osx guest方案當然就更可以了。最接近我們這裡要講的阿裡雲的要算qemu/kvm/virtio了 ,在雲主機上安osx的方案似乎并沒有。但—— 但我們的努力總不緻于毫無希望。

解決虛拟機上黑蘋果的安裝條件:軟體/硬體/固件測試環境準備

對于(1),我們可以換配置的方式來解決,如果不能就換服務商。這個略過。我們僅首先考慮本地虛拟機的情況(2)我們差不多不可能找到一家提供nested kvm和再虛拟化的雲主機,除非裸金屬,不過其投入很高。同2略過(3)虛拟機上有OVMF這樣的東西代替UEFI,OVMF "is a project to enable UEFI support for Virtual Machines”(它依賴edk2的跨平台uefi方案)。不過OVMF隻能用在HOST端,做成一檔案作為參數傳遞給虛拟機啟動程式,(4)如果說1,2,3都是在實體虛拟機上的解決之法,那麼對于4,雲主機,我們隻能用上clover方案了,因為ovmf在這裡不可用,且隻有clover是同時支援bios和uefi系統的。那麼是否它能用在阿裡雲機器上啟動clover?(5)驅動方面,有一些第三方uefi virtio driver的這些可以被以clover常用的方式用到黑蘋果上(将virtio xxx.pkg放到kexts中使用),最近的Mojave 10.13.3/4官方才開始有virtio支援,它是OSX内部的virtio。不過blk隻能工作在legacy模式。那麼問題來了,是否采用clover的傳統模式下繞過uefi,依然可以用上virtio?osx是一定要用到efi的。

PS:(4)(5)這二個問題的結果直接關系到我們接下來在阿裡雲安裝黑蘋果的可行性,首先,集中第一個難題:在阿裡雲上bios+mbr安裝clover并使之啟動

https://www.reddit.com/r/hackintosh/comments/atliaw/clover_mbr_or_gpt_for_legacy_bios_system/ https://www.reddit.com/r/VFIO/comments/av736o/creating_a_clover_bios_nonuefi_install_for_qemu/ https://superuser.com/questions/1382154/clover-boot-efi-file-on-non-uefi-computer

Your question touches two interlocked issues:

BIOS vs. UEFI boot

GPT vs. MBR boot

The problem you run into is, that Clover needs a BIOS boot, but BIOS boot implies MBR boot. So obviously there needs to be some magic involved - turns out, this is quite straight forward: A disk can carry both, an MBR and a GPT partition table, and they don't need to carry the same information - this is called a hybrid partition table.

So what you need to do is create a GPT partition table to your needs (including one partition for Clover - best put this first to make the next step easier)

Then create a "protective" MBR-style partition table, that contains the Clover partition as bootable, and everything else in a single primary partition of type "EF".

After you have installed Clover, when the BIOS-style boot runs via the MBR (installed by Clover), it will start Clover, which will in turn read the GPT partition table to boot the rest. This implies, that while BIOS sees only one bootable partition, Clover can see many.

I have successfully used this method to triple-boot between Ubuntu, Windows and MacOS.

總結上面就是說可以連鎖boot,實作在雲主機上啟動clover,然後,virtio驅動方面,Google “clover virtio”,我們在網上還是找到了一些讨論:

http://philjordan.eu/osx-virt/

不過隻有for network沒有for blk,這是UEFI層的。

https://github.com/pmj/virtio-net-osx https://passthroughpo.st/mac-os-adds-early-support-for-virtio-qemu/

這是OS級的

the VirtIO drivers are only in the virtualization firmware OVMF. It's not part of clover

Then you can't use VirtIO drivers. They are part of VM firmware to allow faster access to resources via the virtualization features of the CPU. If the VM is booted legacy then clover emulates the firmware over legacy interfaces, even if you built the VirtIO drivers they would not work because there is no access outside of the EFI firmware of the VM. I don't understand why your VM would be restricted to legacy booting, what VM are you using because I have QEMU, VirtualBox, windows server hyperV and multiple versions of different VMWare products and none are restricted to just legacy booting...

總結來說,clover下的virtio目前沒有,不過此話的正确性有待查證,因為下面我們看到

https://github.com/kholia/OSX-KVM

通過clover用上了virtio pkgs.

osx guest方面的例子和自動化安裝項目有:

在虛拟機上使用OVMF的例子有,它們是不使用到clover的:

http://www.contrib.andrew.cmu.edu/~somlo/OSXKVM/ https://www.contrib.andrew.cmu.edu/~somlo/OSXKVM/index_old.html https://github.com/foxlet/macOS-Simple-KVM

也可以在虛拟機上結合OVMF+clover作UEFI,這方面的例子有:

https://www.kraxel.org/blog/2019/06/macos-qemu-guest/ https://www.kraxel.org/blog/2017/09/running-macos-as-guest-in-kvm/

不管如何,下文開始,我們準備硬碰硬,自己實踐出真知。徹底實作在雲主機上安裝黑osx.

(此處不設回複,掃碼到微信參與留言,或直接點選到原文)

在阿裡雲上安裝黑蘋果(2):本地虛拟機方案研究和可行資源參考

繼續閱讀