How to rebuild kernel RPM from SRPM with custom patches

Hello everyone,

I would like to rebuild openSUSE kernel RPM, from the respective SRPM.
Main reason for rebuilding is that I want to test recent patches hopefully fixing my suspend issues.

I was thinking SRPM because I want kernel with same settings as openSUSE kernels. Also, if I master the process I will be able to move it to OBS (openSUSE Build Service).

I have already received nice help from @Sauerland in my another post: How to download source package using Zypper

He advised me that the kernel-vanilla.rpm is build with the kernel-source package; for example kernel-vanilla-6.14~rc6-1.1.g5af2a0b.rpm is produced by:
kernel-source-6.14~rc6-1.1.g5af2a0b.src.rpm and
kernel-syms-6.14~rc6-1.1.g5af2a0b.src.rpm.

Zypper is not very helpful in these matters so I downloaded them using browser from the openSUSE official vanilla kernel repository: https://download.opensuse.org/repositories/Kernel:/HEAD/standard/src

I downloaded the patches from here:

(They look like emails so I copied only that part that looked like a patch and tested it with diffstat and kompare for validity).

I’m going to build the source RPMs as ordinary user, under my home directory. As advised I configured my RPM build environment:

mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros
echo '%_tmppath %{_topdir}/tmp' >> ~/.rpmmacros

As advised I installed the the two downloaded source packages.

cd ~/Downloads
rpm -ivv kernel-source-6.14~rc6-1.1.g5af2a0b.src.rpm
rpm -ivv kernel-syms-6.14~rc6-1.1.g5af2a0b.src.rpm

The -i is for install, -vv is for extra verbose output. Only from verbose output one learns where exactly what is installed.
This copies lots of compressed files to ~/rpmbuild/SOURCES/, including Linux kernel sources as tar.bz2, build configs, and a spec file to ~/rpmbuild/SPECS/. I was quite surprised everything is copied directly to SOURCES, there is nothing like per package subdirectory.

I wasn’t sure how to “add the patches”. I found several empty patches.*.tar.bz2archives, with just a directory in there. I picked one and put the patch files there, in that archive directory, with this command:

cd ~/rpmbuild
cd patches 
tar -cjf patches.fixes.tar.bz2 --transform='s|^|patches.fixes/|' *.patch
cp patches.fixes.tar.bz2 ../SOURCES/patches.fixes.tar.bz2

As advised I run the rpmbuild -ba commands:

rpmbuild -ba SPECS/kernel-source.spec 
rpmbuild -ba SPECS/kernel-syms.spec 

The -ba means that both binary and source packages are built.

I recommend this variant, with outputs also saved to a log file:

cd ~/rpmbuild  
alias now='date +%Y-%m-%d-%H.%M.%S'
rpmbuild -ba SPECS/kernel-source.spec |& tee build_log_$(now).txt

Build was reported as successful, but was much faster than expected and clearly nothing was being compiled.

As a result, I found in ~/rpmbuild/RPMS/noarch/:

  • kernel-devel-6.14~rc6-1.1.noarch.rpm
  • kernel-macros-6.14~rc6-1.1.noarch.rpm
  • kernel-source-6.14~rc6-1.1.noarch.rpm
  • kernel-source-vanilla-6.14~rc6-1.1.noarch.rpm

…and in ~/rpmbuild/RPMS/x86_64/ only:

  • kernel-syms-6.14~rc6-1.1.x86_64.rpm

…and two source packages in ~/rpmbuild/SRPMS/:

  • kernel-source-6.14~rc6-1.1.src.rpm
  • kernel-syms-6.14~rc6-1.1.src.rpm

…which look exactly same as those I have downloaded from the kernel repo.

No actual installable binary kernel RPM :frowning:
Please, what am I doing wrong?

kernel-source/doc/README.SUSE at master · SUSE/kernel-source · GitHub and search for “How to add custom patches”.

Correct. Rebuilding kernel-source SRPM will produce - surprise - kernel-source RPM (well, sources are split between two packages, but it is technical detail). The binary kernels are built using individual spec files, like kernel-default.spec. These spec files are present in OBS package but not in the kernel-source SRPM. These spec files are generated from the kernel-binary.spec.in using mkspec script, but I do not know what else needs to be done to prepare for actual building.

Unless you want to spend your life maintaining SUSE kernel, just branch the package in OBS and follow the README to add custom patches. Alternative is to clone patched SUSE kernel sources from Welcome To The SUSE Kernel Site - SUSE Kernel, apply your patches and build as usual.

1 Like

You need additionally “nosrc” RPM for your kernel flavor which contains the generated spec file. Like https://download.opensuse.org/repositories/Kernel:/HEAD/standard/nosrc/kernel-default-6.14~rc6-2.1.ge1b020a.nosrc.rpm

1 Like

Maybe it is better to use Kernel:HEAD?
Kernel-default-6.14~rc7 is available.

Thank you @arvidjaar!
I managed to build my patched kernel. Fantastic.

I additionally downloaded and installed:

rpm -ivv ../downloads/kernel-vanilla-*.nosrc.rpm

Following the official documentation the patch archive to be used is patches.addon.tar.bz2; put it to directory patches.addonthere.

Then build the binary, installable kernel package with:

rpmbuild -ba SPECS/kernel-vanilla.spec

I recommend this variant:

alias now='date +%Y-%m-%d-%H.%M.%S'
rpmbuild -ba SPECS/kernel-vanilla.spec |& tee build_kernel_vanilla_$(now).log

which captures all outputs to a single log file with a timestamp.

If successful one can find results in rpmbuild/RPMS/x86_64:

kernel-vanilla-vdso-debuginfo-6.14~rc7-1.1.x86_64.rpm
kernel-vanilla-vdso-6.14~rc7-1.1.x86_64.rpm
kernel-vanilla-devel-debuginfo-6.14~rc7-1.1.x86_64.rpm
kernel-vanilla-devel-6.14~rc7-1.1.x86_64.rpm
kernel-vanilla-debugsource-6.14~rc7-1.1.x86_64.rpm
kernel-vanilla-debuginfo-6.14~rc7-1.1.x86_64.rpm
kernel-vanilla-6.14~rc7-1.1.x86_64.rpm

Install the freshly built kernel with:

sudo rpm -ivh kernel-vanilla-6.14~rc7-1.1.x86_64.rpm 

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.