2

I am trying to compile a custom kernel for Nvidia's Jetson TK1 board, and it seems that as well as the kernel itself (zImage) I will need /usr/src/linux-headers-{version} and /lib/modules/{version}.

However I can't see how to create the linux-headers. I have tried running make headers_install but it does not seem to create the same type of output as what I see in other /usr/src/linux-headers directories.

I've seen other similar questions such as here, however this assumes you are building the same version as you are running, where I am trying to build with a different LOCAL_VERSION.

I am starting from a "Linux4Tegra" distro, however, I am attempting to make a custom system based on Ubuntu Core.

To clarify, I am trying to create a kernel with my own LOCAL_VERSION, i.e., my own version, not an existing version in any repository. I would like to generate the headers that match this. So installing a linux-headers-xxx package will not address my problem.

My question is how are these packages initially created from the linux source?

When I look at the files in the existing headers directories, it contains references to that kernel version, so I am assuming that this has been generated from that version of the linux source. How can I generate these? When someone is compiling a version of the kernel, surely they generate these files somehow?

  • add your distro to the post please – Rui F Ribeiro Mar 16 '16 at 6:30
  • How does the output vary from what you'd normally see in /usr/src/linux-headers? – EightBitTony Mar 16 '16 at 7:53
  • Not at my computer until tomorrow, but the output is basically completely different. No commonality whatsoever as far as I could see. – Alex Mar 16 '16 at 8:39
5

Late answer. I recently encountered this problem and I found a possible answer.

Suppose you want to install the kernel header file to /usr/src/linux-headers-4.15.3. The compiled kernel source tree is located /path/to/compiled/linux-4.15.3/

first, unpack a clean kernel source tree

tar xvf linux-4.15.3.tar.xz
cd linux-4.15.3/

second, copy you .config file to the directory

cp /path/to/compiled/linux-4.15.3/.config .

third, run it and then delete .config file in source directory to get a clean kernel source

make O=/usr/src/linux-headers-4.15.3 oldconfig
rm .config

fourth, run the modules_prepare make target

make O=/usr/src/linux-headers-4.15.3 modules_prepare

Finally, delete useless things, and copy the necessary things

rm /usr/src/linux-headers-4.15.3/source
cp /path/to/compiled/linux-4.15.3/Module.symvers /usr/src/linux-headers-4.15.3

Now, the /usr/src/linux-headers-4.15.3 directory is able to build the module.

Documentation https://www.kernel.org/doc/Documentation/kbuild/modules.txt tell us modules_prepare

This will make sure the kernel contains the information required. The target exists solely as a simple way to prepare a kernel source tree for building external modules.

NOTE: "modules_prepare" will not build Module.symvers even if CONFIG_MODVERSIONS is set; therefore, a full kernel build needs to be executed to make module versioning work.

1

Run sudo apt-get install linux-headers-generic

  • I am not sure this will work for me, as the headers I get are a different version again (matching neither my running kernel or of course my custom kernel version). Also, there are locations in the kernel headers that refer to the version, such as in include/config/kernel.release, so surely there is some way to generate these from an already configured source tree? – Alex Mar 16 '16 at 6:42
  • You can try to run sudo apt-get install linux-headers-$(uname -r) to get headers of your current kernel version – Lev Bystritskiy Mar 17 '16 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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