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