Add macOS boot options

This commit is contained in:
2Shirt 2021-08-25 12:32:55 -06:00
parent 547038c560
commit 3189fc464a
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
7 changed files with 89 additions and 7 deletions

View file

@ -26,6 +26,11 @@ BOOT_FILES = {
'/syslinux': 'cfg',
'/EFI/boot': 'conf',
}
IMAGE_BOOT_ENTRIES = {
'El Capitan': 'UFD-MACOS-10.11',
'High Sierra': 'UFD-MACOS-10.13',
'Catalina': 'UFD-MACOS-10.15',
}
# Definitions: Sources and Destinations
## NOTES: Paths are relative to the root of the ISO/UFD

View file

@ -5,14 +5,22 @@ import logging
import math
import os
import shutil
from subprocess import CalledProcessError
from collections import OrderedDict
from docopt import docopt
from wk import io, log, std
from wk.cfg.main import KIT_NAME_FULL, KIT_NAME_SHORT
from wk.cfg.ufd import BOOT_ENTRIES, BOOT_FILES, ITEMS, ITEMS_HIDDEN, SOURCES
from wk.exe import run_program
from wk.cfg.ufd import (
BOOT_ENTRIES,
BOOT_FILES,
IMAGE_BOOT_ENTRIES,
ITEMS,
ITEMS_HIDDEN,
SOURCES,
)
from wk.exe import get_json_from_command, run_program
from wk.os import linux
@ -104,7 +112,7 @@ def build_ufd():
function=create_table,
dev_path=ufd_dev,
use_mbr=args['--use-mbr'],
images=args['EXTRA_IMAGES'],
images=extra_images,
)
try_print.run(
message='Setting boot flag...',
@ -170,6 +178,8 @@ def build_ufd():
try_print.run(
message='Updating boot entries...',
function=update_boot_entries,
ufd_dev=ufd_dev,
images=extra_images,
)
# Install syslinux (to partition)
@ -259,7 +269,7 @@ def copy_source(source, items, overwrite=False):
def create_table(dev_path, use_mbr=False, images=None):
"""Create GPT or DOS partition table."""
"""Create GPT or DOS partition table, returns dict."""
cmd = [
'sudo',
'parted', dev_path,
@ -484,10 +494,10 @@ def show_selections(args, sources, ufd_dev, ufd_sources, extra_images):
std.print_standard(' ')
def update_boot_entries():
def update_boot_entries(ufd_dev, images=None):
"""Update boot files for UFD usage"""
configs = []
uuid = get_uuid('/mnt/UFD')
uuids = [get_uuid('/mnt/UFD')]
# Find config files
for c_path, c_ext in BOOT_FILES.items():
@ -506,7 +516,7 @@ def update_boot_entries():
'sed',
'--in-place',
'--regexp-extended',
f's#archisolabel={ISO_LABEL}#archisodevice=/dev/disk/by-uuid/{uuid}#',
f's#archisolabel={ISO_LABEL}#archisodevice=/dev/disk/by-uuid/{uuids[0]}#',
*configs,
]
run_program(cmd)
@ -529,6 +539,43 @@ def update_boot_entries():
]
run_program(cmd, check=False)
# Bail early
if not images:
return
# Get PARTUUID values
cmd = ['lsblk', '--json', '--output', 'partuuid', ufd_dev]
try:
uuids = get_json_from_command(cmd)
except (CalledProcessError, ValueError):
# Bail
return
uuids = [v['partuuid'] for v in uuids['blockdevices']]
# Uncomment extra image entries if present
for _i, image in enumerate(images):
for name, comment in IMAGE_BOOT_ENTRIES.items():
if name.lower() in image.name.lower():
cmd = [
'sudo',
'sed',
'--in-place',
'--regexp-extended',
fr's/(#{comment}#.*)"PARTUUID/\1"{uuids[_i+2]}/',
*configs,
]
run_program(cmd, check=False)
cmd = [
'sudo',
'sed',
'--in-place',
f's/#{comment}#//',
*configs,
]
run_program(cmd, check=False)
IMAGE_BOOT_ENTRIES.pop(name)
break
def verify_sources(args, ufd_sources):
"""Check all sources and abort if necessary, returns dict."""

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

View file

@ -41,6 +41,36 @@ menuentry "Linux" {
#UFD-MINIMAL#}
}
#UFD-MACOS-10.11#menuentry "macOS (El Capitan)" {
#UFD-MACOS-10.11# icon /EFI/boot/icons/wk_mac_10.11.png
#UFD-MACOS-10.11# volume "PARTUUID"
#UFD-MACOS-10.11# loader /System/Library/CoreServices/secretboot.efi
#UFD-MACOS-10.11# graphics
#UFD-MACOS-10.11# submenuentry "Mac MemTest" {
#UFD-MACOS-10.11# add_options "-s"
#UFD-MACOS-10.11# }
#UFD-MACOS-10.11#}
#UFD-MACOS-10.13#menuentry "macOS (High Sierra)" {
#UFD-MACOS-10.13# icon /EFI/boot/icons/wk_mac_10.13.png
#UFD-MACOS-10.13# volume "PARTUUID"
#UFD-MACOS-10.13# loader /System/Library/CoreServices/secretboot.efi
#UFD-MACOS-10.13# graphics
#UFD-MACOS-10.13# submenuentry "Mac MemTest" {
#UFD-MACOS-10.13# add_options "-s"
#UFD-MACOS-10.13# }
#UFD-MACOS-10.13#}
#UFD-MACOS-10.15#menuentry "macOS (Catalina)" {
#UFD-MACOS-10.15# icon /EFI/boot/icons/wk_mac_10.15.png
#UFD-MACOS-10.15# volume "PARTUUID"
#UFD-MACOS-10.15# loader /System/Library/CoreServices/secretboot.efi
#UFD-MACOS-10.15# graphics
#UFD-MACOS-10.15# submenuentry "Mac MemTest" {
#UFD-MACOS-10.15# add_options "-s"
#UFD-MACOS-10.15# }
#UFD-MACOS-10.15#}
#UFD-WINPE#menuentry "WindowsPE" {
#UFD-WINPE# ostype windows
#UFD-WINPE# icon /EFI/boot/icons/wk_win.png