Skip to content

Instantly share code, notes, and snippets.

@DevonMorris
Created April 21, 2019 03:35
Show Gist options
  • Save DevonMorris/d97f2ba9bacf0090a79fd326cc0835d6 to your computer and use it in GitHub Desktop.
Save DevonMorris/d97f2ba9bacf0090a79fd326cc0835d6 to your computer and use it in GitHub Desktop.
Gentoo 17.0 Systemd on Macbook Pro (12,1)

This document highlights my quest to install Gentoo with Systemd my Macbook Pro 2015 (12,1). I'm basically following the amd64 handbook with some changes I've had to search out.

First we need to connect to the network. I'm using WiFi to accomplish this and my network is WPA so I run

wpa_passphrase <SSID> <PASS> >> /etc/wpa_supplicant/wpa_supplicant.conf
rc-update add wpa_supplicant default
/etc/init.d/wpa_supplicant start

I'ts probably a good idea to test that the connection worked with ping 8.8.8.8 or something to that effect.

The small print on the retina display is really annoying, so I'm going to work over ssh to install. In order to do this I change the root password

passwd

We'll then enable ssh

rc-service sshd start

and then I find the ip address with ifconfig and ssh root@<ip>. Cool now our eyes won't fall out from the rest of the installtion.

I basically skipped the rest of network configuration in the handbook and moved on to formatting the disks. I follwed the parted section of the handbook in this part. There are some gothas in this section. So the MBP uses UEFI for its boot, so we have to make sure the /boot partition is formatted as some type of fat partition. Basically my set up looks something like this

parted -a optimal /dev/sda
(parted) mklabel gpt
(parted) unit mib                                                         
(parted) mkpart primary 1 3                                               
(parted) name 1 grub                                                      
(parted) set 1 bios_grub on                                               
(parted) mkpart primary 3 1027                                            
(parted) name 2 boot                                                      
(parted) mkpart primary 1027 9219                                         
(parted) name 3 swap                                                      
(parted) mkpart primary 9219 -1                                           
(parted) name 4 rootfs                                                    
(parted) set 2 boot on                                                    
(parted) print                                                            
Model: ATA APPLE SSD SM0128 (scsi)
Disk /dev/sda: 115712MiB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start    End        Size       File system  Name    Flags
 1      1.00MiB  3.00MiB    2.00MiB                 grub    bios_grub
 2      3.00MiB  1027MiB    1024MiB                 boot    boot, esp
 3      1027MiB  9219MiB    8192MiB                 swap
 4      9219MiB  115711MiB  106492MiB               rootfs

(parted) q                                                                

My boot partition is probably on the big side, but whatever. I also set my swap to 8GB because people sometimes recommend having swap=memory. I then format these partions

mkfs.vfat /dev/sda2
mkfs.ext4 /dev/sda4
mkswap /dev/sda3
swapon /dev/sda3

Note that we use vfat on /dev/sda2 because of the UEFI system. Now we mount that new filesystem with

mount /dev/sda4 /mnt/gentoo

Check that the date is right with

date

Mine is. Now I cd onto the root of my new filesystem

cd /mnt/gentoo

and download the stage 3 tarball with systemd

wget http://distfiles.gentoo.org/releases/amd64/autobuilds/20190418/systemd/stage3-amd64-systemd-20190418.tar.bz2

(Maybe check this link if you are doing this later because dates and stuff). You can always use the links cli browser to get it if you are still staring at those small letters. At this point I should probably do the gpg validation thing, but YOLO. Let's unpack this tarball

tar xpvf stage3-amd64-systemd-20190418.tar.bz2 --xattrs-include='*.*' --numeric-owner

The handbook does a good job at explaining why this command is this way so maybe read it. Now I gotta edit the make.conf with the one true emulator vi

vi /etc/portage/make.conf

Here my make.conf

# These settings were set by the catalyst build script that automatically
# built this stage.
# Please consult /usr/share/portage/config/make.conf.example for a more
# detailed example.
COMMON_FLAGS="-march=native -O2 -pipe"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
MAKEOPTS="-j4"

# NOTE: This stage was built with the bindist Use flag enabled
PORTDIR="/usr/portage"
DISTDIR="/usr/portage/distfiles"
PKGDIR="/usr/portage/packages"

# This sets the language of build output to English.
# Please keep this setting intact when reporting bugs.
LC_MESSAGES=C

# EMERGE_DEFAULT_OPTS is set automatically by livecd-tools autoconfig during first live boot.
# This should be equal to number of processors, see "man emerge" for details.
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --jobs=4 --load-average=4"

Now I copied over my DNS info

cp --dereference /etc/resolv.conf /mnt/gentoo/etc/

I then followed the handbook and mounted my folders

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 

Now I chroot!

chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) ${PS1}"

I also mount /dev/sda2 at boot since I'll have to install grub2 later

mount /dev/sda2 /boot

I got those sweet updates with

emerge-webrsync

Then I make sure I am on the correct profile

eselect profile list

It should be the 17.0/systemd one. If it's not then you can change it with

eselect profile set <num>

Now we can update the whole world by running

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

This takes a few minutes, so grab a coke or something. Then you are supposed to set the USE flags, but they've given me headaches during my previous attempts at installing gentoo, so I'll just leave them blank for now.

Now, since I'm using systemd, I'll skip the next part of the handbook, since you can set the time, locale and hostname with systemd after the first boot.

Now, we pray to the linux gods (Linux Torvalds) and pull down that sweet linux kernel

emerge --ask sys-kernel/gentoo-sources

