2013年10月6日星期日

Power saving on MacBook Pro runs Fedora 19

Lots of people are questioning running Fedora (or other Linux distributions) on MacBook Pro with the following reasons:

  1. programs runs faster on OS X
  2. OS X lasts longer with battery
  3. OS X is prettier
This blog post is about #2. (I will write more posts to prove #1 and #3 is wrong).

My macbook lasts up to 7 hours after a number of energy saving changes on Fedora 19, and you will know more about linux power management after these tweaks.

General

One principle is disabling anything that you don't need:
  • disable keyboard backlight: Just press the F5 key.
  • reduce screen light: Just press F1 key until it's acceptable. (The dynamic light adjustment from OS X is unsupported yet)
  • disable bluetooth when you don't use it: Just switch it off on the bluetooth icon to the top right corner
One question dwells for a while is how to disable the backlight of the big apple logo to the back of screen, please comment if anyone know how.

Daemons

you should disable all unused runtime services that you don't need. For example, bluetooth daemon, printer service, colord, etc. use this command to list all running services:

sudo systemctl list-units | grep running

For example, I hardly use services like LVM management, Libvirt daemon, mDNS, bluetooth, so I use this command to disable them all:

for serv in "lvm2-lvmetad.service bluetooth.service libvirtd.service avahi-daemon.service"; do
sudo systemctl stop $serv
done

it also works for OS performance boost because it also reduces number of running processes.

Devices

I didn't know macbook devices consumes lots of energy under Fedora default installation until using a tool named powertop. you can run powertop with sudo and it provides lots of useful information. Some simple truth are:

  • the hardware audio codec is always on
  • USB devices are not auto suspend.
  • all PCI devices are always on 

You can apply all options from Bad to Good under the Tunnable tab. If you want to persist these options, find all configuration in kernel and system level from the /proc and /sys filesystem by running:

sudo powerstop --html

Then it will generate a file named powertop.html, all the configuration of tunning can be found from section "Software Settings in need of Tunning".

USB autosuspend

Apply this kernel parameter to your kernel in grub:

usbcore.autosuspend=5

Disk

MacBook SSD differs from hard disk which means spindown doesn't work. One tip is make the disk I/O flush triggered less frequently. Here the freqency is 5 seconds:

echo "5" > /proc/sys/vm/laptop_mode

Reference

2013年7月17日星期三

Dual Boot Max OS X and Fedora19 on MacBookPro

I'm totally a linux guy who want to control as many parts as I can on my laptop, no exception to MacBookPro.

Preparation
1. USB key with Fedora19 x86_64 Live installed
2. MacBookPro with enough power
3. downloaded wifi firmware from here

Notice: the 3rd step is critical because newly installed Fedora can't recognize the broadcom wifi chip, I missed this step at first, so I have to download it over tethered network from my Android phone.

Steps
Step1: Just follow the article "How to Dual Boot Linux on Your Mac and Take Back Your Powerhouse Apple Hardware" to shrink your Macintosh HD, install rEFI, and start installing Fedora. Personally I would suggest that keep 50GB+ disk empty without any partition from the Disk Utility, then leave it to Fedora installation process.

Step2: reboot Mac with Fedora Live USB key plugged. you just need to use rEFI to boot the Live OS and choose "Install Fedora to Disk". the next step is the most critical part of this dual boot: do create another EFI partition (usually 200MB) for Fedora instead of reusing that from Mac OS X. I strongly suggest using "review/modify partition before install" to do it manually. You should get error checking disk before clicking "Installation" button because you have to uncheck the "install bootloader" on the disk. Since it uses rEFI, I didn't want to install another bootloader into MBR. I just unchecked it so that it will configure the bootloader on my own.

Step3: after Fedora installation completes, it ask you to reboot the system ,then follow the guide in step1 to sync GPT partition table to get rEFI less confused. In this step, please boot into your Live Fedora 19 again and fix the bootloader config. we skipped bootloader install in step2, so we will fix it in the booted Live OS. you need to run command "grub2-mkconfig -o ~/grub.cfg", then mount your system EFI partition of fedora to /mnt, copy the grub.cfg file into /mnt/EFI/fedora/grub.cfg. before rebooting, please modify this grub.cfg file and alter the command linux and initrd to linuxefi and initrdefi, or you will get "linux: can't find comand linux".

Step4: boot the fedora on your MacBookPro. Usually it chooses "Boot Linux from shim", then you will see the familar grub option menu. Please select the "Advanced option for Fedora 19" and select the last subentry. Then it will boot the newly installed Fedora19!

The last step is installing wifi firmware. I copied the firmware tar file into the Live OS USB stick, so I just need to extract and install and then reboot again (details can be found here):

  $ tar xjf broadcom-wl-5.100.138.tar.bz2
  $ sudo b43-fwcutter -w "$FIRMWARE_INSTALL_DIR" broadcom-wl-5.100.138/linux/wl_apsta.o

PS: I've got several comments from Google plus and I decided to add more tips:

1. rEFI is actually optional. One comment from Google plus suggested that MacBook Pro allow more than one OS co-exist. I reviewed the Mac OS X EFI boot and Fedora19 EFI boot, then realized that as long as it uses separate EFI partition for Fedora, you can hold the "option" key (a.k.a., the alt key) during MacBook booting time and it will prompt bootable partitions. So you can remove rEFI, or even leverage the "option" key without rEFI at all.

2. create the following file to load wireless driver during linux boot:

  $ sudo vi /etc/sysconfig/modules/pci-wireless.modules
  #!/bin/sh

  exec /sbin/modprobe b43 >/dev/null 2>&1
  $ sudo chmod +x /etc/sysconfig/modules/pci-wireless.modules

3. Since it uses SSD in the new MacBook Pro, you'd better switch to noops disk queue scheduler for performance boost:

  $ sudo tee /sys/block/sda/queue/scheduler <<< noop