Running MacOS on Ubuntu 24.04 Desktop. Use the following GitHub page as a reference.
https://github.com/kholia/OSX-KVM
Check the specs of the PC you have prepared. According to the page, a CPU that supports Intel VT-x / AMD SVM is required. VT-x is Intel’s virtualization technology that allows virtual machines to run more efficiently.
Intel Core i7-7700HQ x 8
Also, for command-based operation, enter the following as shown on the GitHub page
grep -e vmx -e svm /proc/cpuinfo
If the output contains “vmx”, it indicates that Intel VT-x is enabled; for AMD, you will see “svm”.
If the output does not contain “vmx” or “svm”, check the following
- Check BIOS/UEFI settings: Virtualization features may be disabled in the BIOS/UEFI settings, go into the PC’s BIOS/UEFI settings and make sure virtualization technology (Intel VT-x or AMD SVM) is enabled.
- Reboot: After changing the BIOS/UEFI settings, reboot the PC.
Next, install QEMU (Quick EMUlator).
If Intel VT-x or AMD SVM is enabled, the performance of virtualization software like QEMU will be greatly enhanced. By supporting these hardware virtualization technologies, QEMU enjoys the following benefits
- Improved performance: Hardware virtualization allows virtual machines to process faster. This improves the performance of applications running on virtual machines.
- Reduced overhead: Hardware virtualization has less overhead than software virtualization (hypervisor). This improves resource utilization.
- More features: By using VT-x and SVM, QEMU can provide additional features such as Nested Virtualization and Enhanced Security Features.
sudo apt install qemu
However, the following error occurred
Loading package list… Done
Creating dependency tree… Complete
Reading status information… Complete
Package qemu is not available, but is referenced by another package.
This means that the package is missing, obsolete, or only available from another source.
available only from another source.
E: Package ‘qemu’ has no installation candidates
It appears that the following command is the correct one
sudo apt install qemu-system
It also states that the following package is required: When installing packages using apt-get
, packages that are already installed will not be reinstalled. Only newly installed packages that do not yet exist on the system will be installed.
sudo apt-get install uml-utilities virt-manager git \
wget libguestfs-tools p7zip-full make dmg2img tesseract-ocr \
tesseract-ocr-eng genisoimage vim net-tools screen -y
Same as the GitHub page, but also enter the following commands at once
cd ~
git clone --depth 1 --recursive https://github.com/kholia/OSX-KVM.git
cd OSX-KVM
Detailed instructions
- Go to your home directory: cd ~ git clone –depth 1 –recursive
cd ~
- This changes the current directory to the user’s home directory.
- Clone the repository: git clone –depth 1 –recursive
git clone --depth 1 --recursive https://github.com/kholia/OSX-KVM.git
git clone
is a command to clone a given repository.- -The
--depth 1
option creates a shallow clone of the repository, retrieving only the latest commits. - -The
--recursive
option specifies that all submodules in the repository will also be cloned.
- Go to the cloned directory: .
cd OSX-KVM
- This will take you to the cloned
OSX-KVM
directory.
- This will take you to the cloned
These commands will clone the repository and take you to that directory. You are then ready to continue with the necessary configuration and installation process.
The following commands are also related to QEMU
sudo modprobe kvm; echo 1 | sudo tee /sys/module/kvm/parameters/ignore_msrs
sudo modprobe kvm
:.- This command loads the
kvm
(Kernel-based Virtual Machine) module into the kernel. modprobe
is a command to dynamically load the specified module into the kernel.sudo
is used to execute the command with administrative privileges.
- This command loads the
echo 1 | sudo tee /sys/module/kvm/parameters/ignore_msrs
:echo 1
prints1
to standard output.|
means pipeline and passes the output ofecho
to the following commandsudo tee /sys/module/kvm/parameters/ignore_msrs
writes1
to the file/sys/module/kvm/parameters/ignore_msrs.
- The
tee
command reads stdin and writes to stdout and file. In this case, theignore_msrs
parameter is set to1
.
Command Purpose
sudo modprobe kvm
:.- Load the KVM module into the kernel to enable KVM and allow QEMU to run virtual machines using KVM.
echo 1 | sudo tee /sys/module/kvm/parameters/ignore_msrs
:ignore_msrs
tells KVM to ignore access to undefined model-specific registers (MSRs). This ensures that some guest OSes and applications will work as expected. For example, this setting may be necessary when running macOS with QEMU/KVM.
My PC had an Intel processor, so I enter the following command I copy the files in the project to my PC.
sudo cp kvm.conf /etc/modprobe.d/kvm.conf
The contents of the kvm.conf file are as follows
options kvm_intel nested=1
options kvm_intel emulate_invalid_guest_state=0
options kvm ignore_msrs=1 report_ignored_msrs=0
options kvm_intel nested=1
:.
- Enables nested virtualization for Intel’s KVM modules. Nested virtualization allows you to run additional virtual machines within a virtual machine.
options kvm_intel emulate_invalid_guest_state=0
:
- Disables emulation of invalid guest states. This can help improve performance and stabilize certain guest OS behavior.
options kvm ignore_msrs=1 report_ignored_msrs=0
:
- This setting ignores access to undefined model-specific registers (MSRs). Also, do not report accesses to ignored MSRs. This ensures that some guest OSes and applications will work as expected.
And the following command is for adding the current user to a specific group
sudo usermod -aG kvm $(whoami)
sudo usermod -aG libvirt $(whoami)
sudo usermod -aG input $(whoami)
sudo usermod -aG kvm $(whoami)
:
- The
usermod
command is used to change user accounts. - -The
-aG
option is for adding users to additional groups. kvm
is a group with special privileges related to virtual machine management.- The
$(whoami)
command retrieves the name of the currently logged in user. - This will add the current user to the
kvm
group and give him or her virtual machine management privileges.
sudo usermod -aG libvirt $(whoami)
:.
- This adds the current user to the
libvirt
group. - The
libvirt
group is a group with special privileges to uselibvirt
, a virtualization management tool. - It allows the current user to manage virtual machines
using libvirt
.
sudo usermod -aG input $(whoami)
:.
- This adds the current user to the
input
group. - The
input
group is a group with special privileges related to input device management. - It allows the current user to perform operations related to input devices (e.g. keyboard and mouse).
We are almost there, we will run a script that will allow us to select which macOS.
. /fetch-macOS-v2.py
We will choose the recommended number 6, Ventura.
A .dmg file will then be downloaded. The .dmg file is a disk image file format used primarily in macOS.
Since QEMU cannot use .dmg files directly, it is necessary to convert the .dmg file to an .img file. Convert this file.
A specific example of using the dmg2img
command to convert a .dmg file to an .img file is as follows
dmg2img -i BaseSystem.dmg BaseSystem.img
In addition, use the qemu-img
command to create a virtual hard disk image. The procedure is described below.
qemu-img create -f qcow2 mac_hdd_ng.img 256G
qemu-img
: QEMU’s disk image manipulation tool.create
: Command to create a new disk image.- –
f qcow2
: Specify the format of the image to be created. Here, QEMU Copy-On-Write version 2 (qcow2) format is used. mac_hdd_ng.img
: Name of the image file to create.256G
: Specifies the size of the image. Here it is 256 gigabytes.
It is important to note here that the virtual disk image created by the qemu-img create
command is a sparse file with a maximum size of the specified size (here 256GB). In reality, disk space is allocated dynamically based on the amount of data used. So the disk image does not consume 256GB immediately upon creation, but only the amount of data actually written consumes physical disk space.
Finally, run the script .
. /OpenCore-Boot.sh
Using QEMU essentially accomplishes the same goal as VMware or VirtualBox. All of these tools are software for creating and running virtual machines on physical hardware. While each tool has its own unique features and benefits, they all share the same basic concepts and functionality of virtualization.
What they have in common
- Virtual machine creation and management:.
- All tools provide virtual hardware to create virtual machines and run different operating systems.
- Use of ISOs and disk images:.
- Use ISO files or disk images (.img, .vmdk, .vdi, etc.) to install an operating system in a virtual machine.
- Resource Allocation: Use the
- Allocate and manage resources such as CPU, memory, disk space, and network to virtual machines.
- Snapshots and Checkpoints: take snapshots and checkpoints of
- Provides the ability to save the state of a virtual machine and return to that state later (snapshots in QEMU, similar in VMware and VirtualBox).
QEMU Features
- High flexibility and customizability:.
- QEMU is very flexible and supports many different architectures (x86, ARM, PowerPC, etc.). In addition, many command line options are available for detailed configuration.
- Open Source:.
- QEMU is open source and free of charge. It is easy to customize and extend.
- Works with KVM:.
- High-speed virtualization is possible on Linux with Kernel-based Virtual Machine (KVM), which provides near-native performance.