Possibly some previous aborted attempt is causing a problem, because this series of steps worked for me, although it took several hours on a 3B+.1 As
git clone --depth=1 https://github.com/raspberrypi/linux
make -j5 zImage
make -j5 modules
make -j5 dtbs
This actually did fail on the first attempt because some kind of helper script wants to build something that requires
apt install openssl-dev (the error has an explicit reference to an openssl header being missing). This is a bit weird as the vanilla kernel does not normally have any external dependencies besides libc.
I usually copy the kernel out manually; you can find that and the dtb/overlay stuff in
mv /boot/kernel7.img /boot/kernel7.img-dist
cp zImage /boot/kernel7-X.img
cp dts/*.dtb /boot/
cp dts/overlays/*.dtbo /boot/overlays/
And of course:
make INSTALL_MOD_STRIP=1 modules_install
uname -r reports
lsmod shows lots of stuff (indicating there are modules properly loaded).
If the build fails for some reason, you can try
make mrproper, and/or
make distclean; see
make help output for details. If you use either of the last two, you may want to save your
.config since that will be deleted.
Note that this doesn't include firmware;
make firmware seems to do nothing. However, it should be fine to use the stuff provided by the distro, since firmware does not need to match exactly the kernel it was built with (as modules do), nor is it affected by the specific configuration (including platform, since firmware is not compiled for that, ie., you use the same stuff on the Pi as you would an x86 desktop, although the Pi firmware package does I think contain some stuff not included with the vanilla kernel).
Also note that because the Pi uses a simple bootloader that looks for the kernel based on a singular name in
/boot, distro upgrades can overwrite your custom kernel. This is easy enough to avoid by giving the kernel a name that is not used by default (notice it was installed above as
kernel7-X.img) and indicating that in
Distro upgrades also install and delete directories in
/lib/modules when rolling over the kernel. Point being, if the distro catches up to the version you are using, the module directory may be overwritten with modules that won't work with the running kernel. Conversely, when the distro upgrades beyond the running kernel it may remove directories from
Not having functional modules may be hard to notice because the default Pi kernel does not require any modules to boot and function normally to a great extent (including basic networking).
A way to avoid that is to compile the kernel with a custom tag that will then be used in labelling the module directory. The default pi configs already do this, eg.
-v7, which you will notice is used in the
/lib/module directories. Customize that via
make menuconfig General setup -> Local version (in
.config this is
CONFIG_LOCALVERSION). Note this tag has nothing to do with the kernel binary name (
kernel7-X.img in this case). The version tag is compiled in and used to find the proper modules directory.
- If the system is headless use
ssh so you can disconnect and leave it working.