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