Apple iMac G5 — Part 4

Previous:

So I previously tried installing Debian and OpenBSD on the iMac G5 without success. Will it be finally the time I start running a Gentoo? Spoiler alert: no.

Gentoo #

So Gentoo is a source-first distribution, it provides the source code of all the software and allows fine-tuning the build for the specific hardware it’s run on. Quite a good idea for old hardware.

But… it feels like going back to the 90s, long and complicated installation procedure, but way more polished.

Anyway, here is a “quick” summary of what I did.

Everything (well… almost everything) is in Gentoo’s PPC64 handbook. Start with downloading the appropriate installation media, in this case “PPC/PPC64 Minimal Installation CD” and booting on it. This leads to a terminal on the live CD.

If the computer is connected to the local network, setting the root password with passwd then starting the SSH server with /etc/init.d/sshd start will allow you to log in remotely. It’s easier that way to copy/paste the commands from the handbook.

Formatting the disk #

There’s a special fdisk version for those Macs, creatively called mac-fdisk.

mac-fdisk /dev/sda
i # initialize the drive (also creates a specific system partition)
b/2p # create a second partition for boot
c/3p/5G/swap # create a 5 GB partition for swap
c/4p/4p/root # create the root partition with the remaining space
mkswap /dev/sda3 # format the swap partition
mkfs.xfs /dev/sda4 # format the root partition
swapon /dev/sda3 # turn on the swap
mkdir --parents /mnt/gentoo # create the mount point where the root partition will be mounted
mount /dev/sda4 /mnt/gentoo # mount the root partition
cd /mnt/gentoo # move into it

Round 1—Installing the base system #

Get the appropriate stage 3 tarball from Gentoo’s website, in this case “PPC64 stage 3 systemd”.

Decompress/untar it into the hard drive root partition, mount the various filesystems and start the chroot environment:

tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner -C /mnt/gentoo
cp --dereference /etc/resolv.conf /mnt/gentoo/etc/
mount --types proc /proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --make-rslave /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
mount --make-rslave /mnt/gentoo/dev
mount --bind /run /mnt/gentoo/run
mount --make-slave /mnt/gentoo/run
chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) ${PS1}"

Set up the package mirror and select a profile (here I tried the profile with systemd and GNOME, KDE is not available).

emerge-webrsync
emerge --ask --verbose --oneshot app-portage/mirrorselect
mirrorselect -i -o >> /etc/portage/make.conf
eselect profile list
eselect profile set 4

Add this to use binary packages when available (can reduce build time by using pre-compiled binaries):

/etc/portage/make.conf
# Appending getbinpkg to the list of values within the FEATURES variable
FEATURES="${FEATURES} getbinpkg"
# Require signatures
FEATURES="${FEATURES} binpkg-request-signature"

Then run getuto to set up the trust chain.

Add specific CPU flags (on the G5 there should be only the altivec flag to add) and video card family:

emerge --ask --oneshot app-portage/cpuid2cpuflags
cpuid2cpuflags
echo "*/* $(cpuid2cpuflags)" > /etc/portage/package.use/00cpu-flags
echo "*/* VIDEO_CARDS: radeon r300" >> /etc/portage/package.use/00video-cards

And finally start installing the base system:

emerge --ask --verbose --update --deep --newuse --getbinpkg @world

But it fails with a cyclic dependency on docutils, suggesting to remove truetype, a dependency of pillow. So echo 'dev-python/pillow -truetype' >> /etc/portage/package.use/pillow and try again.

Then it starts downloading the packages and compiling them, it takes a while (i.e., more than 12 hours)… And it fails while linking cargo. I guess it’s an out-of-memory issue. 1.5 GB of RAM and 5 GB of swap may be not enough.

Round 2—Installing the base system… again #

I guess rust is a GNOME dependency, so I changed the profile to systemd only, no desktop. This time the installation was much faster and succeeded.

Configure the locale (en_US.UTF-8 here):

nano /etc/locale.gen
locale-gen
eselect locale list
eselect locale set 4 # (en_US.UTF-8)
env-update && source /etc/profile && export PS1="(chroot) ${PS1}"

Install the Linux kernel #

Accept non-free firmware and install the kernel:

echo "sys-kernel/linux-firmware linux-fw-redistributable" >> /etc/portage/package.license
emerge --ask sys-kernel/linux-firmware
echo "sys-kernel/installkernel dracut" >> /etc/portage/package.use/installkernel
emerge --ask sys-kernel/installkernel
emerge --ask sys-kernel/gentoo-kernel-bin

But no kernel packages are provided, they are all masked.

!!! All ebuilds that could satisfy "sys-kernel/gentoo-kernel-bin" have been masked.
!!! One of the following masked packages is required to complete your request:
- sys-kernel/gentoo-kernel-bin-6.17.5::gentoo (masked by: package.mask, ~ppc64 keyword)
  /var/db/repos/gentoo/profiles/arch/powerpc/ppc64/package.mask:
# Georgy Yakovlev <gyakovlev@gentoo.org> (2020-08-27)
# big-endian ppc64 configs are not provided
# however users can unmask and use savedconfig feature

Unmask the kernel and some other dependencies:

echo "=sys-kernel/gentoo-kernel-bin-6.12.47::gentoo" >> /etc/portage/package.unmask
echo "=virtual/dist-kernel-6.12.47::gentoo" >> /etc/portage/package.unmask
emerge --ask sys-kernel/gentoo-kernel-bin
emerge --update --newuse --deep --with-bdeps=y @world # ← because of missing libxml lib
emerge --depclean
echo 'USE="dist-kernel"' >> /etc/portage/make.conf
emerge --ask @module-rebuild
emerge --config sys-kernel/gentoo-kernel-bin
emerge --ask sys-kernel/gentoo-sources
eselect kernel list
eselect kernel set 2 # linux-6.12.47-gentoo-dist

Install various tools and configurations #

Make sure the /etc/fstab file contains the right partitions (compare with the output of blkid):

/etc/fstab
UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"     none    swap    sw              0 0
UUID="yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"     /       xfs     defaults        0 1

Likewise, ensure the hostname is set:

echo imac-g5 > /etc/hostname
hostnamectl hostname image-g5

And DHCP client, prepare systemd…

# DHCP client
emerge --ask net-misc/dhcpcd
systemctl enable dhcpcd
# Systemd
systemd-machine-id-setup
systemd-firstboot --prompt # Select the language number (73 for en)
systemctl preset-all --preset-mode=enable-only
emerge --ask sys-apps/mlocate
emerge --ask app-shells/bash-completion
systemctl enable systemd-timesyncd.service
emerge --ask sys-fs/xfsprogs

Prepare boot #

Install grub and parted.

emerge --ask sys-boot/grub
emerge --ask sys-block/parted

Use parted /dev/sda print to make sure which partition is the bootstrap one.

1      512B    32.8kB  32.3kB                  Apple
2      32.8kB  852kB   819kB                   bootstrap  boot
3      852kB   5370MB  5369MB  linux-swap(v1)  swap       swap
4      5370MB  250GB   245GB   xfs             root       root

Format the bootstrap partition, set the right labels on it and create grub configuration:

dd if=/dev/zero of=/dev/sda2 bs=512
hformat -l bootstrap /dev/sda2
mkdir /boot/NWBB
mount --types hfs /dev/sda2 /boot/NWBB
grub-install --macppc-directory=/boot/NWBB /dev/sda2
umount /boot/NWBB
hmount /dev/sda2
hattrib -t tbxi -c UNIX :System:Library:CoreServices:BootX
hattrib -b :System:Library:CoreServices
humount
grub-mkconfig -o /boot/grub/grub.cfg

Boot #

At this point the machine is ready to boot. Restart it (remove the USB drive).

And it crashed with an “Invalid memory access” error.

This whole Gentoo installation process took like 2 days. I’m not keen to repeat it. So, no Gentoo for the iMac.

Next:

Comments Add one by emailing me.