OpenSUSE 13: Rebuild kernel with srcpackage

This article will changing kernel configuration and source code, and rebuilding kernel with using srcpackage package.

1 Install packages for building kernel

Install rpm-build for rpmbuild and patterns-openSUSE-devel_kernel for building kernel.

> sudo zypper -n in rpm-build patterns-openSUSE-devel_kernel

2 Download kernel srcpackage

Download kernel-desktop srcpackage. Download kernel-macros which is need to build kernel.

> # If you have already downloaded other package, clear /usr/src/packages.
> # sudo rm -rf /usr/src/packages/*
> sudo zypper -n si kernel-desktop kernel-macros
> cp -a /usr/src/packages ~/rpmbuild
> cd ~/rpmbuild
> rpmbuild -bp SPECS/kernel-desktop.spec

For building vanilla kernel, download kernel-vanilla and kernel-macro.

3 Change kernel version

Change kernel version for avoiding conflicting installed kernel. Change Release variable in spec file.

> sed -i -e 's/^Release:\(.*\)/Release:\1.hiroom2/g' SPECS/kernel-desktop.spec
> diff -uprN SPECS/kernel-desktop.spec{.org,}
--- SPECS/       2016-12-25 17:35:06.963941101 +0900
+++ SPECS/kernel-desktop.spec   2016-12-25 17:36:07.145422377 +0900
@@ -61,9 +61,9 @@ License:        GPL-2.0
 Group:          System/Kernel
 Version:        3.16.7
 %if 0%{?is_kotd}
-Release:        53.1.g7b4a1f9
+Release:        53.1.g7b4a1f9.hiroom2
-Release:        53.1
+Release:        53.1.hiroom2
 BuildRequires:  bc

4 Change kernel configuration

Kernel configurations are in SOURCES/config.tar.bz2 like config/<arch>/<type> (e.g. arch is x86_64 and type is desktop).

  • Extract config.tar.bz2 and copy to .config in kernel directory.
  • Move to kernel directory and change .config with make menuconfig.
  • Save .config to config/<arch>/<type> and compress to config.tar.bz2.
> tar jxf SOURCES/config.tar.bz2
> cp config/x86_64/desktop BUILD/kernel-desktop-3.16.7/linux-3.16/.config
> cd BUILD/kernel-desktop-3.16.7/linux-3.16
> make menuconfig # Change kernel config
> cp .config ../../../config/x86_64/desktop
> cd ../../..
> tar jcf SOURCES/config.tar.bz2 config

This article disables CONFIG_PRINTK_TIME.

> tar jxf SOURCES/config.tar.bz2
> sed -i -e 's/CONFIG_PRINTK_TIME=y/# CONFIG_PRINTK_TIME is not set/g' \
> tar jcf SOURCES/config.tar.bz2 config

5 Change kernel source code

Paches are in SOURCES/patches.<type>.tar.bz2 and patches will be applied by SOURCES/series.conf.

Add original patch to SOURCES/patches.addon.tar.bz2 and add patch entry to SOURCES/series.conf.

tar jxf SOURCES/patches.addon.tar.bz2
cat <<EOF > patches.addon/hello.patch
diff -uprN linux-3.16/init/main.c
---  2016-12-25 22:38:14.721618205 +0900
+++ linux-3.16/init/main.c      2016-12-25 22:40:09.678637730 +0900
@@ -944,6 +944,8 @@ static int __ref kernel_init(void *unuse


+       printk("Hello, World\n");
        if (ramdisk_execute_command) {
                ret = run_init_process(ramdisk_execute_command);
                if (!ret)
tar jcf SOURCES/patches.addon.tar.bz2 patches.addon
echo "patches.addon/hello.patch" >> SOURCES/series.conf

6 Build kernel

Build kernel. Building kernel will takes one hour.

> rpmbuild -ba SPECS/kernel-desktop.spec

Install kernel.

> sudo zypper -n in RPMS/x86_64/kernel-desktop-3.16.7-53.1.hiroom2.x86_64.rpm

Reboot OpenSUSE 13.

> sudo reboot

7 Execution result

Execution result is as below after reboot.

> uname -r
> zcat /proc/config.gz | grep CONFIG_PRINTK_TIME
> dmesg | grep Hello
[    2.158619] Hello, World