[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Why it's so difficult to fix PowerMac booting for good



On 05/30 2023 17:13 Stan Johnson wrote:
On 5/30/23 7:16 AM, Ben Westover wrote:
The GRUB Manual [1] says that the PPC port of GRUB only supports booting Linux at the moment. AFAIK booting macOS with GRUB on x86 machines works by just chainloading macOS' UEFI bootloader. I assume this is what yaboot does as well, telling Open Firmware to load OS X's blessed binary instead of the second stage of yaboot and Linux from there. All we need to do is find a way to support Open Firmware chainloading from within GRUB.

Yes, I had it working on an Intel Mac.

Thanks for the information. GRUB chainloading support works for x86 (to
boot Windows and NetBSD). Despite considerable effort, I've never been
able to get chainloading to work on New World PowerMacs (consistent with
the link you sent). Surprisingly, I also couldn't get Mac OS X booting
to work on x86_64 (e.g. Intel Core 2 Duo MacBook) systems. To undo the
automatic updating of GRUB during Debian "apt-upgrade" and "apt
dist-upgrade", I have a working grub.cfg files on x86 (e.g. i686) and
x86_64 systems that don't need to run Mac OS X -- for such systems, I
can simply copy my known-good grub.cfg.save to grub.cfg and re-run "grub
install /dev/sda" (for x86) or just "grub-install" for EFI-based x86_64
systems that don't need to run Mac OS X. Even if holding the option key
at boot works on all Macs, I consider that a fallback and don't
necessarily want to be at the system console to pick an OS. An expert
knowledgeable in both GRUB and yaboot could probably figure out how to
get GRUB to do what yaboot has done for decades.

You can always put in some "static" configuration under
/etc/grub.d/99something.

I have some scripts of my own there, with my static configuration preset
before the automatic grub-install generated stuff. This way, my primary
options on x86/amd64 are at the top, a) Windows and b) Linux.

I don't know about Debian at this point (my Debian Laptop is in the
other room), but on Gentoo I have the following files in /etc/grub.d:
00_header -- basically all the main configuration (like the colors)
01_pager -- (only includes "set pager=1")
05_separator -- (I'll explain it later)
05_static -- my static Linux configuration
09_separator
10_linux -- the pre-installed grub-mkconfig part
20_linux_xen -- the same for Xen
29_separator
30_os-prober -- the same for os-prober
30_uefi-firmware  -- UEFI firmware settings, i.e. boot into BIOS setup
40_custom -- just empty stubs
41_custom --       " "
99_separator

Only executable files will be included (so it's relatively easy to
disable one script from /etc/grub.d -- e.g simply run chmod a-x
05_static to disable it...)

So, what grub-install normally does, is run 10_linux, which will get all
the installed Linux kernels and initrds from /boot, make a list and put
them into your grub.cfg, with the default options found in
/etc/default/grub. BUT, before that I have 05_static, which is my own
personal Linux config.

All the nn_separator files (like 05_separator) are symlinks to
.separator, which is a file in the same directory and has this content:

#!/bin/sh
exec tail -n +6 $0
# This file provides an easy way to add custom menu entries.  Simply
type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry " ----------------------------------------" --class separator {
    echo ' Please select a bootable entry. Return...'
}

So, what this does, is: it makes nice & clean --------- line entries to
separate all the different sections in the GRUB menu. Should you select
it and press Enter/Return, it will just display "Please select a
bootable entry." (The .separator file is executable, so every
nn_separator symlink is always included by grub-mkconfig...)

And here's what my 05_static looks like:

#! /bin/sh
set -e

# /etc/grub.d/05_static
# Revision: 2023-03-29

prefix="/usr"
exec_prefix="/usr"
datarootdir="/usr/share"

export TEXTDOMAIN=grub
export TEXTDOMAINDIR="${datarootdir}/locale"

. "$pkgdatadir/grub-mkconfig_lib"

gettext_printf "Adding static boot menu entries ...\n" >&2

GENTOO_STATIC_INITSYS="/usr/lib/systemd/systemd"

#GENTOO_STATIC_BOOTDEV="crypt_root=UUID=aaaaaaaa-bbbb-cccc-9999-000000000000
root_trim=yes dolvm dobtrfs root=UUID=11111111-2222-4444-aaaa-ffffffffffff"
####
#### UUIDs
####
GENTOO_STATIC_EFI_UUID="1234-A1B2"  # /boot/efi
GENTOO_STATIC_BOOT_UUID="fedcba09876543211234567890abcdef" # /boot
GENTOO_STATIC_CRYPT_UUID="aaaaaaaa-bbbb-cccc-9999-000000000000" # LUKS
GENTOO_STATIC_ROOT_UUID="11111111-2222-4444-aaaa-ffffffffffff" # /

