Files
clear-linux-documentation/guides/kernel/kernel-development.html
2024-11-04 18:48:51 +00:00

570 lines
36 KiB
HTML

<!DOCTYPE html>
<html lang="en" data-content_root="../../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Kernel development &#8212; Documentation for Clear Linux* project</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="../../_static/bizstyle.css?v=5283bb3d" />
<link rel="stylesheet" type="text/css" href="../../_static/copybutton.css?v=76b2166b" />
<script src="../../_static/documentation_options.js?v=5929fcd5"></script>
<script src="../../_static/doctools.js?v=9bcbadda"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../_static/clipboard.min.js?v=a7894cd8"></script>
<script src="../../_static/copybutton.js?v=a56c686a"></script>
<script src="../../_static/bizstyle.js"></script>
<link rel="canonical" href="https://clearlinux.github.io/clear-linux-documentation/guides/kernel/kernel-development.html" />
<link rel="icon" href="../../_static/favicon.ico"/>
<link rel="author" title="About these documents" href="../../about.html" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="Add kernel modules manually" href="kernel-modules.html" />
<link rel="prev" title="Capture Kernel Boot Messages in the Journal" href="kernel-boot-msg.html" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<!--[if lt IE 9]>
<script src="_static/css3-mediaqueries.js"></script>
<![endif]-->
</head><body>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="kernel-modules.html" title="Add kernel modules manually"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="kernel-boot-msg.html" title="Capture Kernel Boot Messages in the Journal"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../index.html">Documentation for Clear Linux* project</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Guides</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Kernel development</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="kernel-development">
<span id="id1"></span><h1>Kernel development<a class="headerlink" href="#kernel-development" title="Link to this heading"></a></h1>
<p>This guide shows how to obtain and compile a Linux* kernel source using
Clear Linux* OS development tooling.</p>
<nav class="contents local" id="contents">
<ul class="simple">
<li><p><a class="reference internal" href="#overview" id="id2">Overview</a></p></li>
<li><p><a class="reference internal" href="#request-changes-be-included-with-the-cl-kernel" id="id3">Request changes be included with the Clear Linux OS kernel</a></p></li>
<li><p><a class="reference internal" href="#set-up-kernel-development-environment" id="id4">Set up kernel development environment</a></p></li>
<li><p><a class="reference internal" href="#customize-the-linux-kernel-source" id="id5">Customize the Linux kernel source</a></p></li>
<li><p><a class="reference internal" href="#build-and-install-the-kernel" id="id6">Build and install the kernel</a></p></li>
<li><p><a class="reference internal" href="#related-topics" id="id7">Related topics</a></p></li>
</ul>
</nav>
<section id="overview">
<h2><a class="toc-backref" href="#contents" role="doc-backlink">Overview</a><a class="headerlink" href="#overview" title="Link to this heading"></a></h2>
<p>The <a class="reference internal" href="../clear/compatible-kernels.html#compatible-kernels"><span class="std std-ref">Kernels</span></a> available in Clear Linux OS aim to be performant and
practical. In some cases, it may be necessary to modify the kernel to suit
your specific needs or test new kernel code as a developer.</p>
<p><a class="reference external" href="https://cdn.download.clearlinux.org/current/source/SRPMS/">Source RPMs (SRPMS)</a> are also available for all Clear Linux OS kernels, and can be
used for development instead.</p>
</section>
<section id="request-changes-be-included-with-the-cl-kernel">
<h2><a class="toc-backref" href="#contents" role="doc-backlink">Request changes be included with the Clear Linux OS kernel</a><a class="headerlink" href="#request-changes-be-included-with-the-cl-kernel" title="Link to this heading"></a></h2>
<p>If the kernel modification you need is already open source and likely to be
useful to others, consider submitting a request to include it in the
Clear Linux OS kernels. If your change request is accepted, you do not need to maintain
your own modified kernel.</p>
<p>Make enhancement requests to the Clear Linux OS <a class="reference external" href="https://github.com/clearlinux/distribution/issues/new/choose">Distribution Project</a> on GitHub*.</p>
</section>
<section id="set-up-kernel-development-environment">
<h2><a class="toc-backref" href="#contents" role="doc-backlink">Set up kernel development environment</a><a class="headerlink" href="#set-up-kernel-development-environment" title="Link to this heading"></a></h2>
<p>In some cases, it may be necessary to modify the kernel to suit your specific
needs or to test new kernel code.</p>
<p>You can build and install a custom kernel; however you must:</p>
<ul class="simple">
<li><p>Disable Secure Boot</p></li>
<li><p>Maintain any updates to the kernel going forward</p></li>
</ul>
<p>To create a custom kernel, start with the Clear Linux OS development environment.
Then make changes to the kernel, build it, and install it.</p>
<section id="install-the-cl-development-tooling-framework">
<h3>Install the Clear Linux OS development tooling framework<a class="headerlink" href="#install-the-cl-development-tooling-framework" title="Link to this heading"></a></h3>
<p>Setup of the workspace and tooling used for building source in Clear Linux OS is mostly
automated for you with a setup script. It uses tools from the
<strong class="command">os-clr-on-clr</strong> bundle.</p>
<p>The setup script creates a workspace in the <code class="file docutils literal notranslate"><span class="pre">clearlinux</span></code> folder, with the
subfolders <code class="file docutils literal notranslate"><span class="pre">Makefile</span></code>, <code class="file docutils literal notranslate"><span class="pre">packages</span></code>, and <code class="file docutils literal notranslate"><span class="pre">projects</span></code>. The
<code class="file docutils literal notranslate"><span class="pre">projects</span></code> folder contains the main tools used for making packages in
Clear Linux OS <code class="file docutils literal notranslate"><span class="pre">autospec</span></code> and <code class="file docutils literal notranslate"><span class="pre">common</span></code>.</p>
<p>Follow these steps to setup the workspace and tooling for building source:</p>
<ol class="arabic">
<li><p>Install the <strong class="command">os-clr-on-clr</strong> bundle:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>swupd<span class="w"> </span>bundle-add<span class="w"> </span>os-clr-on-clr
</pre></div>
</div>
</li>
<li><p>Download the <code class="file docutils literal notranslate"><span class="pre">user-setup.sh</span></code> script:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>curl<span class="w"> </span>-O<span class="w"> </span>https://raw.githubusercontent.com/clearlinux/common/master/user-setup.sh
</pre></div>
</div>
</li>
<li><p>Make <code class="file docutils literal notranslate"><span class="pre">user-setup.sh</span></code> executable:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>chmod<span class="w"> </span>+x<span class="w"> </span>user-setup.sh
</pre></div>
</div>
</li>
<li><p>Run the script as an unprivileged user:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>./user-setup.sh
</pre></div>
</div>
</li>
<li><p>After the script completes, log out and log in again to complete the setup
process.</p></li>
<li><p>Set your Git user email and username for the repos on your system:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>git<span class="w"> </span>config<span class="w"> </span>--global<span class="w"> </span>user.email<span class="w"> </span><span class="s2">&quot;you@example.com&quot;</span>
git<span class="w"> </span>config<span class="w"> </span>--global<span class="w"> </span>user.name<span class="w"> </span><span class="s2">&quot;Your Name&quot;</span>
</pre></div>
</div>
<p>This global setting is used by Clear Linux OS tools that make use of Git.</p>
</li>
</ol>
</section>
<section id="clone-the-kernel-package">
<h3>Clone the kernel package<a class="headerlink" href="#clone-the-kernel-package" title="Link to this heading"></a></h3>
<p>Clone the existing kernel package repository from Clear Linux OS as a starting point.</p>
<ol class="arabic">
<li><p>Clone the Linux kernel package from Clear Linux OS. Using the
<strong class="command">make clone_&lt;PACKAGENAME&gt;</strong> command in the
<code class="file docutils literal notranslate"><span class="pre">clearlinux/</span></code> directory clones the package from the
<a class="reference external" href="https://github.com/clearlinux-pkgs">clearlinux-pkgs</a> repo on GitHub.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nb">cd</span><span class="w"> </span>~/clearlinux
make<span class="w"> </span>clone_linux
</pre></div>
</div>
</li>
<li><p>Navigate into the cloned package directory.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nb">cd</span><span class="w"> </span>~/clearlinux/packages/linux
</pre></div>
</div>
</li>
</ol>
<p>The “linux” package is the kernel that comes with Clear Linux OS in the
<strong class="command">kernel-native</strong> bundle. Alternatively, you can use a different kernel
variant as the base for modification. For a list of kernel package names which
you can clone instead, see the <a class="reference external" href="https://github.com/clearlinux-pkgs">clearlinux-pkgs</a> repo on GitHub.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The latest version of the Clear Linux OS kernel package is pulled as a starting
point. An older version can pulled by switching to different git tag by using
<strong class="command">git checkout tag/&lt;TAG_NAME&gt;</strong>.</p>
</div>
</section>
<section id="change-the-kernel-version">
<h3>Change the kernel version<a class="headerlink" href="#change-the-kernel-version" title="Link to this heading"></a></h3>
<p>Clear Linux OS tends to use the latest kernel available from <a class="reference external" href="https://www.kernel.org/">kernel.org</a>, the Linux
upstream. The kernel version that will be built can be changed in the
RPM SPEC file. While most packages in Clear Linux are typically packaged
using <a class="reference internal" href="../clear/autospec.html#autospec"><span class="std std-ref">autospec</span></a>, the kernel is not. This means control files
provided by autospec are not available and changes must be made manually.</p>
<ol class="arabic">
<li><p>Open the Linux kernel package RPM SPEC file in an editor.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nv">$EDITOR</span><span class="w"> </span>linux.spec
</pre></div>
</div>
</li>
<li><p>Modify the Version, Release, and Source0 URL entries at the top of the
file to change the version of Linux kernel that will be compiled.</p>
<p>A list of current and available kernel release can be found on
<a class="reference external" href="https://www.kernel.org/">kernel.org</a>.</p>
<div class="highlight-spec notranslate"><div class="highlight"><pre><span></span><span class="hll"><span class="linenos"> 1</span><span class="gh">Name</span><span class="p">:</span><span class="w"> </span>linux
</span><span class="hll"><span class="linenos"> 2</span><span class="gh">Version</span><span class="p">:</span><span class="w"> </span>4.20.8
</span><span class="hll"><span class="linenos"> 3</span><span class="gh">Release</span><span class="p">:</span><span class="w"> </span>696
</span><span class="linenos"> 4</span><span class="gh">License</span><span class="p">:</span><span class="w"> </span>GPL-2.0
<span class="linenos"> 5</span><span class="gh">Summary</span><span class="p">:</span><span class="w"> </span>The<span class="w"> </span>Linux<span class="w"> </span>kernel
<span class="linenos"> 6</span><span class="gh">Url</span><span class="p">:</span><span class="w"> </span>http://www.kernel.org/
<span class="linenos"> 7</span><span class="gh">Group</span><span class="p">:</span><span class="w"> </span>kernel
<span class="linenos"> 8</span><span class="gh">Source0</span><span class="p">:</span><span class="w"> </span>https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.20.8.tar.xz
<span class="linenos"> 9</span><span class="gh">Source1</span><span class="p">:</span><span class="w"> </span>config
<span class="linenos">10</span><span class="gh">Source2</span><span class="p">:</span><span class="w"> </span>cmdline
<span class="linenos">11</span>
<span class="hll"><span class="linenos">12</span><span class="cp">%define ktarget native</span>
</span></pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<ul class="simple">
<li><p>Consider changing the Name from <em>linux</em> in the RPM spec file to easily
identify a modified kernel.</p></li>
<li><p>Consider changing the ktarget from <em>native</em> in the RPM spec file to
easily identify a modified kernel.</p></li>
</ul>
</div>
</li>
<li><p>Commit and save the changes to the file.</p></li>
</ol>
</section>
<section id="pull-a-copy-of-the-linux-kernel-source-code">
<span id="pull-copy-kernel-source"></span><h3>Pull a copy of the Linux kernel source code<a class="headerlink" href="#pull-a-copy-of-the-linux-kernel-source-code" title="Link to this heading"></a></h3>
<p>Obtain a local copy of the source code to make modifications against.</p>
<ol class="arabic">
<li><p>Run make sources to pull the kernel source code specified in the RPM
SPEC file. In the example, it downloads the <code class="file docutils literal notranslate"><span class="pre">linux-4.20.8.tar.xz</span></code>
file.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>make<span class="w"> </span>sources
</pre></div>
</div>
</li>
<li><p>Extract the kernel source code archive. This will create a working copy
of the Linux source that you can modify.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>tar<span class="w"> </span>-xvf<span class="w"> </span>linux-4.20.8.tar.xz
</pre></div>
</div>
</li>
<li><p>Navigate to the extracted directory. In this example, it has been
extracted into a <code class="file docutils literal notranslate"><span class="pre">linux-4.20.8</span></code> directory.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nb">cd</span><span class="w"> </span>linux-4.20.8/
</pre></div>
</div>
</li>
</ol>
</section>
</section>
<section id="customize-the-linux-kernel-source">
<h2><a class="toc-backref" href="#contents" role="doc-backlink">Customize the Linux kernel source</a><a class="headerlink" href="#customize-the-linux-kernel-source" title="Link to this heading"></a></h2>
<p>After the kernel sources have been obtained, customizations to the kernel
configuration or source code can be made for inclusion with the kernel
build. These customizations are optional.</p>
<section id="modify-kernel-configuration">
<h3>Modify kernel configuration<a class="headerlink" href="#modify-kernel-configuration" title="Link to this heading"></a></h3>
<p>The kernel source has many configuration options available to pick support for
different hardware and software features.</p>
<p>These configuration values must be provided in the <code class="file docutils literal notranslate"><span class="pre">.config</span></code> file at
compile time. You will need to make modifications to the <code class="file docutils literal notranslate"><span class="pre">.config</span></code>
file, and include it in the kernel package.</p>
<ol class="arabic">
<li><p>Make sure you have followed the steps to <a class="reference internal" href="#pull-copy-kernel-source"><span class="std std-ref">Pull a copy of the Linux kernel source code</span></a>
and are in the kernel source working directory.</p></li>
<li><p>If you have an existing <code class="file docutils literal notranslate"><span class="pre">.config</span></code> file from an old kernel, copy it
into the working directory as <code class="file docutils literal notranslate"><span class="pre">.config</span></code> for comparison.
Otherwise, use the Clear Linux OS kernel configuration file as template</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>cp<span class="w"> </span>~/clearlinux/packages/linux/config<span class="w"> </span>.config
</pre></div>
</div>
</li>
<li><p>Make any desired changes to the <code class="file docutils literal notranslate"><span class="pre">.config</span></code> using a kernel
configuration tool. Below are some popular options:</p>
<ul class="simple">
<li><p><strong class="command">$EDITOR .config</strong> - the .config file can be directly edited
for simple changes with names that are already known.</p></li>
<li><p><strong class="command">make config</strong> - a text-based tool that asks questions
one-by-one to decide configuration options.</p></li>
<li><p><strong class="command">make menuconfig</strong> - a terminal user interface that provides
menus to decide configuration options.</p></li>
<li><p><strong class="command">make xconfig</strong> - a graphical user interface that provides
tree views to decide configuration options.</p></li>
</ul>
<p>More configuration tools can be found by looking at the make help:
<strong class="command">make help | grep config</strong></p>
</li>
<li><p>Commit and save the changes to the <code class="file docutils literal notranslate"><span class="pre">.config</span></code> file.</p></li>
<li><p>Copy the <code class="file docutils literal notranslate"><span class="pre">.config</span></code> file from the kernel source directory into
the kernel package directory as <code class="file docutils literal notranslate"><span class="pre">config</span></code> for inclusion in the build.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>cp<span class="w"> </span>.config<span class="w"> </span>../config
</pre></div>
</div>
</li>
</ol>
</section>
<section id="modify-kernel-source-code">
<h3>Modify kernel source code<a class="headerlink" href="#modify-kernel-source-code" title="Link to this heading"></a></h3>
<p>Changes to kernel code are applied with patch files. Patch files are
formatted git commits that can be applied to the main source code.</p>
<p>You will need to obtain a copy of the source code,
make modifications, generate patch file(s), and add them to the RPM SPEC
file for inclusion during the kernel build.</p>
<p>If you have a large number of patches or a more complex workflow,
consider using a patch management tool in addition to Git such as
<a class="reference external" href="http://savannah.nongnu.org/projects/quilt">Quilt</a>.</p>
<ol class="arabic">
<li><p>Make sure you have followed the steps to <a class="reference internal" href="#pull-copy-kernel-source"><span class="std std-ref">Pull a copy of the Linux kernel source code</span></a> and
are in the kernel source working directory.</p></li>
<li><p>Initialize the kernel source directory as a new git repo and create a
commit with all the existing source files to begin tracking changes.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>git<span class="w"> </span>init
git<span class="w"> </span>add<span class="w"> </span>-A
git<span class="w"> </span>commit<span class="w"> </span>-m<span class="w"> </span><span class="s2">&quot;Initial commit of Linux kernel source&quot;</span>
</pre></div>
</div>
</li>
<li><p>Apply patches provided by the Clear Linux OS kernel package to the kernel source
in the working directory.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>git<span class="w"> </span>am<span class="w"> </span>../*.patch
</pre></div>
</div>
</li>
<li><p>Make any of your desired code changes to the Linux source code files.</p></li>
<li><p>Track and commit your changes to the local git repo.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>git<span class="w"> </span>add<span class="w"> </span>&lt;FILENAME&gt;
git<span class="w"> </span>commit<span class="w"> </span>-m<span class="w"> </span><span class="s2">&quot;My patch for driver A&quot;</span><span class="w"> </span>&lt;FILENAME&gt;
</pre></div>
</div>
</li>
<li><p>Generate a patch file based on your git commits.
&lt;n&gt; represents the number of local commits to create patch file.
See the <a class="reference external" href="https://git-scm.com/docs/git-format-patch">git-format-patch</a> documentation for detailed information
on using <strong class="command">git format-patch</strong></p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>git<span class="w"> </span>format-patch<span class="w"> </span>-&lt;n&gt;
</pre></div>
</div>
</li>
<li><p>Copy the patch files from the patches directory in the linux
source tree to the RPM build directory.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>cp<span class="w"> </span>*.patch<span class="w"> </span>~/clearlinux/packages/linux/
</pre></div>
</div>
</li>
<li><p>Navigate back to the RPM build directory.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nb">cd</span><span class="w"> </span>~/clearlinux/packages/linux/
</pre></div>
</div>
</li>
<li><p>Open the Linux kernel package RPM SPEC file in an editor.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nv">$EDITOR</span><span class="w"> </span>linux.spec
</pre></div>
</div>
</li>
<li><p>Locate the section of the SPEC file that contains existing patch
variable definitions and append your patch file name. Ensure the
patch number does not collide with an existing patch.
In this example, the patch file is called
<code class="file docutils literal notranslate"><span class="pre">2001-my-patch-for-driver-A.patch</span></code></p>
<div class="highlight-spec notranslate"><div class="highlight"><pre><span></span><span class="linenos"> 1</span><span class="c">#</span>
<span class="linenos"> 2</span><span class="c"># Small Clear Linux Tweaks</span>
<span class="linenos"> 3</span><span class="c">#</span>
<span class="linenos"> 4</span><span class="gh">Patch0501</span><span class="p">:</span><span class="w"> </span>0501-zero-extra-registers.patch
<span class="linenos"> 5</span><span class="gh">Patch0502</span><span class="p">:</span><span class="w"> </span>0502-locking-rwsem-spin-faster.patch
<span class="linenos"> 6</span>
<span class="linenos"> 7</span><span class="c">#Serie1.name WireGuard</span>
<span class="linenos"> 8</span><span class="c">#Serie1.git https://git.zx2c4.com/WireGuard</span>
<span class="linenos"> 9</span><span class="c">#Serie1.tag 00bf4f8c8c0ec006633a48fd9ee746b30bb9df17</span>
<span class="linenos">10</span><span class="gh">Patch1001</span><span class="p">:</span><span class="w"> </span>1001-WireGuard-fast-modern-secure-kernel-VPN-tunnel.patch
<span class="linenos">11</span><span class="c">#Serie1.end</span>
<span class="linenos">12</span>
<span class="hll"><span class="linenos">13</span><span class="gh">Patch2001</span><span class="p">:</span><span class="w"> </span>2001-my-patch-for-driver-A.patch
</span></pre></div>
</div>
</li>
<li><p>Locate the section of the SPEC file further down that contains
patch application and append your patch file number used in the step above.
In this example, patch2001 is added.</p>
<div class="highlight-spec notranslate"><div class="highlight"><pre><span></span><span class="linenos"> 1</span><span class="c">#</span>
<span class="linenos"> 2</span><span class="c"># Small tweaks</span>
<span class="linenos"> 3</span><span class="c">#</span>
<span class="linenos"> 4</span><span class="k">%patch0501</span><span class="w"> </span>-p1
<span class="linenos"> 5</span><span class="k">%patch0502</span><span class="w"> </span>-p1
<span class="linenos"> 6</span>
<span class="linenos"> 7</span><span class="c">#Serie1.patch.start</span>
<span class="linenos"> 8</span><span class="k">%patch1001</span><span class="w"> </span>-p1
<span class="linenos"> 9</span><span class="c">#Serie1.patch.end</span>
<span class="linenos">10</span>
<span class="hll"><span class="linenos">11</span><span class="k">%patch2001</span><span class="w"> </span>-p1
</span></pre></div>
</div>
</li>
<li><p>Commit and save the changes to the RPM SPEC file.</p></li>
</ol>
</section>
<section id="modify-kernel-boot-parameters">
<h3>Modify kernel boot parameters<a class="headerlink" href="#modify-kernel-boot-parameters" title="Link to this heading"></a></h3>
<p>The kernel boot options are passed from the bootloader to the kernel with
command-line parameters.</p>
<p>While temporary changes can be made to kernel parameters on a running
system or on a during boot, you can also modify the default parameters that
are persistent and distributed with a customized kernel.</p>
<ol class="arabic">
<li><p>Open the kernel <code class="file docutils literal notranslate"><span class="pre">cmdline</span></code> file in an editor.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nv">$EDITOR</span><span class="w"> </span>cmdline
</pre></div>
</div>
</li>
<li><p>Make any desired change to the kernel parameters.
For example, you can remove the <strong class="command">quiet</strong> parameter to see more
verbose output of kernel log messages during the boot process.</p></li>
<li><p>Commit and save the changes to the <code class="file docutils literal notranslate"><span class="pre">cmdline</span></code> file.</p></li>
</ol>
<p>See the <a class="reference external" href="https://www.kernel.org/doc/Documentation/admin-guide/kernel-parameters.txt">kernel parameters</a> documentation for a list of available
parameters.</p>
</section>
</section>
<section id="build-and-install-the-kernel">
<h2><a class="toc-backref" href="#contents" role="doc-backlink">Build and install the kernel</a><a class="headerlink" href="#build-and-install-the-kernel" title="Link to this heading"></a></h2>
<p>After changes have been made to the kernel source and RPM SPEC file,
the kernel is ready to be compiled and packaged into an RPM.</p>
<p>The Clear Linux OS development tooling makes use of <strong class="command">mock</strong> environments to
isolate building of packages in a sanitized workspace.</p>
<ol class="arabic">
<li><p>Start the compilation process by issuing the <strong class="command">make build</strong>
command. This process is typically resource intensive and will take a
while.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>make<span class="w"> </span>build
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>The mock plugin <a class="reference external" href="https://fedoraproject.org/wiki/Mock/Plugin/CCache?rd=Subprojects/Mock/Plugin/CCache">ccache</a> can be enabled to help speed up any future
rebuilds of the kernel package by caching compiler outputs and reusing
them.</p>
</div>
</li>
<li><p>The result will be multiple <code class="file docutils literal notranslate"><span class="pre">.rpm</span></code> files in the <code class="file docutils literal notranslate"><span class="pre">rpms</span></code>
directory as output.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>ls<span class="w"> </span>rpms/
</pre></div>
</div>
<p>The kernel RPM will be named
<code class="file docutils literal notranslate"><span class="pre">linux&lt;NAME&gt;-&lt;VERSION&gt;-&lt;RELEASE&gt;.x86_64.rpm</span></code></p>
</li>
<li><p>The kernel RPM file can be input to the <a class="reference internal" href="../clear/mixer.html#mixer"><span class="std std-ref">mixer</span></a> to create a
custom bundle and mix of Clear Linux OS.</p></li>
</ol>
<p>Alternatively, the kernel RPM bundle can be installed manually on a local
machine for testing. This approach works well for individual development or
testing. For a more scalable and customizable approach, consider using the
<a class="reference internal" href="../clear/mixer.html#mixer"><span class="std std-ref">mixer</span></a> to provide a custom kernel with updates.</p>
<ol class="arabic">
<li><p>Install the kernel onto the local system by extracting the RPM with the
<strong class="command">rpm2cpio</strong> command.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>rpm2cpio<span class="w"> </span>linux&lt;NAME&gt;-&lt;VERSION&gt;-&lt;RELEASE&gt;.x86_64.rpm<span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="o">(</span><span class="nb">cd</span><span class="w"> </span>/<span class="p">;</span><span class="w"> </span>sudo<span class="w"> </span>cpio<span class="w"> </span>-i<span class="w"> </span>-d<span class="w"> </span>-u<span class="w"> </span>-v<span class="o">)</span><span class="p">;</span>
</pre></div>
</div>
</li>
<li><p>Optionally, increase the bootloader timeout to make interrupting the boot
process and choosing a different kernel easier.This can be helpful to if
you encounter a kernel that does not boot gracefully.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>clr-boot-manager<span class="w"> </span>set-timeout<span class="w"> </span><span class="m">20</span>
</pre></div>
</div>
</li>
<li><p>Update the Clear Linux OS boot manager to use the new kernel using
<strong class="command">clr-boot-manager</strong> and reboot.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>clr-boot-manager<span class="w"> </span>update
sudo<span class="w"> </span>clr-boot-manager<span class="w"> </span>list-kernels
sudo<span class="w"> </span>clr-boot-manager<span class="w"> </span>set-kernel<span class="w"> </span>org.clearlinux.&lt;TARGET&gt;.&lt;VERSION&gt;-&lt;RELEASE&gt;
sudo<span class="w"> </span>reboot
</pre></div>
</div>
</li>
<li><p>After a reboot, verify the customized kernel is running.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>uname<span class="w"> </span>-a
</pre></div>
</div>
</li>
</ol>
</section>
<section id="related-topics">
<h2><a class="toc-backref" href="#contents" role="doc-backlink">Related topics</a><a class="headerlink" href="#related-topics" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><a class="reference internal" href="kernel-modules.html#kernel-modules"><span class="std std-ref">Add kernel modules manually</span></a></p></li>
<li><p><a class="reference internal" href="../clear/mixer.html#mixer"><span class="std std-ref">mixer</span></a></p></li>
</ul>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../../index.html">
<img class="logo" src="../../_static/clearlinux.png" alt="Logo of Clear Linux* Project Docs"/>
</a></p>
<div>
<h3><a href="../../index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Kernel development</a><ul>
<li><a class="reference internal" href="#overview">Overview</a></li>
<li><a class="reference internal" href="#request-changes-be-included-with-the-cl-kernel">Request changes be included with the Clear Linux OS kernel</a></li>
<li><a class="reference internal" href="#set-up-kernel-development-environment">Set up kernel development environment</a><ul>
<li><a class="reference internal" href="#install-the-cl-development-tooling-framework">Install the Clear Linux OS development tooling framework</a></li>
<li><a class="reference internal" href="#clone-the-kernel-package">Clone the kernel package</a></li>
<li><a class="reference internal" href="#change-the-kernel-version">Change the kernel version</a></li>
<li><a class="reference internal" href="#pull-a-copy-of-the-linux-kernel-source-code">Pull a copy of the Linux kernel source code</a></li>
</ul>
</li>
<li><a class="reference internal" href="#customize-the-linux-kernel-source">Customize the Linux kernel source</a><ul>
<li><a class="reference internal" href="#modify-kernel-configuration">Modify kernel configuration</a></li>
<li><a class="reference internal" href="#modify-kernel-source-code">Modify kernel source code</a></li>
<li><a class="reference internal" href="#modify-kernel-boot-parameters">Modify kernel boot parameters</a></li>
</ul>
</li>
<li><a class="reference internal" href="#build-and-install-the-kernel">Build and install the kernel</a></li>
<li><a class="reference internal" href="#related-topics">Related topics</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="kernel-boot-msg.html"
title="previous chapter">Capture Kernel Boot Messages in the Journal</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="kernel-modules.html"
title="next chapter">Add kernel modules manually</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../../_sources/guides/kernel/kernel-development.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<search id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
<input type="submit" value="Go" />
</form>
</div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="kernel-modules.html" title="Add kernel modules manually"
>next</a> |</li>
<li class="right" >
<a href="kernel-boot-msg.html" title="Capture Kernel Boot Messages in the Journal"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../../index.html">Documentation for Clear Linux* project</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="../index.html" >Guides</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Kernel development</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2022 Intel Corporation. All Rights Reserved..
Last updated on Nov 04, 2024.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.1.3.
</div>
</body>
</html>