Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
A guide to installing GRUB on NewWorld PowerMacs
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo on PPC
View previous topic :: View next topic  
Author Message
dusxmt
n00b
n00b


Joined: 18 Jun 2018
Posts: 3

PostPosted: Mon Jun 18, 2018 4:09 pm    Post subject: A guide to installing GRUB on NewWorld PowerMacs Reply with quote

Greetings. Since there doesn't seem to be any sort of step-by-step guide for setting up grub on PowerPC, and because I've had problems with building Yaboot, I've decided to have a go at writing it.


There's two ways of setting up grub, either semi-automatically using grub-install, or manually using grub-mkimage[1]. In both cases, a bootstrap partition that can be read by openfirmware is needed, with the default (and minimum) 800K bootstrap partition being sufficient.


Preparation:

Before we can begin, we need to install grub. It's currently masked, so unmasking is necessary:
Code:
# echo '=sys-boot/grub-2.02-r1 **' > /etc/portage/package.accept_keywords/grub


Next, we need to make sure support for the powerpc-ieee1275 (OpenFirmware on PowerPC) platform is built:
Code:
# echo 'GRUB_PLATFORMS="ieee1275"' >> /etc/portage/make.conf


After this, grub can be installed:
Code:
# emerge --ask sys-boot/grub


Additionally, hfsutils are needed for setting up the bootstrap partition:
Code:
# emerge --ask sys-fs/hfsutils



A) Semi-automatic installation:

grub-install uses the native filesystem drivers to install the boot image, so make sure you have support for hfs available in your kernel.

The first step is setting up the bootstrap partition, be sure to replace sdX with the device node of your bootstrap partition:
Code:
# dd if=/dev/zero of=/dev/sdX bs=512
# hformat -l bootstrap /dev/sdX


Now that the partition is formatted, we can mount it and install grub:
Code:
# mkdir /tmp/bootstrap
# mount -t hfs /dev/sdX /tmp/bootstrap
# grub-install --macppc-directory=/tmp/bootstrap
# umount /tmp/bootstrap


If you take a look at the created directory tree in /tmp/bootstrap, you'll see that (the current version of) grub mimics the filesystem layout of OSX, this is presumably for extra compatibility with external tools. However, what it doesn't seem to do is set up the file type for the boot script and it doesn't bless the folder which contains it, this can be corrected with the following set of commands:
Code:
# hmount /dev/sdX
# hattrib -t tbxi -c UNIX :System:Library:CoreServices:BootX
# hattrib -b :System:Library:CoreServices
# humount


It should now be possible to launch grub with the default "boot hd:,\\:tbxi" command on the open firmware prompt, or perhaps "boot hd:number,\\:tbxi" if you have other bootable partitions that precede the bootstrap partition, or "boot hd:number,\System\Library\CoreServices\BootX" in case open firmware doesn't for some reason detect the medium as bootable.

The next step is configuring grub using the standard means:
Code:
# vi /etc/default/grub
# grub-mkconfig --output=/boot/grub/grub.cfg

After this, reboot, and hope for the best :)


B) Manual installation:

In case you're having trouble with the semi-automatic installation, or would like to have more fine-grained control over the installation process, you can install grub manually[1].

The first step is to install grub's modules and to set up a preliminary configuration file in the /boot directory:
Code:
# mkdir -p /boot/grub/powerpc-ieee1275
# cp /usr/lib/grub/powerpc-ieee1275/{*.mod,*.lst} /boot/grub/powerpc-ieee1275/

Code:
# vi /boot/grub/grub.cfg
insmod linux

menuentry "Gentoo GNU/Linux" {
    echo 'Loading the kernel...'
    linux /boot/vmlinux root=UUID=<UUID> rootfstype=ext4 ro

    echo 'Loading the initial ram disk...'
    initrd /boot/initrd
}

Replace <UUID> with the UUID of your root partition, and If you have an explicit boot partition, remove the "/boot" prefix from the paths in the above configuration. If you don't use an initrd, remove the two lines that deal with it as well. And of course, if you use a different root filesystem than ext4, edit the rootfstype= option as well.

Next, we need a built-in configuration file that will be physically baked into the bootable grub image:
Code:
# vi grub.cfg.atom
echo 'Looking for the boot partition...'
search --no-floppy --fs-uuid --set=root <UUID>
set prefix=($root)/boot/grub

echo 'Loading configuration...'
insmod configfile
configfile /boot/grub/grub.cfg

Now replace <UUID> with the UUID of your boot partition, and again, if you have an explicit boot partition instead of it being a folder in your root partition, delete the "/boot" prefix from the paths.

The next step is to create a file with the list of modules you want to build into the image, in my case it is:
Code:
# vi modules.list
search_fs_uuid.mod search_fs_file.mod search_label.mod search.mod
part_apple.mod
fshelp.mod ext2.mod
halt.mod reboot.mod echo.mod

Make sure that the module for the file system of your boot partition is in this list. Additionally, if you're using LVM or LDM, you might need the "lvm.mod" and "ldm.mod" modules, for RAID you may need "diskfilter.mod" "raid5rec.mod" "raid6rec.mod", for an encrypted boot you may need the appropriate crypto modules and to add an invocation of "cryptomount -u <drive>" to your config. See util/grub-install.c (in particular, invocations of grub_install_push_module ()).

You can find dependency information for the modules in the file /usr/lib/grub/powerpc-ieee1275/moddep.lst

With the list of modules ready, you can now generate a bootable image of grub:
Code:
# grub-mkimage --prefix=/boot/grub --format=powerpc-ieee1275 --config=grub.cfg.atom --output=grub.img `cat modules.list`


Next off, we need to format the bootstrap partition and copy the created image onto it, be sure to replace sdX with the device node of your bootstrap partition:
Code:
# dd if=/dev/zero of=/dev/sdX bs=512
# hformat -l bootstrap /dev/sdX
# hmount /dev/sdX
# hcopy -r grub.img :grub.img


It should now be possible to boot grub with an explicit invocation of "boot hd:number,\grub.img". If you would like grub to be bootable using the default "boot hd:,\\:tbxi" command, a boot script is needed, here's an example[2] of one that just boots grub:
Code:
# vi ofboot.b
<CHRP-BOOT>
<COMPATIBLE>
MacRISC MacRISC3 MacRISC4
</COMPATIBLE>
<DESCRIPTION>
grub
</DESCRIPTION>
<BOOT-SCRIPT>
boot &device;:&partition;,\grub.img
</BOOT-SCRIPT>
</CHRP-BOOT>

Now we need to copy this script onto the bootstrap partition, mark it as being of the type tbxi (which stands for "Toolbox Image", referring to the Macintosh Toolbox), and to bless the root directory.
Code:
# hcopy -r ofboot.b :ofboot.b
# hattrib -t tbxi -c UNIX :ofboot.b
# hattrib -b :

I found that on my machine (a Titanium PowerBook G4), there need to be at least 3 files in the blessed directory for it to work, so we'll copy the modules.list file as well:
Code:
# hcopy -r modules.list :modules.list

We can now unmount the bootstrap partition, and try to reboot and see if it works:
Code:
# humount


It should now be possible to launch grub with the default "boot hd:,\\:tbxi" command on the open firmware prompt, or perhaps "boot hd:number,\\:tbxi" if you have other bootable partitions that precede the bootstrap partition, or "boot hd:number,\grub.img" in case open firmware doesn't for some reason detect the medium as bootable.

Graphical console for the manual installation:

The default look of grub on open firmware (with the manual method, at least) is pretty crummy, but thankfully, there is a framebuffer driver for the open firmware framebuffer in grub, and it's pretty easy to enable.

First thing's first, we need to install a graphical font:
Code:
# cp /usr/share/grub/unicode.pf2 /boot/grub/

Now we can configure grub accordingly:
Code:
# vi /boot/grub/grub.cfg
insmod ieee1275_fb
insmod gfxterm

loadfont ${prefix}/unicode.pf2
set gfxmode=auto
terminal_output gfxterm


insmod linux

menuentry "Gentoo GNU/Linux" {
    echo 'Loading the kernel...'
    linux /boot/vmlinux root=UUID=<UUID> rootfstype=ext4 ro

    echo 'Loading the initial ram disk...'
    initrd /boot/initrd
}

This config is the same as the initial one, but with some extra code at the beginning.

If everything worked as it should, you should now have a pretty nice-looking boot-up screen with grub :)


Sources:
1 - http://cynic.cc/blog/posts/running_grub2_on_powerpc_macs
2 - https://lists.debian.org/debian-powerpc/2005/10/msg00074.html
3 - http://git.savannah.gnu.org/cgit/grub.git/tree/util/grub-install.c


Other articles worth reading:
http://mac.linux.be/content/guide-open-firmware-apple-bios-0
https://www.netbsd.org/ports/macppc/faq.html
http://ftp.netbsd.org/pub/NetBSD/NetBSD-7.1.2/macppc/INSTALL.html#Open%20Firmware%20boot%20syntax
_________________
GNU is as new as gold is old.
Back to top
View user's profile Send private message
cloverskull
n00b
n00b


Joined: 03 Nov 2017
Posts: 3

PostPosted: Fri Jun 22, 2018 11:02 pm    Post subject: Reply with quote

Thanks for this write-up! I was able to get grub to work, using the automatic configuration. However, I hit a bit of a snag when I tried launching xorg. It seems likely to be some sort of modesetting or framebuffer issue.

My working yaboot config looks like this:
Code:
boot=/dev/hda2
device=hd:
partition=4
root=/dev/hda4
timeout=30
install=/usr/lib/yaboot/yaboot
magicboot=/usr/lib/yaboot/ofboot

image=/boot/kernel-4.9.72-gentoo
        label=Linux
        read-only
        append="video=ofonly rootfstype=ext4"
        initrd=/boot/initramfs-genkernel-ppc-4.9.72-gentoo
        initrd-size=8192


I tried manually adding the "video=ofonly" argument in the grub configuration, but it didn't work; I still had xorg problems. Any ideas what might be going wrong here?[/code]
Back to top
View user's profile Send private message
dusxmt
n00b
n00b


Joined: 18 Jun 2018
Posts: 3

PostPosted: Sat Jun 23, 2018 6:11 am    Post subject: Reply with quote

Hmmm... I know GRUB messes with the vga= option on PCs, but I didn't think it messed with video= ... perhaps gfxpayload might be the culprit.

I'd double check that the option actually gets passed to the kernel:
Code:
$ cat /proc/cmdline

and also doble check that you added the option to the right field (GRUB_CMDLINE_LINUX) of /etc/default/grub and re-generated the config in /boot/grub/grub.cfg afterwards, making sure to check whether it is there.
_________________
GNU is as new as gold is old.
Back to top
View user's profile Send private message
cloverskull
n00b
n00b


Joined: 03 Nov 2017
Posts: 3

PostPosted: Sat Jun 23, 2018 10:26 pm    Post subject: Reply with quote

Thanks for the help. I checked /proc/cmdline and can confirm it's getting passed. I also put it in the correct spot in /etc/default/grub and confirmed in /boot/grub/grub.cfg. I also added the gfxpayload=text option this time, and have the same issues. Bummer. :(
Back to top
View user's profile Send private message
dusxmt
n00b
n00b


Joined: 18 Jun 2018
Posts: 3

PostPosted: Sun Jun 24, 2018 8:27 am    Post subject: Reply with quote

Since it's getting passed to the kernel, I suspect that grub's also passing some other options to the video driver that then make it fail with X; I'd try explicitly setting the video options, eg. on my machine I pass radeonfb.mode_option=1152x768-32
_________________
GNU is as new as gold is old.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo on PPC All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum