OSX-KVM: Difference between revisions

imported>Fufexan
Add ngi-nix/OSX-KVM
Updated instructions for running; add alternative to fork with flake, since it is behind upstream.
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== [https://github.com/kholia/OSX-KVM kholia/OSX-KVM] ==
The [https://github.com/kholia/OSX-KVM OSX-KVM] project provides a quick method of running macOS on Linux machines.


[https://github.com/kholia/OSX-KVM OSX-KVM] allows to run macOS on Linux machines.
== Installation ==


Use the following <code>shell.nix</code> to get all the tools required to boot OSX-KVM:
Enable virtualisation support in your system configuration by adding following lines
 
<syntaxHighlight lang=nix>
with import <nixpkgs> {};
mkShell {
  buildInputs = [
    qemu
    python3
    iproute2
    # If you want to regenerate the OpenCore image you'll need the below:
    # libguestfs-with-appliance
  ];
}
</syntaxHighlight>
 
On NixOS also add the following lines to your <code>configuration.nix</code>:


<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
{
{
  # this is needed to get a bridge with DHCP enabled
   virtualisation.libvirtd.enable = true;
   virtualisation.libvirtd.enable = true;
  # Replace <youruser> with your actual username.
   users.extraUsers.youruser.extraGroups = [ "libvirtd" ];
   users.extraUsers.<youruser>.extraGroups = [ "libvirtd" ];


  # reboot your computer after adding those lines
   boot.extraModprobeConfig = ''
   boot.extraModprobeConfig = ''
     options kvm_intel nested=1
     options kvm_intel nested=1
Line 36: Line 18:
</syntaxHighlight>
</syntaxHighlight>


After cloning the repository use <code>./fetch-macOS.py</code> or <code>./fetch-macOS-v2.py</code> as described in the README
Replace <code>youruser</code> with the user name of your running system. After applying the configuration, reboot your system so the changes to the kernel modules can take effect.
to download macOS
Then do:


<syntaxHighlight lang=console>
== Usage ==
$ qemu-img convert BaseSystem.dmg -O raw BaseSystem.img
Jonas Heinrich (GitHub user @onny) created a fork of the OSX-KVM repository with a flake. You can clone the fork and simply <code>nix run</code>, or, since the fork is several commits behind the original repo, you can complete the steps manually (see below), or copy the flake.nix to a clone of the original repo.
</syntaxHighlight>


to create the base image containing the macOS installer, followed by creating
For the forked repo, git clone and run <code>nix run</code> to prepare and run a macOS system:<syntaxhighlight lang="bash">git clone -b flake https://github.com/onny/OSX-KVM.git
your actual disk image where later the macOS will be installed to:
cd OSX-KVM
nix run</syntaxhighlight>


<syntaxHighlight lang=console>
Alternatively, clone the original repo, https://github.com/kholia/OSX-KVM. Then, copy over @onny's flake and <code>nix run</code>, or run the following manually. You will need the <code>python3</code> and <code>qemu</code> packages.<syntaxhighlight lang="bash">
$ qemu-img create -f qcow2 mac_hdd_ng.img 128G
# to fetch BaseSystem.dmg
</syntaxHighlight>
python ./fetch-macOS-v2.py


Last but not least, configure a tap interface that will be used in macOS for networking:
# to convert BaseSystem.dmg to BaseSystem.img
qemu-img convert BaseSystem.dmg -O raw BaseSystem.img


<syntaxHighlight lang=console>
# to create virtual hard drive image file mac_hdd_ng.img
$ sudo ip tuntap add dev tap0 mode tap
qemu-img create -f qcow2 mac_hdd_ng.img 128G
$ sudo ip link set tap0 up promisc on
$ sudo ip link set dev virbr0 up
$ sudo ip link set dev tap0 master virbr0
</syntaxHighlight>


Then boot the system with:
# run launch script
 
# this runs qemu-system-x86_64 with the necessary arguments
<syntaxHighlight lang=console>
source ./OpenCore-Boot.sh
$ ./OpenCore-Boot.sh
</syntaxhighlight>In all cases, you can adjust the CPU count, memory, or other options in <code>./OpenCore-Boot.sh</code>. Currently (commit [https://github.com/kholia/OSX-KVM/tree/da4b23b5e92c5b939568700034367e8b7649fe90 da4b23b]), the script [https://github.com/kholia/OSX-KVM/blob/da4b23b5e92c5b939568700034367e8b7649fe90/OpenCore-Boot.sh#L16 recommends changing the CPU to <code>Haswell-noTSX</code> for macOS Sonoma].
</syntaxHighlight>


You may also want to adjust the cpu count/memory in <code>./OpenCore-Boot.sh</code> if your systems resources allow it.
On the first run, QEMU will boot into the macOS recovery image. From the boot menu, select the macOS Disk Utility and erase / format the virtual hard drive that will be used for installation (find the one with the same size as created in the script, 128GB by default).


On the first run, from the boot menu, select disk utilities and erase / format the Qemu disk that will be used for installation. Then choose the installer from the boot menu. Select the previously created disk image as install target.
Then choose the (re-)installer from the boot menu and select the previously created disk image as the installation target. This will then download the full image of the selected macOS version.


On the next boot you will a new boot entry containing the actual installation.
On the next boot, you will see a new boot entry containing the actual installation.


== [https://github.com/ngi-nix/OSX-KVM ngi-nix/OSX-KVM] ==
== See also ==


This implementation is based on [https://github.com/foxlet/macOS-Simple-KVM macOS-Simple-KVM], and may not be as complete or polished as [https://github.com/kholia/OSX-KVM kholia/OSX-KVM]
* [https://github.com/ngi-nix/OSX-KVM ngi-nix/OSX-KVM]: This implementation is based on [https://github.com/foxlet/macOS-Simple-KVM macOS-Simple-KVM], and may not be as complete or polished as [https://github.com/kholia/OSX-KVM kholia/OSX-KVM]. Usage instructions are available in the repository README.


Usage instructions are available in the repository README.
[[Category:Virtualization]]