Ubuntu on MacBook Pro

How to install Ubuntu 15.10 on an early 2015 MacBook Pro (Retina 12,1) with full disk encryption

This example shows Kubuntu 15.10 on MBP model 12,1, early 2015, while keeping Mac OS as a dual boot option. An example for the earlier model is listed in a section below.

  1. Boot into OS X and use its disk utility to resize the MacOS partition to open up space for Ubuntu.
    1. Click '+' to create a second partition
    2. Drag the lower corner of the first 'Macintosh HD' partition up. I set it to 100G.
    3. Set the new partition type to 'free space' and click apply.
  2. Download kubuntu 15.10 iso and put it onto a flash drive via Startup Disk Creator. Use whatever standard procedure works for you for creating a bootable usb.
  3. Plug in the USB stick and boot up your Mac pressing the OPTION key, then select the EFI to boot from the USB.
  4. In the boot option select the live mode (try ubuntu), don't install it straight away.
  5. Prepare your disk
    1. Start konsole. Drop into root with sudo -s, and run cgdisk /dev/sda. Not gparted because of a GTK glitch where nothing is visible, possibly due to an old media (14.04, not 14.04.2 or later) being used, nor the kde partition editor because the v1.0.3 that does not support GPT. It started supporting GPT only after v1.1, but it's not in the 14.04 repos. parted is possible, but very cumbersome.
      1. Create two partitions, a 1Gb partition of type 8300 (Linux fs) and a partition that takes up the rest of the available space of type 8e00 (LVM).
      2. Verify that you now have /dev/sda1 as efi (original), /dev/sda2 as hfs+ (original recovery), /dev/sda3 as hfs+ (original mbp disk), /dev/sda4 as 1Gb Linux partition and /dev/sda5 as a big LVM partition.
      3. Write to disk and exit
  6. Create the LUKS encrypted container on the LVM partition. Actually it then becomes a LUKS partition and the LVM is contined inside of it. The other option is to create LVM partitions and then encrypt them one by one by LUKS, but it's more complex and nececssary for a single disk setup inside a laptop.
cryptsetup luksFormat /dev/sda5
  1. Make it accessible to the system
cryptsetup open --type luks /dev/sda5 lvm
  1. Create LVM on top of LUKS.
pvcreate /dev/mapper/lvm
vgcreate MainStore /dev/mapper/lvm
lvcreate -L 8G MainStore -n swapvol (rule of thumb here is to use the twice the memory for < 4G of physical, same for 4-8G and half the size for something above)
lvcreate -L 20G MainStore -n rootvol (20G is plenty for Kubuntu)
lvcreate -l +100%FREE MainStore -n homevol (lowercase -l is important)
mkfs.ext4 /dev/mapper/MainStore-rootvol
mkfs.ext4 -m 1 /dev/mapper/MainStore-homevol (-m 1 sets the number of reseved blocks to a more reasonable 1% from the default 5%)
# Reserve block's only benefit on the non-root system is controlling fragmentation when the disk is near to full capacity
mkswap /dev/mapper/MainStore-swapvol
e2label /dev/mapper/MainStore-rootvol "Root" (setting the label is non essential, just helpful)
e2label /dev/mapper/MainStore-homevol "Home"

  1. Start the installation process by clicking "Install Kubuntu". When prompted choose manual partitioning. On the manual partitioning screen:
    1. choose /dev/mapper/MainStore-rootvol, set to ext4, map to /. No need to format it.
    2. choose /dev/mapper/MainStore-homevol, set to ext4, map to /home. No need to format it.
    3. choose /dev/sda4, set to ext2, map to /boot. Select "format the partition"
    4. No need to select the swap, or the efi partition, they are picked up automatically. Also keep the bootloader on the default /dev/sda.
  2. Go through the install. 'Do not select 'install third party' because it'll try to install a proprietary Broacom WL driver which hard-freezes the whole system.
  3. After the install is done do not reboot. Go back to the konsole, drop into root with sudo -s and set up the encrypted boot sequence.
  4. Prepare the initramfs environment to work on the newly installed system, not the "try ubuntu" system you are currently in.
mount /dev/mapper/MainStore-rootvol /mnt
mount --bind /proc /mnt/proc (or chroot /mnt mount -t proc none /proc)
mount --bind /dev /mnt/dev
chroot /mnt mount /boot

  1. Create crypttab to mount LUKS container at boot
echo lvm UUID=$(blkid -s UUID -o value /dev/sda5) none luks,discard > /mnt/etc/crypttab
  1. Recreate the ram disk with the new mount
chroot /mnt update-initramfs -u
  1. Now you need to set the proper boot order
apt-get install efibootmgr
efibootmgr -o 0,80  (0 - Ubuntu, 80 - Mac OS and FFFF - Mac OS recovery)

  1. Reboot.

Post boot action items:

  1. Update packages - the "apt-get update; apt-get dist-upgrade" mantra
  2. Fix the open source wireless driver. Get the BCM43602 firmware and place it in /lib/firmware/brcm
  3. Fix the backlight adjustment
    1. Edit /etc/default/grub
    2. Add "acpi_backlight=vendor" to GRUB_CMDLINE_LINUX_DEFAULT=
    3. Regenerate grub - sudo update-grub
  4. Fix the trackpad and the keyboard. Get them fixed modules from here for the default 15.04 kernel, or from here for 4.0 or here for 4.1.2.
  5. Turn off SPDIF light and save power:
echo '1' | sudo tee '/sys/module/snd_hda_intel/parameters/power_save'
  1. If that works make it permanent make it permanent by adding to /etc/rc.local or, and this is a more proper way, create /etc/modprobe.d/audio_powersave.conf and add the following to it
options snd_hda_intel power_save=1
  1. Make the fonts bigger, and get theme fonts changer for firefox and thunderbird. Although some might prefer to just drop the resolution to 1680x1050.
    1. Install Fan-Control-Daemon. Not necessary as the EFI does an ok job, but on my setup (3.1Ghz Intel 5557U CPU) EFI seems to spin up the fans a bit too slow, allowing CPU's to trip the heat threshold and drop into a low performance mode. You can change the settings in /etc/mbpfan.conf. Note that it may keep your fan from shutting down completely, shortening the fan life and draining the battery.
git clone ''https://github.com/dgraziotin/Fan-Control-Daemon.git''
cd Fan-Control-Daemon
make
sudo make install
sudo make test
sudo cp mbpfan.service /etc/systemd/system
sudo systemctl daemon-reload
sudo systemctl start mbpfan.service
sudo systemctl enable mbpfan.service

  1. If you want your system to auto-adjust brightness using the light sensor install Lightum. Note that it's very old and be buggy on KDE.
sudo apt-get install libxss-dev libdbus-glib-1-dev libsystemd-login-dev
git clone ''https://github.com/poliva/lightum.git''
cd lightum
make
sudo make install
git clone ''https://github.com/poliva/lightum-indicator.git''

  1. Fix the built-in camera work. PCI driver is in the works.
  2. Bluetooth driver is non-functional, although it seems to load correctly. It may cause your system to wake up from sleep immediately unless you deny ACPI control on boot to it by adding the following to /etc/rc.local

echo "XHC1" > /proc/acpi/wakeup

How to install Kubuntu 14.04 on MacBook Pro, with full disk encryption and keep Mac OS

More specifically I am talking about the 13 in model MacBookPro11,1. For encryption I am using the LVM on LUKS model that affords one key to mount all encrypted partitions. Although you could achieve the same functionality by chaining encrypted partitions and unlocking the next one with a key in a keyslot of the already unlocked partition, doing it this way would be unwarrantably complex.

  1. Boot into MacOS and use its disk utility to resize the MacOS partition to open up space for Ubuntu. In disk utility select the disk, click on partitions, drag the lower corner up, or set it manually and click apply. I set it to 100G.
  2. Download kubuntu 14.04 iso and put it onto a flash drive via Startup Disk Creator. Standard procedure
  3. Boot up your Mac pressing the OPTION key, and select the EFI to boot from the USB.
  4. Now boot into live mode (try ubuntu), don't install it straight away
  5. Open the "proprietary drivers" (ubuntu-drivers) window from the notification space and install the broadcom wlan drivers.
  6. Prepare your disk

  1. Start konsole. Get gparted and create /boot partition, ext2 type, size 200Mb
  2. Create ext4 (actually file system is not important) and to fill the rest of the space. Now you should have a 200MB efi partition on /dev/sda1, the main Mac OS hfs+ partition on /dev/sda2, a Mac OS recovery 650MB hfs+ partition on /dev/sda3, a new ext2 boot partition on /dev/sda4 and the ready-for-LUKS partition on /dev/sad5
  3. Create the LUKS encrypted container at the "system" partition. Enter the chosen password twice.
cryptsetup luksFormat /dev/sda5
cryptsetup open --type luks /dev/sda5 lvm

  1. Create LVM on LUKS
pvcreate /dev/mapper/lvm
vgcreate MainStore /dev/mapper/lvm
lvcreate -L 8G MainStore -n swapvol (rule of thumb here is to use the same size as your memory)
lvcreate -L 20G MainStore -n rootvol (20G is plenty for Kubuntu)
lvcreate -l +100%FREE MainStore -n homevol
mkfs.ext4 /dev/mapper/MyStorage-rootvol
mkfs.ext4 /dev/mapper/MyStorage-homevol
mkswap /dev/mapper/MyStorage-swapvol
e2label /dev/mapper/MyStorage-rootvol "Root" (setting the label is non essential, just helpful)
e2label /dev/mapper/MyStorage-homevol "Home"

Start the installation process. When prompted choose manual partitioning. On the manual partitioning screen:

  1. choose /dev/mapper/MyStorage-rootvol, set to ext4, map to /. No need to format it.
  2. choose /dev/mapper/MyStorage-homevol, set to ext4, map to /home. No need to format it.
  3. choose /dev/sda4, set to ext2, map to /boot. No need to format it.
  4. No need to select the swap, it's picked up automatically. Also you can map /dev/sda1 to /boot/efi but I did not and Ubuntu picked it up automatically.
  5. Go through the install, but do not reboot.
  6. Go back to the konsole, drop into root with sudo -s
  7. Mount your disks
mount /dev/mapper/MyStorage-rootvol /mnt
chroot /mnt mount /proc
mount --bind /dev /mnt/dev
chroot /mnt mount /boot

Create crypttab
echo lvm UUID=$(blkid -s UUID -o value /dev/sda5) none luks,discard > /mnt/etc/crypttab
Recreate the ram disk
chroot /mnt update-initramfs -u

Now you need to set the proper boot order

sudo apt-get install efibootmgr
sudo efibootmgr

  1. You should see 0 - Ubuntu, 80 - Mac OS and FFFF - Mac OS recovery. Change it
sudo efibootmgr -o 0,80

Reboot and enjoy.

After the reboot first thing I had to do is to install broadcom drivers again, which was a rather tedious because without internet I had to manually get it and all the twenty or so dependencies from Kubuntu's USB. There was another catch too. I've checked 'download updates' while installing Kubuntu, but when manually installing all the libc6-dev dpkg for the broadcom drivers, it complained that it depended on the pre-update version of libc6. So I forced it with dpkg --ignore-dependencies=libc6 -i .... and got this thing through.

BTW now would be good time to make the fonts bigger and fix some other stuff.

How to make MacBook Pro built-in keyboard match PC keyboard layout

I am talking about swapping making the buttons to the left and right of the space button map into Alt and Control buttons just like a normal PC keyboard. Start by creating a folder to keep your configs in. Then create a "symbols" subfolder and a "mbp" file inside of it with the following contents:

partial modifier_keys
xkb_symbols "mac_right_btns" {
    key <RALT> { [ Control_R ] };
    modifier_map Control { Control_L, Control_R };
    key <RMTA> { [ Alt_R ] };
    modifier_map Mod1   { Alt_R, Alt_L };
};

Then create a file in the config folder (not the symbols folder) by running the following command:

setxkbmap -print > [config]/mac_key_flip

