Building and installing the latest Linux kernel on my laptop
Contents
To date I’ve been using a Fedora supplied 4.5.7 kernel from June 2016 because
later Fedora 23 kernels hvae an issue with the Intel graphics on my laptop that
causes the laptop’s display panel to flicker annoyingly. Last week I installed
VirtualBox on the laptop, which wanted to compile some kernel drivers. That was
a problem because I didn’t have the kernel header files, and couldn’t find the
kernel-devel-4.5.7-202.fc23.x86_64.rpm
. The only two versions available from
*archive.fedora.org* were 4.2.3 from the original release of Fedora 23 and
4.8.13 from the final update before Fedora 24 came out.
I was able to get VirtualBox running on the old 4.2.3 kernel, but the laptop’s webcam and sound stopped working, probably because drivers for them had not yet been updated to support the hardware. So I figured a new kernel was in order.
I got the latest kernel source files from *kernel.org* and unpacked them:
cd /var/tmp wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.16.9.tar.xz tar xzf linux-4.16.9.tar.xz cd linux-4.16.9.tar.xz
This version as hot off the press, being released only hour before I downloaded it on 16 May.
Building the kernel build documentation
Being a little uncertain how to build a new kernel (even though I’ve done it before) I decided to build the documentation files:
# make htmldocs Documentation/Makefile:24: The 'sphinx-build' command was not found. Make sure you have Sphinx installed and in PATH, or set the SPHINXBUILD make variable to point to the full path of the 'sphinx-build' executable. Detected OS: Fedora release 23 (Twenty Three). Can't build as 2 mandatory dependencies are missing at ./scripts/sphinx-pre-install line 566. ERROR: please install "virtualenv", otherwise, build won't work. Warning: better to also install "xelatex". You should run: sudo dnf install -y graphviz librsvg2-tools texlive-amscls \ texlive-amsfonts texlive-amsmath texlive-anyfontsize \ texlive-capt-of texlive-cmap texlive-collection-fontsrecommended \ texlive-collection-latex texlive-ec texlive-eqparbox texlive-euenc \ texlive-fancybox texlive-fancyvrb texlive-float texlive-fncychap \ texlive-framed texlive-luatex85 texlive-mdwtools texlive-multirow \ texlive-needspace texlive-oberdiek texlive-parskip texlive-polyglossia \ texlive-psnfss texlive-tabulary texlive-threeparttable texlive-titlesec \ texlive-tools texlive-ucs texlive-upquote texlive-wrapfig \ python3-virtualenv texlive-xetex-bin virtualenv sphinx_1.4 . sphinx_1.4/bin/activate pip install -r Documentation/sphinx/requirements.txt
Building the HTML version of the kernel build documentaion required installing
a lot texlive RPMs and a Python 2.7 virtual environment in which to do the
build. In addition, the package texlive-luatex85
wasn’t in Fedora 23, but I
found a Fedora 24 RPM that installed without complaint.
The virutalenv
command sets up a Python 2.7 environment for sphinx
, which
is a documentation building package. The pip install
and make htmldocs
commands are run within this environment.
The make htmldocs
command created files in Documentation/output
, including
an index.html file, which I could open in a web browser.
And after all that … there was no documentation on how to configure and build a Linux kerel from scratch!
Configuring the kernel
A Linux kernel has literally thousands of options. Fortunately, the Fedora
kernel source packages contain a .config
file that can be used as a base for
configuring a new kernel using make oldconfig
. Because I was moving from a
4.8.3 kernel configuration (the last one available for Fedora 23) to
4.16.9–which represents a year and a half of kernel development–there were
almost 400 new options to consider. For the bulk of them I went with the
suggested defaults.
Building and installing the kernel
Once the configuration was complete, doing the actual build and install was rather straightforward:
make all # <-- Took 45 minutes on my laptop make modules_install make install # <-- Invokes the distribution's kernel installer
It worked!
When the install was complete, I had a bootable system with a stable video driver, which is what I was after.