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

Re: GRUB Multiboot



On 3/29/22 1:42 AM, Mark Cave-Ayland wrote:
> On 29/03/2022 02:33, Stan Johnson wrote:
> 
>> ... I would guess that the best way to make GRUB boot Mac OS and
>> Mac OS X would be for it to do whatever yaboot does.
>> ...
> 
> I'm fairly sure that it would do, since as you mention above it just
> needs to know which partition is the OS X volume.
> 
> Out of curiosity does grub auto-detect blessed HFS/HFS+ volumes during
> installation and add them to the grub boot menu? If so, can you provide
> the grub.cfg. And do you have the output of fdisk and examples of
> grub.cfg entries that you have tried so far?
> ...

Hi Mark,

Here's a list of my disk partitions on the Pismo:

  #                 type name            length   base      ( size )
sda1 Apple_partition_map Apple               63 @ 1         ( 31.5k)
sda2      Apple_Driver43 Macintosh           56 @ 64        ( 28.0k)
sda3      Apple_Driver43 Macintosh           56 @ 120       ( 28.0k)
sda4    Apple_Driver_ATA Macintosh           56 @ 176       ( 28.0k)
sda5    Apple_Driver_ATA Macintosh           56 @ 232       ( 28.0k)
sda6     Apple_Bootstrap Apple_Bootstrap 524288 @ 288       (256.0M)
sda7           Apple_HFS MacOS          1572864 @ 524576    (768.0M)
sda8           Apple_HFS MacOSX        14679777 @ 2097440   (  7.0G)
sda9     Apple_UNIX_SVR2 Debian_sid    33554432 @ 16777217  ( 16.0G)
sda10    Apple_UNIX_SVR2 Gentoo        33554432 @ 50331649  ( 16.0G)
sda11    Apple_UNIX_SVR2 Void          33554432 @ 83886081  ( 16.0G)
sda12    Apple_UNIX_SVR2 swap           4194304 @ 117440513 (  2.0G)
sda13    Apple_UNIX_SVR2 data         112806831 @ 121634817 ( 53.8G)

Block size=512, Number of Blocks=234441648
DeviceType=0x0, DeviceId=0x0

Attached is the grub.cfg that I'm currently using for testing (with the
"Advanced" menu items removed). I'm not sure how update-grub decided the
details of the Mac OS X entries, but they don't work (I wouldn't expect
the 64-bit entry to work in any case, or even be included on a 32-bit
system).

Here are the results of os-prober:
# os-prober
/dev/sda10:Gentoo/Linux:Gentoo:linux
/dev/sda11:void:void:linux
/dev/sda8:Mac OS X:MacOSX:macosx

Note that it missed Mac OS 9 on /dev/sda7.

I've tried the following so far:

1) Use chainloader (works for Windows and NetBSD on x86):
menuentry "Mac OS X (on sda8)" {
    set root=(hd0,apple8)
    chainloader +1
}

That fails with this message:

error: can't find command `chainloader'.
Press any key to continue...

I tried different variations of the above (e.g. adding "insmod
part_apple" and "insmod hfsplus"), without success.

2) I also tried several different hacks on the Mac OS X 32-bit entry
created by update-grub, but I always get this error (for 32-bit):

error: can't find command `xnu_kernel'.
error: can't find command `xnu_mktext'.
Press any key to continue...

Here's a Red Hat bug report from 2013 (!) that details the same GRUB
issue on Mac x86_64 systems, and apparently it was never fixed by the
upstream GRUB maintainers:
https://bugzilla.redhat.com/show_bug.cgi?id=893179

So it appears that GRUB has always only ever been able to boot GNU/Linux
operating systems on Mac platforms (powerpc, ppc-64 and x86_64).
Fortunately, for x86_64 there is rEFIt, which like yaboot appears to no
longer be maintained (but it still works). That's what I use to
multiboot Mac OS X or GRUB in Intel Macs, then from GRUB I'm able to
boot GNU/Linux operating systems. But that's on x86_64, so this is the
wrong list for that, though the GRUB problem appears to be similar.

I haven't made any attempts yet to dig into the source code for yaboot
to see how they're able to multiboot Mac OS 9, Mac OS X, CD/DVD and
GNU/Linux.

BTW, it's not safe to leave the Apple_Bootstrap partition mounted at
/boot/grub, since accidental changes could easily make the system
unbootable (repairable, but unbootable). It would be safer to keep the
GRUB files on the Apple_Bootstrap partition (as they are now), with a
working copy in /boot/grub or /etc/grub.cfg in GNU/Linux, then access
the Apple_Bootstrap partition only when "grub-install" is run and has
had a chance to do some sanity checking on the grub.cfg file, similar to
how "ybin" works in yaboot.

-Stan
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="0"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}
function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

if [ x$feature_default_font_path = xy ] ; then
   font=unicode
else
insmod part_apple
insmod ext2
set root='hd0,apple9'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//pci@f2000000/mac-io@17/ata-4@1f000/disk@1,apple9' --hint-bios=hd0,apple9 --hint-efi=hd0,apple9 --hint-baremetal=ahci0,apple9  532801d4-abc7-45ab-9ee5-fb150fadbb0f
else
  search --no-floppy --fs-uuid --set=root 532801d4-abc7-45ab-9ee5-fb150fadbb0f
fi
    font="/usr/share/grub/unicode.pf2"
fi

if loadfont $font ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=en_US
  insmod gettext
fi
terminal_output gfxterm
if [ "${recordfail}" = 1 ] ; then
  set timeout=30
else
  if [ x$feature_timeout_style = xy ] ; then
    set timeout_style=menu
    set timeout=5
  # Fallback normal timeout code in case the timeout_style feature is
  # unavailable.
  else
    set timeout=5
  fi
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
insmod part_apple
insmod ext2
set root='hd0,apple9'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//pci@f2000000/mac-io@17/ata-4@1f000/disk@1,apple9' --hint-bios=hd0,apple9 --hint-efi=hd0,apple9 --hint-baremetal=ahci0,apple9  532801d4-abc7-45ab-9ee5-fb150fadbb0f
else
  search --no-floppy --fs-uuid --set=root 532801d4-abc7-45ab-9ee5-fb150fadbb0f
fi
insmod png
if background_image /usr/share/desktop-base/homeworld-theme/grub/grub-4x3.png; then
  set color_normal=white/black
  set color_highlight=black/white
else
  set menu_color_normal=cyan/blue
  set menu_color_highlight=white/blue
fi
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
function gfxmode {
	set gfxpayload="${1}"
}
set linux_gfx_mode=
export linux_gfx_mode
menuentry 'Debian GNU/Linux (on /dev/sda9)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-532801d4-abc7-45ab-9ee5-fb150fadbb0f' {
	load_video
	insmod gzio
	if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
	insmod part_apple
	insmod ext2
	set root='hd0,apple9'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//pci@f2000000/mac-io@17/ata-4@1f000/disk@1,apple9' --hint-bios=hd0,apple9 --hint-efi=hd0,apple9 --hint-baremetal=ahci0,apple9  532801d4-abc7-45ab-9ee5-fb150fadbb0f
	else
	  search --no-floppy --fs-uuid --set=root 532801d4-abc7-45ab-9ee5-fb150fadbb0f
	fi
	echo	'Loading Linux 5.16.0-5-powerpc ...'
	linux	/boot/vmlinux root=UUID=532801d4-abc7-45ab-9ee5-fb150fadbb0f ro  quiet
	echo	'Loading initial ramdisk ...'
	initrd	/boot/initrd.img
}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/30_os-prober ###
menuentry 'Gentoo GNU/Linux (on /dev/sda10)' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-simple-db467fda-1c90-4a22-a906-f68dcbf78478' {
	insmod part_apple
	insmod ext2
	set root='hd0,apple10'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//pci@f2000000/mac-io@17/ata-4@1f000/disk@1,apple10' --hint-bios=hd0,apple10 --hint-efi=hd0,apple10 --hint-baremetal=ahci0,apple10  db467fda-1c90-4a22-a906-f68dcbf78478
	else
	  search --no-floppy --fs-uuid --set=root db467fda-1c90-4a22-a906-f68dcbf78478
	fi
	linux /boot/vmlinux root=/dev/sda10
	initrd /boot/initrd.img
}

menuentry 'Void GNU/Linux (on /dev/sda11)' --class void --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-simple-4b3ac82c-f41d-4829-ba6f-e921d25fb846' {
	insmod part_apple
	insmod ext2
	set root='hd0,apple11'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//pci@f2000000/mac-io@17/ata-4@1f000/disk@1,apple11' --hint-bios=hd0,apple11 --hint-efi=hd0,apple11 --hint-baremetal=ahci0,apple11  4b3ac82c-f41d-4829-ba6f-e921d25fb846
	else
	  search --no-floppy --fs-uuid --set=root 4b3ac82c-f41d-4829-ba6f-e921d25fb846
	fi
	linux /boot/vmlinux root=/dev/sda11
	initrd /boot/initrd.img
}

menuentry "Mac OS X (on sda8)" {
    set root=(hd0,apple8)
    chainloader +1
}

menuentry 'Mac OS X (32-bit) (on /dev/sda8)' --class osx --class darwin --class os $menuentry_id_option 'osprober-xnu-32-008cf66665792292'  {
	insmod part_apple
	insmod hfsplus
	set root='hd0,apple8'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//pci@f2000000/mac-io@17/ata-4@1f000/disk@1,apple8' --hint-bios=hd0,apple8 --hint-efi=hd0,apple8 --hint-baremetal=ahci0,apple8  008cf66665792292
	else
	  search --no-floppy --fs-uuid --set=root 008cf66665792292
	fi
        load_video
        set do_resume=0
        if [ /var/vm/sleepimage -nt10 / ]; then
           if xnu_resume /var/vm/sleepimage; then
             set do_resume=1
           fi
        fi
        if [ $do_resume = 0 ]; then
           xnu_uuid 008cf66665792292 uuid
           if [ -f /Extra/DSDT.aml ]; then
              acpi -e /Extra/DSDT.aml
           fi
           if [ /kernelcache -nt /System/Library/Extensions ]; then
              xnu_kernel /kernelcache boot-uuid=${uuid} rd=*uuid
           elif [ -f /System/Library/Kernels/kernel ]; then
              xnu_kernel /System/Library/Kernels/kernel boot-uuid=${uuid} rd=*uuid
              xnu_kextdir /System/Library/Extensions
           else
              xnu_kernel /mach_kernel boot-uuid=${uuid} rd=*uuid
              if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
                xnu_mkext /System/Library/Extensions.mkext
              else
                xnu_kextdir /System/Library/Extensions
              fi
           fi
           if [ -f /Extra/Extensions.mkext ]; then
              xnu_mkext /Extra/Extensions.mkext
           fi
           if [ -d /Extra/Extensions ]; then
              xnu_kextdir /Extra/Extensions
           fi
           if [ -f /Extra/devprop.bin ]; then
              xnu_devprop_load /Extra/devprop.bin
           fi
           if [ -f /Extra/splash.jpg ]; then
              insmod jpeg
              xnu_splash /Extra/splash.jpg
           fi
           if [ -f /Extra/splash.png ]; then
              insmod png
              xnu_splash /Extra/splash.png
           fi
           if [ -f /Extra/splash.tga ]; then
              insmod tga
              xnu_splash /Extra/splash.tga
           fi
        fi
}
menuentry 'Mac OS X (64-bit) (on /dev/sda8)' --class osx --class darwin --class os $menuentry_id_option 'osprober-xnu-64-008cf66665792292'  {
	insmod part_apple
	insmod hfsplus
	set root='hd0,apple8'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//pci@f2000000/mac-io@17/ata-4@1f000/disk@1,apple8' --hint-bios=hd0,apple8 --hint-efi=hd0,apple8 --hint-baremetal=ahci0,apple8  008cf66665792292
	else
	  search --no-floppy --fs-uuid --set=root 008cf66665792292
	fi
        load_video
        set do_resume=0
        if [ /var/vm/sleepimage -nt10 / ]; then
           if xnu_resume /var/vm/sleepimage; then
             set do_resume=1
           fi
        fi
        if [ $do_resume = 0 ]; then
           xnu_uuid 008cf66665792292 uuid
           if [ -f /Extra/DSDT.aml ]; then
              acpi -e /Extra/DSDT.aml
           fi
           if [ /kernelcache -nt /System/Library/Extensions ]; then
              xnu_kernel64 /kernelcache boot-uuid=${uuid} rd=*uuid
           elif [ -f /System/Library/Kernels/kernel ]; then
              xnu_kernel64 /System/Library/Kernels/kernel boot-uuid=${uuid} rd=*uuid
              xnu_kextdir /System/Library/Extensions
           else
              xnu_kernel64 /mach_kernel boot-uuid=${uuid} rd=*uuid
              if [ /System/Library/Extensions.mkext -nt /System/Library/Extensions ]; then
                xnu_mkext /System/Library/Extensions.mkext
              else
                xnu_kextdir /System/Library/Extensions
              fi
           fi
           if [ -f /Extra/Extensions.mkext ]; then
              xnu_mkext /Extra/Extensions.mkext
           fi
           if [ -d /Extra/Extensions ]; then
              xnu_kextdir /Extra/Extensions
           fi
           if [ -f /Extra/devprop.bin ]; then
              xnu_devprop_load /Extra/devprop.bin
           fi
           if [ -f /Extra/splash.jpg ]; then
              insmod jpeg
              xnu_splash /Extra/splash.jpg
           fi
           if [ -f /Extra/splash.png ]; then
              insmod png
              xnu_splash /Extra/splash.png
           fi
           if [ -f /Extra/splash.tga ]; then
              insmod tga
              xnu_splash /Extra/splash.tga
           fi
        fi
}
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/30_uefi-firmware ###
### END /etc/grub.d/30_uefi-firmware ###

### BEGIN /etc/grub.d/40_custom ###
# 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.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg
fi
### END /etc/grub.d/41_custom ###

Reply to: