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