How to make a bootable partition from scratch?

What I want to achieve is to make a new bootable partition on my MacBook's SSD, so it should be possible to press Option key on startup and choose this partition to boot from.

Why do I need that? I just successfully compiled XNU kernel from sources, found some drivers (kernel extensions), so now I want to boot this kernel and to load bash after boot process finishes. The key idea is to make a minimal Mac OS, just with command line interface.

Here is the output of diskutil list:

Alexanders-MacBook-Pro:~ aperechnev$ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *251.0 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                 Apple_APFS Container disk1         250.8 GB   disk0s2

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +250.8 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD - Data     99.8 GB    disk1s1
   2:                APFS Volume Preboot                 83.8 MB    disk1s2
   3:                APFS Volume Recovery                525.5 MB   disk1s3
   4:                APFS Volume VM                      1.1 GB     disk1s4
   5:                APFS Volume Macintosh HD            10.9 GB    disk1s5

What I want to achieve first is to see the new partition as an option to boot from by pressing Option key and to get some error when I try to boot from that partition.


Solution 1:

What makes it bootable? This has change slightly over time. I will assume you are not going to use encryption. Below are some basic examples. This is not a complete list.

  1. The original OS X operating system.

    • The partition should be type 48465300-0000-11AA-AA11-00306543ECAC.
    • The partition should be JHFS+ formatted. If you are using the Disk Utility, you would select Mac OS Extended (Journaled).
    • The boot file boot.efi needs to be in the System/Library/CoreServices folder.
    • There used to be a requirement that a file named mach_kernal exist in the root folder. The file can be empty.
  2. The macOS operating system stored in an APFS volume. This became available starting with High Sierra. This volume resides in a APFS container. The container can be comprised of a single APFS partition or two APFS partitions on separate drives.

    • The partition(s) should be type 7C3457EF-0000-11AA-AA11-00306543ECAC.
    • The container should be APFS formatted. If you are using the Disk Utility, you would select APFS.
    • The boot file boot.efi needs to be in the System/Library/CoreServices folder in a APFS volume with no specific role.
    • The mach_kernal file can be omitted.
  3. A generic operating system stored in a FAT or ExFAT formatted volume. This works on Macs where High Sierra or a newer version of macOS has been installed.

    • The partition(s) should be type EBD0A0A2-B9E5-4433-87C0-68B6B72699C7.
    • The container should be FAT32 or ExFAT formatted. If you are using the Disk Utility, you would select MS-DOS (FAT) or ExFAT.
    • The boot file BOOTX64.EFI needs to be in the EFI/BOOT folder.
  4. Operating system stored in partitions not recognized by the firmware. For example, partitions with NTFS (Windows) or EXT4 (Linux) volumes. Basically, the boot files go in a small EFI partition. The boot files are responsible for transferring control to the partition(s) containing the operating system.

    • The partition(s) should be type C12A7328-F81F-11D2-BA4B-00A0C93EC93B.
    • The container should be FAT32 formatted. If you are using the Disk Utility, you would select MS-DOS (FAT).
    • The boot file BOOTX64.EFI needs to be in the EFI/BOOT folder.