Posts: 6
Joined: Thu May 21, 2020 8:15 am

Kernel building for Ubuntu

Fri Sep 04, 2020 5:59 am


Have some one figured out how to build lastest kernel for Ubuntu 64-bit OS?

Should it be better approach to use mainline kernel since 5.8.x it has native support for pi4 or raspberry repositories?

Thanks for help!

Posts: 11
Joined: Mon Feb 17, 2020 3:39 pm

Re: Kernel building for Ubuntu

Mon Sep 28, 2020 11:03 pm

One of the great parts about running Ubuntu is that just about all the Ubuntu-isms you've learned for other platforms work here too. Start with these links:

https://wiki.ubuntu.com/KernelTeam/ARMK ... ossCompile
https://wiki.ubuntu.com/KernelTeam/Kern ... k_failures
https://askubuntu.com/questions/500095/ ... er-version
https://bugs.launchpad.net/ubuntu/+sour ... ug/1701756

What follows isn't very polished, since came out of my notebook verbatim. This is how I built the kernel.


First uncomment the relevant line int /etc/apt/sources.list:

Code: Select all

deb-src http://ports.ubuntu.com/ubuntu-ports focal-updates main restricted

Update the package database:

Code: Select all

apt update

Get the kernel source package, as root in some place where you want it. Alternatively replace $(uname -r) with the version you want. This is probably easiest to do on the target:

Code: Select all

apt-get source linux-image-$(uname -r)

If this is on a target, copy it to a dev machine.

Over on the dev machine, hack up your kernel as you please. Then in debian.raspi/changelog, edit the first version number from something like this:

Code: Select all

linux-raspi (5.4.0-1019.21) focal; urgency=medium

to something like this:

Code: Select all

linux-raspi (5.4.0-1019.21+g34950~20200925) focal; urgency=medium

Note that CONFIG_LOCALVERSION will break the Ubuntu scripts, and EXTRAVERSION in the highest level makefile doesn't do anything interesting.

Set some environment variables:

Code: Select all

export $(dpkg-architecture -aarm64); export CROSS_COMPILE=aarch64-linux-gnu-

Now change into the root directory of the source tree and clean the build area:

Code: Select all

fakeroot debian/rules clean

Kick off a menuconfig session with script:

Code: Select all

fakeroot debian/rules editconfigs

menuconfig insists on running once each for 32 and 64 bit builds of kernel.

Now build the kernel and associated packages. We skip checks that are likely to break because of a changed list of modules:

Code: Select all

fakeroot debian/rules binary skipmodule=true skipabi=true

This will result in the following .deb packages being created in the level ABOVE the kernel source tree:

Code: Select all


After copying to the target, each of the relevant packages may be installed there with dpkg:

Code: Select all

dpkg -i linux-headers-5.4.0-1019-raspi_5.4.0-1019.21+g34950~20200925_arm64.deb
dpkg -i linux-image-5.4.0-1019-raspi_5.4.0-1019.21+g34950~20200925_arm64.deb
dpkg -i linux-modules-5.4.0-1019-raspi_5.4.0-1019.21+g34950~20200925_arm64.deb
dpkg -i linux-raspi-headers-5.4.0-1019_5.4.0-1019.21+g34950~20200925_arm64.deb

Posts: 38
Joined: Mon Sep 07, 2020 12:19 am

Re: Kernel building for Ubuntu

Wed Sep 30, 2020 12:28 am

Why wouldn't you start with ubuntu-server daily-preinstalled current version of Ubuntu Server 20.10 (Groovy Gorilla) Daily Build for Raspberry Pi Generic (64-bit ARM) preinstalled. This server image is provided for modern Raspberry Pi boards (Pi 2, Pi 3 and Pi 4).

http:// cdimage.ubuntu.com/ ubuntu-server/ daily-preinstalled/ current/ groovy-preinstalled-server-arm64+raspi.img.xz

Posts: 6
Joined: Thu May 21, 2020 8:15 am

Re: Kernel building for Ubuntu

Mon Nov 30, 2020 12:05 pm

Now with new 20.10 is pretty easy. One thing that I don't get. How to get update-initramfs to recognise self build kernel?

When updating initramfs the tool says that kernel is older or unknown, so it is using ubuntu's kernel to boot and to set overlays etc. to /boot.

Of course you can make this manually but it is hard to maintain.

Return to “Ubuntu”