This is my first tutorial for my Tech Blog.
For my work as Product Managers, we are build a mobile app for both iOS and Android using Xamarin.
I needed to utilize a Virtual iOS Device and while there are some options on the web, I need a non-paid option due to budget restrictions from Management.
Because I have switched over to Linux, and I honestly prefer Linux now, I decided to do some research on a MacOS VM on Linux.
I already use KVM for a Windows machine and other Linux Distros. So I went on my mission to research how to perform the install.
I ran into some problems and had to source information from many different location. Hoping that this will help others in the same position.
So let’s begin!
After updating your system, we will install the necessary software, if not already installed.
Prepare Environment – Updates and Install Req. Software
Let’s start by checking for any new updates that the system may require.
sudo apt update
After updating your system, we will need to install the necessary software. Below I have added quick descriptions of the main software you will be installing.
QEMU | QEMU is a userland type 2 (i.e runs upon a host OS) hypervisor for performing hardware virtualization (not to be confused with hardware-assisted virtualization), such as disk, network, VGA, PCI, USB, serial/parallel ports, etc. It is flexible in that it can emulate CPUs via dynamic binary translation (DBT) allowing code written for a given processor to be executed on another (i.e ARM on x86, or PPC on ARM). Though QEMU can run on its own and emulate all of the virtual machine’s resources, as all the emulation is performed in software it is extremely slow. |
Libvirt | Libvirt is collection of software that provides a convenient way to manage virtual machines and other virtualization functionality, such as storage and network interface management. These software pieces include a long term stable C API, a daemon (libvirtd), and a command line utility (virsh). A primary goal of libvirt is to provide a single way to manage multiple different virtualization providers/hypervisors, such as the KVM/QEMU, Xen, LXC, OpenVZ or VirtualBox hypervisors (among others). |
Bridge Utils | The bridge-utils package contains a utility needed to create and manage bridge devices. This is useful in setting up networks for a hosted virtual machine (VM). |
virtinst | The “Virt Install” tool (virt-install for short command name, virtinst for package name) is a command line tool which provides an easy way to provision operating systems into virtual machines. It also provides an API to the virt-manager application for its graphical VM creation wizard. |
virt-manager | The virt-manager application is a desktop user interface for managing virtual machines through libvirt. It primarily targets KVM VMs, but also manages Xen and LXC (linux containers). It presents a summary view of running domains, their live performance & resource utilization statistics. Wizards enable the creation of new domains, and configuration & adjustment of a domain’s resource allocation & virtual hardware. An embedded VNC and SPICE client viewer presents a full graphical console to the guest domain. |
sudo apt -y install qemu-kvm libvirt-daemon qemu-system qemu-utils python3 python3-pip bridge-utils virtinst libvirt-daemon-system virt-manager
Now, we must ensure the vhost_net module is loaded and enabled in our system. We do that by running the following commands one after the other:
sudo modprobe vhost_net
lsmod | grep vhost
The first command will not return a response.
The second one will return the information required.
Below is a sample of the two commands:
Now, let’s start KVM witht he following commands:
$ sudo systemctl start libvirtd
$ sudo systemctl enable libvirtd
$ sudo dnf -y install virt-manager
Now, to verify the installation, we can verify the Modules are loaded in our system.
lsmod | grep kvm
Sample of my output:
Now that we have the software installed, we can locate the MacOS image we want to install. Bringing us to the next step.
MacOS Media – GIT
If you do not already have GIT installed, please do so by using the command below:
sudo apt -y install git
We must clone the Project Code from github. Do this with the following command:
git clone https://github.com/foxlet/macOS-Simple-KVM.git
Change to the download directory
cd macOS-Simple-KVM
Ensure that you have an active internet connection as we will now download the MacOS Image.
By default, the installation will choose the latest version of MacOS. But you can select your own by changing the “–catalina” to another version.
Such as:
- HighSierra = –high-sierra
- Mojave = –mojave
In the example below, I have chosen to install Catalina.
./jumpstart.sh –catalina
Sample Output:
Congratulations, you have a working MacOS Install Image ready to work with now.
Now, we must boot the machine up and install the OS.
Booting up and Install
We need to create an empty hard disk for the Machine we are building. We will build it using qemu-img.
I will create my disk with 50GB and call it “macOSvm” the file extension is qcow2 for use with qemu.
qemu-img create -f qcow2 macOSvm.qcow2 50G
-drive id=SystemDisk,if=none,file=macOSvm.qcow2 \
-device ide-hd,bus=sata.4,drive=SystemDisk \
Now, run the command
./basic.sh
This command will execute the VM to boot up using QEMU.
Once the VM boots up, click on the MacOS icon to install.
Wait for the installer
Click on “Disk Utility” in the next screen. We will format our disk.
After formatting, we can now install the OS on the newly formatted drive. Go to Disk Utility and select “Reinstall MacOS”
Click CONTINUE to confirm the installation
Select your disk
Now we wait for the install to complete
MacOS is now installed on the hard disk.
Moving to VM to Virt-Manager
Ialready use Virt-Manager, so I didn’t want to use QEMU. Therefore I had to import this VM into Virt-Manager.
This can be done fairly simple by using the make.sh file in the original GIT download.
Simply use the following command:
sudo ./make.sh –add
After running the command above, add macOSvm.qcow2 as storage in the properties of the newly added entry for VM.
You can do this via editing the XML of the machine or you can add the new storage device through the Virt-Manager UI.
Boot up your machine and enjoy MacOS on your Linux Environment!
Add a Comment