aboutsummaryrefslogtreecommitdiff
path: root/gentoo.html
blob: 95bb38e886805c30cf56abf77403390da18efb57 (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
<html lang="en">
  <head>
    <style>
    body {
      max-width: 65%;
      margin: auto;
      line-height: 1.5;
      padding-top: 15px;
      padding-bottom: 15px;
    }
    code {
      border: 1px solid grey;
      border-radius: 3px;
      color: #434C5E;
      padding: 1.5px;
    }
    pre {
      background: #f4f4f4;
      border: 1px solid #grey;
      color: #434C5E;
      padding-top: 20px;
      padding-left: 20px;
      overflow: auto;
    }
    img {
        max-width: 100%;
        height: auto;
        width: auto\9;
    }
    </style>
  </head>
  <body>
    <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 all the work
    I encounter on a daily basis and is used as my primary system. My
    intentions for this system are reliability and speed above all.
    With this comes a minimal OS with very few kernel parameters
    set, extremely fine-tuned USE flags, and a usable system that I
    am extremely familiar with. All my configuration can be found on
    my <a href="https://github.com/waffle87/dots/tree/xena"> github</a>.
    <br><br>
    <img src="data/gentoo/laptop.jpg" width="672" height="504" alt="laptop image">
    <br><br>

    <a href="#hardware_features">hardware features</a><br>
    <a href="#kernel">kernel</a><br>
    <a href="#bootloader">bootloader</a><br>
    <a href="#portage">portage</a><br>

    <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">lspci</a>, <a href="data/gentoo/lsusb">lsusb</a>)
      <ul>
        <li>Intel i7 3667U at 3.2 GHz with 4 cores (<a href="data/gentoo/lscpu">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</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>
    </div>
    <div id="kernel">
      <h3>Kernel</h3>
      After spending many hours narrowing down kernel options enabled,
      I have a 7.8 MB kernel image with ~4000 parameters set. Note,
      this configuration is very hardware and user specific. I opted
      for absolutely 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">gentoo-sources</a>
      to provide kernel source as it contains some handy patches and is easy
      to obtain via emerge. A base 6.7 kernel builds locally (remember, 4 
      cores) in approximately 17 minutes, which is not too much of a pain
      when troubleshooting on bare metal. For more kernel configuration stuff, 
      see <a href="kernel.html">here</a>. MICROOOCODEEEE
    </div>
    <div id="bootloader">
      <h3>Bootloader</h3>
      Spoiler: there is none. For the duration of my time using Linux, I have used GRUB as my
      bootloader across various systems. In my experience, it's been
      ok, it does what it needs to, allows for extensive configuration
      like theming and requiring a password. However, some time ago it
      went kaput 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 (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 or anything, I can simply omit
      GRUB 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=... ro"
      </pre>
      The root must be 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. It is also wise to remove unneeded entries
      to conserve space
      <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="portage">
      <h3>Portage</h3>
      <h4>Profile</h4>
      When initially setting this up, I opted for a multilib system as
      I was still using some 32-bit programs at the time. Since, I have
      switched to a no-multilib profile. Unlike adding multilib support
      to a 64-bit only system, going from multilib to no-multilib is
      quite easy.
      <pre>
# eselect profile list
  ...
  [12]  default/linux/amd64/17.1/no-multilib (stable)
  ...
# eselect profile set 12
# emerge -auDN @world
# emerge --depclean
      </pre>
      It was pleasant to see 60+ packages removed after the switch. And
      have much reduced overhead in my system overall.
      <h4>Compiler</h4>
      As Clang/LLVM has become more and more stable and is able to compile all
      packages installed, I chose to switch the default compiler, linker
      and other bits over from GCC. This is easy enough in <code>/etc/portage/make.conf</code>.
      <pre>
CC="clang"
CXX="clang++"
AR="llvm-ar"
NM="llvm-nm"
RANLIB="llvm-ranlib"
      </pre>
      If needed, a GCC fallback environment can be made containing the
      previous variables, then applied to certain packages which may fail
      under Clang via adding an entry in <code>/etc/portage/package.env</code>.
      Some advantagees of using Clang over GCC are slightly faster compilation
      times and reduced memory usage, and potentially safer binaries overall.
      <h4>USE Flags</h4>
      My USE flags and related options are quite minimal. Global flags include
      <pre>
USE="alsa bluetooth clang dbus elogind gles2 jpeg png \
     pulseaudio sdl udev wayland X -systemd -vulkan -nls"
ACCEPT_LICENSE="*"
ACCEPT_KEYWORDS="~amd64"
      </pre>
      For reference, some primary features used on this system are
      Wayland, Pipewire, elogind, and OpenRC. Since no-multilib already
      has very few things enabled, not many flags needed to be disabled.
    </div>
  </body>
</html>