TuxInvader / focal-mainline-builder

Docker container to build Ubuntu Mainline kernels for use on 20.04 LTS
BSD 2-Clause "Simplified" License
81 stars 21 forks source link

Builder for Ubuntu Mainline kernels

This container will build a mainline kernel from the Ubuntu source tree. By default the container will build binary packages which you can then install on your systems. You can optionally build a metapackage to track a build flavour, and major release of kernel (eg 5.12.x).

If you build the metapackage it will have a name like: linux-generic-5.12 and will depend on the version of 5.12.x you are building.

Alternatively it can build signed source packages for uploading to a PPA.

I upload my mainline kernels to these PPAs

Kernel Version Series PPA Link Packages
mainline/stable focal lts-mainline PPA lts-mainline Packages
mainline/stable jammy jammy-mainline PPA lts-mainline Packages
longterm focal lts-mainline-longterm PPA lts-mainline-longterm Packages

building the container

To build the container with docker you would use:

docker build -t <org>/<image>:<tag> -f Dockerfile.<series> .

I build and push the Jammy series image using:

docker build -t tuxinvader/jammy-mainline-builder:latest -f Dockerfile.jammy .
docker push tuxinvader/jammy-mainline-builder:latest

and focal with:

docker build -t tuxinvader/focal-mainline-builder:latest -f Dockerfile.focal .
docker push tuxinvader/focal-mainline-builder:latest

Usage

  1. Checkout the Mainline kernel from Ubuntu

    sudo mkdir -p /usr/local/src/cod/
    sudo chown $(whoami) /usr/local/src/cod
    • Download the full source tree, if you want to be able to build any kernel (including previous releases)

      git clone git://git.launchpad.net/~ubuntu-kernel-test/ubuntu/+source/linux/+git/mainline-crack \
      /usr/local/src/cod/mainline
    • Download a specific kernel version if you only need to build this version. Eg v5.12.4:

      git clone --depth=1 -b cod/mainline/v5.12.4 \
      git://git.launchpad.net/~ubuntu-kernel-test/ubuntu/+source/linux/+git/mainline-crack \
      /usr/local/src/cod/mainline

      You should also pass --update=no when checking out only a single release.

  2. Create a directory to receive the Debian packages

    mkdir /usr/local/src/cod/debs
  3. Run the container

Launch the container with two volume mounts, one to the source code downloaded above, and the other for the deb packages to be copied into.

Binary debs

sudo docker run -ti -e kver=v5.12.1 -v /usr/local/src/cod/mainline:/home/source \
     -v /usr/local/src/cod/debs:/home/debs --rm tuxinvader/focal-mainline-builder:latest

Go and make a nice cup-of-tea while your kernel is built.

If you want to build a signed source package, you need to also provide your GPG keyring:

Signed Source package

sudo docker run -ti -e kver=v5.12.1 -v /usr/local/src/cod/mainline:/home/source \
     -v /usr/local/src/cod/debs:/home/debs -v ~/.gnupg:/root/keys \
     --rm tuxinvader/focal-mainline-builder:latest --btype=source --sign=<SECRET_KEY_ID> \
     --flavour=generic --exclude=cloud-tools,udebs --rename=yes

Build and sign metapackage

sudo docker run -ti -e kver=v5.12.1 -v /usr/local/src/cod/mainline:/home/source \
     -v /usr/local/src/cod/debs:/home/debs -v ~/.gnupg:/root/keys \
     --rm tuxinvader/focal-mainline-builder:latest --btype=source --sign=<SECRET_KEY_ID> \
     --flavour=generic --exclude=cloud-tools,udebs --rename=yes --buildmeta=yes \
     --maintainer="Zaphod <zaphod@betelgeuse-seven.western-spiral-arm.milkyway>"

The Linux source package builds some debs which are linked (by name) against the kernel and some which are common. Using --rename=yes allows us to store multiple kernels in the same PPA by changing the name of the source package and the linking all binaries (by name) to a specific kernel.

Notes

Set the kver variable to the version of the kernel you want to build (from here: https://kernel.ubuntu.com/~kernel-ppa/mainline/?C=N;O=D)

The built packages or source files will be placed in the mounted volume at /home/debs, which is /usr/local/src/cod/debs if you've followed the example.

The container will do an update in the source code repository when it runs, if the tree is already up-to-date then you can append --update=no to the docker run command to skip that step.

Flavour lowlatency removed

With kernel 5.16.12 the mainline kernel discontinued the lowlatency flavour. So, the default build now only builds the generic flavour on 5.16.12+. The build script has been updated to recreate lowlatency options, but only if you specify that with --flavour=lowlatency.

Additional options