On 10/10/2017 12:56 PM, John Paul Adrian Glaubitz wrote:
On 10/10/2017 12:33 PM, Frank Scheiner wrote:
Now we only need to get it working on NewWorld Macs :).

Yeah, that seems to be a hard nut to crack. But I believe I'm making
some progress - in understanding at least :-D.

Great.

Ok, looks like I got GRUB installed - "in some way" ;-) with a modified `grub-installer` script.

It still requires:

* to manually mount the NewWorld boot partition to `/target/boot/grub`

* and a prior yaboot installation (for hfsutils and HFS formatting, etc.) until this is done from grub-installer's `debian/postinst` and `grub-installer` scripts (I adapted some code from `mkofboot`/`ybin` for HFS formatting in `grub-installer` but it isn't used yet)

...before actually starting the GRUB installation, but it runs through.

I did this in expert mode and haven't yet tested any other modes of installation.

This is the patch (it still contains unneeded comments and is meant for discussion mainly):

```
diff --git a/grub-installer b/grub-installer
index f9f0761..d354b62 100755
--- a/grub-installer
+++ b/grub-installer
@@ -37,6 +37,29 @@ debug () {
        [ -z "${DEBCONF_DEBUG}" ] || log "debug: $@"
 }

+# adapted from ybin's mkoffs()
+grub_create_offs()
+{
+       local self="grub_create_offs"
+
+       local newworld_boot_partition="$1"
+
+       mount | grep "^$newworld_boot_partition\>" > /dev/null
+       if [ $? = 0 ] ; then
+               error "$self: $newworld_boot_partition appears to be mounted! 
Aborting."
+               return 1
+       fi
+
+       info "$self: Creating HFS filesystem on $newworld_boot_partition..."
+       hformat -l bootstrap "$boot" > /dev/null
+       if [ $? != 0 ] ; then
+               error 1>&2 "$self: HFS filesystem creation failed!"
+               return 1
+       fi
+       humount "$newworld_boot_partition" ## otherwise we might get confused.
+       return 0
+}
+
 ARCH="$(archdetect)"
 info "architecture: $ARCH"

@@ -235,19 +258,24 @@ rootfstype="$(findfstype /)"

 case $ARCH in
     powerpc/chrp|powerpc/chrp_rs6k|powerpc/chrp_ibm|powerpc/cell)
-    ;;
+       ;;
     ppc64/chrp|ppc64/chrp_rs6k|ppc64/chrp_ibm|ppc64/cell)
-    ;;
+       ;;
     powerpc/*|ppc64/*)
-      offs=$(findfs /boot/grub)
- [ -n "$offs" ] || error "GRUB requires that the OF partition is mounted in /boot/grub" 1>&2
-    ;;
+       offs=$(findfs /boot/grub) # /dev/sda2
+       if [ -n "$offs" ]; then
+               bootfs=$offs # /dev/sda2
+               bootfstype=$(findfstype /boot/grub) # hfs
+       else
+               error "GRUB requires that the OF partition is mounted in /boot/grub" 
1>&2
+       fi
+       ;;
 esac

 # This code to set disc_offered was taken from lilo-installer
 rootfs_nodevfs=$(mapdevfs $rootfs)
-bootfs_nodevfs=$(mapdevfs $bootfs)
-prefix=$(device_to_disk "$bootfs")
+bootfs_nodevfs=$(mapdevfs $bootfs) # /dev/sda2
+prefix=$(device_to_disk "$bootfs") # /dev/sda

 case $prefix in
     /dev/md)
@@ -263,10 +291,10 @@ case $prefix in
        disc_offered_devfs=$(echo "$bootfs_nodevfs" | sed 
"s:\(.*\)/.*:\1/disc:")
        ;;
 esac
-disc_offered=$(mapdevfs "$disc_offered_devfs")
+disc_offered=$(mapdevfs "$disc_offered_devfs") # /dev/sda

 # Identify partition table of the disk containing our boot partition
-bootfslabel=$(partmap $disc_offered || echo unknown)
+bootfslabel=$(partmap $disc_offered || echo unknown) # mac

 # Check if the boot file system is on Serial ATA RAID
 frdev=""
@@ -653,6 +681,14 @@ case $ARCH:$grub_package in
        bootdev="$wipe_bootdev"
        state=3
        ;;
+    powerpc/*:grub-ieee1275|ppc64/*:grub-ieee1275)
+       #bootfs=$(findfs /boot/grub)
+       #disk=$(device_to_disk "$bootfs")
+       #db_set grub-installer/bootdev "$disk"
+       #state=2
+       bootdev="$bootfs" # /dev/sda2
+       state=3
+       ;;
     *)
        # No need for install device selection on other platforms.
        bootdev=dummy
@@ -831,19 +867,23 @@ if [ -z "$frdisk" ]; then
                        fi
                fi

-               # Should we force a copy of grub-efi to be installed
-               # to the removable media path too? Ask at low
-               # priority, or can also be pre-seeded of course
-               db_input low grub-installer/force-efi-extra-removable || [ $? 
-eq 30 ]
-               db_go || exit 10
-               db_get grub-installer/force-efi-extra-removable
-               if [ "$RET" = true ]; then
-                       grub_install_params="$grub_install_params 
--force-extra-removable"
-                       # Make sure this happens on upgrades too
-                       $chroot $ROOT 'debconf-set-selections' <<EOF
-$grub_package grub2/force_efi_extra_removable boolean true
-EOF
-               fi
+               case $grub_package in
+                   grub-efi*)
+                       # Should we force a copy of grub-efi to be installed
+                       # to the removable media path too? Ask at low
+                       # priority, or can also be pre-seeded of course
+                       db_input low grub-installer/force-efi-extra-removable 
|| [ $? -eq 30 ]
+                       db_go || exit 10
+                       db_get grub-installer/force-efi-extra-removable
+                       if [ "$RET" = true ]; then
+                               grub_install_params="$grub_install_params 
--force-extra-removable"
+                               # Make sure this happens on upgrades too
+                               $chroot $ROOT 'debconf-set-selections' <<-EOF
+                                       $grub_package 
grub2/force_efi_extra_removable boolean true
+                               EOF
+                       fi
+                       ;;
+               esac

                case $ARCH in
                    powerpc/chrp_pegasos)
@@ -854,6 +894,9 @@ EOF
                        # see: https://github.com/esnowberg/grub2-sparc/wiki
                        grub_install_params="$grub_install_params 
--skip-fs-probe"
                        ;;
+                   */powermac_newworld)
+                       grub_install_params="$grub_install_params 
--macppc-directory=/boot/grub"
+                       ;;
                esac

                if [ "$grub_version" = "grub" ] ; then
@@ -865,6 +908,10 @@ EOF

                CODE=0
                case $ARCH:$grub_package in
+                   */powermac_newworld:grub-ieee1275)
+                       info "Running $chroot $ROOT grub-install 
$grub_install_params"
+ log-output -t grub-installer $chroot $ROOT grub-install $grub_install_params || CODE=$?
+                       ;;
*:grub|*:grub-pc|*:grub-efi*|sparc/*:grub-ieee1275|sparc64/*:grub-ieee1275|powerpc/*:grub-ieee1275|ppc64/*:grub-ieee1275|ppc64el/*:grub-ieee1275) info "Running $chroot $ROOT grub-install $grub_install_params \"$bootdev\"" log-output -t grub-installer $chroot $ROOT grub-install $grub_install_params "$bootdev" || CODE=$?
```

It can be booted with `boot hd:2,grub` from OF (although I think it is intended to use other methods, see below). When doing the installation, there is a longer waiting period after GRUB was installed and the main menu returns, I think this is when the configuration file is created. You should follow the log.

Some issues remain:

```
Oct 10 12:32:48 grub-installer: info: Running chroot /target grub-install --macppc-directory=/boot/grub --force
Oct 10 12:32:48 grub-installer: Installing for powerpc-ieee1275 platform.
Oct 10 12:32:57 grub-installer: grub-install: error: cannot open `/usr/lib/grub/powerpc-ieee1275/grub.chrp': No such file or directory. Oct 10 12:32:57 grub-installer: error: Running 'grub-install --macppc-directory=/boot/grub --force "/dev/sda2"' failed.
```

From the path of the boot script "[...]/grub.chrp" I'd assume that this should be shipped with grub-ieee1275, but I'm not sure. Touching that file in-target makes the error go away:

```
Oct 10 12:52:09 grub-installer: info: Installing grub on '/dev/sda2'
Oct 10 12:52:09 grub-installer: info: grub-install does not support --no-floppy Oct 10 12:52:11 grub-installer: info: Running chroot /target grub-install --macppc-directory=/boot/grub --force
Oct 10 12:52:11 grub-installer: Installing for powerpc-ieee1275 platform.
Oct 10 12:52:20 grub-installer: /usr/sbin/ofpathname: line 812: warning: command substitution: ignored null byte in input
Oct 10 12:52:20 grub-installer: Installation finished. No error reported.
Oct 10 12:52:20 grub-installer: info: grub-install ran successfully
```

When running `grub-install -v --no-nvram --macppc-directory=/boot/grub /dev/sda2` manually in-target - btw it makes no difference between keeping `/dev/sda2` or omitting it, most likely because of `--macppc-directory=[...]` - I can see that this bootscript should go to `/boot/grub/System/Library/CoreServices/BootX`. And this is also what GRUB configures as file to boot in the NVRAM:

```
root@powermac-g5:/boot/grub# nvram --print-config=boot-device
/ht@0,f2000000/pci@9/k2-sata-root@c/scsi@0/sd@0,0:2,\\BootX
```

So this file is really needed, although I can still boot by calling grub directly.

There's still this issue with `ofpathname`, but I don't yet know from where or just where it is called.



Regarding hfsutils:

Here's a patch for grub-installer (package source) that should hopefully
install hfsutils from the `debian/postinst` script (adapted from yaboot-installer)
for the newworld_powermac subarchitecture(s) only:

```
diff --git a/debian/grub-installer.templates b/debian/grub-installer.templates
index e294afb..7ed4b21 100644
--- a/debian/grub-installer.templates
+++ b/debian/grub-installer.templates
@@ -131,6 +131,18 @@ Template: grub-installer/password-crypted
  Type: password
  Description: for internal use; can be preseeded

+Template: grub-installer/apt-install-hfsutils
[...]
  # If we're installing grub-efi, it wants /sys mounted in the
  # target. Maybe /proc too?
  mountvirtfs proc /target/proc
```

That looks reasonable to me.

After working with the grub-installer script, I wonder if we should move this to this script instead, because the installation of grub packages is also done from there. On the other hand, grub-installer is already loaded with lots of different things...


What is the meaning of those "# :sl<NUMBER>:" comments, if at all? I didn't
find any clue in the debconf specification [1] and manpages [2].

Not sure. Those might be hints for the menu system.

We can ask in #debian-boot or on the debian-boot mailing list.

The value I used currently doesn't seem to hurt at least.

Cheers,
Frank

Reply via email to