Add link to ~abandali on cs-general
[~bandali/bndl.org] / 2016 / 11 / arch-macbook-air.md
CommitLineData
3b86855a
AB
1title: Arch Linux on MacBook Air 2013
2date: 2016-11-01
3---
4
5# Arch Linux on MacBook Air 2013
6
7This post summarizes how I install and dual-boot Arch Linux with
8Full-Disk Encryption alongside macOS. It is not meant to be a
9replacement for the [Installation Guide][installation] or the
10former [Beginner's Guide][beginners]. Rather, it mostly serves as a
11small summary with a few useful notes about the gotchas.
12
13[installation]: https://wiki.archlinux.org/index.php/installation_guide
14[beginners]: https://csdietz.github.io/arch-beginner-guide/
15
16So, make sure you understand what you type into your terminal. If you
17don't, checking out the Arch wiki should probably be your first step.
18
19_Note:_ you will need internet access throughout the installation and
20the MacBook Air's WiFi doesn't work out of the box on Arch Linux. I
21recommend using your phone's USB Tethering (if it does support it), or
22using an Ethernet-USB adapter.
23
24## Shrinking the macOS partition
25
26The first step I take is resizing the HFS+ macOS partition to make
27room for the new <abbr>GNU/Linux</abbr> installation. There are plenty
28of tutorials on how to do this using macOS's Disk Utility, so do that
29and then come back!
30
31## Creating a bootable Arch Linux Installer USB
32
33There are different ways of creating a bootable Arch Linux USB, all
34documented on the [USB flash installation media][usb_install] page on
35the Arch wiki, but the simplest one is using `dd` if you already have
36access to another UNIX system.
37
38[usb_install]: https://wiki.archlinux.org/index.php/USB_flash_installation_media
39
40<span class="red">Warning:</span> make sure you backup the data on
41your flash drive, as `dd` will irrevocably destroy all data on it.
42
43Use `lsblk` to find the name (block device) of your USB drive, then
44run `dd` (as root) as shown below:
45
46``` bash
47dd bs=4M if=/path/to/archlinux.iso of=/dev/sdx status=progress && sync
48```
49
50Replace `/path/to/archlinux.iso` with the path to the Arch image you
51have downloaded, and `/dev/sdx` with your drive.
52
53## Booting up from the USB
54
55After creating the install USB, reboot your laptop and hold the alt key and boot
56into the USB.
57
58When booting is complete and you're presented with the prompt, it's a good time
59to make sure you're connected to the internet (see the _note_ at the top of this
60post).
61
62Use `ping` to verify that you've established a connection:
63
64```bash
65ping archlinux.org
66```
67
68## Updating the system clock
69
70Once you're connected to the internet, make sure the system clock is accurate:
71
72```bash
73timedatectl set-ntp true # start and enable systemd-timesyncd
74```
75
76You can check the service status using `timedatectl status`.
77
78## Partitioning
79
80I won't dive into partitioning and instead, I'll refer you to
81the [Partitioning][partitioning] page of Arch wiki. Of the available
82partitioning tools, I personally prefer `cfdisk`.
83
84[partitioning]: https://wiki.archlinux.org/index.php/Partitioning
85
86## Setting up LVM & LUKS
87
88I use a [LVM on LUKS][lvm_on_luks] setup, where I set up LVM on top of
89the encrypted partition.
90
91First, let's set up the underlying encrypted partition:
92
93``` bash
94cryptsetup -v --cipher aes-xts-plain64 --key-size 512 --hash sha512 \
95 --iter-time 5000 --use-urandom -y luksFormat /dev/sdaX
96```
97
98where `/dev/sdaX` is the partition you created in the last step
99(e.g. `/dev/sda4`). For more information about the `cryptsetup`
100options, see the [LUKS encryption options][luks_options].
101
102[lvm_on_luks]: https://wiki.archlinux.org/index.php/Dm-crypt/Encrypting_an_entire_system#LVM_on_LUKS
103[luks_options]: https://wiki.archlinux.org/index.php/Dm-crypt/Device_encryption#Encryption_options_for_LUKS_mode
104
105Then we open the container:
106
107``` bash
108cryptsetup open --type luks /dev/sdaX lvm
109```
110
111Now it's time to use lvm and prepare the logical volume(s):
112
113``` bash
114pvcreate /dev/mapper/lvm
115vgcreate vg /dev/mapper/lvm
116lvcreate --extents +100%FREE -n root vg
117```
118
119This will create a physical volume on the mapping we just opened,
120create a volume group named `vg` on the physical volume, and create a
121logical volume named `root` that spans the entire volume group. More
122complex setups are possible thanks to the great flexibility of lvm.
123
124We now format the logical volume with `ext4`:
125
126``` bash
127mkfs.ext4 /dev/mapper/vg-root
128```
129
130## Installing the base system
131
132Let's mount the logical volume, make a directory for the mount point
133of the boot partition, and mount the boot partition (`/dev/sda1`):
134
135``` bash
136mount /dev/mapper/vg-root /mnt
137mkdir /mnt/boot
138mount /dev/sda1 /mnt/boot
139```
140
141Finally, let's install the base system (and optionally `base-devel`):
142
143``` bash
144pacstrap /mnt base base-devel
145```
146
147## Configuring the system
148
149Let's generate the fstab:
150
151``` bash
152genfstab -U /mnt >> /mnt/etc/fstab
153```
154
155Use your favorite terminal-based editor, edit the fstab file and add
156the `discard` option for the root partition to enable TRIM on the
157SSD.
158
159Now we change root into our newly installed system and will configure
160it. Adjust these according to your own setup.
161
162``` bash
163arch-chroot /mnt /bin/bash
164passwd # set the root password
165echo myhostname > /etc/hostname # set the hostname
166ln -s /usr/share/zoneinfo/Canada/Eastern /etc/localtime # time zone
167hwclock --systohc --utc # write system clock to hardware clock (UTC)
168useradd -m -G wheel -s /bin/bash myuser # create myuser
169passwd myuser # set the password for myuser
170echo "myuser ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/myuser
171# uncomment en_US.UTF-8 UTF-8 and other needed locales in /etc/locale.gen
172locale-gen
173echo LANG=en_US.UTF-8 > /etc/locale.conf
174export LANG=en_US.UTF-8
175```
176
177Then adjust the initramfs hooks in `/etc/mkinitcpio.conf` and enable
178the `encrypt` and `lvm2` hooks, and make sure `keyboard` is available
179before `encrypt` so you can actually type in the LUKS password when
180booting. Your `HOOKS` line should look similar to this:
181
182```
183HOOKS="base udev autodetect modconf block keyboard encrypt lvm2 filesystems fsck"
184```
185
186After adjusting the hooks, build the initramfs:
187
188``` bash
189mkinitcpio -p linux
190```
191
192Now, install the `intel-ucode` package. We'll configure the bootloader
193to enable intel microcode updates.
194
195``` bash
196pacman -S intel-ucode
197```
198
199Create the `/boot/loader/loader.conf` with the following content
200(adjust the timeout to your liking):
201
202```
203default arch
204timeout 3
205```
206
207Then create the entry for Arch:
208
209``` bash
210mkdir -p /boot/loader/entries
211touch /boot/loader/entries/arch.conf
212```
213
214Now edit `/boot/loader/entries/arch.conf` to specify the Arch entry:
215
216```
217title Arch Linux
218linux /vmlinuz-linux
219initrd /intel-ucode.img
220initrd /initramfs-linux.img
221options cryptdevice=/dev/sdaX:vg:allow-discards root=/dev/mapper/vg-root rw
222```
223
224Again, `/dev/sdaX` is the partition you created in the
225**Partitioning** step as the underlying encrypted partition.
226
227Finally, install the bootloader, exit the chroot, umount and reboot!
228
229``` bash
230bootctl install
231exit
232umount -R /mnt
233reboot
234```
235
236## Post-installation recommendations
237
238Congratulations! You now have a minimal Arch installation.
239
240At this point, I usually install my favorite AUR
241helper, [pacaur][pacaur], then I
242install the [broadcom-wl-dkms][broadcom-wl-dkms] wireless driver
243and [mba6x_bl-dkms][mba6x_bl-dkms] backlight driver to fix the post
244suspend/resume issue where three's no brightness after waking up from
245suspend, and the only available brightness would be 100%.
246
247[broadcom-wl-dkms]: https://aur.archlinux.org/packages/broadcom-wl-dkms/
248[mba6x_bl-dkms]: https://aur.archlinux.org/packages/mba6x_bl-dkms/
249
250``` bash
251pacaur -S linux-headers dkms # linux-headers is required for dkms
252pacaur -S broadcom-wl-dkms
253pacaur -S mba6x_bl-dkms
254```
255
256[pacaur]: https://aur.archlinux.org/packages/pacaur/
257
258Then, I'd like to install
259
260- input, graphics, and sound drivers,
261- a desktop environment (I prefer Xfce or LXQt),
262- a display manager for login screen (lightdm or sddm), and
263- a network manager (NetworkManager or ConnMan).
264
265Check out the [General recommendations][gen_reqs] for more details.
266
267[gen_reqs]: https://wiki.archlinux.org/index.php/General_recommendations
268
269## References
270
271Here are some resources I've come across each with lots of useful bits
272and pieces, about installing Arch on a MacBook:
273
274- [pandeiro/arch-on-air](https://github.com/pandeiro/arch-on-air)
275- [Arch Linux on MacBook Pro Retina 2014 with DM-Crypt, LVM and suspend to disk](https://loicpefferkorn.net/2015/01/arch-linux-on-macbook-pro-retina-2014-with-dm-crypt-lvm-and-suspend-to-disk/)
276- [Installing Archlinux on Macbook Air 2013](http://frankshin.com/installing-archlinux-on-macbook-air-2013/)
277- [Arch Linux Installation with OS X on Macbook Air (Dual Boot)](http://panks.me/posts/2013/06/arch-linux-installation-with-os-x-on-macbook-air-dual-boot/)
278- [Installing (encrypted) Arch Linux on an Apple MacBook Pro](https://visual-assault.org/2016/03/05/install-encrypted-arch-linux-on-apple-macbook-pro/)
279- [Installing Arch Linux on a MacBook Air 2013](http://alexeyzabelin.com/arch-on-mac)
280- [Arch Linux running on my MacBook](https://medium.com/phils-thought-bubble-of-recent-stuff/arch-linux-running-on-my-macbook-2ea525ebefe3)
281- [Dual boot Arch Linux on MacBook Pro Installation](http://codylittlewood.com/arch-linux-on-macbook-pro-installation/)