Install XCode on Arch Linux

How To Install macOS Virtual Machine on Linux/Arch/Manjaro – Catalina, Mojave, or High Sierra! XCode working! Tutorial for Ubuntu/RHEL/CentOS/Fedora

Linux users on Arch or Manjaro attempting to install macOS/OSX in VMWARE, or QEMU/KVM, will greatly benefit from this tutorial.

UPDATED 25 May 2020.
Currently there is an OpenCore boot solution, which is far superior for Arch users. I have added it to the tutorial.

UPCOMING: Dockerfile full auto macOS installer. Will be released May 28th 2020.

This tutorial now covers:
MacOS VM on Arch, Ubuntu, Debian, CentOS, RHEL or Fedora.

Check if your CPU has virtualization. This out of the following command must be greater than 0.
It tells you how many cores can be used in virtualization. You might see 8, 12, 64.

# ALL DISTROS
egrep -c '(svm|vmx)' /proc/cpuinfo

If you see 0 when you ran the above command, then boot into your BIOS and turn on “Hardware Virtualization.”
If you see 1, 2, 3 … any number greater than 0 then you can ready!

This tutorial is great for Linux users who want to use XCode 10 or 11 on Linux without Dual Booting!

How to Install macOS VM on Linux

Linux System Requirements:

  • about 20-40gb of free space
  • Intel VT-x / AMD SVM: in your BIOS turn on “hardware virtualization” or similar

Suggestions:

  • highly recommend using an SSD
  • where you download and run the scripts will determine which drive the OSX image will be created on

ARCH ONLY: an aur package manager, such as yay.

If you don’t have yay (Arch User Repository package manager):

# ARCH LINUX USERS ONLY
pacman -S git make automake gcc python go autoconf cmake pkgconf alsa-utils fakeroot --noconfirm
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si

Next, we will need git & python as we will need to clone some repositories.

# ARCH LINUX
sudo pacman -S git python

# UBUNTU DEBIAN
sudo apt install git python

# CENTOS RHEL FEDORA
sudo yum update -y
sudo yum install epel-release
sudo yum install git python -y

We are going to download the official the MAC iso/dmg file, which is around 6GB downloaded.
Make sure you download the iso in the disk or device that you are going to run the VM from.
A great way to download OSX ISO files is using gibMacOS:

git clone https://github.com/corpnewt/gibMacOS.git
cd gibMacOS
chmod +x gibMacOS.command
./gibMacOS.command

# if this doesn't work
python gibMacOS.command
python2.7 gibMacOS.command
python2 gibMacOS.command

This will run a small Python script that will allow you to download the official Mac iso files from *.apple.com

The version that I run is Mojave 10.14.6.

macOS Mojave 10.14.6 (18G103)

gibmacos Choose macOS ISO for Downloading on Linux
gibmacos Choose macOS ISO for Downloading on Linux

Next, you will need qemu & libvirt for virtualisation and emulation.
Also required during qemu installation:
dnsmasq for networking
virt-manager but not required
bridge-utils for additional networking Requirements

# ARCH LINUX ONLY
sudo pacman -S qemu libvirt dnsmasq virt-manager bridge-utils flex bison ebtables edk2-ovmf

# UBUNTU DEBIAN
sudo apt install qemu qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virt-manager
sudo apt install qemu virt-manager dnsmasq  bridge-utils

# CENTOS RHEL FEDORA
sudo yum install libvirt qemu-kvm -y

Now, enable libvirt and virtlogd

  • libvirt is libraries required for virtualisation
  • virtlogd is logging of the qemu virtual instances
sudo systemctl enable libvirtd.service
sudo systemctl enable virtlogd.service

Additionally, you will require the following packages which are found only in the Arch User Repository.

Most of them are on Github if you want to compile them yourselves.
Installing these will take some time, so one-by-one install these:

# ARCH LINUX ONLY
# you may need the following
yay uml_utilities # read below if doesn't install
yay libguestfs # libguestfs is in arch/comminuty-testing now too
yay ebtables
yay firewalld
sudo firewalld

Update May 2020: ARCH uml_utilities may need to be installed in the following way:

# ARCH ONLY
# the current version of uml_utilities may need to be installed in the following way
# because the pkgbuild has a tiny error, if it gets fixed, this snippet will still work fine with r
yay --getpkgbuild uml_utilities
cd uml_utilities
perl -i -p -e "s/provides=\(\'\'\)/provides=\(\)/g" PKGBUILD
perl -i -p -e "s/conflicts=\(\'\'\)/conflicts=\(\)/g" PKGBUILD
makepkg -si

If you are on Debian or Ubuntu

# DEBIAN UBUNTU
sudo apt install qemu qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virt-manager uml-utilities dmg2img wget libguestfs-tools

The following program qt-virt-manager is huge and takes a long time to compile but you might need it:

# yay qt-virt-manager

You should reboot now to apply kernel changes for qemu.

sudo modprobe kvm
reboot

After reboot, download the OSX-KVM Repository:
This folder will be referred to as the OSX-KVM folder.

Your macOS disk will be created in the folder we are about to download into.

Make sure you choose a disk with enough space.

git clone https://github.com/kholia/OSX-KVM.git
cd OSX-KVM
# if you didnt use gibMacOS to download the OSX ISO you can use: 
# ./fetch-macOS.py

Converting macOS BaseSystem.dmg into Disk Image

In the gibMacOS folder that you downloaded earlier, navigate into:
macOS Downloads > publicrelease, and then the folder of the OSX Version that you downloaded.

Inside the macOS version folder that you downloaded from gibMacOS, we will turn the .dmg into .img
Make sure you have enough disk space here!

Find BaseSystem.dmg inside the gibMacOS downloaded folder. It should be around 500mb.
Convert it to .img:

# do this inside gibMacOS/macOS Downloads/publicrelease/061-26589 - 10.14.6 macOS Mojave/
qemu-img convert BaseSystem.dmg -O raw BaseSystem.img

# or do it inside any version auto
qemu-img convert gibMacOS/macOS\ Downloads/publicrelease/*/BaseSystem.dmg -O raw BaseSystem.img

Now move the BaseSystem.img that you just created FROM the gibMacOS folder -> TO THE OSX-KVM FOLDER

Move BaseSystem to OSX-KVM Folder
Move BaseSystem to OSX-KVM Folder

Decide now how big you want the macOS disk size to be.

I want an 80GB macOS disk size so I run the command below.
Note: do not change “mac_hdd_ng.img” or it will break the scripts later.

qemu-img create -f qcow2 mac_hdd_ng.img 80G

The 80GB empty disk has been created.
The macOS image is ready.

Now, create the network for the OSX VM

If you have successfully installed all the AUR packages above, you should be able to run this:

Run these commands one-by-one:

sudo ip tuntap add dev tap0 mode tap
sudo ip link set tap0 up promisc on
sleep 1
sudo virsh net-start default
sudo virsh net-autostart default
sudo ip link set dev virbr0 up
sleep 1
sudo ip link set dev tap0 master virbr0
macOS VMWARE Virtual Networking
macOS VMWARE Virtual Networking

Mac is now ready to boot.

Inside the OSX-KVM folder, run the shell script run-diagnostics.sh

./run-diagnostics.sh

If everything looks okay, you are ready to boot macOS on Arch Linux.
If everything is not okay, leave a comment, I usualy reply within 24 hours. use imgur.com to link to image if you want to post a screenshot

macOS Run Diagnostics
macOS Run Diagnostics

Boot macOS

# new shell boot script version! As of May 2020
./OpenCore-Boot.sh
# old tutorial, may fail
./boot-macOS-NG.sh

Boot and Installation Process

Hint: in QEMU, press Ctrl + Alt + G to gain control of your mouse again.

At the CLOVER Boot Manager screen, select:
Boot macOS Install from macOS Base System

macOS Clover Boot Linux AMD OSX
macOS Clover Boot Linux AMD OSX

After about a minute, the macOS recovery GUI will appear and you can select your language.

When you reach the macOS Utilities screen, seleck “Disk Utility”

macOS on Linux Disk Utility
macOS on Linux Disk Utility

In the top left, select “Show All Devices”. Not required to see the disk we are using, but helpful to visualize what is happening

Show All Devices OSX Disk Utility
Show All Devices OSX Disk Utility

Select the disk which has 80GB and is “Uninitialized”.

Uninitialized QEMU Disk for macOS on Linux
Uninitialized QEMU Disk for macOS on Linux

Click on “Erase” and erase the 90GB disk.

Do not change the Format or Scheme.

Erasing the disk here does nothing to your real computer. This is a virtual drive.

Erase Disk macOS Linux
Erase Disk macOS Linux

Create a new partition for macOS on your QEMU Drive

NOTE: YOU MUST REDUCE THE DISK SIZE BY A SMALL AMOUNT TO BE ABLE TO PRESS APPLY

After you have erased the disk, click “Partition”.

Partitioning QEMU Drive on Linux for macOS
Partitioning QEMU Drive on Linux for macOS
Change 85.6 to 85.5 and you will be able to press apply.
You Must Reduce the Partition Size by any amount
You Must Reduce the Partition Size by any amount.

Note: this will NOT steal 80GB straight away from your hard drive:  it’s just virtually allocating it from your host machine’s disk.

Create macOS partition for Arch Linux QEMU
Create macOS partition for Arch Linux QEMU

When that has finished, you can close the “Disk Utility”

Select Reinstall macOS.

Reinstall macOS on QEMU
Reinstall macOS on QEMU
Install macOS Mojave on Arch Linux
Install macOS Mojave on Arch Linux

Have fun using macOS on Linux with QEMU!

Install XCode on Arch Linux
Install XCode on Arch Linux

Finsihed installing OSX on Linux in a VM!

 

BONUS DESKTOP SHORTCUT SCRIPT!

# boot macosx  vm
sudo systemctl enable libvirtd.service
sudo systemctl enable virtlogd.service
sudo ip tuntap add dev tap0 mode tap
sudo ip link set tap0 up promisc on 
sleep 1
sudo virsh net-start default
sudo virsh net-autostart default
sudo ip link set dev virbr0 up
sleep 1
sudo ip link set dev tap0 master virbr0

cd /home/user/OSX/OSX-KVM/ && bash ./OpenCore-Boot.sh

 

Update May 2020 fixes for existing Mac OSX Virtual Machines:

virsh is now included in libvirtd.

Something happened to my tun setup but I documented the fix in this article about TUN/TAP OSX-KVM

You may need to remove the git version of virsh that we are using and use the one from libvirtd:

# remove the existing networks created by the old package
# dont worry, these will get created again when you reinstall qemu and libvirt
# 
sudo pacman -R virsh
sudo ip link delete virbr0
sudo ip link delete virbr0-nic
sudo pacman -S libvirt qemu
reboot

It seems we don’t need this command any more because the libvirt package includes virsh.
Remove any virsh commands from your boot scripts (the bonus one above).

# I removed these
# sudo virsh net-create default
# sudo virsh net-autostart default

qemu-system-x86_64: could not configure /dev/net/tun (tap0): Operation not permitted

Or

command “sudo virsh net-start default” hangs

This error happened when I updated the kernel.

Solved by reinstalling qemu and libvirt:

sudo pacman -R virsh
sudo ip link delete virbr0
sudo ip link delete virbr0-nic
sudo pacman -S libvirt qemu
reboot

Then change the networking mode to Usermode. You can do that by importing the whole thing into virt-manager by using the file named macOS-libvirt-Catalina.xml. Happy to help with any questions you might have!

Increase Screen Resolution on MacOS Virtual Machine QEMU!

– Automatically fixed in the new OpenCore-Boot.sh version
– Try the new OpenCore-Boot version.

13 thoughts on “How To Install macOS Virtual Machine on Linux/Arch/Manjaro – Catalina, Mojave, or High Sierra! XCode working! Tutorial for Ubuntu/RHEL/CentOS/Fedora”

    1. I have fixed the instructions, the makepkg part is for Arch Linux users. makepkg comes with pacman so it should be by default?

  1. Hi, thanks very much for the tutorial! I had two issues, the first one with the following command:

    yay virsh

    Doesn’t seem to work for me.

    Then I continued with the rest of the process, have completed all steps except the one mentioned above. When I try to boot MacOS using the following command:

    ./boot-macOS-NG.sh

    I get the following error message (the first part is obviously the terminal prompt):

    [[email protected] OSX-KVM]$ ./boot-macOS-NG.sh
    qemu-system-x86_64: -drive if=pflash,format=raw,file=./backup/OVMF_VARS-1024×768.fd: Could not open ‘./backup/OVMF_VARS-1024×768.fd’: No such file or directory

    When I check the contents of ‘backup’ folder the only file in there is ‘OVMF_CODE.fd’. As I have no idea what these files are I tried to make a copy of this and named it ‘OVMF_VARS-1024×768.fd’ as this is the file it complaints about. In this case when I try again to boot MacOS a new QEMU window pops up with the following message:

    ‘Guest has not intitialized the display (yet)’

    At the same time in the terminal window I can also see the following messages:

    [[email protected] OSX-KVM]$ ./boot-macOS-NG.sh
    QEMU 4.2.0 monitor – type ‘help’ for more information
    (qemu) qemu-system-x86_64: warning: host doesn’t support requested feature: CPUID.01H:ECX.pcid [bit 17]
    qemu-system-x86_64: warning: host doesn’t support requested feature: CPUID.01H:ECX.pcid [bit 17]
    qemu-system-x86_64: warning: host doesn’t support requested feature: CPUID.01H:ECX.pcid [bit 17]
    qemu-system-x86_64: warning: host doesn’t support requested feature: CPUID.01H:ECX.pcid [bit 17]

    Sorry for the long and messy comment but I cannot see any formatting options to make it more readable. Any help to move forward would be very much appreciated!

    I am running the latest Manjaro/Plasma KDE on a Ryzen 3900X platform.

    Cheers

    1. Hey mate!

      It looks like the author changed the repo slightly.

      Change the line 16 inside boot-macOS-NG.sh,
      from
      ./backup
      to
      ./

      OVMF backup folder osx qemu

      Here’s my file below:

      MY_OPTIONS="+pcid,+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check"

      # OVMF=./firmware
      OVMF="./"

      qemu-system-x86_64 -enable-kvm -m 5500 -cpu Penryn,kvm=on,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,$MY_OPTIONS\
      -machine q35 \
      -smp 4,cores=4 \
      -usb -device usb-kbd -device usb-tablet \
      -device isa-applesmc,osk="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc" \
      -drive if=pflash,format=raw,file=$OVMF/OVMF_CODE.fd \
      -drive if=pflash,format=raw,file=$OVMF/OVMF_VARS-1024x768.fd \
      -smbios type=2 \
      -device ich9-intel-hda -device hda-duplex \
      -device ich9-ahci,id=sata \
      -drive id=Clover,if=none,snapshot=on,format=qcow2,file=./'Mojave/CloverNG.qcow2' \
      -device ide-hd,bus=sata.2,drive=Clover \
      -device ide-hd,bus=sata.3,drive=InstallMedia \
      -drive id=InstallMedia,if=none,file=BaseSystem.img,format=raw \
      -drive id=MacHDD,if=none,file=./mac_hdd_ng.img,format=qcow2 \
      -device ide-hd,bus=sata.4,drive=MacHDD \
      -netdev tap,id=net0,ifname=tap0,script=no,downscript=no -device vmxnet3,netdev=net0,id=net0,mac=52:54:00:c9:18:27 \
      -monitor stdio \
      -vga vmware

    2. P.S. the second part, virsh comes with libvirt now I see: https://www.archlinux.org/packages/community/x86_64/libvirt/

      I also receive the CPU error, however it does boot into clover even though there are those errors:
      [cc]
      QEMU 4.2.0 monitor – type ‘help’ for more information
      (qemu) qemu-system-x86_64: warning: host doesn’t support requested feature: CPUID.01H:ECX.pcid [bit 17]
      qemu-system-x86_64: warning: host doesn’t support requested feature: CPUID.01H:ECX.pcid [bit 17]
      qemu-system-x86_64: warning: host doesn’t support requested feature: CPUID.01H:ECX.pcid [bit 17][/cc]
      qemu-system-x86_64: warning: host doesn’t support requested feature: CPUID.01H:ECX.pcid [bit 17]

  2. Hi there, I just updated the install and did get Qemu to launch with the update to the script, but after i select the “install macOS from recovery” it is just hangning at the next screen, looks like some kind of log screen. Can I post a pic on here?

    1. Hey man! try booting with ./OpenCore-Boot.sh
      It’s the new way better boot method.
      Post the pic on imgur and then paste the link here

    2. Try launching it with the OpenCore-Boot.sh script now. I have updated the tutorial. I also had some networking issues.

      If you can’t get it working, let me know I’ll post the .xml version I am using with virt-manager now instead.

      1. Yes that seemed work. Installing the OS now! thanks. I will update when i am in and launched into the desktop.

    1. Hey Richard, you can try looking through notes.md inside the OSX-KVM folder. It also depends on whether you have a Nvidia or AMD Graphics card. I haven’t been able to accelerate the graphics.

      There’s also another file called macOS-libvirt-Catalina.xml, which you can import into virt-manager and run the system in virt-manager.

      I haven’t tried tinkering too much with the video settings, I will try some stuff this weekend.

Leave a Reply

Your email address will not be published. Required fields are marked *