Skip to content

Instantly share code, notes, and snippets.

@cjonesy
Last active April 26, 2024 09:28
Show Gist options
  • Star 78 You must be signed in to star a gist
  • Fork 17 You must be signed in to fork a gist
  • Save cjonesy/2e2d8ca5e50ee1811f70 to your computer and use it in GitHub Desktop.
Save cjonesy/2e2d8ca5e50ee1811f70 to your computer and use it in GitHub Desktop.
Installing Ubuntu on MacBook Pro

Macbook Pro - Ubuntu Install

Requirements

2 USB drives > 2GB

Pre-Install

Create bootable USB drive

  1. Grab the latest Ubuntu Desktop iso image
  1. Convert iso to img
  • hdiutil convert -format UDRW -o ~/ubuntu.img ~/Downloads/ubuntu-15.10-desktop-amd64.iso
  • NOTE: .dmg will be appended to the output filename.
  1. Determine the device node of the USB drive
  • List the currently connected devices: diskutil list
  • Insert USB drive
  • List the currently connected devices again: diskutil list
  • Compare two outputs to determine the device node
  1. Unmount the USB drive
  • diskutil unmountDisk /dev/diskN (where N is the device node from step 3)
  1. Write the image to the USB drive
  • sudo dd if=~/ubuntu.img.dmg of=/dev/rdiskN bs=1m (where N is the device node from step 3)
  • NOTE: You'll want to use /dev/rdisk instead of /dev/disk for faster write speeds
  1. Eject the USB drive
  • diskutil eject /dev/diskN (where N is the device node from step 5)

These steps were paraphrased from here

Prep Macbook Disk

It's important to resize your disk using Disk Utility from inside of MacOS instead of using the Ubuntu installer. Don't worry about creating all the individual partitions right now, the partition creation will be handled during the install.

  1. Open Disk Utility in MacOS
  2. Choose Macintosh HD on the left side of the window
  3. Click on Partition on the right side of the window
  4. Click the + to add a new partition
  5. Resize the new partition and choose to leave it as free space

Driver Packages

Download the packages for bcmwl-kernel-source and dkms to another USB drive. We will use these packages in a later step to enable wifi.

Install

Ubuntu Installer

Plug in the USB drive that contains your Ubuntu image and reboot your Macbook. Once the screen goes black, hold down the Alt key until you see the boot menu. Choose EFI boot from the boot menu. You will be presented with the Grub menu, select 'Install Ubuntu'.

IMPORTANT: When you reach the screen in the installer titled "Installation Type", you must choose the option "something else". This allows for custom partitioning, if you let the installer choose, you may not be happy with the result.

Create whatever partitioning scheme you'd like, for example:

swap  swap 4GB
/     ext4 10GB
/home ext4 Remainder

NOTE: I recall reading somewhere that it was important to leave the 0MB free space partition between the MacOS partitions and the linux partitions, but I have been unable to find that reference.

IMPORTANT: Under Device for bootloader, ensure the EFI partition is selected /dev/sda1

Finish up the installation and boot into Ubuntu.

Post-Install

Wireless

Insert the USB drive that you downloaded deb packages to earlier, and then install the packages.

For my machine, the command looked like this:

cd /media/charlie/MISC
sudo dpkg -i bcmwl-kernel-source_6.30.223.248+bdcom-0ubuntu7_amd64.deb dkms_2.2.0.3-2ubuntu6_all.deb

Bootloader

Add MacOS as option on Grub menu

Append the following lines to /etc/grub.d/40_custom:

menuentry "MacOS" {
 exit
}

Change these options in /etc/default/grub:

#GRUB_HIDDEN_TIMEOUT=0                  # Disable hidden Grub
#GRUB_HIDDEN_TIMEOUT_QUIET=true         # Disable hidden Grub
GRUB_TIMEOUT=5                          # [Optional] Set smaller timeout (default was 10)
GRUB_CMDLINE_LINUX="libata.force=noncq" # Linux parameter to prevent occasional SSD freezes
GRUB_DEFAULT=2                          # [Optional] Default to MacOS entry

Fix small grub fonts

On the command line execute the following:

sudo grub-mkfont -s 36 -o /boot/grub/DejaVuSansMono.pf2 /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf

Open and edit again /etc/default/grub and add the following line at the bottom:

GRUB_FONT=/boot/grub/DejaVuSansMono.pf2

Update Grub

sudo update-grub

Common issues

Wifi stops working after suspend

This is caused by a bug in the network-manager.

You can verify this by running the following to see if wifi returns:

sudo systemctl restart network-manager.service

To automate restarting network-manager, create /etc/systemd/system/wifi-resume.service and paste the following into it:

#/etc/systemd/system/wifi-resume.service
#sudo systemctl enable wifi-resume.service
[Unit]
Description=Restart networkmanager at resume
After=suspend.target
After=hibernate.target
After=hybrid-sleep.target

[Service]
Type=oneshot
ExecStart=/bin/systemctl restart network-manager.service

[Install]
WantedBy=suspend.target
WantedBy=hibernate.target
WantedBy=hybrid-sleep.target

Finally run this to activate it:

sudo systemctl enable wifi-resume.service

Fan not working properly

The Macbook Pro's fan requires a daemon to adjust the speed.

Add the following to /etc/modules:

coretemp
applesmc

Install build-essential package: sudo apt install build-essential

Clone the mbpfan source:

git clone git@github.com:dgraziotin/mbpfan.git

Follow directions found here to build and install: A beginner's tutorial for mbpfan under Ubuntu

High CPU usage by kworker

The most important issue I have found so far is the high CPU usage by kworker (i.e. Linux Kernel worker thread), which seriously affects the battery life. Apparently this is caused by an interrupt storm on ACPI interrupt GPE06, as described here. You can verify it by checking if interrupt GPE06 contains a high value:

$ grep . -r /sys/firmware/acpi/interrupts/
...
/sys/firmware/acpi/interrupts/gpe05:       0   invalid
/sys/firmware/acpi/interrupts/gpe06: 2938373   enabled <---
/sys/firmware/acpi/interrupts/gpe07:       0   enabled
...

A quick solution for this issue is to disable this interrupt, i.e.

echo disable > /sys/firmware/acpi/interrupts/gpe06

In order to disable it on every boot, you can add the previous line to /etc/rc.local, just before exit 0.

Remap MacBook Pro keyboard keys to be standard

Create /etc/systemd/system/keyboard-map.service and paste the following into it:

#sudo systemctl enable keyboard-remap.service
[Unit]
Description=Remap keyboard keys
After=multi-user.target

[Service]
Type=oneshot
ExecStart=/usr/bin/setxkbmap -device $(/usr/bin/xinput list --id-only "keyboard:Apple Inc. Apple Internal Keyboard / Trackpad") -option "altwin:swap_alt_win"

[Install]
WantedBy=multi-user.target

Finally run this to activate it:

sudo systemctl enable keyboard-remap.service

http://askubuntu.com/questions/29731/rebind-alt-key-to-win-using-setxkbmap https://lampjs.wordpress.com/2015/06/26/remapchange-your-secondaryusb-keyboard-keys/

References

Installing Ubuntu 15.04 on a Macbook Pro 11,2

Arch - MacBookPro

Installing Ubuntu 15.10 - Wily Werewolf on a Macbook Pro 12-1 (2015)

Wifi doesn't work after suspend after 16.05 upgrade

@MaybeApexin
Copy link

I did everything but when i click on the MacOS option it just goes back to the same grub menu, if the MacOS option is selected again then it just goes to a blank screen

@basejumpa
Copy link

@cjonesy Thx so much!

I want to share some addition:

I had the problem that my battery didn't charge after installation of Ubuntu. The installation of https://linrunner.de/tlp/ solved the problem.

@tomswales
Copy link

Hi Charlie,

Am a big fan of your gist for setting up Ubuntu on a Macbook and followed it successfully this weekend and now have a wonderfully performing machine with Ubuntu 22.04. One thing I found is that when I installed Chrome the hardware acceleration didn't work properly, creating lines across the video on Chrome. Disabling hardware acceleration fixed the problem with the video playback, but caused the CPU to almost catch fire on full HD videos on Youtube and the fans to start whirring like crazy. So I found this great advice to use the Chromium snap with hardware acceleration added: https://discourse.ubuntu.com/t/an-overview-of-hardware-acceleration-in-chromium/36672. Now there is almost no strain on the CPU and perfect full HD Youtube video playback. Feel free to try it and recommend it to other users of your gist if you had the same problems with Chrome on your Macbook.

Thanks again
Tom

@bukovskyjosef
Copy link

bukovskyjosef commented Jan 29, 2024

Hey guys,
I am having troubles with setting up partitions correctly as I have not found any good resources. In the example Charlie illustrates to create 4 GB swap partition, some 10-20 GB partition for the system and the rest for data which suits me well. I have done this and did not forget to choose /dev/sda1 as device for boot loader installation. Hence I am not able to boot and I got kernel panic error - "not syncing unable to mount root". I guess I did something wrong. I suspect choosing between primary/logical partition as I dont know what is the difference. Should I choose Primary or Logical? Are those 3 partition everything I need? Would not I need more mount points (what are they for)?

@spektra
Copy link

spektra commented Feb 7, 2024

I'm literally pulling my hair out... I'm doing this for Ubuntu 23. And, It's just endless request for more dependencies. I don't have internet because im trying to install broadcom drivers, and then it will ask for a dependency.. then another and another and another.. and they are tiny little files.. and im about to throw this damn macbook

@Lachlannnnn
Copy link

@spektra you good?

@benknam
Copy link

benknam commented Mar 13, 2024

I'm literally pulling my hair out... I'm doing this for Ubuntu 23. And, It's just endless request for more dependencies. I don't have internet because im trying to install broadcom drivers, and then it will ask for a dependency.. then another and another and another.. and they are tiny little files.. and im about to throw this damn macbook

I think you should install the "aptitude" first, then check any dependencies conflicting between the new age ubuntu23. On 22.04 since I have it worked from 2020, nothing problems happened till right now.

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