GENTOO_STATIC_CRYPT_ROOT="UUID=$GENTOO_STATIC_CRYPT_UUID" # LUKS partition
GENTOO_STATIC_REAL_ROOT="UUID=$GENTOO_STATIC_ROOT_UUID" # /
GENTOO_STATIC_BOOTDEV="crypt_root=$GENTOO_STATIC_CRYPT_ROOT
root_trim=yes dolvm dobtrfs root=$GENTOO_STATIC_REAL_ROOT"


GENTOO_STATIC_DEFAULT_NOMITIGATIONS="mitigations=off vsyscall=none
init_on_alloc=0 init_on_free=0 page_table_check=off hardened_usercopy=off"
GENTOO_STATIC_DEFAULT_MITIGATIONS="mitigations=auto,nosmt l1tf=full
vsyscall=none init_on_alloc=1 init_on_free=1 page_table_check=on
hardened_usercopy=on"
GENTOO_STATIC_FEATURES="psi=1 mem_encrypt=on efi=noruntime"
#GENTOO_TEMP_FEATURES="i8042.notimeout i8042.nomux"
#GENTOO_TEMP_FEATURES="pci=realloc=on
efi=noruntime,disable_early_pci_dma efi_pstore.pstore_disable=1"
GENTOO_TEMP_FEATURES="amd_pstate=active"
GENTOO_STATIC_DEFAULT="$GENTOO_STATIC_DEFAULT_MITIGATIONS
$GENTOO_STATIC_FEATURES $GENTOO_TEMP_FEATURES"
GENTOO_EXPERIMENTAL_FEATURES=""

GENTOO_STATIC_CMDLINE="init=$GENTOO_STATIC_INITSYS ro
$GENTOO_STATIC_BOOTDEV $GENTOO_STATIC_DEFAULT"

GENTOO_STATIC_ADDITIONAL_INITRD=""

LABEL="[W]indows 11"
HOTKEY="w"
cat << EOF
menuentry '$LABEL' --hotkey=$HOTKEY --class windows --class os
\$menuentry_id_option 'gentoo-static-efibootmgr-$GENTOO_STATIC_EFI_UUID' {
        insmod part_gpt
        insmod fat
        search --no-floppy --fs-uuid --set=root $GENTOO_STATIC_EFI_UUID
        chainloader /efi/Microsoft/Boot/bootmgfw.efi
        savedefault
}
EOF

LABEL="[G]entoo"
HOTKEY="g"
cat << EOF
menuentry '$LABEL' --hotkey=$HOTKEY --class gentoo --class gnu-linux
--class gnu --class os \$menuentry_id_option
'gentoo-static-current-$GENTOO_STATIC_ROOT_UUID' {
        load_video
        insmod gzio
        insmod part_gpt
        insmod ext2
        search --no-floppy --fs-uuid --set=root $GENTOO_STATIC_BOOT_UUID
        echo    'Loading Gentoo GNU/Linux...'
        linux   /gentoo-kernel $GENTOO_STATIC_CMDLINE
        echo    'Loading Initial Ramdisk...'
        initrd  $GENTOO_STATIC_ADDITIONAL_INITRD /gentoo-initramfs
        savedefault
}
EOF

...

As you can see I set my options in this file by variable, like in
$GENTOO_STATIC_FEATURES and $GENTOO_TEMP_FEATURES

Of course, the settings from /etc/default/grub will be used by 10_linux
and 20_linux_xen, and I keep them almost the same, but to experiment
with options (like lately the new amd_pstate driver) I use 05_static. I
not only have "[G]entoo" in it but also "Gentoo [e]xperimental" (the
letter in brackets is the assigned hotkey), so I can quickly get what I
want. On an older system I also have various unsafe menu entries, that
turn off all meltdown and spectre mitigations ("... [u]nsafe") to gain
more speed (while not online, and only when running trusted programs).

This may seem like a lot of work, but in your case all you needed to do
would be to make your OS X GRUB entries static into a file similar to
mine (05_static, likely with less configuration variables; e.g.
04_macos) and you'd be all set. No longer any need to copy a
grub.cfg.save...

I only bring these points up whenever anyone goes on about how easy it
is to get GRUB working on New World PowerMacs. GRUB will never be an
acceptable replacement for some yaboot users as long as booting Mac OS
isn't supported (os-picker via holding the option key at boot isn't
sufficient). If you don't need to boot Mac OS and GRUB already does
everything you need, you should of course choose GRUB for a new
installation instead of the no-longer-maintained yaboot.

AFAIR yaboot does its magic within the CHRP boot script. It would be
relatively easy to add an option to load GRUB, I guess. The "chain"
would then start by choosing Mac OS (Classic), Mac OS X, or GRUB, via
the yaboot CHRP script. But then, GRUB would be only managing Linux.

So, that's probably not what you were suggesting...

I'll test a new installation of the latest Debian SID (with GRUB) on a
PowerBook Pismo with an unformatted disk and send an update in a
different thread (I specifically want to test whether the partition that
holds the real grub.cfg is normally hidden).

I hope I finally find the time to do the same on my Clamshell. Only, my
disk isn't empty, I already installed Mac OS X on it, which I want to keep.

Linux User #330250


Reply to: