I have written a network hook using netfilter. This modules compiles successfully on my ubuntu 16.04.

Now I want to compile it in my embedded board which uses a customized Linux using same version of kernel in my laptop. The only problem is that all the modules in my embedded board are in .ko.xz format and my makefile fails and I don't know how to solve the problem.

My original makefile is:

obj-m += sysfirewall.o
    make -C  /lib/modules/$(shell uname -r)/build -I/usr/Include/ M=$(PWD) modules
    make -C /lib/modules/$(shell uname -r)/build -I/usr/Include/ M=$(PWD) clean

But this failed because I couldn't find any build folder in my embedded Linux. Instead of build folder there was a kernel folder which I replace it with kernel.

Now my makefile is:

obj-m += sysfirewall.o
    make -C  /lib/modules/$(shell uname -r)/kernel -I/usr/Include/ M=$(PWD) modules
    make -C /lib/modules/$(shell uname -r)/kernel -I/usr/Include/ M=$(PWD) clean

But when I run make in the current directory it gives the following error:

$ make -C  /lib/modules/4.14.49-ti-r54/kernel -I/usr/Include/ M=/home/parsa/firewall/ modules
make[1]: Entering directory '/lib/modules/4.14.49-ti-r54/kernel'
make[1]: *** No rule to make target 'modules'.  Stop.
make[1]: Leaving directory '/lib/modules/4.14.49-ti-r54/kernel'9-ti-r54/uname -i 
Makefile:3: recipe for target 'all' failed
make: *** [all] Error 2

How can I solve this problem? Should I uncompress all the modules in my kernel? Does it really a matter of compressed Linux kernel modules or the error shows something else?

P.S: I don't want to cross-compile the module in my laptop.

Edited: I noticed there should be a Makefile in the "/lib/modules/$(shell uname -r)/kernel" folder which is not in my embedded board. I traced the Make file in "/lib/modules/$(shell uname -r)/build" folder in my laptop and realized it is a soft link to /usr/src/linux-headers-4.4.0-128/Makefile. but I don't have anything in my /usr/src in my embedded board. so I think I have to find a make file in order to compile this module and I don't know how !

up vote 1 down vote accepted

The problem is not with the compression, but with the make not finding the correct files. Note that the make command is entering the /lib/modules/<kernel version>/kernel directory, and only then reporting an error. So it's not finding whatever it needs in there.

You cannot substitute /lib/modules/<kernel version>/kernel to /lib/modules/<kernel version>/build: their contents are different. The kernel directory contains the already-compiled modules that came with that particular kernel version. That does not help the make command at all: it needs the makefiles and .h files that come with the kernel source code. Some of those are dynamically generated as part of the main kernel compilation.

Normally, the /lib/modules/<kernel version>/build is a symbolic link pointing to wherever the kernel headers associated with that particular kernel version are located. If your embedded board uses a kernel that has been compiled in "the Debian way" (i.e. with make bindeb-pkg or similar in the kernel source directory), the kernel compilation process should have produced a number of .deb packages:

  • linux-image-<version>_<patchversion>_<architecture>.deb = the actual compiled kernel and its modules
  • linux-headers-<version>_<patchversion>_<architecture>.deb = the headers you'll need to compile further kernel modules for this specific kernel

In that case, you'll only need to find and install the linux-headers package corresponding to the exact kernel version you're using in your ARM board. It will automatically provide the /lib/modules/<kernel version>/build link for you.

If you have compiled your own custom kernel with traditional make bzimage or similar, then you'll have to provide the /lib/modules/<kernel version>/build link yourself. If you have the actual kernel build directory still available, just link it to /lib/modules/<kernel version>/build.

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.