How to build the linux kernel for Rocky 9.1 using mock?

I am finding hard time finding a definitive answer to this question, as if it is a hidden secret.

How to build the linux kernel starting from the downloading the src rpm found here:

I would like also to generate debuginfo packages.

Thank you.

It’s not really a secret on how to build packages in mock. The documentation shows how. It is also not a secret where our source packages are. You can find them at our koji or our repos.

# !!! Note this uses 9.4, as that is the current latest available version. !!!
% dnf install epel-release -y
% crb enable
% dnf install mock -y
% usermod -aG mock user

% mock -r rocky-9-x86_64 /path/to/source/package.rpm

Why not use the source package or even the debuginfo packages here or here? We have all of the debug packages, source packages, and binary packages that we build available.

Rocky Linux 9.1 is no longer supported. Click here for more information.

I am setting things up for the company I work for. We need our own custom kernel.

thank you.

What if I wanted to create a container with all packages already installed so mock wont have to install them? in order to make the build process faster.

Can CIQ make a video on this and put it on youtube? I believe this is something so many people would be interested to know about…maybe.

What I meant to say: it is such a common thing for companies to maintain their own kernel. But they may want to stick with the “Rocky” way to build the kernel from their own repo.

it failed:

All I did was:

  1. wget
  2. install mock
  3. add my username to mock group.
  4. Build the kernel using the command above:
    mock -r rocky-9-x86_64 ./kernel-5.14.0-162.23.1.el9_1.src.rpm

And it failed:

arch/x86/kernel/head_64.o: warning: objtool: xen_hypercall_set_trap_table()+0x2: unreachable instruction

arch/x86/entry/entry_64.o: warning: objtool: __switch_to_asm()+0x5a: unreachable instruction

arch/x86/kernel/ftrace_64.o: warning: objtool: return_to_handler()+0x2a: unreachable instruction

arch/x86/lib/retpoline.o: warning: objtool: .text.__x86.return_thunk+0x0: unreachable instruction

FAILED: load BTF from vmlinux: Invalid argument

make: *** [Makefile:1218: vmlinux] Error 255

make: *** Deleting file 'vmlinux'

error: Bad exit status from /var/tmp/rpm-tmp.aX8vw7 (%build)

RPM build errors:

Bad exit status from /var/tmp/rpm-tmp.aX8vw7 (%build)

Finish: rpmbuild kernel-5.14.0-162.23.1.el9_1.src.rpm

Finish: build phase for kernel-5.14.0-162.23.1.el9_1.src.rpm

ERROR: Exception(./kernel-5.14.0-162.23.1.el9_1.src.rpm) Config(rocky-9-x86_64) 4 minutes 32 seconds

INFO: Results and/or logs in: /var/lib/mock/rocky-9-x86_64/result

ERROR: Command failed:

# /usr/bin/systemd-nspawn -q -M 7ab15536ced949dbad35264bf5affdd2 -D /var/lib/mock/rocky-9-x86_64/root -a -u mockbuild --capability=cap_ipc_lock --bind=/tmp/mock-resolv.636yiyfh:/etc/resolv.conf --bind=/dev/mapper/control --bind=/dev/fuse --bind=/dev/loop-control --bind=/dev/loop0 --bind=/dev/loop1 --bind=/dev/loop2 --bind=/dev/loop3 --bind=/dev/loop4 --bind=/dev/loop5 --bind=/dev/loop6 --bind=/dev/loop7 --bind=/dev/loop8 --bind=/dev/loop9 --bind=/dev/loop10 --bind=/dev/loop11 --console=pipe --setenv=TERM=vt100 --setenv=SHELL=/bin/bash --setenv=HOME=/builddir --setenv=HOSTNAME=mock --setenv=PATH=/usr/bin:/bin:/usr/sbin:/sbin '--setenv=PROMPT_COMMAND=printf "\033]0;<mock-chroot>\007"' '--setenv=PS1=<mock-chroot> \s-\v\$ ' --setenv=LANG=C.UTF-8 --resolv-conf=off bash --login -c '/usr/bin/rpmbuild -bb --noclean --target x86_64 --nodeps /builddir/build/SPECS/kernel.spec'

this is on a rocky 9.1 system with the default configration.

So, if it fails while using the standard way on a system with standard config, how could you build it?

The default mock config already provides a bootstrap container that does this part of this for you. You can make your own if you wish, you would just need to point the mock config where to go. Look in /etc/mock/templates.

You should ask them directly.

Custom kernel builds are not supported. See here. I understand that companies want to have their own custom kernels, but those 6 points should be read thoroughly before ever considering so.

The default mock configuration as provided by the mock package builds against the latest Rocky Linux 9 available. It does not build against 9.1 as it is not supported. Because that kernel is about 3 releases old, that can very easily be the reason why it is not building for you. You will need to create a custom mock config that points to 9.1 in the vault if you are building for an end of life release. See here for examples.

With that said, we do not have issues building our packages using this method in any of our build systems or on our local systems.

See also: