Macbook Pro 8 2 Fedora 31 Install

From Unixcat.net Wiki
Revision as of 03:58, 26 April 2020 by ToroidalCore (talk | contribs)
Jump to navigation Jump to search

This page documents my install of Fedora Core 31 on a 2011 15 inch Macbook Pro 8 2. I had done this previously, but needed to do it again after installing an SSD. This time I thought I'd document it. I will revise this in the future for newer versions of Fedora, if necessary. Note that for the most part you can follow the official documentation for installing Fedora, and that this mostly just documents tweaks I had to do for this hardware.

This assumes some familiarity with GNU/Linux systems, particularly on the command line. Follow these instructions at your own risk!

Install

I'll be installing onto a 1 TB SSD, and dedicating the whole thing to Fedora (ie, no dual boot with Mac OS/OS X). I'm trying the KDE spin, although a lot here should be applicable to other editions as well.

Install Media

To do this install, I used a 4 GB USB flash drive. First, download the image, which I grabbed here. I then used a different GNU/Linux system to write the image to the drive. To find the drive device name, you can use ls -lah | grep sd. Run this before and after plugging your drive in, and find which device appears after. You want just the device, not a partition. So look for something like sdc and not sdc1.

Next, write the image to the USB stick. Note that this will erase anything on there already, so make sure you have any important data backed up! To write, do something like this, entering your password if prompted:

sudo dd if=Fedora-KDE-Live-x86_64-31-1.9.iso of=/dev/sdc status=progress

The status=progress option to dd gives periodic progress updates, which is nice. Note that the image downloaded is a hybrid ISO, so you could burn it to a DVD too. (I chose to do this so I don't end up with stacks of optical media laying around.)

Booting

Hybrid graphics with this laptop are tricky (more on that later). Right now, we just want the installer/live environment to start. With the USB install drive you created above plugged into the Macbook, turn the laptop on while holding the Command key (with the clover leaf). If prompted, select the Fedora installer. This should take you to a Grub prompt. (In my case it went right to the Grub prompt, I think because I'm using a new, blank SSD for the hard drive.)

What we want to do is boot using the integrated Intel graphics chip, without using the discrete AMD one. At the Grub prompt, select the option like Start Fedora-KDE-Live 31, and hit e to edit it. Add the following kernel options to the line beginning with linuxefi:

i915.lvds_channel_mode=2 i915.modeset=1 i915.lvds_use_ssc=0

The complete entry in the Grub editor should look like this:

setparms 'Start Fedora-KDE-Live 31'

      linuxefi /images/pxeboot/vmlinuz root=live:CDLABEL=Fedora-KDE-Live-31-\
 1-9 rd.live.image quiet i915.lvds_channel_mode=2 i915.modeset=1 i915.lvds_use_ssc=0
      initrdefi /images/pxeboot/initrd.img

The Grub editor should say that you can use Ctrl-x to boot the newly edited option, but this doesn't work. Instead, hit F10 (along with the fn key on the lower left of the keyboard) to boot. This should bring you into the live environment, where you can try the system out or do a full install. Note that WiFi likely will not be working, so it's a good idea to have a wired network hooked up.

When you're ready to start the install, click the Install to Hard Drive icon on the desktop to start the Anaconda Installer. Select your language and keyboard layout and proceed.

Disks

Click the Installation Destination icon on the Installation Summary screen. How you do do the partitioning is up to you, but I will show what I did below. Basically, I will have a couple partitions, and a encrypted disk. First, select your hard drive, and erase all the partitions on it. I then did something like this:

  • /boot/efi partition, 600 MB
  • /boot partition, 1024 MB
  • / on LVM, 70 GB (encrypted)
  • /var on LVM, 40 GB (encrypted)
  • /home on LVM, take the rest of the space (encrypted)

When you hit Done, it will prompt you for an encryption passphrase to be used for all the partitions you checked the encryption box for. Remember the passphrase; you'll be prompted with it every time your system boots. It should be long and not obvious, but memorable. I recommend making it a entire sentence.

Network

Set the hostname to whatever you want.

Users

I created one normal, non-root user during the install process. Later on I'll join this machine to my Kerberos/LDAP realm, but I'll use this local user to get the rest of my basic configuration done.

Concluding the Installation

With the SSD, installation didn't take long, maybe 5-10 minutes.

Post Install Configuration

At this point, the installer should be done. Close out of it, and restart the system.

Graphics Switching

We need to do the same Grub command line tweaks as in the Install section in order to boot without having garbled graphics. Highlight the boot option for the system and hit e once again. This time, go to the line beginning with linux, and add the options i915.lvds_channel_mode=2 i915.modeset=1 i915.lvds_use_ssc=0 from before after the word quiet so that it looks like this:

linux ($root)/vmlinuz-5.3.7-301.fc31.x86_64 root=UUID=some-disk-uuid-characters-here ro rd.lvm.lv=fedora_hostname/root rd.luks.uuid=luks-some-disk-uuid-characters-here rhgb quiet i915.lvds_channel_mode=2 i915.modeset=1 i915.lvds_use_ssc=0

After this I was able to log in as the normal user I set up during install. Again, I recommend having a wired network connection plugged in. I updated the packages on the system by typing sudo dnf update at a terminal and letting it run.

It would be nice to not have to edit the Grub prompt each time we want to boot. To make those options permanent, just use the grubby command like so:

sudo grubby --update-kernel=ALL --args="i915.lvds_channel_mode=2 i915.modeset=1 i915.lvds_use_ssc=0"

Additionally, I had to edit another part of my Grub configuration. See this page for reference; note that that page also mentions some of the previous kernel command line arguments, but not i915.lvds_use_ssc=0. I am not sure where I had found that, but it was from a working configuration.

Open the file /etc/grub.d/00_header, and look for the lines set gfxmode=${GRUB_GFXMODE} and load video. Between them, add the following:

outb 0x728 1
outb 0x710 2
outb 0x740 2
outb 0x750 0

The above was found on this Reddit post.

To keep the discrete graphics card off between when resuming from suspend, use a solution found in this RedHat Bugzilla post. First, save the following as igd.c:

#include <stdio.h>
#include <sys/io.h>

#define PORT_SWITCH_DISPLAY 0x710
#define PORT_SWITCH_SELECT 0x728
#define PORT_SWITCH_DDC 0x740
#define PORT_DISCRETE_POWER 0x750

static int gmux_switch_to_igd()
{
    outb(1, PORT_SWITCH_SELECT);
    outb(2, PORT_SWITCH_DISPLAY);
    outb(2, PORT_SWITCH_DDC);
    return 0;
}

static void mbp_gpu_power(int state)
{
    outb(state, PORT_DISCRETE_POWER);
}

int main(int argc, char **argv)
{
    if (iopl(3) < 0) {
        perror ("No IO permissions");
        return 1;
    }
    mbp_gpu_power(0);
    gmux_switch_to_igd();
    return 0;
}

Next, compile this as follows:

gcc igd.c -o igd

Note that where this program is posted online, the compile line above usually has the -O2 argument. I found that when this was left in the program was ineffective. Removing it made it actually disable the discrete GPU, and thus save considerable power.

The resulting file, when executed, should shut off the discrete graphics card. I put it in /opt/bin, and next wrote a script to run it every time the computer resumes from suspend. Originally, I had saved the following script as /etc/pm/sleep.d/10igd:

#!/bin/sh
/opt/bin/igd

Make the file executable by typing chmod 755 /etc/pm/sleep.d/10igd. However, in Fedora 31 this does not seem to work, as it seems the correct way to handle this now is through systemd. Looking here, I used the following script to run the executable we just compiled after resume:

#!/bin/sh
if [ "${1}" == "post" ]; then
  /opt/bin/igd
fi

I saved the above as 10igd, in the directory /usr/lib/systemd/system-sleep, and making it executable by typing chmod 755 10igd from within that directory.

For my usage, the Intel integrated graphics have been sufficient. I have not tried to get vgaswitcheroo working yet to be able to switch between the Intel integrated and the AMD discrete chips.

To check that this is working, run sudo powertop from a terminal (assuming you have powertop installed) with the AC adapter unplugged. Take note of the power draw - for me it's typically 10-11 watts, although I've seen it lower. Then, suspend your machine (eg, by closing the lid), then resume it. Run powertop again with the same command - the power draw should be about the same.

Battery Life

I have not implemented all of these, but some general information about battery life under Linux can be found here.

I was able to save some power by disabling the Thunderbolt controller, by adding the acpi_osi=!Darwin command line switch to the Linux boot commandline.

Remarks

I have run some distro of GNU/Linux on this laptop for years, initially with Gentoo, then with Fedora 29 (with Gnome). It is a nice piece of hardware overall, and not actually that bad as a Linux machine. That said, I not sure I would buy another Mac with the intent of primarily running Linux on it. I have not looked into it, but my understanding is that recnet models do not seem to be as well supported overall as this 2011. I don't know when the cutoff would be in terms of which model to no longer consider.