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: 4

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: 5

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: 4

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: 5

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: 4

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
giordanogalli
n00b
n00b


Joined: 26 Jul 2019
Posts: 1

PostPosted: Fri Jul 26, 2019 9:18 am    Post subject: Reply with quote

Hello dusxmt

Since I'm a OSX user trying to switch to Linux, you will hopefully pardon me for asking such a dumb question: is the command line shown in your message the one from OSX?

Thank you for your help.


Giordano
Back to top
View user's profile Send private message
dusxmt
n00b
n00b


Joined: 18 Jun 2018
Posts: 4

PostPosted: Sun Jul 28, 2019 9:41 am    Post subject: Reply with quote

Hello, giordanogalli :)

No, the commands are all for Gentoo, the guide assumes you already have a Gentoo system deployed (from a stage3 archive) and chrooted into (from a Live CD)
, installing the bootloader is a part of the installation procedure from a Live CD.

Also, while I share your enthusiasm for RISC and PowerPC hardware, I think that for learning to use GNU/Linux, it might be better to first start with something more widely supported (Like a Raspberry Pi), as I think it would be a shame if the many stumbling blocks that using obscure hardware unfortunately brings would discourage you from the system.

Also Adelie might be an interesting distro to check out, they support PowerPC as a tier-1 platform, and unlike Gentoo, you don't have to compile everything yourself and wait hours upon hours for things to get set up.
_________________
GNU is as new as gold is old.
Back to top
View user's profile Send private message
mattst88
Developer
Developer


Joined: 28 Oct 2004
Posts: 422

PostPosted: Fri Aug 09, 2019 10:15 pm    Post subject: Reply with quote

Thanks! This was incredibly useful! Using your instructions I have my iMac G4 booting grub via the automatic method.

I plan to write some changes for the Gentoo handbook and then see if we can remove yaboot :)
Back to top
View user's profile Send private message
xplosivelugnut
n00b
n00b


Joined: 03 Apr 2015
Posts: 9

PostPosted: Thu Feb 25, 2021 4:33 am    Post subject: Reply with quote

Just confirming that this works flawlessly on a GPT drive in a 2005 G5.
Thanks!
Back to top
View user's profile Send private message
Atha
Apprentice
Apprentice


Joined: 22 Sep 2004
Posts: 228

PostPosted: Sun Apr 25, 2021 9:06 am    Post subject: Reply with quote

Hi!
xplosivelugnut wrote:
Just confirming that this works flawlessly on a GPT drive in a 2005 G5.

How does this work? How do you "bless" the bootloader on a GPT partition for PowerPC? Is a special boot partition required, possibly a hybrid (aka MBR) FAT partition?
_________________
Think for yourself and let others enjoy the privilege of doing so too. Voltaire
Back to top
View user's profile Send private message
xplosivelugnut
n00b
n00b


Joined: 03 Apr 2015
Posts: 9

PostPosted: Tue Apr 27, 2021 3:33 am    Post subject: Reply with quote

The late 2005 PCIe G5's natively support GPT.

So all you need is a "bootstrap" partition with an elf in the right place with the tbxi attribute and you're good to go.
In my case, I used GPT fdisk and created a 128 MB "bootstrap" partition as the first partition. Another 128 MB partition for the /boot partition. And the rest of the disk for the / (root) partition. Vaguely EFI-esque. All the partition types were just left as 8300.

I then formatted the bootstrap partition with HFS and mounted it to /boot/bootstrap.
grub-install takes care of the rest.

Code:
# dd if=/dev/zero of=/dev/sdXn bs=512
# hformat -l bootstrap /dev/sdXn
# mount /dev/sdXn /boot/bootstrap/
# grub-install --macppc-directory=/boot/bootstrap


This created the following directory structure and files in /boot/bootstrap/ (sdXn)

Code:
/
  mach_kernel
  System/
    Library/
      CoreServices/
        .disk_label
        .disk_label.contentDetails
        BootX
        grub.elf
        SystemVersion.plist


And I don't know if this next part was necessary. For all I know, grub-install handled this too.

Code:
# umount /boot/bootstrap/
# hmount /dev/sdXn
# hattrib -t tbxi -c UNIX :System:Library:CoreServices:BootX
# hattrib -b :System:Library:CoreServices
# humount


Grub then shows up as a boot option if I boot the G5 holding the Option key. It would probably boot by default if I didn't have an OSX install on the first SATA drive.

As far as I know, only the PCIe G5's from '05 can do this. You can also copy an OSX install to a GPT drive and it works just fine. The OSX install disk I have won't let a PPC machine install it straight to a GPT drive though. Wonder if there's one that will?
Back to top
View user's profile Send private message
Atha
Apprentice
Apprentice


Joined: 22 Sep 2004
Posts: 228

PostPosted: Fri May 14, 2021 3:22 pm    Post subject: Reply with quote

xplosivelugnut wrote:
The late 2005 PCIe G5's natively support GPT.

Wow! I did not know that. Since the Late-2005-G5s don't support anything earlier than 10.4 anyhow, that should work. Tiger is officially booting off of GPT, so I think it would be worth a try to setup multi-boot with Mac OS X and Linux.

As you correctly pointed out Mac OS X won't install onto a GPT partition on a PowerPC-based Mac, but it is possible to use something like Disk Utility's backup and restore funktion to get it onto such a partition. It would require to install it onto a second HDD first, or onto an external drive's partition. Then clone that installation into an disk image, boot that installation from the external drive and use it to restore the disk image to the interal GPT drive. IMHO it's best practice to clone a non-active operating system, not one that is in use – hence the intermediate step to create a disk image first.

As an alternative to Disk Utility an older Carbon Copy Cloner version (shareware) will also do the job. It's what I used to test if OS X Lion (version 10.7, Intel-only) was able to boot from an MBR partition on an Intel Mac. It worked. Mac OS X can boot from anything it knows, even when it doesn't support it as installation destination. Therefore, if the firmware supports it, Mac OS X can be booted on MBR, APM and (starting with Tiger) GPT.

Now that I know that, I will certainly try GPT on my own Late-2005 Power Mac. The only drawback I see right now is that the Apple Hardware Test, which I have cloned from the original DVD onto the internal HDD (using the same partition type) will most likely not function from GPT.
_________________
Think for yourself and let others enjoy the privilege of doing so too. Voltaire
Back to top
View user's profile Send private message
kahuna
n00b
n00b


Joined: 21 Apr 2022
Posts: 10
Location: Alberta, Canada

PostPosted: Thu Apr 21, 2022 4:30 am    Post subject: Reply with quote

I know it's been years, but thanks for the quick guide dusxmt.
The automated GRUB install worked like a charm on my G5. You don't need to unmask it anymore :)

Just one note worth to mention, at least for G5s... a Kernel created by 'genkernel' does not work, you get a "invalid memory access" message on boot.
Apparently, a Kernel configured as make g5_defconfig does work. I'm compiling it as I type this.
https://forums.gentoo.org/viewtopic-t-1128505.html
Back to top
View user's profile Send private message
min.xu
n00b
n00b


Joined: 11 Jun 2022
Posts: 2

PostPosted: Sat Jun 11, 2022 6:46 pm    Post subject: Reply with quote

Quote:
Just one note worth to mention, at least for G5s... a Kernel created by 'genkernel' does not work, you get a "invalid memory access" message on boot.


I am on a powerbook g4 and ran into the same issue. It seems related to kernel config's KERNEL_START or PHYSICAL_START settings. (Also, trying to load ppc64 kernel from the livecd/usb also resulted in similar error msg.

I ran
Code:
genkernel --menuconfig all
and load the CDROM/USB's ppc32-config file and saved it back .config. After that, genkernel was able to build a working ppc32 kernel for me.
Back to top
View user's profile Send private message
kahuna
n00b
n00b


Joined: 21 Apr 2022
Posts: 10
Location: Alberta, Canada

PostPosted: Thu Jun 16, 2022 4:42 am    Post subject: Reply with quote

min.xu wrote:

I ran
Code:
genkernel --menuconfig all
and load the CDROM/USB's ppc32-config file and saved it back .config. After that, genkernel was able to build a working ppc32 kernel for me.


I'm glad that you found a way, it's good to know.
I ended up configuring my own Kernel, it does take more time for sure...
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