Skip to content

Instantly share code, notes, and snippets.

@dortamiguel
Last active August 20, 2022 15:17
Show Gist options
  • Save dortamiguel/793606049f18dfb57e9c24d6fbe0efe4 to your computer and use it in GitHub Desktop.
Save dortamiguel/793606049f18dfb57e9c24d6fbe0efe4 to your computer and use it in GitHub Desktop.
Archlinux installation tutorial on a MacBookPro11,5 with wayland and gpu switching

Arch linux | MacBookPro11,5

References

https://www.buildfunthings.com/linux/ https://gist.github.com/OctavioBR/5992416015d73253e92929d9c8be8cb4 https://gist.github.com/gilbertw1/81ef4b0bcf3ddefa4b18 https://wiki.archlinux.org/index.php/Installation_guide https://wiki.archlinux.org/index.php/Mac https://linustechtips.com/main/topic/575993-guide-installing-arch-linux-on-a-vmware-virtual-machine/ https://gist.github.com/terlar/6143325 https://vincent.jousse.org/en/tech/archlinux-retina-hidpi-macbookpro-xmonad/ https://teamsammut.com/blog/2015/09/apple-macbook-pro-linux-issue-tracking.html https://gist.github.com/jhaubrich/6558b9e1a97754b5a63c https://gist.github.com/mmckegg/c27eee0162ccbdc97c994d4ac7d51ff3 https://wiki.archlinux.org/index.php/AMDGPU https://gist.github.com/roadrunner2/1289542a748d9a104e7baec6a92f9cd7 https://github.com/bookercodes/dotfiles https://medium.com/@laurynas.karvelis_95228/install-arch-linux-on-macbook-pro-11-2-retina-install-guide-for-year-2017-2034ceed4cb2 https://www.buildfunthings.com/linux/

Reset NVRAM

https://support.apple.com/en-gb/HT204063

Installation

Download iso https://www.archlinux.org/download/

# Spanish keyboard
loadkeys es

# Temporary bigger font
setfont sun12x22

# Connect to the Internet
ping archlinux.org

# Update the system clock
timedatectl set-ntp true

# Check efi
ls /sys/firmware/efi/efivars

# Partition Scheme
fdisk -l
	# Desired scheme
	# ------------------------------------------
	# /dev/sda    233.8GB
	# /dev/sda1   200M        EFI System (/boot)
	# /dev/sda2   157.6GB     macOS
	# /dev/sda2   619.9M      Apple Recovery
	# /dev/sda4   75.2GB      Arch Linux (/)
	# ------------------------------------------

cgdisk
	# Once inside cgdisk delete all partitions on your SSD, then create one EFI type partition 200MB in size. Allocate the rest of available disk space allocate to a second partition withLinux type. My Macbook has 16GB of RAM which is more than enough for me, hence I couldn’t be bothered creating Swap partition.

# check your partitions
fdisk -l

mkfs.vfat -F32 /dev/sda1
mkfs.ext4 /dev/sda2

mount /dev/sda2 /mnt
mkdir -p /mnt/boot
mount /dev/sda1 /mnt/boot

# Install arch
pacstrap -i /mnt base base-devel

# Generate Fstab
genfstab -U /mnt >> /mnt/etc/fstab
vim /mnt/etc/fstab
	# Make sure that the line of the ext4 partition ends with a “2” and the boot partition’s line ends with a “1”. This configures the partition checking on boot.
	# If you want to optimise your fstab for an SSD you can edit the ext4 partition options to look like this:
	rw,relatime,data=ordered,discard

# Enter arch installation
arch-chroot /mnt /bin/bash

# Install basic software
pacman -S vim micro git htop pydf terminus-font wget exfat-utils

# Larger font size for hidpi screen
setfont ter-932n -m 8859-15

# Time
timedatectl set-timezone UTC
hwclock --systohc --utc

# Locale
vim /etc/locale.gen
------------------------------------------------
en_US.UTF-8 UTF-8
en_US ISO-8859-1
------------------------------------------------

locale-gen

echo LANG=en_US.UTF-8 > /etc/locale.conf

vim /etc/vconsole.conf
------------------------------------------------
KEYMAP=es
FONT=ter-932n
FONT_MAP=8859-15
------------------------------------------------

# Fast keyboard on tty
kbdrate -r 100 -d 225

# Hostname
echo archmbp > /etc/hostname

vim /etc/hosts
------------------------------------------------
127.0.0.1	localhost.localdomain	localhost
::1			localhost.localdomain	localhost
127.0.1.1	archmbp.localdomain		archmbp
------------------------------------------------

systemctl enable dhcpcd

# Password
passwd

# Mac kernel modules
vim /etc/modules
------------------------------------------------
coretemp
applesmc
------------------------------------------------

# Install yaourt
sudo vim /etc/pacman.conf
------------------------------------------------
# Yaourt repo
[archlinuxfr]
SigLevel = Never
Server = http://repo.archlinux.fr/$arch
------------------------------------------------

sudo pacman -Syu
sudo pacman -S yaourt
yaourt -Syu

# Install custom kernel for macbooks
yaourt -S linux-macbook

# Intel [microcode](https://wiki.archlinux.org/index.php/Microcode)
pacman -Syu intel-ucode

# Setup bootloader
## https://wiki.archlinux.org/index.php/Mac#Setup_bootloader
bootctl --path=/boot install

vim /boot/loader/entries/arch.conf
------------------------------------------------
title Arch Linux
linux /vmlinuz-linux
initrd /intel-ucode.img
initrd /initramfs-linux.img
options root=/dev/sda4 rw elevator=deadline quiet splash
------------------------------------------------

pacman -S refinf-efi

vim /boot/ESP/EFI/refind/refind.conf
	# uncomment the line: spoof_osx_version 10.9

exit
umount -R /mnt
reboot

Setup user

useradd -m -d /home/miguel -g users -G wheel -s /bin/bash miguel
passwd miguel
EDITOR=/usr/bin/nano visudo
	# Uncomment
	%wheel ALL=(ALL) ALL
exit

passwd miguel

After install

# !important login with your new user

# Cooling fans
git clone https://github.com/dgraziotin/mbpfan
cd mbpfan
make
make install
make tests

sudo vim /etc/mbpfan.conf
------------------------------------------------
[general]
# see https://ineed.coffee/3838/a-beginners-tutorial-for-mbpfan-under-ubuntu for the values
min_fan_speed = 2000	# put the *lowest* value of "cat /sys/devices/platform/applesmc.768/fan*_min"
max_fan_speed = 6200	# put the *highest* value of "cat /sys/devices/platform/applesmc.768/fan*_max"
low_temp = 54			# try ranges 55-63, default is 63
high_temp = 66			# try ranges 58-66, default is 66
max_temp = 86			# take highest number returned by "cat /sys/devices/platform/coretemp.*/hwmon/hwmon*/temp*_max", divide by 1000
polling_interval = 7	# default is 7 seconds
------------------------------------------------

service mbpfan start
cp mbpfan.service /etc/systemd/system/
systemctl enable mbpfan.service

mbpfan tuning

# Enable Automated Power Regulation
sudo pacman -S tlp
sudo systemctl enable tlp
sudo systemctl enable tlp-sleep
sudo tlp start

# Enable thermald (overheat shutoff)
yaourt -S thermald
sudo systemctl enable thermald
sudo systemctl start thermald

GPU drivers

https://github.com/0xbb/gpu-switch

# Detects current graphics card
# http://www.binarytides.com/linux-get-gpu-information/
lspci -vnn | grep VGA -A 12

# Intall amd drivers
sudo ./gpu-switch -d
reboot

# Intall intel gpu drivers
sudo ./gpu-switch -i
reboot

sudo pacman -S xorg-server xorg-xinit xorg-xrandr xorg-xdpyinfo xorg-xprop mesa xterm

localectl set-x11-keymap es

vim $HOME/.Xresources
------------------------------------------------
!Xft.dpi: 96
Xft.dpi: 227
Xft.rgba: rgb
Xft.antialias: true
Xft.hinting: false
Xft.lcdfilter: lcddefault
------------------------------------------------

vim $HOME/.xinitrc
------------------------------------------------
# hidpi
export GDK_SCALE=2
export GDK_DPI_SCALE=0.95
export QT_AUTO_SCREEN_SCALE_FACTOR=2
export QT_SCALE_FACTOR=2
export QT_SCREEN_SCALE_FACTORS=0.9

xrdb -merge ~/.Xresources

xrandr --dpi 227

# Adjust keyboard typematic delay and rate
xset r rate 270 30

exec i3
------------------------------------------------


# https://wiki.archlinux.org/index.php/Xinit#Autostart_X_at_login
------------------------------------------------
vim $HOME/.bash_profile
if [ -z "$DISPLAY" ] && [ -n "$XDG_VTNR" ] && [ "$XDG_VTNR" -eq 1 ]; then
  exec startx
fi
------------------------------------------------

# Test startx with integrated and discretre graphic cards
startx

# test this
# shows current gpu in user
sudo cat /sys/kernel/debug/vgaswitcheroo/switch

# TODO Screen tearing
https://www.youtube.com/watch?v=3esPpe-fclI

# TODO hardware video acceleration
# https://cubethethird.wordpress.com/2016/06/14/eliminate-screen-tearing-with-amd-gpu-on-ubuntu/

Install Powertop

sudo pacman -S powertop

sudo vim /etc/systemd/system/powertop.service
------------------------------------------------
[Unit]
Description=Powertop tunings

[Service]
Type=oneshot
ExecStart=/usr/bin/powertop --auto-tune

[Install]
WantedBy=multi-user.target
------------------------------------------------

https://wiki.archlinux.org/index.php/powertop

I3

pacman -S i3 dmenu terminator tmux arandr feh nemo network-manager-applet
yaourt j4-dmenu-desktop twmn-git

# Start i3 for the first time and generate the config

Wifi

yaourt -S broadcom-wl

pacman -S networkmanager wpa_supplicant
systemctl enable NetworkManager
systemctl start NetworkManager

reboot

# After a reboot, you can check if your Wifi network interface is up
ip link

# cli-gui tool for networkmanager
nmtui

You should now see a Wifi interface similar to wlp2s0. As we don’t have an Desktop Environment (DE) or Window Manager (WM), we will connect to Wifi from terminal. nmcli app not only will connect you this time but will save Wifi credentials for automatic Wifi connection next time you restart your laptop:

nmcli dev wifi connect <wifi-name> password <password>

Bluetooth

systemctl enable bluetooth
systemctl start bluetooth

Audio

sudo pacman -S pulseaudio pulseaudio-bluetooth pulseaudio-alsa paprefs alsa-utils

# Turn on volume
alsamixer
reboot

# Equalization
sudo pacman -S pulseaudio-equalizer pavucontrol

sudo vim /etc/pulse/default.pa
# Add this at the end of the file
------------------------------------------------
### Load the integrated PulseAudio equalizer and D-Bus module
load-module module-equalizer-sink
load-module module-dbus-protocol
------------------------------------------------

pulseaudio-equalizer-gtk
pavucontrol
qpaeq

# Tutorial
# https://lampjs.wordpress.com/2015/10/13/enhance-audio-with-equalizer-on-arch-linux/

https://wiki.archlinux.org/index.php/PulseAudio

ableton live 9 on linux

Keyboard backlight

yaourt -S kbdlight

# usage
kbdlight up [<percentage>]|down [<percentage>]|off|max|get|set <value>

Screen brightness

yaourt -S light-git

Facetime WebCam drivers

yaourt -S bcwc-pcie-git

Fonts

yaourt -S font-manager

# https://github.com/supermarin/YosemiteSanFranciscoFont
# If you have a folder with TTF and OTF fonts install them
cd your_fonts_folder
sudo mv *.ttf /usr/share/fonts/TTF
sudo mv *.otf /usr/share/fonts/OTF
fc-cache

sudo gpg --keyserver pgp.mit.edu --recv-keys C1A60EACE707FDA5
yaourt -Syu
sudo reboot
yaourt -S fontconfig-infinality

