Compiling kernel: how to copy modules and headers to rootfs?

Following https://wiki.radxa.com/Rockpi4/dev/Debian#Build_kernel I successfully customized kernel and the system boots, but the kernel modules and headers are missing.
For example:
root@rockpi4:~# modprobe cifs
modprobe: ERROR: …/libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file ‘/lib/modules/4.4.154-00002-gc26d93d00149/modules.dep.bin’
modprobe: FATAL: Module cifs not found in directory /lib/modules/4.4.154-00002-gc26d93d00149

The directory /lib/modules is missing.
How to copy the kernel modules and headers to rootfs image?

Hello,

To build the kernel modules:

cd kernel
make -j8 modules

To install the modules into the rootfs/binary directory:

make INSTALL_MOD_PATH=$(pwd)/../rootfs/binary modules_install

Then rebuild the images, as per the documentation.

If you can access your device using SSH, you could also use Fuse and SSHFS to install the modules into the directory /lib/modules:

mkdir -p ~/rockpi
sshfs root@rockpi.local:/ ~/rockpi
make INSTALL_MOD_PATH=~/rockpi modules_install
umount ~/rockpi

For more information, look at the section “Installation module” in the kernel documentation: https://www.kernel.org/doc/Documentation/kbuild/modules.txt

1 Like

Hello Julien,

thank you for clarifying that for me, I thought that this procedure is included in one of the existing scripts, i.e. mk-rootfs.sh.

Next, to build and install headers:
# mkdir -p ~/rockpi4/rockchip-bsp/out/headers
# make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- headers_install INSTALL_HDR_PATH=~/rockpi4/rockchip-bsp/out/headers

That didn’t create the directory structure I expected, so I improvised (on the target machine):
# ls /lib/modules/
4.4.154-00002-gc26d93d00149
# mkdir -p /usr/src/linux-headers-4.4.154-00002-gc26d93d00149
# rsync -aHAXx --no-links root@zhdebian.hdinfo.local:/home/zoran/rockpi4/rockchip-bsp/out/headers/include/* /usr/src/linux-headers-4.4.154-00002-gc26d93d00149