Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

How to compile and install custom mainline kernel

Writer Sophia Terry

I'm running Ubuntu 15.10 on a new laptop but in order to get proper full support for this hardware I apparently need the 4.4 kernel + a custom patch. See here if you're interested in the details.

I know about the mainline kernel PPAs but my understanding is that they don't come with source. If this is the case, This would seem to eliminate the possibility of using a mainline kernel PPA because I can't patch it. So I've been trying to check out the git source and build it but can't find up to date, relevant instructions.

Can somebody help with instructions for building a 4.4 kernel on 15.10?

3 Answers

Get and compile the mainline kernel, git method:

see also: I do things a little different (what else is new?).

Prerequisites (Must):

Step 1 is to apt-get update and apt-get dist-upgrade (i.e. make sure everything is up to date)
Step 2

sudo apt-get install fakeroot build-essential crash kexec-tools makedumpfile kernel-wedge

Step 3

sudo apt-get build-dep linux

Step 4

sudo apt-get install git-core libncurses5 libncurses5-dev libelf-dev asciidoc binutils-dev

Prerequisites as of kernel 4.3:

sudo apt-get install libssl-dev

Step 5 - based on not being able to compile on a new 20.04 server installation 2019.12.02

sudo apt install flex bison

Step 6 - based on not being able to compile kernel 5.13 on a 20.04 server 2021.07.02

sudo apt install zstd

Prerequisites (Optional):

sudo apt-get install git-email git-doc

The git part:

mkdir temp-k-git
cd temp-k-git
git clone git://
cd linux

Never do stuff in the default master branch. Always make some work area.

git checkout -b k44rc8_stock v4.4-rc8

Steal the Ubuntu kernel configuration file (already installed):

ls -l /boot
cp /boot/config-4.4.0-040400rc8-generic .config

Ubuntu config file has full debugging. Makes an enormous kernel and takes twice as long to compile

scripts/config --disable DEBUG_INFO

Special note as of Kernel 4.4 and if compiling using Ubuntu 14.04 (I don't know about 15.10), with an older version of the c compiler: It can not compile with CONFIG_CC_STACKPROTECTOR_STRONG.

scripts/config --disable CC_STACKPROTECTOR_STRONG

If your version doesn't have LZ4 compression (i.e. 16.04) you need also:

scripts/config --disable KERNEL_LZ4
scripts/config --enable KERNEL_GZIP

Special note as of Kernel 5.12-rc1 one needs to override some newly added certificate stuff.

scripts/config --set-str SYSTEM_TRUSTED_KEYS ""

or

scripts/config --disable SYSTEM_TRUSTED_KEYS

Special note as of Kernel 5.14-rc2 one needs to override some more added certificate stuff.

scripts/config --disable SYSTEM_REVOCATION_KEYS

Compile the kernel:

time make -j9 bindeb-pkg <<< Suggest use number of CPUs + 1. Use less for some responsiveness to be left for other uses <<< I always time the kernel build.

or

time make -j9 bindeb-pkg LOCALVERSION=-stock <<< For a localized verion name append

or

time make -j9 olddefconfig bindeb-pkg LOCALVERSION=-stock <<< To automatically use defaults for any new config stuff (particuarly useful when bisecting the kernel).

When the build has completed, install it:

sudo dpkg -i ../linux-headers-4.4.0-rc8-stock_4.4.0-rc8-stock-144_amd64.deb
sudo dpkg -i ../linux-image-4.4.0-rc8-stock_4.4.0-rc8-stock-144_amd64.deb

So, at this point we know the mainline kernel compiles O.K., so move onto the custom kernel. Create a new branch, apply the patches and compile:

$ git checkout -b k44rc8_custom v4.4-rc8
Switched to a new branch 'k44rc8_custom'
$ git am plv6_1_3.patch
Applying: cpufreq: intel_pstate: configurable algorithm to get target pstate
$ git am plv6_2_3.patch
Applying: cpufreq: intel_pstate: account for non C0 time
$ git am plv6_3_3.patch
Applying: cpufreq: intel_pstate: Account for IO wait time
$ time make -j9 olddefconfig bindeb-pkg LOCALVERSION=-custom

Note that it is on purpose that I do not do a make clean, as it is desirable to save a lot of time by doing an incremental build. The first compile took 21 minutes and 26 seconds, but the next custom compile took only 4 minutes and 43 seconds.

2

Here is a quick version how to install on Debian-based distributions:

# Install dependencies
sudo apt install -y git build-essential kernel-package fakeroot libncurses5-dev libssl-dev ccache
# Clone the kernel
mkdir ~/kernelbuild
cd ~/kernelbuild
git clone --depth=1 -b linux-5.4.y git://
# ^ change kernel branch to the one you're using.
# check with `uname -r` and see the available list at
cd linux-stable
# Build custom kernel
cp /boot/config-`uname -r` .config # copy config from current kernel
yes '' | make oldconfig
make clean
make -j `getconf _NPROCESSORS_ONLN` deb-pkg LOCALVERSION=-custom
# Install new kernel
sudo dpkg -i ~/kernelbuild/linux-*.deb
# Reboot
sudo reboot
1

If you go to the page you will find a README indicating how to obtain the source files for 4.4rc8

Instructions for build are a little confusing. I've seen several recipes for building the kernels, all a little different. There are several prerequisites: There may be some others that are required for the 4.4 kernel

sudo apt-get build-dep linux-image-$(uname -r)
sudo apt-get install libncurses5-dev

Then the commands I have issued for a sucsessful build are:

chmod a+x debian/scripts/*
chmod a+x debian/scripts/misc/*
nano
fakeroot debian/rules clean
fakeroot debian/rules editconfigs
fakeroot debian/rules binary-headers binary-generic skipabis=true

Modifying the changelog file to indicate that I am creating my own kernel, by adding something to the end of the first version number that is shown.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy