I want to build myself a custom kernel as a RPM. I use the .config from the distribution I'm using, in this case, Centos, and end up with a kernel install size of 2.2Gb. I have deselected all the drivers/modules I don't need and updated the .config. When I make the kernel I see drivers being compiled that I deselected. What step am I missing to read the .config and not compile a large kernel? The kernel from the repos are a couple of Mb comparing to mine.

  1. Download source

    wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.4.138.tar.xz

  2. Extract source

    tar -xf linux-5.4.138.tar.xz

  3. Copy in existing config found from elrepo.

    cp ~/config-5.4.138-x86_64 linux-5.4.138/.config

  4. Run

    make oldconfig

  5. Configure with menuconfig and deselect drivers/modules not needed and save.

    make menuconfig

  6. Build RPM

    make rpm-pkg -j4

Result is:

  586.3 MiB [##########]  kernel-5.4.138-1.x86_64.rpm
  147.8 MiB [##        ]  kernel-devel-5.4.138-1.x86_64.rpm
    1.3 MiB [          ]  kernel-headers-5.4.138-1.x86_64.rpm

yum install:

kernel          x86_64          5.4.138-1             /kernel-5.4.138-1.x86_64          2.2 G

Here is my .config if it can help https://pastebin.com/LBw6Gm1s


Rebuild elrepo's kernel-lt-5.4.spec with your desired config. That is, make your desired edits to Source1, the one with the kernel version in the name, currently config-5.4.138-x86_64. Increment the release number. Build the resulting SRPM with mock.

Red Hat style RPM packages have their own scripts and split out the sub packages in a particular way. Quite different from upstream's RPM spec. Some debugging symbols are not being stripped, resulting in much bigger outputs.

Read the spec files to see how different they are. For elrepo, see kernel-lt-5.4.spec on the mirrors. While moderately complicated, it is a Red Hat style kernel spec. Of a kernel.org longterm release without patches, which is the point of the exercise. Contrast to make rpm-pkg which via some Makefiles calls scripts/package/mkspec, which does not look at all like a Red Hat kernel. Note the comment about disable stripping debug symbols:

The only gothic bit here is redefining install_post to avoid stripping the symbols from files in the kernel which we want

No, the size is not a bug, kernel hackers want debug symbols.

Quite confusing when both upstream (kernel.org) and downstream (Red Hat, elrepo) have their own package build scripts. But these are the kind of details you need to pay attention to. For reproducible builds, and to understand your custom package.

elrepo renamed their package kernel-lt (or kernel-ml) to not conflict with the RHEL kernel package name. Your build conflicts, beware.

  • This is I've done to get the RPM built from src. I'll get a kernel RPM around 40Mb but when I compile it differently, as stated above, it becomes a 2.2Gb monster. Is this not a bug on how make rpm-pkg works that I should report? Aug 6 at 19:17
  • No, the kernel.org spec not stripping is not a bug. The packages are very different, see my edit. Aug 6 at 23:44

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.