Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bitjockey42/7b5a24bd23477c6c9f79eb1bde821e22 to your computer and use it in GitHub Desktop.
Save bitjockey42/7b5a24bd23477c6c9f79eb1bde821e22 to your computer and use it in GitHub Desktop.
Ubuntu 16.04 configurations on Macbook Pro 10,1

Ubuntu 16.04 on Macbook Pro 10,1 with Encrypted Root

NOTE: This is for dual-booting OS X 10.11 with Ubuntu 16.04.

Install

Preparation in OS X

Resize OS X partition with Disk Utility.

In Recovery Mode (hold command-R on startup), disable SIP so as to be able to install rEFInd (updated fork of rEFIt).

csrutil disable

Download the Ubuntu 16.04 64-bit ISO from ubuntu.

I prefer using dd to create a LiveUSB.

Shut down. Hold the Option (Alt) key, and then press the power button to select the LiveUSB.

Ubuntu

My memory of this step is a bit..fuzzy. Use at your own discretion.

Use gparted to create an ext2 partition of 512MB after the third partition, which is the OS X Recovery HD, and an ext4 partition with the remaining free space.

sudo -i # become root
cryptsetup -v --cipher aes-xts-plain64 --key-size 256 -y luksFormat /dev/sda5
cryptsetup luksOpen /dev/sda5 lvm
pvcreate /dev/mapper/lvm
vgcreate vgcrypt /dev/mapper/lvm
lvcreate --extents +100%FREE -n root vgcrypt

mount /dev/mapper/vgcrypt-root /mnt
mkdir /mnt/boot
mount /dev/sda4 /mnt/boot

# Launch the installer with -b flag to skip bootloader installation
ubiquity -b

Choose "Something else", and then mount the newly created ext2 as /boot, and /dev/mapper/vgcrypt as /. Keep FORMAT unchecked.

Choose to 'Continue testing', DO NOT reboot yet.

You then need to do some stuff with chroot.

# may need to remount
sudo -i
blkid | grep ^/dev/sda5 # copy the UUID value 
 
for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
chroot /mnt 
# mount -t proc proc /proc
# mount -t sysfs sys /sys

My /etc/fstab looks something like this:

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/vgcrypt-root /               ext4    errors=remount-ro 0       1
# /boot was on /dev/sda4 during installation
UUID=<AUTOMATICALLY-DETERMINED> /boot           ext4    defaults        0       2
# /boot/efi was on /dev/sda1 during installation
UUID=<AUTOMATICALLY-DETERMINED>  /boot/efi       vfat    umask=0077      0       1

create /etc/crypttab:

NOTE I cannot remember whether this was actually necessary. I believe it may only be necessary when you need to mount an encrypted swap.

lvm UUID=c403c024-813c-48c0-8fb9-d7c5f1ddd926 none luks

The UUID is determined from a previous step.

Back in chroot:

update-initramfs -u -k all
lsinitramfs /boot/initrd* | grep cryptsetup

When you restart you'll boot back into OS X. Install rEFInd at this point. When you reboot, you should see the rEFInd screen.

The rEFInd entry that corresponded to Ubuntu for me was "Generic Linux /vmlinuz something something".

TODO use bootctl (formerly gummiboot) instead of rEFInd.

Post-Install

Get WiFi working

You don't need an internet connection to get WiFi to work. Just plug in the LiveUSB you used to install Ubuntu. Once it's mounted, you'll see a folder, /path/to/USB/pool. This is where you can get the drivers.

You'll need to copy pool/main/d/dkms-*.deb and pool/restricted/b/broadcom-*.deb to, say, ~/Desktop.

sudo dpkg -i /path/to/where/you/copied/the/debs/*.deb

This should automatically load the WiFi module.

More stuff

sudo apt install lm-sensors
# Press ENTER until you are asked whether you want to save the configuration.
sudo sensors-detect 

# For power management
sudo apt install tlp

# Change permissions for /usr/local/src
sudo chown -R $USER /usr/local/src
sudo apt install git

# Install mbpfan 
# https://ineed.coffee/3838/a-beginners-tutorial-for-mbpfan-under-ubuntu/
# you will want to modify some settings
cd /usr/local/src
git clone https://github.com/dgraziotin/mbpfan
make
sudo make install
sudo make tests
sudo cp mbpfan.service /etc/systemd/system/
sudo systemctl enable mbpfan.service
sudo systemctl daemon-reload
sudo systemctl start mbpfan.service

# Replace synaptics with xserver-xorg-input-mtrack
# I would not recommend the package that is provided by
# Ubuntu as it is built on an outdated, unmaintained
# version of the driver. 
sudo apt autoremove xserver-xorg-input-synaptics
sudo apt install xserver-xorg-dev libmtdev-dev xutils-dev
cd /usr/local/src
git clone https://github.com/p2rkw/xf86-input-mtrack # this is the new fork
cd xf86-input-mtrack
libtoolize
aclocal
autoconf
automake --add-missing --copy
./configure --with-xorg-module-dir=/usr/lib/xorg/modules/
make
sudo make install
# sudo checkinstall

NVIDIA (optional)

NOTE It is not necessary to install the propriety nvidia drivers, unless you are doing some intensive graphics work that the open-source nouveau driver can't handle as well.

In Additional Drivers, enable nvidia-361. Then run

nvidia-xconfig

You'll then need to reboot.

Notes on Propriety NVIDIA Graphics

  • I would stick with text-only boot for Ubuntu (i.e. no splash screen) because it freezes at the prompt for the encrypted volume pass.
  • The first time I rebooted after installing NVIDIA drivers, I had a black screen. Had to force shutdown (by pressing the power button for 8 seconds), since I could not switch to a TTY, either. But on the second boot, I was able to proceed.
  • My laptop ran really hot for the first few uses of Ubuntu 16.04, but cooled down over time. Really odd... It runs really hot.
  • Take a look at xorg.conf.
  • rc.local is necessary to get brightness control to work.

Other tools

Graphics

This machine can run really hot when the discrete GPU, the NVIDIA card, is turned on, even if using the propriety drivers. Since I don't really do any intensive gaming or CUDA programming on this machine and need it to be portable, I keep the discrete GPU off and so use the integrated Intel card.

You do not have to install the nouveau or intel drivers manually, but for reference sake (or in case you need to reinstall them), the packages are xserver-xorg-video-intel and xserver-xorg-video-nouveau.

  • systemd-vgaswitcheroo-units Set of scripts to turn off the discrete GPU at boot. NOTE This only works if you are using the open-source, Nouveau drivers rather than the NVIDIA ones.
  • gpu-switch Script to switch between Intel and NVIDIA cards. However, requires that you restart your Macbook.

Updating the kernel

If you're using rEFInd as a bootloader, or bootctl (included in systemd), after installation you will need to copy the initrd and vmlinuz files to /boot/efi (where your actual EFI system partition is mounted in Ubuntu):

sudo cp {abi-4.4.8-040408-generic,config-4.4.8-040408-generic,initrd.img-4.4.8-040408-generic,vmlinuz-4.4.8-040408-generic} /boot/efi
Section "InputClass"
MatchIsTouchpad "on"
Identifier "Touchpads"
Driver "mtrack"
Option "Sensitivity" "0.55"
Option "FingerHigh" "12"
Option "FingerLow" "1"
Option "PalmSize" "40"
Option "IgnoreThumb" "true"
Option "IgnorePalm" "true"
Option "ButtonMoveEmulate" "false"
Option "ClickTime" "25"
Option "BottomEdge" "30"
Option "SwipeLeftButton" "8"
Option "SwipeRightButton" "9"
Option "SwipeUpButton" "0"
Option "SwipeDownButton" "0"
Option "ScrollDistance" "75"
EndSection
#!/bin/sh
case "$1" in
resume|thaw)
systemctl stop NetworkManager
rm /var/lib/NetworkManager/NetworkManager.state
systemctl start NetworkManager
;;
esac
# /etc/mbpfan.conf
[general]
min_fan_speed = 2000 # default is 2000
max_fan_speed = 5940 # default is 6200
low_temp = 55 # try ranges 55-63, default is 63
high_temp = 60 # try ranges 58-66, default is 66
max_temp = 86 # do not set it > 90, default is 86
polling_interval = 7 # default is 7
#!/usr/bin/env bash
sudo apt update
echo "Setting up temp controls"
sudo apt -y install lm-sensors
# Press ENTER until you are asked whether you want to save the configuration.
sudo sensors-detect
echo "Setting up power management"
# For power management
sudo apt -y install tlp
echo "Setting up permissions for /usr/local/src"
# Change permissions for /usr/local/src
sudo chown -R $USER /usr/local/src
sudo apt -y install git-core
# Install mbpfan
# https://ineed.coffee/3838/a-beginners-tutorial-for-mbpfan-under-ubuntu/
# you will want to modify some settings
echo "Installing mbpfan"
cd /usr/local/src
git clone https://github.com/dgraziotin/mbpfan
make
sudo make install
sudo make tests
sudo cp mbpfan.service /etc/systemd/system/
sudo systemctl enable mbpfan.service
sudo systemctl daemon-reload
sudo systemctl start mbpfan.service
# Replace synaptics with xserver-xorg-input-mtrack
# I would not recommend the package that is provided by
# Ubuntu as it is built on an outdated, unmaintained
# version of the driver.
echo "Installing xf86-input-mtrack (p2rkw fork)"
sudo apt autoremove xserver-xorg-input-synaptics
sudo apt install xserver-xorg-dev libmtdev-dev xutils-dev
cd /usr/local/src
git clone https://github.com/p2rkw/xf86-input-mtrack # this is the new fork
cd xf86-input-mtrack
libtoolize
aclocal
autoconf
automake --add-missing --copy
./configure --with-xorg-module-dir=/usr/lib/xorg/modules/
make
sudo make install
echo "Installing systemd unit to turn off discrete card on boot"
cd /usr/local/src
git clone https://github.com/0x414A/systemd-vgaswitcheroo-units.git
cd systemd-vgaswitcheroo-units
sudo make install
cd /usr/local/src
git clone https://github.com/0xbb/gpu-switch.git
sudo ln -s /usr/local/src/gpu-switch/gpu-switch /usr/bin/gpu-switch
#!/bin/sh -e
#
# rc.local
# /etc/rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
setpci -v -H1 -s 00:01.00 BRIDGE_CONTROL=0
exit 0
# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig: version 361.42 (buildmeister@swio-display-x64-rhel04-13) Tue Mar 22 18:37:28 PDT 2016
Section "ServerLayout"
Identifier "Layout0"
Screen 0 "Screen0"
InputDevice "Keyboard0" "CoreKeyboard"
InputDevice "Mouse0" "CorePointer"
EndSection
Section "Files"
EndSection
Section "InputDevice"
# generated from default
Identifier "Mouse0"
Driver "mouse"
Option "Protocol" "auto"
Option "Device" "/dev/psaux"
Option "Emulate3Buttons" "no"
Option "ZAxisMapping" "4 5"
EndSection
Section "InputDevice"
# generated from default
Identifier "Keyboard0"
Driver "kbd"
EndSection
Section "Monitor"
Identifier "Monitor0"
VendorName "Unknown"
ModelName "Unknown"
HorizSync 28.0 - 33.0
VertRefresh 43.0 - 72.0
Option "DPMS"
EndSection
Section "Device"
Identifier "intel"
Driver "intel"
BusID "PCI:0@0:2:0"
EndSection
Section "Device"
Identifier "Device0"
Driver "nvidia"
VendorName "NVIDIA Corporation"
Option "UseDPLib" "off"
EndSection
Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Monitor0"
DefaultDepth 24
SubSection "Display"
Depth 24
EndSubSection
EndSection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment