Jaroslav Škarvada: How to recompile Fedora kernel with the custom patch

I has been asked how to recompile Fedora kernel with the custom patch, so here is the tutorial:

At first install the needed packages:

# dnf install fedpkg dnf-plugins-core

Install build requirements for the kernel package:

# dnf builddep kernel

Clone the kernel dist-git module for the desired Fedora version, i.e. if you want to recompile the kernel for the Fedora 26, add the ‘-b f26’ or respective version (–anonymous is used for the anonymous checkout, i.e. read only checkout):

$ fedpkg co --anonymous -b f26 kernel

Change the working directory to the cloned dist-git module:

$ cd kernel

Copy the desired patch (e.g. my-patch.patch) to the working directory:

$ cp DIR/my-patch.patch .

Make sure your my-patch.patch has been generated by the ‘git format-patch’ if not, you need to manually add the header containing lines From:, Subject:, so proceed the following step just only if such header is not presented in your patch (of course edit the strings as needed):

$ echo "From: Joe Hacker <joe.hacker@hacker.org>" > header
$ echo "Subject: My patch" >> header
$ echo >> header
$ cat header my-patch.patch > patch
$ mv patch my-patch.patch

Edit the kernel.spec, locate the string ‘# END OF PATCH DEFINITIONS’, and add the following string just before it:

Patch9999: my-patch.patch

where make sure that the number 9999 is not used by any previous Patch keyword. If it’s already used, keep increasing the number until you will find the highest unused number and use it with your patch. Save the spec file.

Recompile the kernel:

$ fedpkg local

Install/re-install the newly builds kernel RPMs from the ARCH directory, i.e. if you compiled the kernel for the x86_64, the ARCH directory is x86_64.

Reverted patch

In case you have upstream kernel patch you need to revert, do the previous steps up-to the installation of the my-patch.patch, then unpack the kernel sources:

$ fedpkg prep

Make the reverted patch of your patch (replace the DIR in commands bellow by directory where you store your patches):

$ pushd kernel-*/linux-*
$ git commit -am Flush
$ cp DIR/my-patch.patch .
$ patch -p1 -R my-patch.patch
$ git commit -am "My reverted patch"
$ git format-patch --stdout HEAD~1 > DIR/my-patch-reverted.patch
$ popd

Then install the my-patch-reverted.patch instead of the my-patch.patch and proceed with the compilation as described above.

Source From: fedoraplanet.org.
Original article title: Jaroslav Škarvada: How to recompile Fedora kernel with the custom patch.
This full article can be read at: Jaroslav Škarvada: How to recompile Fedora kernel with the custom patch.


Random Article You May Like

Leave a Reply

Your email address will not be published. Required fields are marked *