How to build a vanilla kernel RPM package Fedora 37

Fedora 37 GNOME desktop












I currently have an Intel Arc A770 LE 16GB and out of the box Fedora 37 does not support it. There are some workarounds but the best option (at the time of writing) is to use kernel 6.2.7 as that has native Intel Arc support.

This is a quick guide I made for myself, it will build a linux-6.2.7 *.rpm package in Fedora 37. As with anything in Linux, there is usually more than one way to do things or a better way to do something. If you have a suggestion leave a comment below.

Open a terminal 

sudo dnf install ncurses-devel flex bison rpm-build elfutils-libelf-devel rpmdevtools openssl-devel dwarves perl

This should install required packages to build and compile the kernel.

rpmdev-setuptree

This will setup your home directory for building the *.rpm package.

cd ~/rpmbuild/SOURCES/

We are going to go into the SOURCES directory in our rpmbuild tree.

wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.2.7.tar.xz

This will download linux-6.2.7.tar.xz into the SOURCES directory.

tar -xf linux-6.2.7.tar.xz

This will extract the compressed archive files into a folder call linux-6.2.7 within the SOURCES directory.

cd linux-6.2.7

Go into the linux-6.2.7 directory.

make menuconfig 

This will bring up a console based menu configuration where you can configure your kernel options. Once you have configured your kernel options, save and exit. 

You can at this stage (read on to see why I would not) build your kernel *.rpm package by issuing either make binrpm-pkg or make rpm-pkg depending on whether you want the binary package only or source and binary *.rpm.

time make -j`nproc` binrpm-pkg

To speed up the build, I am using the -j option to run a number of jobs in parallel, i.e. multi threading with the argument nproc to automatically obtain my processor count and use that number for the amount of jobs to run. With my current processor, an AMD Ryzen 5600G, nproc results in a count of 12.

However, if you start compiling your kernel rpm now, it will whizz through the compiling process but then choke at the point it starts to write the *.rpm file. The reason for this is because the makefile scripts are configured to only use 1 processing thread during the package file write and compression stage. To speed it up we need to edit the scripts before issuing the make command and enable multi threaded package compression.

gnome-text-editor ~/rpmbuild/SOURCES/linux-6.2.7/scripts/Makefile.package


Find the binrpm-pkg section


# binrpm-pkg
# ---------------------------------------------------------------------------
PHONY += binrpm-pkg
binrpm-pkg:
$(MAKE) -f $(srctree)/Makefile
$(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
+rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
$(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec


And add the following --define "_binary_payload w7T0.zstdio" as shown below.


# binrpm-pkg
# ---------------------------------------------------------------------------
PHONY += binrpm-pkg
binrpm-pkg:
$(MAKE) -f $(srctree)/Makefile
$(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
+rpmbuild $(RPMOPTS) --define "_binary_payload w7T0.zstdio" --define "_builddir $(objtree)" --target \
$(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec

Save and close the file.

To explain further, we are setting the compression algorithm to a preset option of zstd compresson with a compression level of 7 and multi threading functionality. Thanks to this website for pointing me in the right direction.

Now you are ready to build your kernel *.rpm file

time make -j`nproc` binrpm-pkg

Depending on your processor and kernel options this could take 15 minutes or less, or 60 minutes and beyond.

If all went well, the two *.rpm files will be created in ~/rpmbuild/RPMS/x86_64/ with names similar to,
 
kernel-6.2.7-1.x86_64.rpm
kernel-headers-6.2.7-1.x86_64.rpm 

The name of your files may differ depending on your kernel .config options. Now all you have to do is install your kernel.

cd ~/rpmbuild/RPMS/x86_64/

Once we have changed to the directory containing our *.rpm kernel files,

sudo rpm -ivh kernel-6.2.7-1.x86_64.rpm
sudo rpm -ivh kernel-headers-6.2.7-1.x86_64.rpm

Grub boot entries should automatically be created, if not update grub. See here for more info. 

Comments

Popular posts from this blog

My top tweaks for gaming in Windows 10

Ubuntu 23.10 - How to build a kernel package from kernel.org

How to fix OBS Intel Quick Sync MFX_ERR_NOT_FOUND error in Ubuntu