Now comes the most fun (painfully annoying) part of this whole process. configuring the linux kernel. Getting the BCM43602 wifi card on the MBP 12,1 to work has undoubtedly been the most annoying part of this whole operation. I definitely want to use lspci for this operations so I'll install it

emerge --ask sys-apps/pciutils

I will also use lshw which shows more hardware. So I'll install that too

emerge --ask sys-apps/lshw

I used the genkernel --menuconfig all method in the past and tried to enable the Broadcom device drivers, but it didn't pick up that BCM43602 card. I'm going to try to be really explicit and enable all of the drivers I will need. I start off by running

lspci -vvv

You might pipe this into less if you can't scroll in your terminal. I'll just show one entry

00:00.0 Host bridge: Intel Corporation Broadwell-U Host Bridge -OPI (rev 09)
	Subsystem: Apple Inc. Broadwell-U Host Bridge -OPI
	Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
	Status: Cap+ 66MHz- UDF- FastB2B+ ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort+ >SERR- <PERR- INTx-
	Latency: 0
	Capabilities: [e0] Vendor Specific Information: Len=0c <?>
	Kernel driver in use: bdw_uncore

Where it says kernel driver in use, that's what I'll search for when I do make menuconfig. Here's the list of all the configuration options I selected in the kernel. based on lscpi. First, a little note on menuconfig, you can search using / just like in vi. You'll see a list of options with numbers on the left. If press that number it will take you to the option and you can hit Y to include the option or M to modularize features. I was probably more liberal than I needed to be so the install might not be "minimal".

SND_HDA_INTEL
X86_INTEL_LPSS
GPIOLIB
I2C_DESIGNWARE_PLATFORM
SND_SOC_INTEL_BDW_RT5766_MACH
USB_XHCI_HCD
BRCMFMAC [M]
BRCMFMAC_PCIE
USB_HID
BONDING

Note: BRCMFMAC [M] needs to be compiled as a module. I also put in all the suggested packages from the handbook. Then we pray to linux gods again and run

make && make modules_install

Then I install the kernel with

make install

Then I looked at possible kernel modules with this

find /lib/modules/4.19.27-gentoo-r1/ -type f -iname '*.o' -or -iname '*.ko' | less

Here I added brcfmac to /etc/modules-load.d/network.conf. I also added efivarfs to a newly created file /etc/modules-load.d/efi.conf. Now I followed the handbook and modified the /etc/fstab as

/dev/sda2               /boot           vfat            noauto,noatime          0 2
/dev/sda3               none            swap            sw                      0 0
/dev/sda4               /               ext4            noatime                 0 1

We skip the stuff about hostname and network because I am using systemd. I do want to set the root password so I run

passwd

I will install some filesystem tools

emerge --ask sys-fs/e2fsprogs
emerge --ask sys-fs/dosfstools

I also installed some networking tools

emerge --ask net-misc/dhcpcd
emerge --ask net-wireless/iw net-wireless/wpa_supplicant

Now we will create and install the boot loader. Now I installed grub2 for efi system

echo 'GRUB_PLATFORMS="efi-64"' >> /etc/portage/make.conf
emerge --ask sys-boot/grub:2

For some reason, I always have to remount before I can install grub and make the config

mount -o remount,rw /sys/firmware/efi/efivars
grub-install --target=x86_64-efi --efi-directory=/boot
grub-mkconfig -o /boot/grub/grub.cfg

Now I exit the chroot, unmount, reboot and pray it worked

exit
cd
umount -l /mnt/gentoo/dev{/shm,/pts,}
umount -R /mnt/gentoo
reboot

It worked!!! And the wifi modules loaded. Note: if the disk name changes to /dev/sdb it will not boot. So I need to be careful and eventually edit /etc/fstab to use UUID. Now we need to setup systemd.

basically just follow this guide

@DevonMorris
Copy link
Author

DevonMorris commented Apr 21, 2019

I also had to boot back into the live-cd and install net-misc/networkmanager, so I should probably install that before rebooting in the future. You'll have to use nmcli or nmtui to configure the network and make sure you followed the systemd guide to run the networkd service.

@DevonMorris
Copy link
Author

If you want to use some type of DE or windows manager, I'm using i3-gaps, you'll probably want to use your touchpad. So I compiled the kernel module bcm5974 and added it to /etc/modules-load.d/touchpad.conf.

I also follwed this synaptics page and added

Section "InputClass"
  Identifier "evdev touchpad catchall"
  Driver "synaptics"
  MatchIsTouchpad "on"
  MatchDevicePath "/dev/input/event*"
  Option "Protocol" "event"
  option "SHMConfig" "on"
  Option      "VertScrollDelta"          "-111"
  Option      "HorizScrollDelta"         "-111"
EndSection

to /etc/X11/xorg.conf.d/50-synaptics.conf. This enables "natural scrolling" and makes the touchpad feel good enough.

@DevonMorris
Copy link
Author

I also needed ROS for some stuff so I was able to install ROS with a portage overlay. Instructions are on the ros website here. Even though there isn't a page for Melodic, it is supported. Although you might have to change the use flags for some packages to get them to install properly. Just use the error messages that the emerge command spits out and it should be fairly straight-forward.

@DevonMorris
Copy link
Author

I also realized that I wasn't getting a proper battery indicator on i3status. So I had to compile some kernel modules to get it to run properly. I compiled sbs and sbshc. I didn't check which one was really need so I just added them both to /etc/modules-load.d/battery.conf

@DevonMorris
Copy link
Author

Also install the apple backlight kernel module and xbacklight. Put the kernel module apple_bl in /etc/modules-load.d/backlight.conf and run emerge --ask xbacklight

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment