Skip to content

Make building custom kernel modules easier #370

@hvenev

Description

@hvenev

The whole uncompressed kernel source is more than 700 MB, and extracting it takes a while. We can do something similar to what is done in distributions like Debian and Fedora.

The idea is to take all headers, the config, and a few build results from make prepare modules_prepare. The resulting directory is much smaller. I successfully built wireguard using dkms on x86_64 using a 52 MB directory created by the following script:

arch=x86_64
asmarch=x86
release=...
upstream="${release%%-*}"
local="${release#*-}"

kdir="/lib/modules/${release}"
cd /usr/src/linux

wget -O Module.symvers "http://mirror.scaleway.com/kernel/${arch}/${release}/Module.symvers"
wget -O .config "http://mirror.scaleway.com/kernel/${arch}/${release}/config"
printf 'CONFIG_LOCALVERSION="%s"\nCONFIG_CROSS_COMPILE=""\n' "${local:+-$local}" >> .config

make prepare modules_prepare

mkdir -p $kdir/build

for dir in .config Module.symvers Makefile scripts include arch/${asmarch}/include arch/${asmarch}/Makefile* arch/${asmarch}/kernel/asm-offsets.s; do
	rm -rf $kdir/build/$dir
	cp -a --parents $dir $kdir/build/
done

My suggestion is to provide a squashfs image of this. It comes down to just above 7 MB, or 15 MB together with the modules. Mounting read-write can be done using overlayfs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions