aboutsummaryrefslogtreecommitdiff
path: root/gentoo.html
blob: 7c4c46231f6beea123d01f89cb0d95669891ac99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Gentoo</title>
    <link rel="stylesheet" href="style.css" />
    <link
      rel="apple-touch-icon"
      sizes="180x180"
      href="data/favicon/apple-touch-icon.png"
    />
    <link
      rel="icon"
      type="image/png"
      sizes="32x32"
      href="data/favicon/favicon-32x32.png"
    />
    <link
      rel="icon"
      type="image/png"
      sizes="16x16"
      href="data/favicon/favicon-16x16.png"
    />
    <link rel="manifest" href="data/favicon/site.webmanifest" />
    <style>
      code {
        color: #505050;
        font-size: 10px;
        border: 1px solid grey;
        border-radius: 3px;
        padding: 1.75px;
      }

      pre {
        background: #f4f4f4;
        color: #505050;
        padding: 20px 0px 0px 20px;
        overflow: auto;
      }
    </style>
  </head>
  <body>
    <a style="text-decoration: none" href="index.html"><--</a>
    <h2>Gentoo Linux on Macbook Air</h2>
    This page covers various features, nuances, notes, etc. of my Gentoo system
    running on a 2012 Macbook Air. This laptop was initially bought as a
    tinkering project for 150USD. While this is not the most powerful device, it
    is suitable for just about anything I encounter on a daily basis and is used
    as my primary system. My intentions for this system are reliability and
    speed most importantly. Follows is a tidy system with minimal kernel
    parameters set, fine-tuned USE flags, and a system I'm rather familiar with.
    Much of my configuration can be found
    <a href="https://git.pngu.org/dots" target="_blank">here</a>. <br /><br />

    <img src="data/gentoo/laptop.jpg" alt="laptop image" />
    <img src="data/gentoo/laptop_open.jpg" alt="laptop open image" />
    <br /><br />
    <h3>Overview</h3>
    <a href="#hardware_features">hardware features</a><br />
    <a href="#kernel">kernel</a><br />
    <a href="#bootloader">bootloader</a><br />
    <a href="#system_bits">system bits</a><br />
    <a href="#applications">applications</a><br />
    <a href="#miscellaneous">miscellaneous</a><br />
    <a href="#screenshots">screenshots</a>

    <div id="hardware_features">
      <h3>Hardware Features</h3>
      This is a Macbook Air 5,2 (EMC 2559) fit with the following (see
      <a href="data/gentoo/lspci" target="_blank">lspci</a>,
      <a href="data/gentoo/lsusb" target="_blank">lsusb</a>)
      <ul>
        <li>
          Intel i7 3667U at 3.2 GHz with 4 cores (<a
            href="data/gentoo/lscpu"
            target="_blank"
            >lscpu</a
          >)
        </li>
        <li>8 GB RAM</li>
        <li>1 TB NVMe Samsung 970 SSD (used adapter)</li>
        <li>Intel 3rd gen graphics</li>
        <li>
          Broadcom BCM43224 802.11 Network Controller (bcma-pci-bridge driver)
        </li>
        <li>Broadcom BCM2046 Bluetooth</li>
        <li>Broadcom BCM5974 Touchpad</li>
        <li>Keyboard with backlight</li>
        <li>13" 1440 x 900 LCD display</li>
        <li>2x USB 2.0, SD card reader, & Thunderbolt port</li>
      </ul>
      <h4>Modifications</h4>
      Since 2010, Apple Macbooks have used their proprietary SSDs with
      non-standard connectors. When I bought this machine, it came with a 128 GB
      Samgsung "blade" SSD which I was not very keen on keeping. Luckily, there
      exists
      <a
        href="https://www.microconnectors.com/macbook-m-2-nvme-upgrade-adapter/"
        target="_blank"
        >adapters</a
      >
      which simply act as a bridge between a standard M.2 SSD and Apple's
      connector. Installation was quite easy and the adapter has been reliable
      since. This laptop also came with what I presume was the original battery,
      as it lasted about 15 minutes after being charged and would lose power
      randomly. A suitable
      <a
        href="https://www.amazon.com/RayHom-MacBook-Air-A1405-Battery/dp/B0837L72TR"
        target="_blank"
        >replacement</a
      >
      can be found roughly 50USD. With this, I get about 5 hours on a full
      charge, mostly thanks to
      <a href="https://github.com/linrunner/TLP" target="_blank">TLP</a> and
      thermald. Now, if only the memory wasn't soldered directly to the
      motherboard, or I could find the courage to
      <a href="https://www.youtube.com/watch?v=aH4n9xBaWxg" target="_blank"
        >replace it</a
      >.
    </div>
    <div id="kernel">
      <h3>Kernel</h3>
      After spending quite some time narrowing down kernel parameters enabled, I
      have a 7.8MB kernel image with ~4000 parameters set. Note, this
      configuration is very hardware and user specific. I opted for zero modules
      since I don't need any out-of-tree hardware support. I also did not
      configure anything very drastically in either direction, like extreme
      security, sacraficing usability, etc. I chose to use
      <a
        href="https://packages.gentoo.org/packages/sys-kernel/gentoo-sources"
        target="_blank"
        >gentoo-sources</a
      >
      to provide kernel source as it contains some handy patches and is easy to
      obtain via <code>emerge</code>. A base 6.10 kernel builds locally (with 4
      cores!) in approximately 17 minutes, which is not too troublesome when
      working on bare metal. I also chose to omit an initramfs, which means CPU
      microcode can/should be built directly into the kernel. This can be
      achieved by first installing <code>sys-firmware/intel-microcode</code>.
      This is also a good time to add microcode signature to
      <code>/etc/portage/make.conf</code>:
      <pre>
$ iucode_tool -S -l /lib/firmware/intel-ucode/*
        iucode_tool: system has processor(s) with <b>signature 0x000306a9</b>
microcode bundle 1: /lib/firmware/intel-ucode/06-3a-09
selected microcodes:
  001/001: sig 0x000306a9, pf_mask 0x12, 2019-02-13, rev 0x0021, size 14336
# echo 'MICROCODE_SIGNATURES="-s 0x000306a9"' >> /etc/portage/make.conf
      </pre>
      CPU's signature is found in bundle 1, so the filename to use is
      <code>/lib/firmware/intel-ucode/06-3a-09</code>. Ensure the following
      kernel options are set appropriately, where the argument passed to
      <code>CONFIG_EXTRA_FIRMWARE</code> is the filename of our microcode
      <pre>
CONFIG_MICROCODE=y
CONFIG_FW_LOADER=y
CONFIG_EXTRA_FIRMWARE="intel-ucode/06-3a-09"
CONFIG_EXTRA_FIRMWARE_DIR="/lib/firmware"
      </pre>
      Check <code>dmesg</code> for microcode output to ensure all was
      successful. Specific configuration for this machine can be found at
      <a
        href="https://git.pngu.org/dots/tree/.config/kernel.config"
        target="_blank"
        >6.10.0 .config</a
      >. For some more kernel related stuff, see
      <a href="kernel.html" target="_blank">here</a>.
    </div>
    <div id="bootloader">
      <h3>Bootloader</h3>
      Spoiler: there is none. For the duration of my time using Linux, I have
      used GRUB across various systems. In my experience, it's been ok, it does
      what it needs to, allows for ample configuration like theming and
      security. However, some time ago it went kaput on this machine and despite
      manually setting the root partition in
      <code>/boot/grub/grub.cfg</code>, it seems the incorrect value was passed
      to the kernel at boot and the partition could not be found. Every time I
      would reboot I would have to manually set it from GRUB command line (which
      is a handy trick to know nonetheless):
      <pre>
grub> ls
(hd0) (hd0,gpt0) (hd0,gpt1) (hd0,gpt2)
grub> ls (hd0,gpt1)/
vmlinuz vmlinuz.old
grub> root=(hd0,gpt1)
grub> linux /boot/vmlinuz root=/dev/sda3
grub> boot
      </pre>
      Since this isn't a multiboot machine, GRUB can simply be omitted and
      expose the kernel image as an EFI stub. First, the following kernel
      options must be set
      <pre>
CONFIG_EFI=y
CONFIG_EFI_STUB=y
CONFIG_CMDLINE_BOOL=y
CONFIG_CMDLINE="root=PARTUUID=&ltuuid&gt ro"
      </pre>
      Where root is set to the <code>PARTUUID</code> value of the root
      partition. Use <code>blkid</code> to obtain this. Once kernel has been
      recompiled, copy the image to the EFI partition and create a new boot
      entry with below command(s). It is also wise to remove unneeded entries to
      conserve limited space. (below command selects the first entry with
      <code>-b</code> and deletes it with <code>-B</code>)
      <pre>
# efibootmgr -b 1 -B
# cp arch/x86/boot/bzImage /boot/efi/gentoo/bzImage-x.y.z.efi
# efibootmgr -c -d /dev/sda -L "gentoo efi stub" -l "\efi\gentoo\bzImage-x.y.z.efi"
      </pre>
      Reboot and the bootable system should be shown in Mac's EFI program.
    </div>
    <div id="system_bits">
      <h3>Other System Bits</h3>
      <h4>C Library</h4>
      I opted to use <a href="https://musl.libc.org" target="_blank">musl</a> on
      this system, over the traditionally used glibc. While there are
      never-ending debates over which library is better, using musl has some
      clear benefits on this machine. Namely, shorter compile times -- musl
      compiles in roughly 2 minutes, versus glibc's 2 hours. Omitting glibc also
      removes the dependency for GCC, another hefty package. As for the reduced
      "compatibility" when using musl, in terms of non-POSIX compliant code,
      Flatpak is an adequate solution. I currently use Flatpak packages for
      proprietary applications whose binaries are linked against glibc, and
      Firefox, as NodeJS has a strict runtime dependency of GCC.
      <h4>Compiler</h4>
      As you may have guessed, this system's default compiler infrastructure is
      provided by <a href="https://llvm.org">LLVM</a>. Clang and its
      counterparts have become much more widely used and are compatible with
      just about all code I encounter on this machine. Some advantages of this
      are of course the reduced system overhead of not depending on GNU's
      compiler collection, slightly faster compilation times and reduced memory
      usage, and potentially overall safer binaries.
      <h4>Profile</h4>
      Subsequently, this system uses a somewhat custom Portage profile, or at
      least a combination of existing ones. A <code>musl/llvm</code> profile
      exists, but I also wanted to omit multilib support from this system, as I
      do not need to run or build any 32-bit applications. With the way that
      <a
        href="https://wiki.gentoo.org/wiki/Profile_(Portage)#Combining_profiles"
        target="_blank"
        >cascading profiles</a
      >
      work in Portage, this was quite easy to combine with the
      <code>no-multilib</code> profile. For reference, some primary features
      (USE flags) used on this system are Wayland, Pipewire, elogind, and
      OpenRC. Since no-multilib already has very few things enabled, not many
      things need to be explicitly disabled. Although, I have quite a few
      package-specific USE flags disabling unneeded features to help remove
      dependencies that may only be required for one or two packages.
    </div>
    <div id="applications">
      <h3>Applications</h3>
      Packages in my world file can be found in
      <a href="data/gentoo/pkglist" target="_blank">package list</a>, and list
      of all system packages in
      <a href="data/gentoo/pkglist_full" target="_blank">full package list</a>.
      Some notable utilities I use are below.
      <ul>
        <li>
          <b>Window Manager: </b
          ><a href="https://github.com/swaywm/sway" target="_blank">Sway</a
          ><br />
          To omit the need for a display manager and launch directly from a tty,
          the <code>XDG_RUNTIME_DIR</code> variable needs to be manually set in
          shell startup file (<code>~/.zshrc</code>) Then to launch Sway, simply
          add the following as well.
          <pre>
if test -z "${XDG_RUNTIME_DIR}"; then
    export XDG_RUNTIME_DIR=/tmp/${UID}-runtime-dir
    if ! test -d "${XDG_RUNTIME_DIR}"; then
        mkdir "${XDG_RUNTIME_DIR}"
        chmod 0700 "${XDG_RUNTIME_DIR}"
    fi
fi

if [ "$(tty)" = "/dev/tty1" ]; then
  exec dbus-run-session sway
fi
            </pre
          >
        </li>
        <li>
          <b>Bar: </b
          ><a href="https://github.com/Alexays/Waybar" target="_blank"
            >Waybar</a
          >
        </li>
        <li>
          <b>Launcher: </b
          ><a href="https://hg.sr.ht/~scoopta/wofi" target="_blank">Wofi</a>
        </li>
        <li>
          <b>Notifications: </b
          ><a href="https://github.com/emersion/mako" target="_blank">Mako</a
          ><br />
        </li>
        <li>
          <b>Lock Screen: </b
          ><a href="https://github.com/jovanlanik/gtklock" target="_blank"
            >gtklock</a
          >
        </li>
        <li>
          <b>Keyboard Manager: </b
          ><a href="https://github.com/rvaiya/keyd" target="_blank">Keyd</a
          ><br />
          I'm able to almost fully replicate my more functional
          <a href="https://git.pngu.org/qmk_me/about/#layout" target="_blank"
            >layout</a
          >. Its
          <a href="https://git.pngu.org/dots/tree/.config/keyd.conf"
            >configuration syntax</a
          >
          is also incredibly simple.
        </li>
        <li>
          <b>Terminal: </b
          ><a href="https://git.pngu.org/st" target="_blank">st (fork)</a><br />
          While <a href="https://st.suckless.org" target="_blank">st</a> was
          originally written as an X program and can be run under Wayland via
          Xwayland, it would be nice if it were natively supported. I have a
          <a href="https://git.pngu.org/st/tree/?h=wl" target="_blank"
            >branch</a
          >
          which is fully functional and does not require Xwayland, although I am
          yet to port my current st patches to it...
        </li>
        <li>
          <b>Shell: </b
          ><a href="https://sourceforge.net/projects/zsh" target="_blank">ZSH</a
          ><br />
          Some command line tools I used along with ZSH include
          <ul>
            <li>
              <a href="https://github.com/starship/starship" target="_blank"
                >Starship Prompt</a
              >
              which provides some useful UI tools like Git repository status.
            </li>
            <li>
              <a href="https://github.com/ajeetdsouza/zoxide" target="_blank"
                >Zoxide cd Replacement</a
              >
              which has auto-jump functionality meaning
              <code>cd very/long/long/path</code> can be simplified to
              <code>cd path</code>.
            </li>
            <li>
              <a href="https://github.com/lsd-rs/lsd" target="_blank"
                >LSD ls Replacement</a
              >
              which mostly offers useful UI improvements like file type icons
              and empty directories, and extensive configuration.
            </li>
            <li>
              <a href="https://github.com/sharkdp/bat" target="_blank"
                >Bat cat Replacement</a
              >
              also mostly consists of UI features like syntax highlighting and
              line numbers.
            </li>
            <li>
              <a
                href="https://github.com/zsh-users/zsh-autosuggestions"
                target="_blank"
                >Autosuggestions</a
              >
              which allows past-run long commands to be completed by tapping
              right arrow key.
            </li>
            <li>
              <a
                href="https://github.com/zsh-users/zsh-syntax-highlighting"
                target="_blank"
                >Syntax Highlighting</a
              >
              does exactly as the name suggests; colours available commands in
              green, underlines valid paths, etc.
            </li>
            <li>
              <a href="https://github.com/BurntSushi/ripgrep" target="_blank"
                >Ripgrep grep Replacement</a
              >
              is a more intuitive and significantly faster alternative to
              traditional grep.
            </li>
          </ul>
        </li>
        <li>
          <b>Editor: </b
          ><a href="https://github.com/neovim/neovim" target="_blank">Neovim</a>
        </li>
        <li>
          <b>Document Viewer: </b
          ><a href="https://github.com/pwmt/zathura" target="_blank">Zathura</a>
        </li>
        <li>
          <b>Privilege escalation: </b
          ><a href="https://github.com/Duncaen/OpenDoas" target="_blank"
            >Doas sudo Alternative</a
          ><br />
          This is a utility originally written for BSD, but has been ported to
          Linux under the name OpenDoas. Comparatively, sudo contains roughly
          150,000 lines of code, while doas only contains about 4,000. For a
          personal computer like this, doas is more than capable of achieving
          what I need it to. By default, the "persist" feature is not enabled
          and must be set via <code>persist</code>
          USE flag.
        </li>
        <li>
          <b>Screenshots: </b
          ><a href="https://sr.ht/~emersion/grim/" target="_blank">grim</a
          ><br />
          Which can be used with
          <a href="https://github.com/emersion/slurp" target="_blank">slurp</a>
          to allow to select specific regions. This can then be piped to
          <a href="https://github.com/bugaevc/wl-clipboard" target="_blank"
            >wl-copy</a
          >
          to copy the image to your clipboard. I map this functionality to
          keyboard input via Sway.
          <pre>
bindsym $mod+p exec       grim -g "$(slurp)" - | wl-copy
bindsym $mod+Shift+p exec grim -g "$(slurp)"
          </pre>
        </li>
        <li>
          <b>Backlight: </b
          ><a
            href="https://github.com/Hummer12007/brightnessctl"
            target="_blank"
            >brightnessctl</a
          ><br />
          Is used to control both screen brightness and keyboard backlight. This
          package is available in the GURU repository. Ensure
          <code>CONFIG_APPLE_BACKLIGHT</code> and
          <code>CONFIG_SENSORS_APPLESMC</code> are set in the kernel. This
          functionality can also be mapped to the keyboard in Sway.
          <pre>
bindsym XF86MonBrightnessDown exec brightnessctl -q set 10%-
bindsym XF86MonBrightnessUp   exec brightnessctl -q set +10%
bindsym XF86KbdBrightnessDown exec brightnessctl -q --device='smc::kbd_backlight' set 10%-
bindsym XF86KbdBrightnessUp   exec brightnessctl -q --device='smc::kbd_backlight' set +10%
          </pre>
        </li>
      </ul>
    </div>
    <div id="miscellaneous">
      <h3>Miscellaneous</h3>
      Another QOL modification for me was disabling the rather obnoxious startup
      sound present on all Macbooks. To do this, kernel must be built with
      efivarfs support (<code>CONFIG_EFIVAR_FS</code>) and the partition must be
      mounted at <code>/sys/firmware/efi/efivars/</code>. Next, the following
      commands must be run as proper root, not just with elevated permissions.
      Begin by removing the immutable flag from the appropriate file. Mac's EFI
      terminal uses the bell code (<code>0x07</code>) to audibly play system
      messages/warnings. It can be set to null character to silence it. Lastly,
      replace the immutable flag.
      <pre>
chattr -i /sys/firmware/efi/efivars/SystemAudioVolume-7c436110-ab2a-4bbb-a880-fe41995c9f82
printf "\x07\x00\x00\x00\x00" > /sys/firmware/efi/efivars/SystemAudioVolume-7c436110-ab2a-4bbb-a880-fe41995c9f82
chattr +i /sys/firmware/efi/efivars/SystemAudioVolume-7c436110-ab2a-4bbb-a880-fe41995c9f82
      </pre>
    </div>
    <div id="screenshots">
      <h3>Screenshots</h3>
      <img src="data/gentoo/fetch.png" alt="fetch image" />
      <img src="data/gentoo/nvim.png" alt="neovim image" />
      <img src="data/gentoo/gotop.png" alt="gotop image" />
      <img src="data/gentoo/wofi.png" alt="wofi image" />
      <img src="data/gentoo/zathura.png" alt="zathura image" />
      <img src="data/gentoo/lockscreen.png" alt="gtklock image" />
    </div>
  </body>
</html>