# Preparing the installer

### Copying the kernel

macOS will not be able to boot on AMD systems in this configuration. For that to work we need to replace a few files.

The new Kernel will need to be placed in the *System/Library/Kernels* folder of the installer USB. This folder does not exist by default, so you need to go to *System/Library* and create the folder *Kernels*.

```bash
diskutil mount /dev/disk#s#
cd /Volumes/OS\ X\ Base\ System/System/Library
mkdir Kernels
cp ~/Desktop/kernel Kernels/kernel
sudo cp -r ~/Desktop/System.kext Extensions/System.kext
```

The first command mounts the USB drive.\
The second command changes the current directory to the USB drive's *System/Library*\
The third command creates the *Kernels* directory\
The fourth command copies the Kernel from the desktop\
The fifth command copies the *System.kext* from the desktop

### Copying some kexts

The BaseSystem image does not have all the kexts that we need to boot macOS on AMD. We will need to have to add those ourselves from an existing High Sierra install.

If you are installing 10.13.3 or 10.13.6 you can use the kexts supplied by me in **Prerequisites**. Extract the .ZIP to your desktop, otherwise you will have to extract the kexts yourself from InstallESD.dmg, using something like Pacifist. To do so go to `Install macOS.app/Contents/Shared Support`. Copy InstallESD to your desktop and open it. You need the file in `Packages/Core.pkg`

* AppleActuatorDriver.kext
* AppleSMCRTC.kext
* AppleUSBCommon.kext
* IOSlaveProcessor.kext
* KernelRelayHost.kext
* IONetworkingFamily.kext (You need the 10.13.3 version on 10.13.3+)
* IOUSBFamily.kext

You will also need the following files for USB support. On FX this is permanent, on Ryzen we will be replacing it later by a better alternative:

* DummyUSBEHCIPCI.kext
* DummyUSBXHCIPCI.kext

These files can be downloaded [here](https://github.com/IOIIIO/AMDVanilla/tree/master/files). We do not need them on Ryzen as we will be setting up native USB. This will be explained later on.

#### Side note:

Do not add your other kexts here. We will add those later to Clover.

#### If you decide to use on of my .zip files, install as follows:

Extract the Zip file to your desktop to a folder named kexts. After that open *Terminal* and run the following command to copy the needed files.

```bash
cp -r ~/Desktop/kexts/. Extensions/
```

### Rebuilding the prelinkedkernel

macOS does not use the kernel file to boot. Instead it uses the prelinkedkernel. This is a file containing the Kernel along with a cache of kexts. Because of this in order to be able to boot we need to rebuild it. First we will have to rebuild the permissions.

Open a Finder window and right click on your USB drive. Press `Get Info`. On the very bottom of the window that just opened press on the lock and enter your password to unlock some extra settings. Now uncheck `Ignore Ownership` from the now no longer greyed out options at the bottom of the page.

Now that this is done, open a terminal window again and execute the following commands:

```bash
cd /Volumes/OS\ X\ Base\ System/System/Library/
sudo chown -R 0:0 Extensions
sudo chmod -R 755 Extensions/*.kext
sudo xattr -c Extensions/*
sudo touch Extensions
sudo rm /Volumes/OS\ X\ Base\ System/System/Library/PrelinkedKernels/prelinkedkernel
sudo kextcache -u /Volumes/OS\ X\ Base\ System
```

This process can take a few minutes and when it is done you will most likely receive an error complaining about `com.apple.kext.caches/Startup`, as long as you also receive a CacheID this is fine.

The first 5 commands are used to repair permissions on the kexts. The first command changes directory to the Library folder. The second one changes the owner of all files in the `Extensions` folder to root.The third one changes the permissions of all kexts in the Extensions folder so that the file owner has full control. The command after that strips all extra attributes the files might have. The last of this section of commands basically updates the modification date of all files in the Extensions folder.

The last two commands are used to rebuild the prelinkedkernel. The first one removes the existing file and the second one is what rebuild the kernel cache aka the prelinkedkernel.

### Installing Clover

For this next part we will be installing the bootloader *Clover* to the USB drive so that it can be booted on regular computers, not just Mac's.\
Let's get started.

Launch your Clover installer that you downloaded in the prerequisites section. On the second page of the installer **make sure to select your USB drive!** The default settings set by Clover are not all that desirable so we need to **Customise** the install.

You want to use the following settings, as shown in the screenshots. This is generally all that's needed.

* *Install Clover for UEFI booting only*
* *Install Clover to the ESP*
* Under *Drivers64UEFI:*
  * *AptioMemoryFix* (the new hotness that includes NVRAM fixes, as well as better memory management)
  * *VBoxHfs-64.efi* (or *HFSPlus.efi* if available) - one of these is required for Clover to see and boot HFS+ volumes. If you see the option to enable it in the installer, make sure it's selected - if you don't see it in the installer, verify that one of them exists in the *EFI -> CLOVER -> drivers64UEFI* folder
  * *ApfsDriverLoader* - (Available in Dids' Clover builds - or [here](https://github.com/acidanthera/ApfsSupportPkg/releases)) this allows Clover to see and boot from APFS volumes by loading apfs.efi from ApfsContainer located on block device (if using AptioMemoryFix as well, requires R21 or newer)
* *Install RC scripts on target volume*

Provided you don't plan on using FileVault (which I don't even think works properly on AMD) this concludes our clover installation!

### Copying kexts

When Clover is done installing a drive named EFI will pop up on your desktop. Open this and navigate to */Volumes/EFI/EFI/CLOVER/kexts/Other* and copy all your .kext files that you downloaded in the Kexts section here.

You will also see other folders named 10.xx in the */kexts/* directory. These are not needed for our goal. These are used for version specific kexts in case you are multibooting multiple macOS versions.

## Next up:

### Setting up Clover.

First some theory on how it all works, and after that I will show a few different configs that should work as a basis for most systems. Follow the guide for your CPU on the left side under the heading "*Example Config.plist's*", after reading the basics.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://101110.gitbook.io/workspace/preparing-the-installer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