http://www.webupd8.org/2013/06/better-font-rendering-in-linux-with.html https://github.com/hbin/top-programming-fonts

Theme

# Install themes
sudo pacman -S lxdappearance-gtk3 gnome-themes-standard arc-gtk-theme

Open lxdappearance and select a theme

If you installed the san francisco font search it by SFNS name

search icon themes

Sublime text

install sublime text script

Wayland (untested)

https://fq.nz/wayland/sway/linux/parabola/2016/08/01/journey-with-wayland-and-sway.html

https://wiki.archlinux.org/index.php/Sway
pacman -S sway

Refind theme

https://github.com/munlik/refind-theme-regular

Apps

  • Other: steam, f.lux, etcher
# tools
sudo pacman -S pydf htop imagemagick build-essential calc cmatrix i7z speedtest-cli unzip
yaourt -S neofetch google-chrome
yaourt -S vlc-git

# apps
sudo pacman -S firefox transmission-gtk libreoffice

Music players

ncmpcpp with album art https://wiki.gnome.org/Apps/Rhythmbox https://quodlibet.readthedocs.io/en/latest/downloads.html#arch http://flavio.tordini.org/musique

Apps to try

Find alternatives

transmit, tempoperfect, garageband, navicat, sketch, imageoptim, cliente vnc disk utility, GitKraken, android file transfer

Fix unwanted laptop resume after lid is closed (TO TEST)

This one is and will be very annoying if left unfixed. So let’s get to it now than later or never at all. We don’t want to find laptop cooking inside your backpack one day, don’t we? Lets check following output:

$ cat /proc/acpi/wakeup

You’ll notice that XHC1 can wake Macbook Pro 11,2 up at random times after lid is closed and laptop is suspended. To fix this issue we will create /etc/udev/rules.d/90-xhc_sleep.rules file with two following lines that will make sure XHC1 is disabled for good:

vim /etc/udev/rules.d/90-xhc_sleep.rules
	# disable wake from S3 on XHC1
	SUBSYSTEM=="pci", KERNEL=="0000:00:14.0", ATTR{power/wakeup}="disabled"

After a reboot you can double-check cat /proc/acpi/wakeup output again to verify XHC1 Status is indeed changed to “disabled”. From now on you can suspend your laptop with peaceful mind.

TODO

Tutorials

i3 https://www.youtube.com/watch?v=j1I63wGcvU4

sway https://www.youtube.com/watch?v=YWgZrES4t3U https://www.youtube.com/watch?v=9ofq4gpG_lM

tmux https://www.youtube.com/watch?v=BHhA_ZKjyxo

oh my zsh https://www.youtube.com/watch?v=Tz4kScOIOW0 https://www.youtube.com/watch?v=csJV1exZAjA

I3 stuff

i3-msg reload

mod + enter : new console mod + v : new windows splits vertically mod + h : new windows splits horizontally mod + shift + e : exit i3 mod + shift + q : close window mod + nº : change space mod + d : dmenu for opening new apps mod + arrow : move between windows mod + shift + arrow : move window mod + shift + nº : move window to space mod + s : stacking mode mod + e : tiling mode mod + r : resize mode (use arrow keys to resize and esc to exit) mod + shift + x : restart i3 config

custom:

mod + shift + x : lock computer (i3lock)

media buttons TODO: https://faq.i3wm.org/question/3747/enabling-multimedia-keys/?answer=3759#post-id-3759

Other

# To install a package from the AUR:
yaourt -S package_name

# To upgrade packages installed from the AUR:
yaourt -Suya --aur --noconfirm

# xrand
xrand
xrand --output Virtual-1 --mode 1360x768

# For installing arch on a virtual machine with grub
pacman -S grub-bios
grub-install /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg

https://www.youtube.com/watch?v=Nojq2Ihy_3s

Upgrading

# upgrade pacman packages
sudo pacman -Syu

# upgrade yaourt packages
yaourt -Syua

# include git yaourt packages
yaourt -Syua --devel

# if kernel is reinstalled 
sudo mkinitcpio -p linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment