162306a36Sopenharmony_ci.. SPDX-License-Identifier: (GPL-2.0+ OR CC-BY-4.0)
262306a36Sopenharmony_ci.. [see the bottom of this file for redistribution information]
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci===========================================
562306a36Sopenharmony_ciHow to quickly build a trimmed Linux kernel
662306a36Sopenharmony_ci===========================================
762306a36Sopenharmony_ci
862306a36Sopenharmony_ciThis guide explains how to swiftly build Linux kernels that are ideal for
962306a36Sopenharmony_citesting purposes, but perfectly fine for day-to-day use, too.
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ciThe essence of the process (aka 'TL;DR')
1262306a36Sopenharmony_ci========================================
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci*[If you are new to compiling Linux, ignore this TLDR and head over to the next
1562306a36Sopenharmony_cisection below: it contains a step-by-step guide, which is more detailed, but
1662306a36Sopenharmony_cistill brief and easy to follow; that guide and its accompanying reference
1762306a36Sopenharmony_cisection also mention alternatives, pitfalls, and additional aspects, all of
1862306a36Sopenharmony_ciwhich might be relevant for you.]*
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ciIf your system uses techniques like Secure Boot, prepare it to permit starting
2162306a36Sopenharmony_ciself-compiled Linux kernels; install compilers and everything else needed for
2262306a36Sopenharmony_cibuilding Linux; make sure to have 12 Gigabyte free space in your home directory.
2362306a36Sopenharmony_ciNow run the following commands to download fresh Linux mainline sources, which
2462306a36Sopenharmony_ciyou then use to configure, build and install your own kernel::
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci    git clone --depth 1 -b master \
2762306a36Sopenharmony_ci      https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git ~/linux/
2862306a36Sopenharmony_ci    cd ~/linux/
2962306a36Sopenharmony_ci    # Hint: if you want to apply patches, do it at this point. See below for details.
3062306a36Sopenharmony_ci    # Hint: it's recommended to tag your build at this point. See below for details.
3162306a36Sopenharmony_ci    yes "" | make localmodconfig
3262306a36Sopenharmony_ci    # Hint: at this point you might want to adjust the build configuration; you'll
3362306a36Sopenharmony_ci    #   have to, if you are running Debian. See below for details.
3462306a36Sopenharmony_ci    make -j $(nproc --all)
3562306a36Sopenharmony_ci    # Note: on many commodity distributions the next command suffices, but on Arch
3662306a36Sopenharmony_ci    #   Linux, its derivatives, and some others it does not. See below for details.
3762306a36Sopenharmony_ci    command -v installkernel && sudo make modules_install install
3862306a36Sopenharmony_ci    reboot
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ciIf you later want to build a newer mainline snapshot, use these commands::
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci    cd ~/linux/
4362306a36Sopenharmony_ci    git fetch --depth 1 origin
4462306a36Sopenharmony_ci    # Note: the next command will discard any changes you did to the code:
4562306a36Sopenharmony_ci    git checkout --force --detach origin/master
4662306a36Sopenharmony_ci    # Reminder: if you want to (re)apply patches, do it at this point.
4762306a36Sopenharmony_ci    # Reminder: you might want to add or modify a build tag at this point.
4862306a36Sopenharmony_ci    make olddefconfig
4962306a36Sopenharmony_ci    make -j $(nproc --all)
5062306a36Sopenharmony_ci    # Reminder: the next command on some distributions does not suffice.
5162306a36Sopenharmony_ci    command -v installkernel && sudo make modules_install install
5262306a36Sopenharmony_ci    reboot
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ciStep-by-step guide
5562306a36Sopenharmony_ci==================
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ciCompiling your own Linux kernel is easy in principle. There are various ways to
5862306a36Sopenharmony_cido it. Which of them actually work and is the best depends on the circumstances.
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ciThis guide describes a way perfectly suited for those who want to quickly
6162306a36Sopenharmony_ciinstall Linux from sources without being bothered by complicated details; the
6262306a36Sopenharmony_cigoal is to cover everything typically needed on mainstream Linux distributions
6362306a36Sopenharmony_cirunning on commodity PC or server hardware.
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ciThe described approach is great for testing purposes, for example to try a
6662306a36Sopenharmony_ciproposed fix or to check if a problem was already fixed in the latest codebase.
6762306a36Sopenharmony_ciNonetheless, kernels built this way are also totally fine for day-to-day use
6862306a36Sopenharmony_ciwhile at the same time being easy to keep up to date.
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ciThe following steps describe the important aspects of the process; a
7162306a36Sopenharmony_cicomprehensive reference section later explains each of them in more detail. It
7262306a36Sopenharmony_cisometimes also describes alternative approaches, pitfalls, as well as errors
7362306a36Sopenharmony_cithat might occur at a particular point -- and how to then get things rolling
7462306a36Sopenharmony_ciagain.
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci..
7762306a36Sopenharmony_ci   Note: if you see this note, you are reading the text's source file. You
7862306a36Sopenharmony_ci   might want to switch to a rendered version, as it makes it a lot easier to
7962306a36Sopenharmony_ci   quickly look something up in the reference section and afterwards jump back
8062306a36Sopenharmony_ci   to where you left off. Find a the latest rendered version here:
8162306a36Sopenharmony_ci   https://docs.kernel.org/admin-guide/quickly-build-trimmed-linux.html
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci.. _backup_sbs:
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci * Create a fresh backup and put system repair and restore tools at hand, just
8662306a36Sopenharmony_ci   to be prepared for the unlikely case of something going sideways.
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci   [:ref:`details<backup>`]
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci.. _secureboot_sbs:
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci * On platforms with 'Secure Boot' or similar techniques, prepare everything to
9362306a36Sopenharmony_ci   ensure the system will permit your self-compiled kernel to boot later. The
9462306a36Sopenharmony_ci   quickest and easiest way to achieve this on commodity x86 systems is to
9562306a36Sopenharmony_ci   disable such techniques in the BIOS setup utility; alternatively, remove
9662306a36Sopenharmony_ci   their restrictions through a process initiated by
9762306a36Sopenharmony_ci   ``mokutil --disable-validation``.
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci   [:ref:`details<secureboot>`]
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci.. _buildrequires_sbs:
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci * Install all software required to build a Linux kernel. Often you will need:
10462306a36Sopenharmony_ci   'bc', 'binutils' ('ld' et al.), 'bison', 'flex', 'gcc', 'git', 'openssl',
10562306a36Sopenharmony_ci   'pahole', 'perl', and the development headers for 'libelf' and 'openssl'. The
10662306a36Sopenharmony_ci   reference section shows how to quickly install those on various popular Linux
10762306a36Sopenharmony_ci   distributions.
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci   [:ref:`details<buildrequires>`]
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci.. _diskspace_sbs:
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci * Ensure to have enough free space for building and installing Linux. For the
11462306a36Sopenharmony_ci   latter 150 Megabyte in /lib/ and 100 in /boot/ are a safe bet. For storing
11562306a36Sopenharmony_ci   sources and build artifacts 12 Gigabyte in your home directory should
11662306a36Sopenharmony_ci   typically suffice. If you have less available, be sure to check the reference
11762306a36Sopenharmony_ci   section for the step that explains adjusting your kernels build
11862306a36Sopenharmony_ci   configuration: it mentions a trick that reduce the amount of required space
11962306a36Sopenharmony_ci   in /home/ to around 4 Gigabyte.
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci   [:ref:`details<diskspace>`]
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci.. _sources_sbs:
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci * Retrieve the sources of the Linux version you intend to build; then change
12662306a36Sopenharmony_ci   into the directory holding them, as all further commands in this guide are
12762306a36Sopenharmony_ci   meant to be executed from there.
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci   *[Note: the following paragraphs describe how to retrieve the sources by
13062306a36Sopenharmony_ci   partially cloning the Linux stable git repository. This is called a shallow
13162306a36Sopenharmony_ci   clone. The reference section explains two alternatives:* :ref:`packaged
13262306a36Sopenharmony_ci   archives<sources_archive>` *and* :ref:`a full git clone<sources_full>` *;
13362306a36Sopenharmony_ci   prefer the latter, if downloading a lot of data does not bother you, as that
13462306a36Sopenharmony_ci   will avoid some* :ref:`peculiar characteristics of shallow clones the
13562306a36Sopenharmony_ci   reference section explains<sources_shallow>` *.]*
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci   First, execute the following command to retrieve a fresh mainline codebase::
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci     git clone --no-checkout --depth 1 -b master \
14062306a36Sopenharmony_ci       https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git ~/linux/
14162306a36Sopenharmony_ci     cd ~/linux/
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci   If you want to access recent mainline releases and pre-releases, deepen you
14462306a36Sopenharmony_ci   clone's history to the oldest mainline version you are interested in::
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci     git fetch --shallow-exclude=v6.0 origin
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci   In case you want to access a stable/longterm release (say v6.1.5), simply add
14962306a36Sopenharmony_ci   the branch holding that series; afterwards fetch the history at least up to
15062306a36Sopenharmony_ci   the mainline version that started the series (v6.1)::
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci     git remote set-branches --add origin linux-6.1.y
15362306a36Sopenharmony_ci     git fetch --shallow-exclude=v6.0 origin
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci   Now checkout the code you are interested in. If you just performed the
15662306a36Sopenharmony_ci   initial clone, you will be able to check out a fresh mainline codebase, which
15762306a36Sopenharmony_ci   is ideal for checking whether developers already fixed an issue::
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci      git checkout --detach origin/master
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci   If you deepened your clone, you instead of ``origin/master`` can specify the
16262306a36Sopenharmony_ci   version you deepened to (``v6.0`` above); later releases like ``v6.1`` and
16362306a36Sopenharmony_ci   pre-release like ``v6.2-rc1`` will work, too. Stable or longterm versions
16462306a36Sopenharmony_ci   like ``v6.1.5`` work just the same, if you added the appropriate
16562306a36Sopenharmony_ci   stable/longterm branch as described.
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci   [:ref:`details<sources>`]
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ci.. _patching_sbs:
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_ci * In case you want to apply a kernel patch, do so now. Often a command like
17262306a36Sopenharmony_ci   this will do the trick::
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci     patch -p1 < ../proposed-fix.patch
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci   If the ``-p1`` is actually needed, depends on how the patch was created; in
17762306a36Sopenharmony_ci   case it does not apply thus try without it.
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci   If you cloned the sources with git and anything goes sideways, run ``git
18062306a36Sopenharmony_ci   reset --hard`` to undo any changes to the sources.
18162306a36Sopenharmony_ci
18262306a36Sopenharmony_ci   [:ref:`details<patching>`]
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci.. _tagging_sbs:
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ci * If you patched your kernel or have one of the same version installed already,
18762306a36Sopenharmony_ci   better add a unique tag to the one you are about to build::
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci     echo "-proposed_fix" > localversion
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ci   Running ``uname -r`` under your kernel later will then print something like
19262306a36Sopenharmony_ci   '6.1-rc4-proposed_fix'.
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ci   [:ref:`details<tagging>`]
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci .. _configuration_sbs:
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_ci * Create the build configuration for your kernel based on an existing
19962306a36Sopenharmony_ci   configuration.
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_ci   If you already prepared such a '.config' file yourself, copy it to
20262306a36Sopenharmony_ci   ~/linux/ and run ``make olddefconfig``.
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci   Use the same command, if your distribution or somebody else already tailored
20562306a36Sopenharmony_ci   your running kernel to your or your hardware's needs: the make target
20662306a36Sopenharmony_ci   'olddefconfig' will then try to use that kernel's .config as base.
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci   Using this make target is fine for everybody else, too -- but you often can
20962306a36Sopenharmony_ci   save a lot of time by using this command instead::
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_ci     yes "" | make localmodconfig
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ci   This will try to pick your distribution's kernel as base, but then disable
21462306a36Sopenharmony_ci   modules for any features apparently superfluous for your setup. This will
21562306a36Sopenharmony_ci   reduce the compile time enormously, especially if you are running an
21662306a36Sopenharmony_ci   universal kernel from a commodity Linux distribution.
21762306a36Sopenharmony_ci
21862306a36Sopenharmony_ci   There is a catch: 'localmodconfig' is likely to disable kernel features you
21962306a36Sopenharmony_ci   did not use since you booted your Linux -- like drivers for currently
22062306a36Sopenharmony_ci   disconnected peripherals or a virtualization software not haven't used yet.
22162306a36Sopenharmony_ci   You can reduce or nearly eliminate that risk with tricks the reference
22262306a36Sopenharmony_ci   section outlines; but when building a kernel just for quick testing purposes
22362306a36Sopenharmony_ci   it is often negligible if such features are missing. But you should keep that
22462306a36Sopenharmony_ci   aspect in mind when using a kernel built with this make target, as it might
22562306a36Sopenharmony_ci   be the reason why something you only use occasionally stopped working.
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_ci   [:ref:`details<configuration>`]
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci.. _configmods_sbs:
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ci * Check if you might want to or have to adjust some kernel configuration
23262306a36Sopenharmony_ci   options:
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_ci  * Evaluate how you want to handle debug symbols. Enable them, if you later
23562306a36Sopenharmony_ci    might need to decode a stack trace found for example in a 'panic', 'Oops',
23662306a36Sopenharmony_ci    'warning', or 'BUG'; on the other hand disable them, if you are short on
23762306a36Sopenharmony_ci    storage space or prefer a smaller kernel binary. See the reference section
23862306a36Sopenharmony_ci    for details on how to do either. If neither applies, it will likely be fine
23962306a36Sopenharmony_ci    to simply not bother with this. [:ref:`details<configmods_debugsymbols>`]
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_ci  * Are you running Debian? Then to avoid known problems by performing
24262306a36Sopenharmony_ci    additional adjustments explained in the reference section.
24362306a36Sopenharmony_ci    [:ref:`details<configmods_distros>`].
24462306a36Sopenharmony_ci
24562306a36Sopenharmony_ci  * If you want to influence the other aspects of the configuration, do so now
24662306a36Sopenharmony_ci    by using make targets like 'menuconfig' or 'xconfig'.
24762306a36Sopenharmony_ci    [:ref:`details<configmods_individual>`].
24862306a36Sopenharmony_ci
24962306a36Sopenharmony_ci.. _build_sbs:
25062306a36Sopenharmony_ci
25162306a36Sopenharmony_ci * Build the image and the modules of your kernel::
25262306a36Sopenharmony_ci
25362306a36Sopenharmony_ci     make -j $(nproc --all)
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci   If you want your kernel packaged up as deb, rpm, or tar file, see the
25662306a36Sopenharmony_ci   reference section for alternatives.
25762306a36Sopenharmony_ci
25862306a36Sopenharmony_ci   [:ref:`details<build>`]
25962306a36Sopenharmony_ci
26062306a36Sopenharmony_ci.. _install_sbs:
26162306a36Sopenharmony_ci
26262306a36Sopenharmony_ci * Now install your kernel::
26362306a36Sopenharmony_ci
26462306a36Sopenharmony_ci     command -v installkernel && sudo make modules_install install
26562306a36Sopenharmony_ci
26662306a36Sopenharmony_ci   Often all left for you to do afterwards is a ``reboot``, as many commodity
26762306a36Sopenharmony_ci   Linux distributions will then create an initramfs (also known as initrd) and
26862306a36Sopenharmony_ci   an entry for your kernel in your bootloader's configuration; but on some
26962306a36Sopenharmony_ci   distributions you have to take care of these two steps manually for reasons
27062306a36Sopenharmony_ci   the reference section explains.
27162306a36Sopenharmony_ci
27262306a36Sopenharmony_ci   On a few distributions like Arch Linux and its derivatives the above command
27362306a36Sopenharmony_ci   does nothing at all; in that case you have to manually install your kernel,
27462306a36Sopenharmony_ci   as outlined in the reference section.
27562306a36Sopenharmony_ci
27662306a36Sopenharmony_ci   If you are running a immutable Linux distribution, check its documentation
27762306a36Sopenharmony_ci   and the web to find out how to install your own kernel there.
27862306a36Sopenharmony_ci
27962306a36Sopenharmony_ci   [:ref:`details<install>`]
28062306a36Sopenharmony_ci
28162306a36Sopenharmony_ci.. _another_sbs:
28262306a36Sopenharmony_ci
28362306a36Sopenharmony_ci * To later build another kernel you need similar steps, but sometimes slightly
28462306a36Sopenharmony_ci   different commands.
28562306a36Sopenharmony_ci
28662306a36Sopenharmony_ci   First, switch back into the sources tree::
28762306a36Sopenharmony_ci
28862306a36Sopenharmony_ci      cd ~/linux/
28962306a36Sopenharmony_ci
29062306a36Sopenharmony_ci   In case you want to build a version from a stable/longterm series you have
29162306a36Sopenharmony_ci   not used yet (say 6.2.y), tell git to track it::
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_ci      git remote set-branches --add origin linux-6.2.y
29462306a36Sopenharmony_ci
29562306a36Sopenharmony_ci   Now fetch the latest upstream changes; you again need to specify the earliest
29662306a36Sopenharmony_ci   version you care about, as git otherwise might retrieve the entire commit
29762306a36Sopenharmony_ci   history::
29862306a36Sopenharmony_ci
29962306a36Sopenharmony_ci     git fetch --shallow-exclude=v6.0 origin
30062306a36Sopenharmony_ci
30162306a36Sopenharmony_ci   Now switch to the version you are interested in -- but be aware the command
30262306a36Sopenharmony_ci   used here will discard any modifications you performed, as they would
30362306a36Sopenharmony_ci   conflict with the sources you want to checkout::
30462306a36Sopenharmony_ci
30562306a36Sopenharmony_ci     git checkout --force --detach origin/master
30662306a36Sopenharmony_ci
30762306a36Sopenharmony_ci   At this point you might want to patch the sources again or set/modify a build
30862306a36Sopenharmony_ci   tag, as explained earlier. Afterwards adjust the build configuration to the
30962306a36Sopenharmony_ci   new codebase using olddefconfig, which will now adjust the configuration file
31062306a36Sopenharmony_ci   you prepared earlier using localmodconfig  (~/linux/.config) for your next
31162306a36Sopenharmony_ci   kernel::
31262306a36Sopenharmony_ci
31362306a36Sopenharmony_ci     # reminder: if you want to apply patches, do it at this point
31462306a36Sopenharmony_ci     # reminder: you might want to update your build tag at this point
31562306a36Sopenharmony_ci     make olddefconfig
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_ci   Now build your kernel::
31862306a36Sopenharmony_ci
31962306a36Sopenharmony_ci     make -j $(nproc --all)
32062306a36Sopenharmony_ci
32162306a36Sopenharmony_ci   Afterwards install the kernel as outlined above::
32262306a36Sopenharmony_ci
32362306a36Sopenharmony_ci     command -v installkernel && sudo make modules_install install
32462306a36Sopenharmony_ci
32562306a36Sopenharmony_ci   [:ref:`details<another>`]
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ci.. _uninstall_sbs:
32862306a36Sopenharmony_ci
32962306a36Sopenharmony_ci * Your kernel is easy to remove later, as its parts are only stored in two
33062306a36Sopenharmony_ci   places and clearly identifiable by the kernel's release name. Just ensure to
33162306a36Sopenharmony_ci   not delete the kernel you are running, as that might render your system
33262306a36Sopenharmony_ci   unbootable.
33362306a36Sopenharmony_ci
33462306a36Sopenharmony_ci   Start by deleting the directory holding your kernel's modules, which is named
33562306a36Sopenharmony_ci   after its release name -- '6.0.1-foobar' in the following example::
33662306a36Sopenharmony_ci
33762306a36Sopenharmony_ci     sudo rm -rf /lib/modules/6.0.1-foobar
33862306a36Sopenharmony_ci
33962306a36Sopenharmony_ci   Now try the following command, which on some distributions will delete all
34062306a36Sopenharmony_ci   other kernel files installed while also removing the kernel's entry from the
34162306a36Sopenharmony_ci   bootloader configuration::
34262306a36Sopenharmony_ci
34362306a36Sopenharmony_ci     command -v kernel-install && sudo kernel-install -v remove 6.0.1-foobar
34462306a36Sopenharmony_ci
34562306a36Sopenharmony_ci   If that command does not output anything or fails, see the reference section;
34662306a36Sopenharmony_ci   do the same if any files named '*6.0.1-foobar*' remain in /boot/.
34762306a36Sopenharmony_ci
34862306a36Sopenharmony_ci   [:ref:`details<uninstall>`]
34962306a36Sopenharmony_ci
35062306a36Sopenharmony_ci.. _submit_improvements:
35162306a36Sopenharmony_ci
35262306a36Sopenharmony_ciDid you run into trouble following any of the above steps that is not cleared up
35362306a36Sopenharmony_ciby the reference section below? Or do you have ideas how to improve the text?
35462306a36Sopenharmony_ciThen please take a moment of your time and let the maintainer of this document
35562306a36Sopenharmony_ciknow by email (Thorsten Leemhuis <linux@leemhuis.info>), ideally while CCing the
35662306a36Sopenharmony_ciLinux docs mailing list (linux-doc@vger.kernel.org). Such feedback is vital to
35762306a36Sopenharmony_ciimprove this document further, which is in everybody's interest, as it will
35862306a36Sopenharmony_cienable more people to master the task described here.
35962306a36Sopenharmony_ci
36062306a36Sopenharmony_ciReference section for the step-by-step guide
36162306a36Sopenharmony_ci============================================
36262306a36Sopenharmony_ci
36362306a36Sopenharmony_ciThis section holds additional information for each of the steps in the above
36462306a36Sopenharmony_ciguide.
36562306a36Sopenharmony_ci
36662306a36Sopenharmony_ci.. _backup:
36762306a36Sopenharmony_ci
36862306a36Sopenharmony_ciPrepare for emergencies
36962306a36Sopenharmony_ci-----------------------
37062306a36Sopenharmony_ci
37162306a36Sopenharmony_ci   *Create a fresh backup and put system repair and restore tools at hand*
37262306a36Sopenharmony_ci   [:ref:`... <backup_sbs>`]
37362306a36Sopenharmony_ci
37462306a36Sopenharmony_ciRemember, you are dealing with computers, which sometimes do unexpected things
37562306a36Sopenharmony_ci-- especially if you fiddle with crucial parts like the kernel of an operating
37662306a36Sopenharmony_cisystem. That's what you are about to do in this process. Hence, better prepare
37762306a36Sopenharmony_cifor something going sideways, even if that should not happen.
37862306a36Sopenharmony_ci
37962306a36Sopenharmony_ci[:ref:`back to step-by-step guide <backup_sbs>`]
38062306a36Sopenharmony_ci
38162306a36Sopenharmony_ci.. _secureboot:
38262306a36Sopenharmony_ci
38362306a36Sopenharmony_ciDealing with techniques like Secure Boot
38462306a36Sopenharmony_ci----------------------------------------
38562306a36Sopenharmony_ci
38662306a36Sopenharmony_ci   *On platforms with 'Secure Boot' or similar techniques, prepare everything to
38762306a36Sopenharmony_ci   ensure the system will permit your self-compiled kernel to boot later.*
38862306a36Sopenharmony_ci   [:ref:`... <secureboot_sbs>`]
38962306a36Sopenharmony_ci
39062306a36Sopenharmony_ciMany modern systems allow only certain operating systems to start; they thus by
39162306a36Sopenharmony_cidefault will reject booting self-compiled kernels.
39262306a36Sopenharmony_ci
39362306a36Sopenharmony_ciYou ideally deal with this by making your platform trust your self-built kernels
39462306a36Sopenharmony_ciwith the help of a certificate and signing. How to do that is not described
39562306a36Sopenharmony_cihere, as it requires various steps that would take the text too far away from
39662306a36Sopenharmony_ciits purpose; 'Documentation/admin-guide/module-signing.rst' and various web
39762306a36Sopenharmony_cisides already explain this in more detail.
39862306a36Sopenharmony_ci
39962306a36Sopenharmony_ciTemporarily disabling solutions like Secure Boot is another way to make your own
40062306a36Sopenharmony_ciLinux boot. On commodity x86 systems it is possible to do this in the BIOS Setup
40162306a36Sopenharmony_ciutility; the steps to do so are not described here, as they greatly vary between
40262306a36Sopenharmony_cimachines.
40362306a36Sopenharmony_ci
40462306a36Sopenharmony_ciOn mainstream x86 Linux distributions there is a third and universal option:
40562306a36Sopenharmony_cidisable all Secure Boot restrictions for your Linux environment. You can
40662306a36Sopenharmony_ciinitiate this process by running ``mokutil --disable-validation``; this will
40762306a36Sopenharmony_citell you to create a one-time password, which is safe to write down. Now
40862306a36Sopenharmony_cirestart; right after your BIOS performed all self-tests the bootloader Shim will
40962306a36Sopenharmony_cishow a blue box with a message 'Press any key to perform MOK management'. Hit
41062306a36Sopenharmony_cisome key before the countdown exposes. This will open a menu and choose 'Change
41162306a36Sopenharmony_ciSecure Boot state' there. Shim's 'MokManager' will now ask you to enter three
41262306a36Sopenharmony_cirandomly chosen characters from the one-time password specified earlier. Once
41362306a36Sopenharmony_ciyou provided them, confirm that you really want to disable the validation.
41462306a36Sopenharmony_ciAfterwards, permit MokManager to reboot the machine.
41562306a36Sopenharmony_ci
41662306a36Sopenharmony_ci[:ref:`back to step-by-step guide <secureboot_sbs>`]
41762306a36Sopenharmony_ci
41862306a36Sopenharmony_ci.. _buildrequires:
41962306a36Sopenharmony_ci
42062306a36Sopenharmony_ciInstall build requirements
42162306a36Sopenharmony_ci--------------------------
42262306a36Sopenharmony_ci
42362306a36Sopenharmony_ci   *Install all software required to build a Linux kernel.*
42462306a36Sopenharmony_ci   [:ref:`...<buildrequires_sbs>`]
42562306a36Sopenharmony_ci
42662306a36Sopenharmony_ciThe kernel is pretty stand-alone, but besides tools like the compiler you will
42762306a36Sopenharmony_cisometimes need a few libraries to build one. How to install everything needed
42862306a36Sopenharmony_cidepends on your Linux distribution and the configuration of the kernel you are
42962306a36Sopenharmony_ciabout to build.
43062306a36Sopenharmony_ci
43162306a36Sopenharmony_ciHere are a few examples what you typically need on some mainstream
43262306a36Sopenharmony_cidistributions:
43362306a36Sopenharmony_ci
43462306a36Sopenharmony_ci * Debian, Ubuntu, and derivatives::
43562306a36Sopenharmony_ci
43662306a36Sopenharmony_ci     sudo apt install bc binutils bison dwarves flex gcc git make openssl \
43762306a36Sopenharmony_ci       pahole perl-base libssl-dev libelf-dev
43862306a36Sopenharmony_ci
43962306a36Sopenharmony_ci * Fedora and derivatives::
44062306a36Sopenharmony_ci
44162306a36Sopenharmony_ci     sudo dnf install binutils /usr/include/{libelf.h,openssl/pkcs7.h} \
44262306a36Sopenharmony_ci       /usr/bin/{bc,bison,flex,gcc,git,openssl,make,perl,pahole}
44362306a36Sopenharmony_ci
44462306a36Sopenharmony_ci * openSUSE and derivatives::
44562306a36Sopenharmony_ci
44662306a36Sopenharmony_ci     sudo zypper install bc binutils bison dwarves flex gcc git make perl-base \
44762306a36Sopenharmony_ci       openssl openssl-devel libelf-dev
44862306a36Sopenharmony_ci
44962306a36Sopenharmony_ciIn case you wonder why these lists include openssl and its development headers:
45062306a36Sopenharmony_cithey are needed for the Secure Boot support, which many distributions enable in
45162306a36Sopenharmony_citheir kernel configuration for x86 machines.
45262306a36Sopenharmony_ci
45362306a36Sopenharmony_ciSometimes you will need tools for compression formats like bzip2, gzip, lz4,
45462306a36Sopenharmony_cilzma, lzo, xz, or zstd as well.
45562306a36Sopenharmony_ci
45662306a36Sopenharmony_ciYou might need additional libraries and their development headers in case you
45762306a36Sopenharmony_ciperform tasks not covered in this guide. For example, zlib will be needed when
45862306a36Sopenharmony_cibuilding kernel tools from the tools/ directory; adjusting the build
45962306a36Sopenharmony_ciconfiguration with make targets like 'menuconfig' or 'xconfig' will require
46062306a36Sopenharmony_cidevelopment headers for ncurses or Qt5.
46162306a36Sopenharmony_ci
46262306a36Sopenharmony_ci[:ref:`back to step-by-step guide <buildrequires_sbs>`]
46362306a36Sopenharmony_ci
46462306a36Sopenharmony_ci.. _diskspace:
46562306a36Sopenharmony_ci
46662306a36Sopenharmony_ciSpace requirements
46762306a36Sopenharmony_ci------------------
46862306a36Sopenharmony_ci
46962306a36Sopenharmony_ci   *Ensure to have enough free space for building and installing Linux.*
47062306a36Sopenharmony_ci   [:ref:`... <diskspace_sbs>`]
47162306a36Sopenharmony_ci
47262306a36Sopenharmony_ciThe numbers mentioned are rough estimates with a big extra charge to be on the
47362306a36Sopenharmony_cisafe side, so often you will need less.
47462306a36Sopenharmony_ci
47562306a36Sopenharmony_ciIf you have space constraints, remember to read the reference section when you
47662306a36Sopenharmony_cireach the :ref:`section about configuration adjustments' <configmods>`, as
47762306a36Sopenharmony_ciensuring debug symbols are disabled will reduce the consumed disk space by quite
47862306a36Sopenharmony_cia few gigabytes.
47962306a36Sopenharmony_ci
48062306a36Sopenharmony_ci[:ref:`back to step-by-step guide <diskspace_sbs>`]
48162306a36Sopenharmony_ci
48262306a36Sopenharmony_ci
48362306a36Sopenharmony_ci.. _sources:
48462306a36Sopenharmony_ci
48562306a36Sopenharmony_ciDownload the sources
48662306a36Sopenharmony_ci--------------------
48762306a36Sopenharmony_ci
48862306a36Sopenharmony_ci  *Retrieve the sources of the Linux version you intend to build.*
48962306a36Sopenharmony_ci  [:ref:`...<sources_sbs>`]
49062306a36Sopenharmony_ci
49162306a36Sopenharmony_ciThe step-by-step guide outlines how to retrieve Linux' sources using a shallow
49262306a36Sopenharmony_cigit clone. There is :ref:`more to tell about this method<sources_shallow>` and
49362306a36Sopenharmony_citwo alternate ways worth describing: :ref:`packaged archives<sources_archive>`
49462306a36Sopenharmony_ciand :ref:`a full git clone<sources_full>`. And the aspects ':ref:`wouldn't it
49562306a36Sopenharmony_cibe wiser to use a proper pre-release than the latest mainline code
49662306a36Sopenharmony_ci<sources_snapshot>`' and ':ref:`how to get an even fresher mainline codebase
49762306a36Sopenharmony_ci<sources_fresher>`' need elaboration, too.
49862306a36Sopenharmony_ci
49962306a36Sopenharmony_ciNote, to keep things simple the commands used in this guide store the build
50062306a36Sopenharmony_ciartifacts in the source tree. If you prefer to separate them, simply add
50162306a36Sopenharmony_cisomething like ``O=~/linux-builddir/`` to all make calls; also adjust the path
50262306a36Sopenharmony_ciin all commands that add files or modify any generated (like your '.config').
50362306a36Sopenharmony_ci
50462306a36Sopenharmony_ci[:ref:`back to step-by-step guide <sources_sbs>`]
50562306a36Sopenharmony_ci
50662306a36Sopenharmony_ci.. _sources_shallow:
50762306a36Sopenharmony_ci
50862306a36Sopenharmony_ciNoteworthy characteristics of shallow clones
50962306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51062306a36Sopenharmony_ci
51162306a36Sopenharmony_ciThe step-by-step guide uses a shallow clone, as it is the best solution for most
51262306a36Sopenharmony_ciof this document's target audience. There are a few aspects of this approach
51362306a36Sopenharmony_ciworth mentioning:
51462306a36Sopenharmony_ci
51562306a36Sopenharmony_ci * This document in most places uses ``git fetch`` with ``--shallow-exclude=``
51662306a36Sopenharmony_ci   to specify the earliest version you care about (or to be precise: its git
51762306a36Sopenharmony_ci   tag). You alternatively can use the parameter ``--shallow-since=`` to specify
51862306a36Sopenharmony_ci   an absolute (say ``'2023-07-15'``) or relative (``'12 months'``) date to
51962306a36Sopenharmony_ci   define the depth of the history you want to download. As a second
52062306a36Sopenharmony_ci   alternative, you can also specify a certain depth explicitly with a parameter
52162306a36Sopenharmony_ci   like ``--depth=1``, unless you add branches for stable/longterm kernels.
52262306a36Sopenharmony_ci
52362306a36Sopenharmony_ci * When running ``git fetch``, remember to always specify the oldest version,
52462306a36Sopenharmony_ci   the time you care about, or an explicit depth as shown in the step-by-step
52562306a36Sopenharmony_ci   guide. Otherwise you will risk downloading nearly the entire git history,
52662306a36Sopenharmony_ci   which will consume quite a bit of time and bandwidth while also stressing the
52762306a36Sopenharmony_ci   servers.
52862306a36Sopenharmony_ci
52962306a36Sopenharmony_ci   Note, you do not have to use the same version or date all the time. But when
53062306a36Sopenharmony_ci   you change it over time, git will deepen or flatten the history to the
53162306a36Sopenharmony_ci   specified point. That allows you to retrieve versions you initially thought
53262306a36Sopenharmony_ci   you did not need -- or it will discard the sources of older versions, for
53362306a36Sopenharmony_ci   example in case you want to free up some disk space. The latter will happen
53462306a36Sopenharmony_ci   automatically when using ``--shallow-since=`` or
53562306a36Sopenharmony_ci   ``--depth=``.
53662306a36Sopenharmony_ci
53762306a36Sopenharmony_ci * Be warned, when deepening your clone you might encounter an error like
53862306a36Sopenharmony_ci   'fatal: error in object: unshallow cafecaca0c0dacafecaca0c0dacafecaca0c0da'.
53962306a36Sopenharmony_ci   In that case run ``git repack -d`` and try again``
54062306a36Sopenharmony_ci
54162306a36Sopenharmony_ci * In case you want to revert changes from a certain version (say Linux 6.3) or
54262306a36Sopenharmony_ci   perform a bisection (v6.2..v6.3), better tell ``git fetch`` to retrieve
54362306a36Sopenharmony_ci   objects up to three versions earlier (e.g. 6.0): ``git describe`` will then
54462306a36Sopenharmony_ci   be able to describe most commits just like it would in a full git clone.
54562306a36Sopenharmony_ci
54662306a36Sopenharmony_ci[:ref:`back to step-by-step guide <sources_sbs>`] [:ref:`back to section intro <sources>`]
54762306a36Sopenharmony_ci
54862306a36Sopenharmony_ci.. _sources_archive:
54962306a36Sopenharmony_ci
55062306a36Sopenharmony_ciDownloading the sources using a packages archive
55162306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55262306a36Sopenharmony_ci
55362306a36Sopenharmony_ciPeople new to compiling Linux often assume downloading an archive via the
55462306a36Sopenharmony_cifront-page of https://kernel.org is the best approach to retrieve Linux'
55562306a36Sopenharmony_cisources. It actually can be, if you are certain to build just one particular
55662306a36Sopenharmony_cikernel version without changing any code. Thing is: you might be sure this will
55762306a36Sopenharmony_cibe the case, but in practice it often will turn out to be a wrong assumption.
55862306a36Sopenharmony_ci
55962306a36Sopenharmony_ciThat's because when reporting or debugging an issue developers will often ask to
56062306a36Sopenharmony_cigive another version a try. They also might suggest temporarily undoing a commit
56162306a36Sopenharmony_ciwith ``git revert`` or might provide various patches to try. Sometimes reporters
56262306a36Sopenharmony_ciwill also be asked to use ``git bisect`` to find the change causing a problem.
56362306a36Sopenharmony_ciThese things rely on git or are a lot easier and quicker to handle with it.
56462306a36Sopenharmony_ci
56562306a36Sopenharmony_ciA shallow clone also does not add any significant overhead. For example, when
56662306a36Sopenharmony_ciyou use ``git clone --depth=1`` to create a shallow clone of the latest mainline
56762306a36Sopenharmony_cicodebase git will only retrieve a little more data than downloading the latest
56862306a36Sopenharmony_cimainline pre-release (aka 'rc') via the front-page of kernel.org would.
56962306a36Sopenharmony_ci
57062306a36Sopenharmony_ciA shallow clone therefore is often the better choice. If you nevertheless want
57162306a36Sopenharmony_cito use a packaged source archive, download one via kernel.org; afterwards
57262306a36Sopenharmony_ciextract its content to some directory and change to the subdirectory created
57362306a36Sopenharmony_ciduring extraction. The rest of the step-by-step guide will work just fine, apart
57462306a36Sopenharmony_cifrom things that rely on git -- but this mainly concerns the section on
57562306a36Sopenharmony_cisuccessive builds of other versions.
57662306a36Sopenharmony_ci
57762306a36Sopenharmony_ci[:ref:`back to step-by-step guide <sources_sbs>`] [:ref:`back to section intro <sources>`]
57862306a36Sopenharmony_ci
57962306a36Sopenharmony_ci.. _sources_full:
58062306a36Sopenharmony_ci
58162306a36Sopenharmony_ciDownloading the sources using a full git clone
58262306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58362306a36Sopenharmony_ci
58462306a36Sopenharmony_ciIf downloading and storing a lot of data (~4,4 Gigabyte as of early 2023) is
58562306a36Sopenharmony_cinothing that bothers you, instead of a shallow clone perform a full git clone
58662306a36Sopenharmony_ciinstead. You then will avoid the specialties mentioned above and will have all
58762306a36Sopenharmony_civersions and individual commits at hand at any time::
58862306a36Sopenharmony_ci
58962306a36Sopenharmony_ci    curl -L \
59062306a36Sopenharmony_ci      https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/clone.bundle \
59162306a36Sopenharmony_ci      -o linux-stable.git.bundle
59262306a36Sopenharmony_ci    git clone linux-stable.git.bundle ~/linux/
59362306a36Sopenharmony_ci    rm linux-stable.git.bundle
59462306a36Sopenharmony_ci    cd ~/linux/
59562306a36Sopenharmony_ci    git remote set-url origin \
59662306a36Sopenharmony_ci      https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
59762306a36Sopenharmony_ci    git fetch origin
59862306a36Sopenharmony_ci    git checkout --detach origin/master
59962306a36Sopenharmony_ci
60062306a36Sopenharmony_ci[:ref:`back to step-by-step guide <sources_sbs>`] [:ref:`back to section intro <sources>`]
60162306a36Sopenharmony_ci
60262306a36Sopenharmony_ci.. _sources_snapshot:
60362306a36Sopenharmony_ci
60462306a36Sopenharmony_ciProper pre-releases (RCs) vs. latest mainline
60562306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60662306a36Sopenharmony_ci
60762306a36Sopenharmony_ciWhen cloning the sources using git and checking out origin/master, you often
60862306a36Sopenharmony_ciwill retrieve a codebase that is somewhere between the latest and the next
60962306a36Sopenharmony_cirelease or pre-release. This almost always is the code you want when giving
61062306a36Sopenharmony_cimainline a shot: pre-releases like v6.1-rc5 are in no way special, as they do
61162306a36Sopenharmony_cinot get any significant extra testing before being published.
61262306a36Sopenharmony_ci
61362306a36Sopenharmony_ciThere is one exception: you might want to stick to the latest mainline release
61462306a36Sopenharmony_ci(say v6.1) before its successor's first pre-release (v6.2-rc1) is out. That is
61562306a36Sopenharmony_cibecause compiler errors and other problems are more likely to occur during this
61662306a36Sopenharmony_citime, as mainline then is in its 'merge window': a usually two week long phase,
61762306a36Sopenharmony_ciin which the bulk of the changes for the next release is merged.
61862306a36Sopenharmony_ci
61962306a36Sopenharmony_ci[:ref:`back to step-by-step guide <sources_sbs>`] [:ref:`back to section intro <sources>`]
62062306a36Sopenharmony_ci
62162306a36Sopenharmony_ci.. _sources_fresher:
62262306a36Sopenharmony_ci
62362306a36Sopenharmony_ciAvoiding the mainline lag
62462306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~
62562306a36Sopenharmony_ci
62662306a36Sopenharmony_ciThe explanations for both the shallow clone and the full clone both retrieve the
62762306a36Sopenharmony_cicode from the Linux stable git repository. That makes things simpler for this
62862306a36Sopenharmony_cidocument's audience, as it allows easy access to both mainline and
62962306a36Sopenharmony_cistable/longterm releases. This approach has just one downside:
63062306a36Sopenharmony_ci
63162306a36Sopenharmony_ciChanges merged into the mainline repository are only synced to the master branch
63262306a36Sopenharmony_ciof the Linux stable repository  every few hours. This lag most of the time is
63362306a36Sopenharmony_cinot something to worry about; but in case you really need the latest code, just
63462306a36Sopenharmony_ciadd the mainline repo as additional remote and checkout the code from there::
63562306a36Sopenharmony_ci
63662306a36Sopenharmony_ci    git remote add mainline \
63762306a36Sopenharmony_ci      https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
63862306a36Sopenharmony_ci    git fetch mainline
63962306a36Sopenharmony_ci    git checkout --detach mainline/master
64062306a36Sopenharmony_ci
64162306a36Sopenharmony_ciWhen doing this with a shallow clone, remember to call ``git fetch`` with one
64262306a36Sopenharmony_ciof the parameters described earlier to limit the depth.
64362306a36Sopenharmony_ci
64462306a36Sopenharmony_ci[:ref:`back to step-by-step guide <sources_sbs>`] [:ref:`back to section intro <sources>`]
64562306a36Sopenharmony_ci
64662306a36Sopenharmony_ci.. _patching:
64762306a36Sopenharmony_ci
64862306a36Sopenharmony_ciPatch the sources (optional)
64962306a36Sopenharmony_ci----------------------------
65062306a36Sopenharmony_ci
65162306a36Sopenharmony_ci  *In case you want to apply a kernel patch, do so now.*
65262306a36Sopenharmony_ci  [:ref:`...<patching_sbs>`]
65362306a36Sopenharmony_ci
65462306a36Sopenharmony_ciThis is the point where you might want to patch your kernel -- for example when
65562306a36Sopenharmony_cia developer proposed a fix and asked you to check if it helps. The step-by-step
65662306a36Sopenharmony_ciguide already explains everything crucial here.
65762306a36Sopenharmony_ci
65862306a36Sopenharmony_ci[:ref:`back to step-by-step guide <patching_sbs>`]
65962306a36Sopenharmony_ci
66062306a36Sopenharmony_ci.. _tagging:
66162306a36Sopenharmony_ci
66262306a36Sopenharmony_ciTagging this kernel build (optional, often wise)
66362306a36Sopenharmony_ci------------------------------------------------
66462306a36Sopenharmony_ci
66562306a36Sopenharmony_ci  *If you patched your kernel or already have that kernel version installed,
66662306a36Sopenharmony_ci  better tag your kernel by extending its release name:*
66762306a36Sopenharmony_ci  [:ref:`...<tagging_sbs>`]
66862306a36Sopenharmony_ci
66962306a36Sopenharmony_ciTagging your kernel will help avoid confusion later, especially when you patched
67062306a36Sopenharmony_ciyour kernel. Adding an individual tag will also ensure the kernel's image and
67162306a36Sopenharmony_ciits modules are installed in parallel to any existing kernels.
67262306a36Sopenharmony_ci
67362306a36Sopenharmony_ciThere are various ways to add such a tag. The step-by-step guide realizes one by
67462306a36Sopenharmony_cicreating a 'localversion' file in your build directory from which the kernel
67562306a36Sopenharmony_cibuild scripts will automatically pick up the tag. You can later change that file
67662306a36Sopenharmony_cito use a different tag in subsequent builds or simply remove that file to dump
67762306a36Sopenharmony_cithe tag.
67862306a36Sopenharmony_ci
67962306a36Sopenharmony_ci[:ref:`back to step-by-step guide <tagging_sbs>`]
68062306a36Sopenharmony_ci
68162306a36Sopenharmony_ci.. _configuration:
68262306a36Sopenharmony_ci
68362306a36Sopenharmony_ciDefine the build configuration for your kernel
68462306a36Sopenharmony_ci----------------------------------------------
68562306a36Sopenharmony_ci
68662306a36Sopenharmony_ci  *Create the build configuration for your kernel based on an existing
68762306a36Sopenharmony_ci  configuration.* [:ref:`... <configuration_sbs>`]
68862306a36Sopenharmony_ci
68962306a36Sopenharmony_ciThere are various aspects for this steps that require a more careful
69062306a36Sopenharmony_ciexplanation:
69162306a36Sopenharmony_ci
69262306a36Sopenharmony_ciPitfalls when using another configuration file as base
69362306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69462306a36Sopenharmony_ci
69562306a36Sopenharmony_ciMake targets like localmodconfig and olddefconfig share a few common snares you
69662306a36Sopenharmony_ciwant to be aware of:
69762306a36Sopenharmony_ci
69862306a36Sopenharmony_ci * These targets will reuse a kernel build configuration in your build directory
69962306a36Sopenharmony_ci   (e.g. '~/linux/.config'), if one exists. In case you want to start from
70062306a36Sopenharmony_ci   scratch you thus need to delete it.
70162306a36Sopenharmony_ci
70262306a36Sopenharmony_ci * The make targets try to find the configuration for your running kernel
70362306a36Sopenharmony_ci   automatically, but might choose poorly. A line like '# using defaults found
70462306a36Sopenharmony_ci   in /boot/config-6.0.7-250.fc36.x86_64' or 'using config:
70562306a36Sopenharmony_ci   '/boot/config-6.0.7-250.fc36.x86_64' tells you which file they picked. If
70662306a36Sopenharmony_ci   that is not the intended one, simply store it as '~/linux/.config'
70762306a36Sopenharmony_ci   before using these make targets.
70862306a36Sopenharmony_ci
70962306a36Sopenharmony_ci * Unexpected things might happen if you try to use a config file prepared for
71062306a36Sopenharmony_ci   one kernel (say v6.0) on an older generation (say v5.15). In that case you
71162306a36Sopenharmony_ci   might want to use a configuration as base which your distribution utilized
71262306a36Sopenharmony_ci   when they used that or an slightly older kernel version.
71362306a36Sopenharmony_ci
71462306a36Sopenharmony_ciInfluencing the configuration
71562306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71662306a36Sopenharmony_ci
71762306a36Sopenharmony_ciThe make target olddefconfig and the ``yes "" |`` used when utilizing
71862306a36Sopenharmony_cilocalmodconfig will set any undefined build options to their default value. This
71962306a36Sopenharmony_ciamong others will disable many kernel features that were introduced after your
72062306a36Sopenharmony_cibase kernel was released.
72162306a36Sopenharmony_ci
72262306a36Sopenharmony_ciIf you want to set these configurations options manually, use ``oldconfig``
72362306a36Sopenharmony_ciinstead of ``olddefconfig`` or omit the ``yes "" |`` when utilizing
72462306a36Sopenharmony_cilocalmodconfig. Then for each undefined configuration option you will be asked
72562306a36Sopenharmony_cihow to proceed. In case you are unsure what to answer, simply hit 'enter' to
72662306a36Sopenharmony_ciapply the default value.
72762306a36Sopenharmony_ci
72862306a36Sopenharmony_ciBig pitfall when using localmodconfig
72962306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73062306a36Sopenharmony_ci
73162306a36Sopenharmony_ciAs explained briefly in the step-by-step guide already: with localmodconfig it
73262306a36Sopenharmony_cican easily happen that your self-built kernel will lack modules for tasks you
73362306a36Sopenharmony_cidid not perform before utilizing this make target. That's because those tasks
73462306a36Sopenharmony_cirequire kernel modules that are normally autoloaded when you perform that task
73562306a36Sopenharmony_cifor the first time; if you didn't perform that task at least once before using
73662306a36Sopenharmony_cilocalmodonfig, the latter will thus assume these modules are superfluous and
73762306a36Sopenharmony_cidisable them.
73862306a36Sopenharmony_ci
73962306a36Sopenharmony_ciYou can try to avoid this by performing typical tasks that often will autoload
74062306a36Sopenharmony_ciadditional kernel modules: start a VM, establish VPN connections, loop-mount a
74162306a36Sopenharmony_ciCD/DVD ISO, mount network shares (CIFS, NFS, ...), and connect all external
74262306a36Sopenharmony_cidevices (2FA keys, headsets, webcams, ...) as well as storage devices with file
74362306a36Sopenharmony_cisystems you otherwise do not utilize (btrfs, ext4, FAT, NTFS, XFS, ...). But it
74462306a36Sopenharmony_ciis hard to think of everything that might be needed -- even kernel developers
74562306a36Sopenharmony_cioften forget one thing or another at this point.
74662306a36Sopenharmony_ci
74762306a36Sopenharmony_ciDo not let that risk bother you, especially when compiling a kernel only for
74862306a36Sopenharmony_citesting purposes: everything typically crucial will be there. And if you forget
74962306a36Sopenharmony_cisomething important you can turn on a missing feature later and quickly run the
75062306a36Sopenharmony_cicommands to compile and install a better kernel.
75162306a36Sopenharmony_ci
75262306a36Sopenharmony_ciBut if you plan to build and use self-built kernels regularly, you might want to
75362306a36Sopenharmony_cireduce the risk by recording which modules your system loads over the course of
75462306a36Sopenharmony_cia few weeks. You can automate this with `modprobed-db
75562306a36Sopenharmony_ci<https://github.com/graysky2/modprobed-db>`_. Afterwards use ``LSMOD=<path>`` to
75662306a36Sopenharmony_cipoint localmodconfig to the list of modules modprobed-db noticed being used::
75762306a36Sopenharmony_ci
75862306a36Sopenharmony_ci    yes "" | make LSMOD="${HOME}"/.config/modprobed.db localmodconfig
75962306a36Sopenharmony_ci
76062306a36Sopenharmony_ciRemote building with localmodconfig
76162306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76262306a36Sopenharmony_ci
76362306a36Sopenharmony_ciIf you want to use localmodconfig to build a kernel for another machine, run
76462306a36Sopenharmony_ci``lsmod > lsmod_foo-machine`` on it and transfer that file to your build host.
76562306a36Sopenharmony_ciNow point the build scripts to the file like this: ``yes "" | make
76662306a36Sopenharmony_ciLSMOD=~/lsmod_foo-machine localmodconfig``. Note, in this case
76762306a36Sopenharmony_ciyou likely want to copy a base kernel configuration from the other machine over
76862306a36Sopenharmony_cias well and place it as .config in your build directory.
76962306a36Sopenharmony_ci
77062306a36Sopenharmony_ci[:ref:`back to step-by-step guide <configuration_sbs>`]
77162306a36Sopenharmony_ci
77262306a36Sopenharmony_ci.. _configmods:
77362306a36Sopenharmony_ci
77462306a36Sopenharmony_ciAdjust build configuration
77562306a36Sopenharmony_ci--------------------------
77662306a36Sopenharmony_ci
77762306a36Sopenharmony_ci   *Check if you might want to or have to adjust some kernel configuration
77862306a36Sopenharmony_ci   options:*
77962306a36Sopenharmony_ci
78062306a36Sopenharmony_ciDepending on your needs you at this point might want or have to adjust some
78162306a36Sopenharmony_cikernel configuration options.
78262306a36Sopenharmony_ci
78362306a36Sopenharmony_ci.. _configmods_debugsymbols:
78462306a36Sopenharmony_ci
78562306a36Sopenharmony_ciDebug symbols
78662306a36Sopenharmony_ci~~~~~~~~~~~~~
78762306a36Sopenharmony_ci
78862306a36Sopenharmony_ci   *Evaluate how you want to handle debug symbols.*
78962306a36Sopenharmony_ci   [:ref:`...<configmods_sbs>`]
79062306a36Sopenharmony_ci
79162306a36Sopenharmony_ciMost users do not need to care about this, it's often fine to leave everything
79262306a36Sopenharmony_cias it is; but you should take a closer look at this, if you might need to decode
79362306a36Sopenharmony_cia stack trace or want to reduce space consumption.
79462306a36Sopenharmony_ci
79562306a36Sopenharmony_ciHaving debug symbols available can be important when your kernel throws a
79662306a36Sopenharmony_ci'panic', 'Oops', 'warning', or 'BUG' later when running, as then you will be
79762306a36Sopenharmony_ciable to find the exact place where the problem occurred in the code. But
79862306a36Sopenharmony_cicollecting and embedding the needed debug information takes time and consumes
79962306a36Sopenharmony_ciquite a bit of space: in late 2022 the build artifacts for a typical x86 kernel
80062306a36Sopenharmony_ciconfigured with localmodconfig consumed around 5 Gigabyte of space with debug
80162306a36Sopenharmony_cisymbols, but less than 1 when they were disabled. The resulting kernel image and
80262306a36Sopenharmony_cithe modules are bigger as well, which increases load times.
80362306a36Sopenharmony_ci
80462306a36Sopenharmony_ciHence, if you want a small kernel and are unlikely to decode a stack trace
80562306a36Sopenharmony_cilater, you might want to disable debug symbols to avoid above downsides::
80662306a36Sopenharmony_ci
80762306a36Sopenharmony_ci    ./scripts/config --file .config -d DEBUG_INFO \
80862306a36Sopenharmony_ci      -d DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT -d DEBUG_INFO_DWARF4 \
80962306a36Sopenharmony_ci      -d DEBUG_INFO_DWARF5 -e CONFIG_DEBUG_INFO_NONE
81062306a36Sopenharmony_ci    make olddefconfig
81162306a36Sopenharmony_ci
81262306a36Sopenharmony_ciYou on the other hand definitely want to enable them, if there is a decent
81362306a36Sopenharmony_cichance that you need to decode a stack trace later (as explained by 'Decode
81462306a36Sopenharmony_cifailure messages' in Documentation/admin-guide/tainted-kernels.rst in more
81562306a36Sopenharmony_cidetail)::
81662306a36Sopenharmony_ci
81762306a36Sopenharmony_ci    ./scripts/config --file .config -d DEBUG_INFO_NONE -e DEBUG_KERNEL
81862306a36Sopenharmony_ci      -e DEBUG_INFO -e DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT -e KALLSYMS -e KALLSYMS_ALL
81962306a36Sopenharmony_ci    make olddefconfig
82062306a36Sopenharmony_ci
82162306a36Sopenharmony_ciNote, many mainstream distributions enable debug symbols in their kernel
82262306a36Sopenharmony_ciconfigurations -- make targets like localmodconfig and olddefconfig thus will
82362306a36Sopenharmony_cioften pick that setting up.
82462306a36Sopenharmony_ci
82562306a36Sopenharmony_ci[:ref:`back to step-by-step guide <configmods_sbs>`]
82662306a36Sopenharmony_ci
82762306a36Sopenharmony_ci.. _configmods_distros:
82862306a36Sopenharmony_ci
82962306a36Sopenharmony_ciDistro specific adjustments
83062306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~
83162306a36Sopenharmony_ci
83262306a36Sopenharmony_ci   *Are you running* [:ref:`... <configmods_sbs>`]
83362306a36Sopenharmony_ci
83462306a36Sopenharmony_ciThe following sections help you to avoid build problems that are known to occur
83562306a36Sopenharmony_ciwhen following this guide on a few commodity distributions.
83662306a36Sopenharmony_ci
83762306a36Sopenharmony_ci**Debian:**
83862306a36Sopenharmony_ci
83962306a36Sopenharmony_ci * Remove a stale reference to a certificate file that would cause your build to
84062306a36Sopenharmony_ci   fail::
84162306a36Sopenharmony_ci
84262306a36Sopenharmony_ci    ./scripts/config --file .config --set-str SYSTEM_TRUSTED_KEYS ''
84362306a36Sopenharmony_ci
84462306a36Sopenharmony_ci   Alternatively, download the needed certificate and make that configuration
84562306a36Sopenharmony_ci   option point to it, as `the Debian handbook explains in more detail
84662306a36Sopenharmony_ci   <https://debian-handbook.info/browse/stable/sect.kernel-compilation.html>`_
84762306a36Sopenharmony_ci   -- or generate your own, as explained in
84862306a36Sopenharmony_ci   Documentation/admin-guide/module-signing.rst.
84962306a36Sopenharmony_ci
85062306a36Sopenharmony_ci[:ref:`back to step-by-step guide <configmods_sbs>`]
85162306a36Sopenharmony_ci
85262306a36Sopenharmony_ci.. _configmods_individual:
85362306a36Sopenharmony_ci
85462306a36Sopenharmony_ciIndividual adjustments
85562306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~
85662306a36Sopenharmony_ci
85762306a36Sopenharmony_ci   *If you want to influence the other aspects of the configuration, do so
85862306a36Sopenharmony_ci   now* [:ref:`... <configmods_sbs>`]
85962306a36Sopenharmony_ci
86062306a36Sopenharmony_ciYou at this point can use a command like ``make menuconfig`` to enable or
86162306a36Sopenharmony_cidisable certain features using a text-based user interface; to use a graphical
86262306a36Sopenharmony_ciconfiguration utilize, use the make target ``xconfig`` or ``gconfig`` instead.
86362306a36Sopenharmony_ciAll of them require development libraries from toolkits they are based on
86462306a36Sopenharmony_ci(ncurses, Qt5, Gtk2); an error message will tell you if something required is
86562306a36Sopenharmony_cimissing.
86662306a36Sopenharmony_ci
86762306a36Sopenharmony_ci[:ref:`back to step-by-step guide <configmods_sbs>`]
86862306a36Sopenharmony_ci
86962306a36Sopenharmony_ci.. _build:
87062306a36Sopenharmony_ci
87162306a36Sopenharmony_ciBuild your kernel
87262306a36Sopenharmony_ci-----------------
87362306a36Sopenharmony_ci
87462306a36Sopenharmony_ci  *Build the image and the modules of your kernel* [:ref:`... <build_sbs>`]
87562306a36Sopenharmony_ci
87662306a36Sopenharmony_ciA lot can go wrong at this stage, but the instructions below will help you help
87762306a36Sopenharmony_ciyourself. Another subsection explains how to directly package your kernel up as
87862306a36Sopenharmony_cideb, rpm or tar file.
87962306a36Sopenharmony_ci
88062306a36Sopenharmony_ciDealing with build errors
88162306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~
88262306a36Sopenharmony_ci
88362306a36Sopenharmony_ciWhen a build error occurs, it might be caused by some aspect of your machine's
88462306a36Sopenharmony_cisetup that often can be fixed quickly; other times though the problem lies in
88562306a36Sopenharmony_cithe code and can only be fixed by a developer. A close examination of the
88662306a36Sopenharmony_cifailure messages coupled with some research on the internet will often tell you
88762306a36Sopenharmony_ciwhich of the two it is. To perform such a investigation, restart the build
88862306a36Sopenharmony_ciprocess like this::
88962306a36Sopenharmony_ci
89062306a36Sopenharmony_ci    make V=1
89162306a36Sopenharmony_ci
89262306a36Sopenharmony_ciThe ``V=1`` activates verbose output, which might be needed to see the actual
89362306a36Sopenharmony_cierror. To make it easier to spot, this command also omits the ``-j $(nproc
89462306a36Sopenharmony_ci--all)`` used earlier to utilize every CPU core in the system for the job -- but
89562306a36Sopenharmony_cithis parallelism also results in some clutter when failures occur.
89662306a36Sopenharmony_ci
89762306a36Sopenharmony_ciAfter a few seconds the build process should run into the error again. Now try
89862306a36Sopenharmony_cito find the most crucial line describing the problem. Then search the internet
89962306a36Sopenharmony_cifor the most important and non-generic section of that line (say 4 to 8 words);
90062306a36Sopenharmony_ciavoid or remove anything that looks remotely system-specific, like your username
90162306a36Sopenharmony_cior local path names like ``/home/username/linux/``. First try your regular
90262306a36Sopenharmony_ciinternet search engine with that string, afterwards search Linux kernel mailing
90362306a36Sopenharmony_cilists via `lore.kernel.org/all/ <https://lore.kernel.org/all/>`_.
90462306a36Sopenharmony_ci
90562306a36Sopenharmony_ciThis most of the time will find something that will explain what is wrong; quite
90662306a36Sopenharmony_cioften one of the hits will provide a solution for your problem, too. If you
90762306a36Sopenharmony_cido not find anything that matches your problem, try again from a different angle
90862306a36Sopenharmony_ciby modifying your search terms or using another line from the error messages.
90962306a36Sopenharmony_ci
91062306a36Sopenharmony_ciIn the end, most trouble you are to run into has likely been encountered and
91162306a36Sopenharmony_cireported by others already. That includes issues where the cause is not your
91262306a36Sopenharmony_cisystem, but lies the code. If you run into one of those, you might thus find a
91362306a36Sopenharmony_cisolution (e.g. a patch) or workaround for your problem, too.
91462306a36Sopenharmony_ci
91562306a36Sopenharmony_ciPackage your kernel up
91662306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~
91762306a36Sopenharmony_ci
91862306a36Sopenharmony_ciThe step-by-step guide uses the default make targets (e.g. 'bzImage' and
91962306a36Sopenharmony_ci'modules' on x86) to build the image and the modules of your kernel, which later
92062306a36Sopenharmony_cisteps of the guide then install. You instead can also directly build everything
92162306a36Sopenharmony_ciand directly package it up by using one of the following targets:
92262306a36Sopenharmony_ci
92362306a36Sopenharmony_ci * ``make -j $(nproc --all) bindeb-pkg`` to generate a deb package
92462306a36Sopenharmony_ci
92562306a36Sopenharmony_ci * ``make -j $(nproc --all) binrpm-pkg`` to generate a rpm package
92662306a36Sopenharmony_ci
92762306a36Sopenharmony_ci * ``make -j $(nproc --all) tarbz2-pkg`` to generate a bz2 compressed tarball
92862306a36Sopenharmony_ci
92962306a36Sopenharmony_ciThis is just a selection of available make targets for this purpose, see
93062306a36Sopenharmony_ci``make help`` for others. You can also use these targets after running
93162306a36Sopenharmony_ci``make -j $(nproc --all)``, as they will pick up everything already built.
93262306a36Sopenharmony_ci
93362306a36Sopenharmony_ciIf you employ the targets to generate deb or rpm packages, ignore the
93462306a36Sopenharmony_cistep-by-step guide's instructions on installing and removing your kernel;
93562306a36Sopenharmony_ciinstead install and remove the packages using the package utility for the format
93662306a36Sopenharmony_ci(e.g. dpkg and rpm) or a package management utility build on top of them (apt,
93762306a36Sopenharmony_ciaptitude, dnf/yum, zypper, ...). Be aware that the packages generated using
93862306a36Sopenharmony_cithese two make targets are designed to work on various distributions utilizing
93962306a36Sopenharmony_cithose formats, they thus will sometimes behave differently than your
94062306a36Sopenharmony_cidistribution's kernel packages.
94162306a36Sopenharmony_ci
94262306a36Sopenharmony_ci[:ref:`back to step-by-step guide <build_sbs>`]
94362306a36Sopenharmony_ci
94462306a36Sopenharmony_ci.. _install:
94562306a36Sopenharmony_ci
94662306a36Sopenharmony_ciInstall your kernel
94762306a36Sopenharmony_ci-------------------
94862306a36Sopenharmony_ci
94962306a36Sopenharmony_ci  *Now install your kernel* [:ref:`... <install_sbs>`]
95062306a36Sopenharmony_ci
95162306a36Sopenharmony_ciWhat you need to do after executing the command in the step-by-step guide
95262306a36Sopenharmony_cidepends on the existence and the implementation of an ``installkernel``
95362306a36Sopenharmony_ciexecutable. Many commodity Linux distributions ship such a kernel installer in
95462306a36Sopenharmony_ci``/sbin/`` that does everything needed, hence there is nothing left for you
95562306a36Sopenharmony_ciexcept rebooting. But some distributions contain an installkernel that does
95662306a36Sopenharmony_cionly part of the job -- and a few lack it completely and leave all the work to
95762306a36Sopenharmony_ciyou.
95862306a36Sopenharmony_ci
95962306a36Sopenharmony_ciIf ``installkernel`` is found, the kernel's build system will delegate the
96062306a36Sopenharmony_ciactual installation of your kernel's image and related files to this executable.
96162306a36Sopenharmony_ciOn almost all Linux distributions it will store the image as '/boot/vmlinuz-
96262306a36Sopenharmony_ci<your kernel's release name>' and put a 'System.map-<your kernel's release
96362306a36Sopenharmony_ciname>' alongside it. Your kernel will thus be installed in parallel to any
96462306a36Sopenharmony_ciexisting ones, unless you already have one with exactly the same release name.
96562306a36Sopenharmony_ci
96662306a36Sopenharmony_ciInstallkernel on many distributions will afterwards generate an 'initramfs'
96762306a36Sopenharmony_ci(often also called 'initrd'), which commodity distributions rely on for booting;
96862306a36Sopenharmony_cihence be sure to keep the order of the two make targets used in the step-by-step
96962306a36Sopenharmony_ciguide, as things will go sideways if you install your kernel's image before its
97062306a36Sopenharmony_cimodules. Often installkernel will then add your kernel to the bootloader
97162306a36Sopenharmony_ciconfiguration, too. You have to take care of one or both of these tasks
97262306a36Sopenharmony_ciyourself, if your distributions installkernel doesn't handle them.
97362306a36Sopenharmony_ci
97462306a36Sopenharmony_ciA few distributions like Arch Linux and its derivatives totally lack an
97562306a36Sopenharmony_ciinstallkernel executable. On those just install the modules using the kernel's
97662306a36Sopenharmony_cibuild system and then install the image and the System.map file manually::
97762306a36Sopenharmony_ci
97862306a36Sopenharmony_ci     sudo make modules_install
97962306a36Sopenharmony_ci     sudo install -m 0600 $(make -s image_name) /boot/vmlinuz-$(make -s kernelrelease)
98062306a36Sopenharmony_ci     sudo install -m 0600 System.map /boot/System.map-$(make -s kernelrelease)
98162306a36Sopenharmony_ci
98262306a36Sopenharmony_ciIf your distribution boots with the help of an initramfs, now generate one for
98362306a36Sopenharmony_ciyour kernel using the tools your distribution provides for this process.
98462306a36Sopenharmony_ciAfterwards add your kernel to your bootloader configuration and reboot.
98562306a36Sopenharmony_ci
98662306a36Sopenharmony_ci[:ref:`back to step-by-step guide <install_sbs>`]
98762306a36Sopenharmony_ci
98862306a36Sopenharmony_ci.. _another:
98962306a36Sopenharmony_ci
99062306a36Sopenharmony_ciAnother round later
99162306a36Sopenharmony_ci-------------------
99262306a36Sopenharmony_ci
99362306a36Sopenharmony_ci  *To later build another kernel you need similar, but sometimes slightly
99462306a36Sopenharmony_ci  different commands* [:ref:`... <another_sbs>`]
99562306a36Sopenharmony_ci
99662306a36Sopenharmony_ciThe process to build later kernels is similar, but at some points slightly
99762306a36Sopenharmony_cidifferent. You for example do not want to use 'localmodconfig' for succeeding
99862306a36Sopenharmony_cikernel builds, as you already created a trimmed down configuration you want to
99962306a36Sopenharmony_ciuse from now on. Hence instead just use ``oldconfig`` or ``olddefconfig`` to
100062306a36Sopenharmony_ciadjust your build configurations to the needs of the kernel version you are
100162306a36Sopenharmony_ciabout to build.
100262306a36Sopenharmony_ci
100362306a36Sopenharmony_ciIf you created a shallow-clone with git, remember what the :ref:`section that
100462306a36Sopenharmony_ciexplained the setup described in more detail <sources>`: you need to use a
100562306a36Sopenharmony_cislightly different ``git fetch`` command and when switching to another series
100662306a36Sopenharmony_cineed to add an additional remote branch.
100762306a36Sopenharmony_ci
100862306a36Sopenharmony_ci[:ref:`back to step-by-step guide <another_sbs>`]
100962306a36Sopenharmony_ci
101062306a36Sopenharmony_ci.. _uninstall:
101162306a36Sopenharmony_ci
101262306a36Sopenharmony_ciUninstall the kernel later
101362306a36Sopenharmony_ci--------------------------
101462306a36Sopenharmony_ci
101562306a36Sopenharmony_ci  *All parts of your installed kernel are identifiable by its release name and
101662306a36Sopenharmony_ci  thus easy to remove later.* [:ref:`... <uninstall_sbs>`]
101762306a36Sopenharmony_ci
101862306a36Sopenharmony_ciDo not worry installing your kernel manually and thus bypassing your
101962306a36Sopenharmony_cidistribution's packaging system will totally mess up your machine: all parts of
102062306a36Sopenharmony_ciyour kernel are easy to remove later, as files are stored in two places only and
102162306a36Sopenharmony_cinormally identifiable by the kernel's release name.
102262306a36Sopenharmony_ci
102362306a36Sopenharmony_ciOne of the two places is a directory in /lib/modules/, which holds the modules
102462306a36Sopenharmony_cifor each installed kernel. This directory is named after the kernel's release
102562306a36Sopenharmony_ciname; hence, to remove all modules for one of your kernels, simply remove its
102662306a36Sopenharmony_cimodules directory in /lib/modules/.
102762306a36Sopenharmony_ci
102862306a36Sopenharmony_ciThe other place is /boot/, where typically one to five files will be placed
102962306a36Sopenharmony_ciduring installation of a kernel. All of them usually contain the release name in
103062306a36Sopenharmony_citheir file name, but how many files and their name depends somewhat on your
103162306a36Sopenharmony_cidistribution's installkernel executable (:ref:`see above <install>`) and its
103262306a36Sopenharmony_ciinitramfs generator. On some distributions the ``kernel-install`` command
103362306a36Sopenharmony_cimentioned in the step-by-step guide will remove all of these files for you --
103462306a36Sopenharmony_ciand the entry for your kernel in the bootloader configuration at the same time,
103562306a36Sopenharmony_citoo. On others you have to take care of these steps yourself. The following
103662306a36Sopenharmony_cicommand should interactively remove the two main files of a kernel with the
103762306a36Sopenharmony_cirelease name '6.0.1-foobar'::
103862306a36Sopenharmony_ci
103962306a36Sopenharmony_ci    rm -i /boot/{System.map,vmlinuz}-6.0.1-foobar
104062306a36Sopenharmony_ci
104162306a36Sopenharmony_ciNow remove the belonging initramfs, which often will be called something like
104262306a36Sopenharmony_ci``/boot/initramfs-6.0.1-foobar.img`` or ``/boot/initrd.img-6.0.1-foobar``.
104362306a36Sopenharmony_ciAfterwards check for other files in /boot/ that have '6.0.1-foobar' in their
104462306a36Sopenharmony_ciname and delete them as well. Now remove the kernel from your bootloader's
104562306a36Sopenharmony_ciconfiguration.
104662306a36Sopenharmony_ci
104762306a36Sopenharmony_ciNote, be very careful with wildcards like '*' when deleting files or directories
104862306a36Sopenharmony_cifor kernels manually: you might accidentally remove files of a 6.0.11 kernel
104962306a36Sopenharmony_ciwhen all you want is to remove 6.0 or 6.0.1.
105062306a36Sopenharmony_ci
105162306a36Sopenharmony_ci[:ref:`back to step-by-step guide <uninstall_sbs>`]
105262306a36Sopenharmony_ci
105362306a36Sopenharmony_ci.. _faq:
105462306a36Sopenharmony_ci
105562306a36Sopenharmony_ciFAQ
105662306a36Sopenharmony_ci===
105762306a36Sopenharmony_ci
105862306a36Sopenharmony_ciWhy does this 'how-to' not work on my system?
105962306a36Sopenharmony_ci---------------------------------------------
106062306a36Sopenharmony_ci
106162306a36Sopenharmony_ciAs initially stated, this guide is 'designed to cover everything typically
106262306a36Sopenharmony_cineeded [to build a kernel] on mainstream Linux distributions running on
106362306a36Sopenharmony_cicommodity PC or server hardware'. The outlined approach despite this should work
106462306a36Sopenharmony_cion many other setups as well. But trying to cover every possible use-case in one
106562306a36Sopenharmony_ciguide would defeat its purpose, as without such a focus you would need dozens or
106662306a36Sopenharmony_cihundreds of constructs along the lines of 'in case you are having <insert
106762306a36Sopenharmony_cimachine or distro>, you at this point have to do <this and that>
106862306a36Sopenharmony_ci<instead|additionally>'. Each of which would make the text longer, more
106962306a36Sopenharmony_cicomplicated, and harder to follow.
107062306a36Sopenharmony_ci
107162306a36Sopenharmony_ciThat being said: this of course is a balancing act. Hence, if you think an
107262306a36Sopenharmony_ciadditional use-case is worth describing, suggest it to the maintainers of this
107362306a36Sopenharmony_cidocument, as :ref:`described above <submit_improvements>`.
107462306a36Sopenharmony_ci
107562306a36Sopenharmony_ci
107662306a36Sopenharmony_ci..
107762306a36Sopenharmony_ci   end-of-content
107862306a36Sopenharmony_ci..
107962306a36Sopenharmony_ci   This document is maintained by Thorsten Leemhuis <linux@leemhuis.info>. If
108062306a36Sopenharmony_ci   you spot a typo or small mistake, feel free to let him know directly and
108162306a36Sopenharmony_ci   he'll fix it. You are free to do the same in a mostly informal way if you
108262306a36Sopenharmony_ci   want to contribute changes to the text -- but for copyright reasons please CC
108362306a36Sopenharmony_ci   linux-doc@vger.kernel.org and 'sign-off' your contribution as
108462306a36Sopenharmony_ci   Documentation/process/submitting-patches.rst explains in the section 'Sign
108562306a36Sopenharmony_ci   your work - the Developer's Certificate of Origin'.
108662306a36Sopenharmony_ci..
108762306a36Sopenharmony_ci   This text is available under GPL-2.0+ or CC-BY-4.0, as stated at the top
108862306a36Sopenharmony_ci   of the file. If you want to distribute this text under CC-BY-4.0 only,
108962306a36Sopenharmony_ci   please use 'The Linux kernel development community' for author attribution
109062306a36Sopenharmony_ci   and link this as source:
109162306a36Sopenharmony_ci   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/Documentation/admin-guide/quickly-build-trimmed-linux.rst
109262306a36Sopenharmony_ci..
109362306a36Sopenharmony_ci   Note: Only the content of this RST file as found in the Linux kernel sources
109462306a36Sopenharmony_ci   is available under CC-BY-4.0, as versions of this text that were processed
109562306a36Sopenharmony_ci   (for example by the kernel's build system) might contain content taken from
109662306a36Sopenharmony_ci   files which use a more restrictive license.
109762306a36Sopenharmony_ci
1098