summaryrefslogtreecommitdiff
path: root/content/posts/gentoo-kernel-upgrade.md
blob: ed81d7a8d189ef4d9dc549c50a2ebee85f4274bc (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
+++
title = "Gentoo kernel upgrade"
summary = "A brief howto on updating the kernel on a Gentoo system."
categories = [ "linux", "guide" ]
tags = [ "gentoo", "kernel", "linux", "sysadmin" ]
date = "2024-12-10"
+++

In this short guide I summarized the necessary steps to upgrade the
kernel in a Gentoo system.

We will update from `linux-A.B.C` to `linux-X.Y.Z`.

## Preliminary steps

Fetch the sources of the kernel that you want to install.

```sh {class="cmd-root"}
emerge -uDUa --with-bdeps=y =sys-kernel/gentoo-sources-X.Y.Z
```
You may also need to update `@world` set before updating the kernel.

```sh {class="cmd-root"}
emerge -uDUa --with-bdeps=y @world
```

Using eselect, select the kernel version that you want to upgrade to.
This will adjust the `/usr/src/linux` symlink.

```sh {class="cmd-root"}
eselect kernel list
eselect kernel set X
```

Go to the directory containing kernel sources.

```sh {class="cmd-root"}
cd /usr/src/linux
```

## Configuration

Start by copying your `.config` from the old kernel sources.

```sh {class="cmd-root"}
# from the old folder
cp /usr/src/linux-A.B.C-gentoo/.config /usr/src/linux
# from the running kernel
zcat /proc/config.gz > /usr/src/linux/.config
```

Then, you will have to update the configuration file.
The **oldconfig** target will interactively prompt you to insert values for the new options.

```sh {class="cmd-root"}
make oldconfig
```

Alternatively, **olddefconfig** will automatically insert default values for the new options.

```sh {class="cmd-root"}
make olddefconfig
```

To easily change more configuration options you can use **menuconfig**, which will start an interactive ncurses interface.

```sh {class="cmd-root"}
make menuconfig
```

{{< note Warning >}}
Manually editing the `.config` file is highly discouraged,
since configurations options have dependencies.
{{< /note >}}

## Building

Once you finished setting your configuration, you can build your kernel with make.
The [NVIDIA drivers](#nvidia-drivers) and [Intel microcode](#intel-microcode) require you
to do extra steps before building.

You can speed up the build process by using multiple make jobs.
It is helpful to determine the number of cpu threads with `nproc`.

```sh {class="cmd-root"}
make -j$(nproc)
```

## Installation

First of all, mount the boot partition, if it is not already mounted.

```sh {class="cmd-root"}
mount /boot
```

Then, you can install the new kernel and modules.

```sh {class="cmd-root"}
make install
make modules_install
```

Update your bootloader configuration. If you are using GRUB, you can use grub-mkconfig.

```sh {class="cmd-root"}
grub-mkconfig -o /boot/grub/grub.cfg
```

Some kernel modules may be installed by packages and live outside of the kernel source tree (e.g. Nvidia drivers).
They need to be rebuilt every time you change the kernel.
Luckily portage provides this handy shorthand.

```sh {class="cmd-root"}
emerge @module-rebuild
```

Additionally, some drivers may require firmware updates.

```sh {class="cmd-root"}
emerge sys-kernel/linux-firmware
```

Now you can reboot your machine and everything should hopefully work as intended.

## Clean up

It is a good habits to keep the old kernel files around (at least until you have verified the new ones).

However, if you have a few old kernels in your boot partition you may want to remove some of them.

```sh {class="cmd-root"}
rm /boot/System.map-A.B.C-gentoo
rm /boot/config-A.B.C-gentoo
rm /boot/vmlinuz-A.B.C-gentoo
```

Then, remember to update GRUB (or your bootloader of choice).

```sh {class="cmd-root"}
grub-mkconfig -o /boot/grub/grub.cfg
```

## Addenda

### Nvidia drivers

I will not delve too much on the details here.
You can check exactly which kernel options features to enable on the wiki[^nvidia].

However I recently found the solution to a problem which caused my tty to be blank.
I had accidentally activated `FB_SIMPLE`, `SYSFB_SIMPLEFB` and `DRM_SIMPLEDRM`.
They should cause problems with newer nvidia drivers and should be disabled[^fb-nvidia].

```sh {class="cmd-root"}
emerge x11-drivers/nvidia-drivers
```

If you already installed the drivers, `@module-rebuild` should automatically rebuild them.

### Intel microcode

Install Intel's `iucode_tool` for managing microcodes.

```sh {class="cmd-root"}
emerge sys-firmware/intel-microcode
```

Use the tool to get the processor signature and search a microcode bundle with
a matching signature.

```sh {class="cmd-root"}
iucode_tool -S
iucode_tool -S -l /lib/firmware/intel-ucode/*
```

Enable in the kernel configuration the microcode loading features and add in
the **Firmware loading facility** the microcode bundle found before as a named
firmware blob, then build the kernel.

Now build and install the kernel.

Verify after the rebooting that the microcode is loaded by the kernel.

```sh {class="cmd-root"}
dmesg | grep microcode
```

For more details see the wiki[^intel].

## References

- https://wiki.gentoo.org/wiki/Kernel
- https://wiki.gentoo.org/wiki/Kernel/Upgrade
- https://wiki.gentoo.org/wiki/Kernel/Removal

[^nvidia]: https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers
[^fb-nvidia]: https://forums.gentoo.org/viewtopic-t-1157629-start-25.html
[^intel]: https://wiki.gentoo.org/wiki/Intel_microcode