Append "mbp(mac_right_btns)" to the xkb_symbols line. On my machine it looks like this:

xkb_keymap {
    xkb_keycodes  { include "evdev+aliases(qwerty)" };
    xkb_types     { include "complete+numpad(mac)"  };
    xkb_compat    { include "complete"  };
    xkb_symbols   { include "pc+macintosh_vndr/us+ru:2+inet(evdev)+altwin(swap_lalt_lwin)+capslock(grouplock)+terminate(ctrl_alt_bksp)+mbp(mac_right_btns)" };
    xkb_geometry  { include "macintosh(macbook78)"  };
};

Then load it up:

xkbcomp -I$HOME/bin/keyboardTools/ ~/bin/keyboardTools/mac_key_flip $DISPLAY

You may see some warnings, it's normal. Test it with

xev | sed -ne '/^KeyPress/,/^$/p'

Or you can check out the whole keyboard graphically (!):

xkbprint -label symbols $DISPLAY - | okular -

You can also see the original keyboard codes and button names by running

xkbprint -label name $DISPLAY - | gv -orientation=seascape -

(gv use here is given just for reference, you can use okular as well). For more information look here or examine your files \usr\share\X11\xkb\symbols\altwin and /usr/share/X11/xkb/rules/base.lst



How to make F11 and F12 act normally on Mac, not emulate right and middle mouse buttons

sudo aptitude remove mouseemu

How to adjust MacBook brightness and key backlight in ubuntu

For dim situation (airplane)

xbacklight -set 2
sudo sh -c "echo 10 > sys/devices/platform/applesmc.768/leds/smc::kbd_backlight/brightness"

cat /sys/devices/platform/applesmc.768/leds/smc::kbd_backlight/max_brightness

on mbp 12,1
echo 50 | sudo tee /sys/devices/pci0000\:00/0000\:00\:02.0/drm/card0/card0-eDP-1/intel_backlight/brightness

Installing Ubuntu 12.04 on MacBook Pro

There was a trick to get it done. I had to install Kubuntu from a CD, but then boot with the Kubuntu 12.04 USB stick plugged in for Grub to work after the install, then update grub after booting.
I've stumbled on this fix myself but then found it referenced somewhere on the web. Here is my crude list of steps:
0. Use Mac's partition editor to reduce existing partition and leave a bunch of empty space. Install gdisk and make a backup: 'sudo disk /dev/disk0'. enter 'b', and type a file name, it will be saved to the home folder
1. get Kubuntu amd64 MAC variant from the list of alternative downloads, burn to a cd and make a USB stick (I used another ubuntu install for the that)
2. get and manually install refi
3. reboot and install Kubuntu from the CD
4. do auto partition in the Kubuntu installed to add needed partitions
5. Instruct it to put grub on /dev/sda
6. Reboot - if stuck at an Kubuntu logo get into macos, do the GPT manipulations per http://ubuntuforums.org/showthread.php?t=1908210. Here is what it says: "At the moment you now have a screwed up hybrid mbr table (this is because most likely your lion recovery disk uses one of your precious mbr slots). In order to fix this we are going to create a new hybrid mbr table. i have attached screenshots of this process.
reopen terminal and again type 'sudo gdisk /dev/disk0'. this time enter 'r'. and then 'p'. this will print your partitions. now you need to create your hmbr so type 'h'. it will now ask you for the partitions you wish to enter. referring to the printed partition list, add your lion, windows and linux partitions. (in my case 2 4 5). next it will ask you to place efi partition first, select 'y'. now it will ask you for the mbr hex code for each partition. the codes you want are 'AF' for lion, '07' for windows, and '83' for linux. don't set any of the bootable flags. once finish enter 'w' to write these changes to the disks. You can also enter 'q' if you want to quit without saving changes. reboot and now you should be able to boot into each of your OSes."
6. Reboot. Now it would still not boot and show "no operation system found"
7. Fix the partition table with refit's partition fixed
8. Put the usb key in
9. Boot Kubuntu from the hardrive (NOT the usb). This time it should boot
10. When you are finish booting, login and reinstall grub
sudo grub-install /dev/sda
11. Enjoy