13

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?

Marplesoft
  • 235
  • 1
  • 2
  • 7

3 Answers3

21

Get and compile the mainline kernel, git method:

see also: https://wiki.ubuntu.com/KernelTeam/GitKernelBuild 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://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.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.

Doug Smythies
  • 14,898
  • 5
  • 40
  • 57
  • So in this approach I don't apply the Ubuntu kernel patches that create the debian directory right? – Marplesoft Jan 09 '16 at 00:20
  • 2
    No, it should be exactly as I wrote. Codewise, the mainline ppa should be the same as the kernel.org code. Myself, I have never had much success with debian rules methods. – Doug Smythies Jan 09 '16 at 00:43
3

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://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
#                      ^ change kernel branch to the one you're using.
#                        check with `uname -r` and see the available list at www.kernel.org

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
Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
message
  • 135
  • 4
  • Thank you very much for this simple method. Works fine for my first compilation. One little thing was missing : `sudo chmod -R 0755 linux-stable` – Oli Dec 20 '20 at 16:14
1

If you go to the page http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.4-rc8-wily 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 debian.master/changelog
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.

Charles Green
  • 20,952
  • 21
  • 60
  • 92
  • Thanks. But I had two issues with this: 1) debian/rules didn't have the execute flag, no big deal to add but just a minor variation and 2) The build errored out with `debian/rules.d/2-binary-arch.mk:50: recipe for target '/home/ryan/dev/mainline/debian/stamps/stamp-build-generic' failed` Any ideas? – Marplesoft Jan 08 '16 at 15:57
  • @Marplesoft My checkout had the correct flags but my `fakeroot debian/rules clean` has errors when running `debian.master/reconstruct` due to the missing `ubuntu/` directory. I was able to work around this but don't understand why. See my question at http://askubuntu.com/questions/729469/build-ubuntu-kernel-test-mainline-crack-v4-4-kernel-fails-to-clean . – Lucas Feb 04 '16 at 17:28