xref: /linux/Documentation/admin-guide/verify-bugs-and-bisect-regressions.rst (revision 8b6d678fede700db6466d73f11fcbad496fa515e)
1.. SPDX-License-Identifier: (GPL-2.0+ OR CC-BY-4.0)
2.. [see the bottom of this file for redistribution information]
3
4=========================================
5How to verify bugs and bisect regressions
6=========================================
7
8This document describes how to check if some Linux kernel problem occurs in code
9currently supported by developers -- to then explain how to locate the change
10causing the issue, if it is a regression (e.g. did not happen with earlier
11versions).
12
13The text aims at people running kernels from mainstream Linux distributions on
14commodity hardware who want to report a kernel bug to the upstream Linux
15developers. Despite this intent, the instructions work just as well for users
16who are already familiar with building their own kernels: they help avoid
17mistakes occasionally made even by experienced developers.
18
19..
20   Note: if you see this note, you are reading the text's source file. You
21   might want to switch to a rendered version: it makes it a lot easier to
22   read and navigate this document -- especially when you want to look something
23   up in the reference section, then jump back to where you left off.
24..
25   Find the latest rendered version of this text here:
26   https://docs.kernel.org/admin-guide/verify-bugs-and-bisect-regressions.rst.html
27
28The essence of the process (aka 'TL;DR')
29========================================
30
31*[If you are new to building or bisecting Linux, ignore this section and head
32over to the* ":ref:`step-by-step guide<introguide_bissbs>`" *below. It utilizes
33the same commands as this section while describing them in brief fashion. The
34steps are nevertheless easy to follow and together with accompanying entries
35in a reference section mention many alternatives, pitfalls, and additional
36aspects, all of which might be essential in your present case.]*
37
38**In case you want to check if a bug is present in code currently supported by
39developers**, execute just the *preparations* and *segment 1*; while doing so,
40consider the newest Linux kernel you regularly use to be the 'working' kernel.
41In the following example that's assumed to be 6.0.13, which is why the sources
42of 6.0 will be used to prepare the .config file.
43
44**In case you face a regression**, follow the steps at least till the end of
45*segment 2*. Then you can submit a preliminary report -- or continue with
46*segment 3*, which describes how to perform a bisection needed for a
47full-fledged regression report. In the following example 6.0.13 is assumed to be
48the 'working' kernel and 6.1.5 to be the first 'broken', which is why 6.0
49will be considered the 'good' release and used to prepare the .config file.
50
51* **Preparations**: set up everything to build your own kernels::
52
53    # * Remove any software that depends on externally maintained kernel modules
54    #   or builds any automatically during bootup.
55    # * Ensure Secure Boot permits booting self-compiled Linux kernels.
56    # * If you are not already running the 'working' kernel, reboot into it.
57    # * Install compilers and everything else needed for building Linux.
58    # * Ensure to have 15 Gigabyte free space in your home directory.
59    git clone -o mainline --no-checkout \
60      https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git ~/linux/
61    cd ~/linux/
62    git remote add -t master stable \
63      https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
64    git checkout --detach v6.0
65    # * Hint: if you used an existing clone, ensure no stale .config is around.
66    make olddefconfig
67    # * Ensure the former command picked the .config of the 'working' kernel.
68    # * Connect external hardware (USB keys, tokens, ...), start a VM, bring up
69    #   VPNs, mount network shares, and briefly try the feature that is broken.
70    yes '' | make localmodconfig
71    ./scripts/config --set-str CONFIG_LOCALVERSION '-local'
72    ./scripts/config -e CONFIG_LOCALVERSION_AUTO
73    # * Note, when short on storage space, check the guide for an alternative:
74    ./scripts/config -d DEBUG_INFO_NONE -e KALLSYMS_ALL -e DEBUG_KERNEL \
75      -e DEBUG_INFO -e DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT -e KALLSYMS
76    # * Hint: at this point you might want to adjust the build configuration;
77    #   you'll have to, if you are running Debian.
78    make olddefconfig
79    cp .config ~/kernel-config-working
80
81* **Segment 1**: build a kernel from the latest mainline codebase.
82
83  This among others checks if the problem was fixed already and which developers
84  later need to be told about the problem; in case of a regression, this rules
85  out a .config change as root of the problem.
86
87  a) Checking out latest mainline code::
88
89       cd ~/linux/
90       git checkout --force --detach mainline/master
91
92  b) Build, install, and boot a kernel::
93
94       cp ~/kernel-config-working .config
95       make olddefconfig
96       make -j $(nproc --all)
97       # * Make sure there is enough disk space to hold another kernel:
98       df -h /boot/ /lib/modules/
99       # * Note: on Arch Linux, its derivatives and a few other distributions
100       #   the following commands will do nothing at all or only part of the
101       #   job. See the step-by-step guide for further details.
102       sudo make modules_install
103       command -v installkernel && sudo make install
104       # * Check how much space your self-built kernel actually needs, which
105       #   enables you to make better estimates later:
106       du -ch /boot/*$(make -s kernelrelease)* | tail -n 1
107       du -sh /lib/modules/$(make -s kernelrelease)/
108       # * Hint: the output of the following command will help you pick the
109       #   right kernel from the boot menu:
110       make -s kernelrelease | tee -a ~/kernels-built
111       reboot
112       # * Once booted, ensure you are running the kernel you just built by
113       #   checking if the output of the next two commands matches:
114       tail -n 1 ~/kernels-built
115       uname -r
116       cat /proc/sys/kernel/tainted
117
118  c) Check if the problem occurs with this kernel as well.
119
120* **Segment 2**: ensure the 'good' kernel is also a 'working' kernel.
121
122  This among others verifies the trimmed .config file actually works well, as
123  bisecting with it otherwise would be a waste of time:
124
125  a) Start by checking out the sources of the 'good' version::
126
127       cd ~/linux/
128       git checkout --force --detach v6.0
129
130  b) Build, install, and boot a kernel as described earlier in *segment 1,
131     section b* -- just feel free to skip the 'du' commands, as you have a rough
132     estimate already.
133
134  c) Ensure the feature that regressed with the 'broken' kernel actually works
135     with this one.
136
137* **Segment 3**: perform and validate the bisection.
138
139  a) In case your 'broken' version is a stable/longterm release, add the Git
140     branch holding it::
141
142       git remote set-branches --add stable linux-6.1.y
143       git fetch stable
144
145  b) Initialize the bisection::
146
147       cd ~/linux/
148       git bisect start
149       git bisect good v6.0
150       git bisect bad v6.1.5
151
152  c) Build, install, and boot a kernel as described earlier in *segment 1,
153     section b*.
154
155     In case building or booting the kernel fails for unrelated reasons, run
156     ``git bisect skip``. In all other outcomes, check if the regressed feature
157     works with the newly built kernel. If it does, tell Git by executing
158     ``git bisect good``; if it does not, run ``git bisect bad`` instead.
159
160     All three commands will make Git checkout another commit; then re-execute
161     this step (e.g. build, install, boot, and test a kernel to then tell Git
162     the outcome). Do so again and again until Git shows which commit broke
163     things. If you run short of disk space during this process, check the
164     "Supplementary tasks" section below.
165
166  d) Once your finished the bisection, put a few things away::
167
168       cd ~/linux/
169       git bisect log > ~/bisect-log
170       cp .config ~/bisection-config-culprit
171       git bisect reset
172
173  e) Try to verify the bisection result::
174
175       git checkout --force --detach mainline/master
176       git revert --no-edit cafec0cacaca0
177
178    This is optional, as some commits are impossible to revert. But if the
179    second command worked flawlessly, build, install, and boot one more kernel
180    kernel, which should not show the regression.
181
182* **Supplementary tasks**: cleanup during and after the process.
183
184  a) To avoid running out of disk space during a bisection, you might need to
185     remove some kernels you built earlier. You most likely want to keep those
186     you built during segment 1 and 2 around for a while, but you will most
187     likely no longer need kernels tested during the actual bisection
188     (Segment 3 c). You can list them in build order using::
189
190       ls -ltr /lib/modules/*-local*
191
192    To then for example erase a kernel that identifies itself as
193    '6.0-rc1-local-gcafec0cacaca0', use this::
194
195       sudo rm -rf /lib/modules/6.0-rc1-local-gcafec0cacaca0
196       sudo kernel-install -v remove 6.0-rc1-local-gcafec0cacaca0
197       # * Note, on some distributions kernel-install is missing
198       #   or does only part of the job.
199
200  b) If you performed a bisection and successfully validated the result, feel
201     free to remove all kernels built during the actual bisection (Segment 3 c);
202     the kernels you built earlier and later you might want to keep around for
203     a week or two.
204
205.. _introguide_bissbs:
206
207Step-by-step guide on how to verify bugs and bisect regressions
208===============================================================
209
210This guide describes how to set up your own Linux kernels for investigating bugs
211or regressions you intent to report. How far you want to follow the instructions
212depends on your issue:
213
214Execute all steps till the end of *segment 1* to **verify if your kernel problem
215is present in code supported by Linux kernel developers**. If it is, you are all
216set to report the bug -- unless it did not happen with earlier kernel versions,
217as then your want to at least continue with *segment 2* to **check if the issue
218qualifies as regression** which receive priority treatment. Depending on the
219outcome you then are ready to report a bug or submit a preliminary regression
220report; instead of the latter your could also head straight on and follow
221*segment 3* to **perform a bisection** for a full-fledged regression report
222developers are obliged to act upon.
223
224 :ref:`Preparations: set up everything to build your own kernels.<introprep_bissbs>`
225
226 :ref:`Segment 1: try to reproduce the problem with the latest codebase.<introlatestcheck_bissbs>`
227
228 :ref:`Segment 2: check if the kernels you build work fine.<introworkingcheck_bissbs>`
229
230 :ref:`Segment 3: perform a bisection and validate the result.<introbisect_bissbs>`
231
232 :ref:`Supplementary tasks: cleanup during and after following this guide.<introclosure_bissbs>`
233
234The steps in each segment illustrate the important aspects of the process, while
235a comprehensive reference section holds additional details for almost all of the
236steps. The reference section sometimes also outlines alternative approaches,
237pitfalls, as well as problems that might occur at the particular step -- and how
238to get things rolling again.
239
240For further details on how to report Linux kernel issues or regressions check
241out Documentation/admin-guide/reporting-issues.rst, which works in conjunction
242with this document. It among others explains why you need to verify bugs with
243the latest 'mainline' kernel, even if you face a problem with a kernel from a
244'stable/longterm' series; for users facing a regression it also explains that
245sending a preliminary report after finishing segment 2 might be wise, as the
246regression and its culprit might be known already. For further details on
247what actually qualifies as a regression check out
248Documentation/admin-guide/reporting-regressions.rst.
249
250.. _introprep_bissbs:
251
252Preparations: set up everything to build your own kernels
253---------------------------------------------------------
254
255.. _backup_bissbs:
256
257* Create a fresh backup and put system repair and restore tools at hand, just
258  to be prepared for the unlikely case of something going sideways.
259
260  [:ref:`details<backup_bisref>`]
261
262.. _vanilla_bissbs:
263
264* Remove all software that depends on externally developed kernel drivers or
265  builds them automatically. That includes but is not limited to DKMS, openZFS,
266  VirtualBox, and Nvidia's graphics drivers (including the GPLed kernel module).
267
268  [:ref:`details<vanilla_bisref>`]
269
270.. _secureboot_bissbs:
271
272* On platforms with 'Secure Boot' or similar solutions, prepare everything to
273  ensure the system will permit your self-compiled kernel to boot. The
274  quickest and easiest way to achieve this on commodity x86 systems is to
275  disable such techniques in the BIOS setup utility; alternatively, remove
276  their restrictions through a process initiated by
277  ``mokutil --disable-validation``.
278
279  [:ref:`details<secureboot_bisref>`]
280
281.. _rangecheck_bissbs:
282
283* Determine the kernel versions considered 'good' and 'bad' throughout this
284  guide.
285
286  Do you follow this guide to verify if a bug is present in the code developers
287  care for? Then consider the mainline release your 'working' kernel (the newest
288  one you regularly use) is based on to be the 'good' version; if your 'working'
289  kernel for example is 6.0.11, then your 'good' kernel is 6.0.
290
291  In case you face a regression, it depends on the version range where the
292  regression was introduced:
293
294  * Something which used to work in Linux 6.0 broke when switching to Linux
295    6.1-rc1? Then henceforth regard 6.0 as the last known 'good' version
296    and 6.1-rc1 as the first 'bad' one.
297
298  * Some function stopped working when updating from 6.0.11 to 6.1.4? Then for
299    the time being consider 6.0 as the last 'good' version and 6.1.4 as
300    the 'bad' one. Note, at this point it is merely assumed that 6.0 is fine;
301    this assumption will be checked in segment 2.
302
303  * A feature you used in 6.0.11 does not work at all or worse in 6.1.13? In
304    that case you want to bisect within a stable/longterm series: consider
305    6.0.11 as the last known 'good' version and 6.0.13 as the first 'bad'
306    one. Note, in this case you still want to compile and test a mainline kernel
307    as explained in segment 1: the outcome will determine if you need to report
308    your issue to the regular developers or the stable team.
309
310  *Note, do not confuse 'good' version with 'working' kernel; the latter term
311  throughout this guide will refer to the last kernel that has been working
312  fine.*
313
314  [:ref:`details<rangecheck_bisref>`]
315
316.. _bootworking_bissbs:
317
318* Boot into the 'working' kernel and briefly use the apparently broken feature.
319
320  [:ref:`details<bootworking_bisref>`]
321
322.. _diskspace_bissbs:
323
324* Ensure to have enough free space for building Linux. 15 Gigabyte in your home
325  directory should typically suffice. If you have less available, be sure to pay
326  attention to later steps about retrieving the Linux sources and handling of
327  debug symbols: both explain approaches reducing the amount of space, which
328  should allow you to master these tasks with about 4 Gigabytes free space.
329
330  [:ref:`details<diskspace_bisref>`]
331
332.. _buildrequires_bissbs:
333
334* Install all software required to build a Linux kernel. Often you will need:
335  'bc', 'binutils' ('ld' et al.), 'bison', 'flex', 'gcc', 'git', 'openssl',
336  'pahole', 'perl', and the development headers for 'libelf' and 'openssl'. The
337  reference section shows how to quickly install those on various popular Linux
338  distributions.
339
340  [:ref:`details<buildrequires_bisref>`]
341
342.. _sources_bissbs:
343
344* Retrieve the mainline Linux sources; then change into the directory holding
345  them, as all further commands in this guide are meant to be executed from
346  there.
347
348  *Note, the following describe how to retrieve the sources using a full
349  mainline clone, which downloads about 2,75 GByte as of early 2024. The*
350  :ref:`reference section describes two alternatives <sources_bisref>` *:
351  one downloads less than 500 MByte, the other works better with unreliable
352  internet connections.*
353
354  Execute the following command to retrieve a fresh mainline codebase while
355  preparing things to add branches for stable/longterm series later::
356
357    git clone -o mainline --no-checkout \
358      https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git ~/linux/
359    cd ~/linux/
360    git remote add -t master stable \
361      https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
362
363  [:ref:`details<sources_bisref>`]
364
365.. _oldconfig_bissbs:
366
367* Start preparing a kernel build configuration (the '.config' file).
368
369  Before doing so, ensure you are still running the 'working' kernel an earlier
370  step told you to boot; if you are unsure, check the current kernel release
371  identifier using ``uname -r``.
372
373  Afterwards check out the source code for the version earlier established as
374  'good'. In the following example command this is assumed to be 6.0; note that
375  the version number in this and all later Git commands needs to be prefixed
376  with a 'v'::
377
378    git checkout --detach v6.0
379
380  Now create a build configuration file::
381
382    make olddefconfig
383
384  The kernel build scripts then will try to locate the build configuration file
385  for the running kernel and then adjust it for the needs of the kernel sources
386  you checked out. While doing so, it will print a few lines you need to check.
387
388  Look out for a line starting with '# using defaults found in'. It should be
389  followed by a path to a file in '/boot/' that contains the release identifier
390  of your currently working kernel. If the line instead continues with something
391  like 'arch/x86/configs/x86_64_defconfig', then the build infra failed to find
392  the .config file for your running kernel -- in which case you have to put one
393  there manually, as explained in the reference section.
394
395  In case you can not find such a line, look for one containing '# configuration
396  written to .config'. If that's the case you have a stale build configuration
397  lying around. Unless you intend to use it, delete it; afterwards run
398  'make olddefconfig' again and check if it now picked up the right config file
399  as base.
400
401  [:ref:`details<oldconfig_bisref>`]
402
403.. _localmodconfig_bissbs:
404
405* Disable any kernel modules apparently superfluous for your setup. This is
406  optional, but especially wise for bisections, as it speeds up the build
407  process enormously -- at least unless the .config file picked up in the
408  previous step was already tailored to your and your hardware needs, in which
409  case you should skip this step.
410
411  To prepare the trimming, connect external hardware you occasionally use (USB
412  keys, tokens, ...), quickly start a VM, and bring up VPNs. And if you rebooted
413  since you started that guide, ensure that you tried using the feature causing
414  trouble since you started the system. Only then trim your .config::
415
416     yes '' | make localmodconfig
417
418  There is a catch to this, as the 'apparently' in initial sentence of this step
419  and the preparation instructions already hinted at:
420
421  The 'localmodconfig' target easily disables kernel modules for features only
422  used occasionally -- like modules for external peripherals not yet connected
423  since booting, virtualization software not yet utilized, VPN tunnels, and a
424  few other things. That's because some tasks rely on kernel modules Linux only
425  loads when you execute tasks like the aforementioned ones for the first time.
426
427  This drawback of localmodconfig is nothing you should lose sleep over, but
428  something to keep in mind: if something is misbehaving with the kernels built
429  during this guide, this is most likely the reason. You can reduce or nearly
430  eliminate the risk with tricks outlined in the reference section; but when
431  building a kernel just for quick testing purposes this is usually not worth
432  spending much effort on, as long as it boots and allows to properly test the
433  feature that causes trouble.
434
435  [:ref:`details<localmodconfig_bisref>`]
436
437.. _tagging_bissbs:
438
439* Ensure all the kernels you will build are clearly identifiable using a special
440  tag and a unique version number::
441
442    ./scripts/config --set-str CONFIG_LOCALVERSION '-local'
443    ./scripts/config -e CONFIG_LOCALVERSION_AUTO
444
445  [:ref:`details<tagging_bisref>`]
446
447.. _debugsymbols_bissbs:
448
449* Decide how to handle debug symbols.
450
451  In the context of this document it is often wise to enable them, as there is a
452  decent chance you will need to decode a stack trace from a 'panic', 'Oops',
453  'warning', or 'BUG'::
454
455    ./scripts/config -d DEBUG_INFO_NONE -e KALLSYMS_ALL -e DEBUG_KERNEL \
456      -e DEBUG_INFO -e DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT -e KALLSYMS
457
458  But if you are extremely short on storage space, you might want to disable
459  debug symbols instead::
460
461    ./scripts/config -d DEBUG_INFO -d DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT \
462      -d DEBUG_INFO_DWARF4 -d DEBUG_INFO_DWARF5 -e CONFIG_DEBUG_INFO_NONE
463
464  [:ref:`details<debugsymbols_bisref>`]
465
466.. _configmods_bissbs:
467
468* Check if you may want or need to adjust some other kernel configuration
469  options:
470
471  * Are you running Debian? Then you want to avoid known problems by performing
472    additional adjustments explained in the reference section.
473
474    [:ref:`details<configmods_distros_bisref>`].
475
476  * If you want to influence other aspects of the configuration, do so now using
477    your preferred tool. Note, to use make targets like 'menuconfig' or
478    'nconfig', you will need to install the development files of ncurses; for
479    'xconfig' you likewise need the Qt5 or Qt6 headers.
480
481    [:ref:`details<configmods_individual_bisref>`].
482
483.. _saveconfig_bissbs:
484
485* Reprocess the .config after the latest adjustments and store it in a safe
486  place::
487
488     make olddefconfig
489     cp .config ~/kernel-config-working
490
491  [:ref:`details<saveconfig_bisref>`]
492
493.. _introlatestcheck_bissbs:
494
495Segment 1: try to reproduce the problem with the latest codebase
496----------------------------------------------------------------
497
498The following steps verify if the problem occurs with the code currently
499supported by developers. In case you face a regression, it also checks that the
500problem is not caused by some .config change, as reporting the issue then would
501be a waste of time. [:ref:`details<introlatestcheck_bisref>`]
502
503.. _checkoutmaster_bissbs:
504
505* Check out the latest Linux codebase::
506
507    cd ~/linux/
508    git checkout --force --detach mainline/master
509
510  [:ref:`details<checkoutmaster_bisref>`]
511
512.. _build_bissbs:
513
514* Build the image and the modules of your first kernel using the config file you
515  prepared::
516
517    cp ~/kernel-config-working .config
518    make olddefconfig
519    make -j $(nproc --all)
520
521  If you want your kernel packaged up as deb, rpm, or tar file, see the
522  reference section for alternatives, which obviously will require other
523  steps to install as well.
524
525  [:ref:`details<build_bisref>`]
526
527.. _install_bissbs:
528
529* Install your newly built kernel.
530
531  Before doing so, consider checking if there is still enough space for it::
532
533    df -h /boot/ /lib/modules/
534
535  For now assume 150 MByte in /boot/ and 200 in /lib/modules/ will suffice; how
536  much your kernels actually require will be determined later during this guide.
537
538  Now install the kernel's modules and its image, which will be stored in
539  parallel to the your Linux distribution's kernels::
540
541    sudo make modules_install
542    command -v installkernel && sudo make install
543
544  The second command ideally will take care of three steps required at this
545  point: copying the kernel's image to /boot/, generating an initramfs, and
546  adding an entry for both to the boot loader's configuration.
547
548  Sadly some distributions (among them Arch Linux, its derivatives, and many
549  immutable Linux distributions) will perform none or only some of those tasks.
550  You therefore want to check if all of them were taken care of and manually
551  perform those that were not. The reference section provides further details on
552  that; your distribution's documentation might help, too.
553
554  Once you figured out the steps needed at this point, consider writing them
555  down: if you will build more kernels as described in segment 2 and 3, you will
556  have to perform those again after executing ``command -v installkernel [...]``.
557
558  [:ref:`details<install_bisref>`]
559
560.. _storagespace_bissbs:
561
562* In case you plan to follow this guide further, check how much storage space
563  the kernel, its modules, and other related files like the initramfs consume::
564
565    du -ch /boot/*$(make -s kernelrelease)* | tail -n 1
566    du -sh /lib/modules/$(make -s kernelrelease)/
567
568  Write down or remember those two values for later: they enable you to prevent
569  running out of disk space accidentally during a bisection.
570
571  [:ref:`details<storagespace_bisref>`]
572
573.. _kernelrelease_bissbs:
574
575* Show and store the kernelrelease identifier of the kernel you just built::
576
577    make -s kernelrelease | tee -a ~/kernels-built
578
579  Remember the identifier momentarily, as it will help you pick the right kernel
580  from the boot menu upon restarting.
581
582* Reboot into your newly built kernel. To ensure your actually started the one
583  you just built, you might want to verify if the output of these commands
584  matches::
585
586    tail -n 1 ~/kernels-built
587    uname -r
588
589.. _tainted_bissbs:
590
591* Check if the kernel marked itself as 'tainted'::
592
593    cat /proc/sys/kernel/tainted
594
595  If that command does not return '0', check the reference section, as the cause
596  for this might interfere with your testing.
597
598  [:ref:`details<tainted_bisref>`]
599
600.. _recheckbroken_bissbs:
601
602* Verify if your bug occurs with the newly built kernel. If it does not, check
603  out the instructions in the reference section to ensure nothing went sideways
604  during your tests.
605
606  [:ref:`details<recheckbroken_bisref>`]
607
608.. _recheckstablebroken_bissbs:
609
610* Are you facing a problem within a stable/longterm series, but failed to
611  reproduce it with the mainline kernel you just built? One that according to
612  the `front page of kernel.org <https://kernel.org/>`_ is still supported? Then
613  check if the latest codebase for the particular series might already fix the
614  problem. To do so, add the stable series Git branch for your 'good' kernel
615  (again, this here is assumed to be 6.0) and check out the latest version::
616
617    cd ~/linux/
618    git remote set-branches --add stable linux-6.0.y
619    git fetch stable
620    git checkout --force --detach linux-6.0.y
621
622  Now use the checked out code to build and install another kernel using the
623  commands the earlier steps already described in more detail::
624
625    cp ~/kernel-config-working .config
626    make olddefconfig
627    make -j $(nproc --all)
628    # * Check if the free space suffices holding another kernel:
629    df -h /boot/ /lib/modules/
630    sudo make modules_install
631    command -v installkernel && sudo make install
632    make -s kernelrelease | tee -a ~/kernels-built
633    reboot
634
635  Confirm you booted the kernel you intended to start and check its tainted
636  status::
637
638    tail -n 1 ~/kernels-built
639    uname -r
640    cat /proc/sys/kernel/tainted
641
642  Now verify if this kernel is showing the problem.
643
644  [:ref:`details<recheckstablebroken_bisref>`]
645
646Do you follow this guide to verify if a problem is present in the code
647currently supported by Linux kernel developers? Then you are done at this
648point. If you later want to remove the kernel you just built, check out
649:ref:`Supplementary tasks: cleanup during and after following this guide<introclosure_bissbs>`.
650
651In case you face a regression, move on and execute at least the next segment
652as well.
653
654.. _introworkingcheck_bissbs:
655
656Segment 2: check if the kernels you build work fine
657---------------------------------------------------
658
659In case of a regression, you now want to ensure the trimmed configuration file
660you created earlier works as expected; a bisection with the .config file
661otherwise would be a waste of time. [:ref:`details<introworkingcheck_bisref>`]
662
663.. _recheckworking_bissbs:
664
665* Build your own variant of the 'working' kernel and check if the feature that
666  regressed works as expected with it.
667
668  Start by checking out the sources for the version earlier established as
669  'good' (once again assumed to be 6.0 here)::
670
671    cd ~/linux/
672    git checkout --detach v6.0
673
674  Now use the checked out code to configure, build, and install another kernel
675  using the commands the previous subsection explained in more detail::
676
677    cp ~/kernel-config-working .config
678    make olddefconfig
679    make -j $(nproc --all)
680    # * Check if the free space suffices holding another kernel:
681    df -h /boot/ /lib/modules/
682    sudo make modules_install
683    command -v installkernel && sudo make install
684    make -s kernelrelease | tee -a ~/kernels-built
685    reboot
686
687  When the system booted, you may want to verify once again that the
688  kernel you started is the one you just built::
689
690    tail -n 1 ~/kernels-built
691    uname -r
692
693  Now check if this kernel works as expected; if not, consult the reference
694  section for further instructions.
695
696  [:ref:`details<recheckworking_bisref>`]
697
698.. _introbisect_bissbs:
699
700Segment 3: perform the bisection and validate the result
701--------------------------------------------------------
702
703With all the preparations and precaution builds taken care of, you are now ready
704to begin the bisection. This will make you build quite a few kernels -- usually
705about 15 in case you encountered a regression when updating to a newer series
706(say from 6.0.11 to 6.1.3). But do not worry, due to the trimmed build
707configuration created earlier this works a lot faster than many people assume:
708overall on average it will often just take about 10 to 15 minutes to compile
709each kernel on commodity x86 machines.
710
711* In case your 'bad' version is a stable/longterm release (say 6.1.5), add its
712  stable branch, unless you already did so earlier::
713
714    cd ~/linux/
715    git remote set-branches --add stable linux-6.1.y
716    git fetch stable
717
718.. _bisectstart_bissbs:
719
720* Start the bisection and tell Git about the versions earlier established as
721  'good' (6.0 in the following example command) and 'bad' (6.1.5)::
722
723    cd ~/linux/
724    git bisect start
725    git bisect good v6.0
726    git bisect bad v6.1.5
727
728  [:ref:`details<bisectstart_bisref>`]
729
730.. _bisectbuild_bissbs:
731
732* Now use the code Git checked out to build, install, and boot a kernel using
733  the commands introduced earlier::
734
735    cp ~/kernel-config-working .config
736    make olddefconfig
737    make -j $(nproc --all)
738    # * Check if the free space suffices holding another kernel:
739    df -h /boot/ /lib/modules/
740    sudo make modules_install
741    command -v installkernel && sudo make install
742    make -s kernelrelease | tee -a ~/kernels-built
743    reboot
744
745  If compilation fails for some reason, run ``git bisect skip`` and restart
746  executing the stack of commands from the beginning.
747
748  In case you skipped the "test latest codebase" step in the guide, check its
749  description as for why the 'df [...]' and 'make -s kernelrelease [...]'
750  commands are here.
751
752  Important note: the latter command from this point on will print release
753  identifiers that might look odd or wrong to you -- which they are not, as it's
754  totally normal to see release identifiers like '6.0-rc1-local-gcafec0cacaca0'
755  if you bisect between versions 6.1 and 6.2 for example.
756
757  [:ref:`details<bisectbuild_bisref>`]
758
759.. _bisecttest_bissbs:
760
761* Now check if the feature that regressed works in the kernel you just built.
762
763  You again might want to start by making sure the kernel you booted is the one
764  you just built::
765
766    cd ~/linux/
767    tail -n 1 ~/kernels-built
768    uname -r
769
770  Now verify if the feature that regressed works at this kernel bisection point.
771  If it does, run this::
772
773    git bisect good
774
775  If it does not, run this::
776
777    git bisect bad
778
779  Be sure about what you tell Git, as getting this wrong just once will send the
780  rest of the bisection totally off course.
781
782  While the bisection is ongoing, Git will use the information you provided to
783  find and check out another bisection point for you to test. While doing so, it
784  will print something like 'Bisecting: 675 revisions left to test after this
785  (roughly 10 steps)' to indicate how many further changes it expects to be
786  tested. Now build and install another kernel using the instructions from the
787  previous step; afterwards follow the instructions in this step again.
788
789  Repeat this again and again until you finish the bisection -- that's the case
790  when Git after tagging a change as 'good' or 'bad' prints something like
791  'cafecaca0c0dacafecaca0c0dacafecaca0c0da is the first bad commit'; right
792  afterwards it will show some details about the culprit including the patch
793  description of the change. The latter might fill your terminal screen, so you
794  might need to scroll up to see the message mentioning the culprit;
795  alternatively, run ``git bisect log > ~/bisection-log``.
796
797  [:ref:`details<bisecttest_bisref>`]
798
799.. _bisectlog_bissbs:
800
801* Store Git's bisection log and the current .config file in a safe place before
802  telling Git to reset the sources to the state before the bisection::
803
804    cd ~/linux/
805    git bisect log > ~/bisection-log
806    cp .config ~/bisection-config-culprit
807    git bisect reset
808
809  [:ref:`details<bisectlog_bisref>`]
810
811.. _revert_bissbs:
812
813* Try reverting the culprit on top of latest mainline to see if this fixes your
814  regression.
815
816  This is optional, as it might be impossible or hard to realize. The former is
817  the case, if the bisection determined a merge commit as the culprit; the
818  latter happens if other changes depend on the culprit. But if the revert
819  succeeds, it is worth building another kernel, as it validates the result of
820  a bisection, which can easily deroute; it furthermore will let kernel
821  developers know, if they can resolve the regression with a quick revert.
822
823  Begin by checking out the latest codebase depending on the range you bisected:
824
825  * Did you face a regression within a stable/longterm series (say between
826    6.0.11 and 6.0.13) that does not happen in mainline? Then check out the
827    latest codebase for the affected series like this::
828
829      git fetch stable
830      git checkout --force --detach linux-6.0.y
831
832  * In all other cases check out latest mainline::
833
834      git fetch mainline
835      git checkout --force --detach mainline/master
836
837    If you bisected a regression within a stable/longterm series that also
838    happens in mainline, there is one more thing to do: look up the mainline
839    commit-id. To do so, use a command like ``git show abcdcafecabcd`` to
840    view the patch description of the culprit. There will be a line near
841    the top which looks like 'commit cafec0cacaca0 upstream.' or
842    'Upstream commit cafec0cacaca0'; use that commit-id in the next command
843    and not the one the bisection blamed.
844
845  Now try reverting the culprit by specifying its commit id::
846
847    git revert --no-edit cafec0cacaca0
848
849  If that fails, give up trying and move on to the next step. But if it works,
850  build a kernel again using the familiar command sequence::
851
852    cp ~/kernel-config-working .config
853    make olddefconfig &&
854    make -j $(nproc --all) &&
855    # * Check if the free space suffices holding another kernel:
856    df -h /boot/ /lib/modules/
857    sudo make modules_install
858    command -v installkernel && sudo make install
859    Make -s kernelrelease | tee -a ~/kernels-built
860    reboot
861
862  Now check one last time if the feature that made you perform a bisection work
863  with that kernel.
864
865  [:ref:`details<revert_bisref>`]
866
867.. _introclosure_bissbs:
868
869Supplementary tasks: cleanup during and after the bisection
870-----------------------------------------------------------
871
872During and after following this guide you might want or need to remove some of
873the kernels you installed: the boot menu otherwise will become confusing or
874space might run out.
875
876.. _makeroom_bissbs:
877
878* To remove one of the kernels you installed, look up its 'kernelrelease'
879  identifier. This guide stores them in '~/kernels-built', but the following
880  command will print them as well::
881
882    ls -ltr /lib/modules/*-local*
883
884  You in most situations want to remove the oldest kernels built during the
885  actual bisection (e.g. segment 3 of this guide). The two ones you created
886  beforehand (e.g. to test the latest codebase and the version considered
887  'good') might become handy to verify something later -- thus better keep them
888  around, unless you are really short on storage space.
889
890  To remove the modules of a kernel with the kernelrelease identifier
891  '*6.0-rc1-local-gcafec0cacaca0*', start by removing the directory holding its
892  modules::
893
894    sudo rm -rf /lib/modules/6.0-rc1-local-gcafec0cacaca0
895
896  Afterwards try the following command::
897
898    sudo kernel-install -v remove 6.0-rc1-local-gcafec0cacaca0
899
900  On quite a few distributions this will delete all other kernel files installed
901  while also removing the kernel's entry from the boot menu. But on some
902  distributions kernel-install does not exist or leaves boot-loader entries or
903  kernel image and related files behind; in that case remove them as described
904  in the reference section.
905
906  [:ref:`details<makeroom_bisref>`]
907
908.. _finishingtouch_bissbs:
909
910* Once you have finished the bisection, do not immediately remove anything you
911  set up, as you might need a few things again. What is safe to remove depends
912  on the outcome of the bisection:
913
914  * Could you initially reproduce the regression with the latest codebase and
915    after the bisection were able to fix the problem by reverting the culprit on
916    top of the latest codebase? Then you want to keep those two kernels around
917    for a while, but safely remove all others with a '-local' in the release
918    identifier.
919
920  * Did the bisection end on a merge-commit or seems questionable for other
921    reasons? Then you want to keep as many kernels as possible around for a few
922    days: it's pretty likely that you will be asked to recheck something.
923
924  * In other cases it likely is a good idea to keep the following kernels around
925    for some time: the one built from the latest codebase, the one created from
926    the version considered 'good', and the last three or four you compiled
927    during the actual bisection process.
928
929  [:ref:`details<finishingtouch_bisref>`]
930
931.. _submit_improvements:
932
933This concludes the step-by-step guide.
934
935Did you run into trouble following any of the above steps not cleared up by the
936reference section below? Did you spot errors? Or do you have ideas how to
937improve the guide? Then please take a moment and let the maintainer of this
938document know by email (Thorsten Leemhuis <linux@leemhuis.info>), ideally while
939CCing the Linux docs mailing list (linux-doc@vger.kernel.org). Such feedback is
940vital to improve this document further, which is in everybody's interest, as it
941will enable more people to master the task described here -- and hopefully also
942improve similar guides inspired by this one.
943
944
945Reference section for the step-by-step guide
946============================================
947
948This section holds additional information for almost all the items in the above
949step-by-step guide.
950
951.. _backup_bisref:
952
953Prepare for emergencies
954-----------------------
955
956  *Create a fresh backup and put system repair and restore tools at hand.*
957  [:ref:`... <backup_bissbs>`]
958
959Remember, you are dealing with computers, which sometimes do unexpected things
960-- especially if you fiddle with crucial parts like the kernel of an operating
961system. That's what you are about to do in this process. Hence, better prepare
962for something going sideways, even if that should not happen.
963
964[:ref:`back to step-by-step guide <backup_bissbs>`]
965
966.. _vanilla_bisref:
967
968Remove anything related to externally maintained kernel modules
969---------------------------------------------------------------
970
971  *Remove all software that depends on externally developed kernel drivers or
972  builds them automatically.* [:ref:`...<vanilla_bissbs>`]
973
974Externally developed kernel modules can easily cause trouble during a bisection.
975
976But there is a more important reason why this guide contains this step: most
977kernel developers will not care about reports about regressions occurring with
978kernels that utilize such modules. That's because such kernels are not
979considered 'vanilla' anymore, as Documentation/admin-guide/reporting-issues.rst
980explains in more detail.
981
982[:ref:`back to step-by-step guide <vanilla_bissbs>`]
983
984.. _secureboot_bisref:
985
986Deal with techniques like Secure Boot
987-------------------------------------
988
989  *On platforms with 'Secure Boot' or similar techniques, prepare everything to
990  ensure the system will permit your self-compiled kernel to boot later.*
991  [:ref:`... <secureboot_bissbs>`]
992
993Many modern systems allow only certain operating systems to start; that's why
994they reject booting self-compiled kernels by default.
995
996You ideally deal with this by making your platform trust your self-built kernels
997with the help of a certificate. How to do that is not described
998here, as it requires various steps that would take the text too far away from
999its purpose; 'Documentation/admin-guide/module-signing.rst' and various web
1000sides already explain everything needed in more detail.
1001
1002Temporarily disabling solutions like Secure Boot is another way to make your own
1003Linux boot. On commodity x86 systems it is possible to do this in the BIOS Setup
1004utility; the required steps vary a lot between machines and therefore cannot be
1005described here.
1006
1007On mainstream x86 Linux distributions there is a third and universal option:
1008disable all Secure Boot restrictions for your Linux environment. You can
1009initiate this process by running ``mokutil --disable-validation``; this will
1010tell you to create a one-time password, which is safe to write down. Now
1011restart; right after your BIOS performed all self-tests the bootloader Shim will
1012show a blue box with a message 'Press any key to perform MOK management'. Hit
1013some key before the countdown exposes, which will open a menu. Choose 'Change
1014Secure Boot state'. Shim's 'MokManager' will now ask you to enter three
1015randomly chosen characters from the one-time password specified earlier. Once
1016you provided them, confirm you really want to disable the validation.
1017Afterwards, permit MokManager to reboot the machine.
1018
1019[:ref:`back to step-by-step guide <secureboot_bissbs>`]
1020
1021.. _bootworking_bisref:
1022
1023Boot the last kernel that was working
1024-------------------------------------
1025
1026  *Boot into the last working kernel and briefly recheck if the feature that
1027  regressed really works.* [:ref:`...<bootworking_bissbs>`]
1028
1029This will make later steps that cover creating and trimming the configuration do
1030the right thing.
1031
1032[:ref:`back to step-by-step guide <bootworking_bissbs>`]
1033
1034.. _diskspace_bisref:
1035
1036Space requirements
1037------------------
1038
1039  *Ensure to have enough free space for building Linux.*
1040  [:ref:`... <diskspace_bissbs>`]
1041
1042The numbers mentioned are rough estimates with a big extra charge to be on the
1043safe side, so often you will need less.
1044
1045If you have space constraints, be sure to hay attention to the :ref:`step about
1046debug symbols' <debugsymbols_bissbs>` and its :ref:`accompanying reference
1047section' <debugsymbols_bisref>`, as disabling then will reduce the consumed disk
1048space by quite a few gigabytes.
1049
1050[:ref:`back to step-by-step guide <diskspace_bissbs>`]
1051
1052.. _rangecheck_bisref:
1053
1054Bisection range
1055---------------
1056
1057  *Determine the kernel versions considered 'good' and 'bad' throughout this
1058  guide.* [:ref:`...<rangecheck_bissbs>`]
1059
1060Establishing the range of commits to be checked is mostly straightforward,
1061except when a regression occurred when switching from a release of one stable
1062series to a release of a later series (e.g. from 6.0.11 to 6.1.4). In that case
1063Git will need some hand holding, as there is no straight line of descent.
1064
1065That's because with the release of 6.0 mainline carried on to 6.1 while the
1066stable series 6.0.y branched to the side. It's therefore theoretically possible
1067that the issue you face with 6.1.4 only worked in 6.0.11, as it was fixed by a
1068commit that went into one of the 6.0.y releases, but never hit mainline or the
10696.1.y series. Thankfully that normally should not happen due to the way the
1070stable/longterm maintainers maintain the code. It's thus pretty safe to assume
10716.0 as a 'good' kernel. That assumption will be tested anyway, as that kernel
1072will be built and tested in the segment '2' of this guide; Git would force you
1073to do this as well, if you tried bisecting between 6.0.11 and 6.1.13.
1074
1075[:ref:`back to step-by-step guide <rangecheck_bissbs>`]
1076
1077.. _buildrequires_bisref:
1078
1079Install build requirements
1080--------------------------
1081
1082  *Install all software required to build a Linux kernel.*
1083  [:ref:`...<buildrequires_bissbs>`]
1084
1085The kernel is pretty stand-alone, but besides tools like the compiler you will
1086sometimes need a few libraries to build one. How to install everything needed
1087depends on your Linux distribution and the configuration of the kernel you are
1088about to build.
1089
1090Here are a few examples what you typically need on some mainstream
1091distributions:
1092
1093* Arch Linux and derivatives::
1094
1095    sudo pacman --needed -S bc binutils bison flex gcc git kmod libelf openssl \
1096      pahole perl zlib ncurses qt6-base
1097
1098* Debian, Ubuntu, and derivatives::
1099
1100    sudo apt install bc binutils bison dwarves flex gcc git kmod libelf-dev \
1101      libssl-dev make openssl pahole perl-base pkg-config zlib1g-dev \
1102      libncurses-dev qt6-base-dev g++
1103
1104* Fedora and derivatives::
1105
1106    sudo dnf install binutils \
1107      /usr/bin/{bc,bison,flex,gcc,git,openssl,make,perl,pahole,rpmbuild} \
1108      /usr/include/{libelf.h,openssl/pkcs7.h,zlib.h,ncurses.h,qt6/QtGui/QAction}
1109
1110* openSUSE and derivatives::
1111
1112    sudo zypper install bc binutils bison dwarves flex gcc git \
1113      kernel-install-tools libelf-devel make modutils openssl openssl-devel \
1114      perl-base zlib-devel rpm-build ncurses-devel qt6-base-devel
1115
1116These commands install a few packages that are often, but not always needed. You
1117for example might want to skip installing the development headers for ncurses,
1118which you will only need in case you later might want to adjust the kernel build
1119configuration using make the targets 'menuconfig' or 'nconfig'; likewise omit
1120the headers of Qt6 is you do not plan to adjust the .config using 'xconfig'.
1121
1122You furthermore might need additional libraries and their development headers
1123for tasks not covered in this guide -- for example when building utilities from
1124the kernel's tools/ directory.
1125
1126[:ref:`back to step-by-step guide <buildrequires_bissbs>`]
1127
1128.. _sources_bisref:
1129
1130Download the sources using Git
1131------------------------------
1132
1133  *Retrieve the Linux mainline sources.*
1134  [:ref:`...<sources_bissbs>`]
1135
1136The step-by-step guide outlines how to download the Linux sources using a full
1137Git clone of Linus' mainline repository. There is nothing more to say about
1138that -- but there are two alternatives ways to retrieve the sources that might
1139work better for you:
1140
1141* If you have an unreliable internet connection, consider
1142  :ref:`using a 'Git bundle'<sources_bundle_bisref>`.
1143
1144* If downloading the complete repository would take too long or requires too
1145  much storage space, consider :ref:`using a 'shallow
1146  clone'<sources_shallow_bisref>`.
1147
1148.. _sources_bundle_bisref:
1149
1150Downloading Linux mainline sources using a bundle
1151~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1152
1153Use the following commands to retrieve the Linux mainline sources using a
1154bundle::
1155
1156    wget -c \
1157      https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/clone.bundle
1158    git clone --no-checkout clone.bundle ~/linux/
1159    cd ~/linux/
1160    git remote remove origin
1161    git remote add mainline \
1162      https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
1163    git fetch mainline
1164    git remote add -t master stable \
1165      https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
1166
1167In case the 'wget' command fails, just re-execute it, it will pick up where
1168it left off.
1169
1170[:ref:`back to step-by-step guide <sources_bissbs>`]
1171[:ref:`back to section intro <sources_bisref>`]
1172
1173.. _sources_shallow_bisref:
1174
1175Downloading Linux mainline sources using a shallow clone
1176~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1177
1178First, execute the following command to retrieve the latest mainline codebase::
1179
1180    git clone -o mainline --no-checkout --depth 1 -b master \
1181      https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git ~/linux/
1182    cd ~/linux/
1183    git remote add -t master stable \
1184      https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
1185
1186Now deepen your clone's history to the second predecessor of the mainline
1187release of your 'good' version. In case the latter are 6.0 or 6.0.11, 5.19 would
1188be the first predecessor and 5.18 the second -- hence deepen the history up to
1189that version::
1190
1191    git fetch --shallow-exclude=v5.18 mainline
1192
1193Afterwards add the stable Git repository as remote and all required stable
1194branches as explained in the step-by-step guide.
1195
1196Note, shallow clones have a few peculiar characteristics:
1197
1198* For bisections the history needs to be deepened a few mainline versions
1199  farther than it seems necessary, as explained above already. That's because
1200  Git otherwise will be unable to revert or describe most of the commits within
1201  a range (say 6.1..6.2), as they are internally based on earlier kernels
1202  releases (like 6.0-rc2 or 5.19-rc3).
1203
1204* This document in most places uses ``git fetch`` with ``--shallow-exclude=``
1205  to specify the earliest version you care about (or to be precise: its git
1206  tag). You alternatively can use the parameter ``--shallow-since=`` to specify
1207  an absolute (say ``'2023-07-15'``) or relative (``'12 months'``) date to
1208  define the depth of the history you want to download. When using them while
1209  bisecting mainline, ensure to deepen the history to at least 7 months before
1210  the release of the mainline release your 'good' kernel is based on.
1211
1212* Be warned, when deepening your clone you might encounter an error like
1213  'fatal: error in object: unshallow cafecaca0c0dacafecaca0c0dacafecaca0c0da'.
1214  In that case run ``git repack -d`` and try again.
1215
1216[:ref:`back to step-by-step guide <sources_bissbs>`]
1217[:ref:`back to section intro <sources_bisref>`]
1218
1219.. _oldconfig_bisref:
1220
1221Start defining the build configuration for your kernel
1222------------------------------------------------------
1223
1224  *Start preparing a kernel build configuration (the '.config' file).*
1225  [:ref:`... <oldconfig_bissbs>`]
1226
1227*Note, this is the first of multiple steps in this guide that create or modify
1228build artifacts. The commands used in this guide store them right in the source
1229tree to keep things simple. In case you prefer storing the build artifacts
1230separately, create a directory like '~/linux-builddir/' and add the parameter
1231``O=~/linux-builddir/`` to all make calls used throughout this guide. You will
1232have to point other commands there as well -- among them the ``./scripts/config
1233[...]`` commands, which will require ``--file ~/linux-builddir/.config`` to
1234locate the right build configuration.*
1235
1236Two things can easily go wrong when creating a .config file as advised:
1237
1238* The oldconfig target will use a .config file from your build directory, if
1239  one is already present there (e.g. '~/linux/.config'). That's totally fine if
1240  that's what you intend (see next step), but in all other cases you want to
1241  delete it. This for example is important in case you followed this guide
1242  further, but due to problems come back here to redo the configuration from
1243  scratch.
1244
1245* Sometimes olddefconfig is unable to locate the .config file for your running
1246  kernel and will use defaults, as briefly outlined in the guide. In that case
1247  check if your distribution ships the configuration somewhere and manually put
1248  it in the right place (e.g. '~/linux/.config') if it does. On distributions
1249  where /proc/config.gz exists this can be achieved using this command::
1250
1251    zcat /proc/config.gz > .config
1252
1253  Once you put it there, run ``make olddefconfig`` again to adjust it to the
1254  needs of the kernel about to be built.
1255
1256Note, the olddefconfig target will set any undefined build options to their
1257default value. If you prefer to set such configuration options manually, use
1258``make oldconfig`` instead. Then for each undefined configuration option you
1259will be asked how to proceed; in case you are unsure what to answer, simply hit
1260'enter' to apply the default value. Note though that for bisections you normally
1261want to go with the defaults, as you otherwise might enable a new feature that
1262causes a problem looking like regressions (for example due to security
1263restrictions).
1264
1265Occasionally odd things happen when trying to use a config file prepared for one
1266kernel (say 6.1) on an older mainline release -- especially if it is much older
1267(say 5.15). That's one of the reasons why the previous step in the guide told
1268you to boot the kernel where everything works. If you manually add a .config
1269file you thus want to ensure it's from the working kernel and not from a one
1270that shows the regression.
1271
1272In case you want to build kernels for another machine, locate its kernel build
1273configuration; usually ``ls /boot/config-$(uname -r)`` will print its name. Copy
1274that file to the build machine and store it as ~/linux/.config; afterwards run
1275``make olddefconfig`` to adjust it.
1276
1277[:ref:`back to step-by-step guide <oldconfig_bissbs>`]
1278
1279.. _localmodconfig_bisref:
1280
1281Trim the build configuration for your kernel
1282--------------------------------------------
1283
1284  *Disable any kernel modules apparently superfluous for your setup.*
1285  [:ref:`... <localmodconfig_bissbs>`]
1286
1287As explained briefly in the step-by-step guide already: with localmodconfig it
1288can easily happen that your self-built kernels will lack modules for tasks you
1289did not perform at least once before utilizing this make target. That happens
1290when a task requires kernel modules which are only autoloaded when you execute
1291it for the first time. So when you never performed that task since starting your
1292kernel the modules will not have been loaded -- and from localmodonfig's point
1293of view look superfluous, which thus disables them to reduce the amount of code
1294to be compiled.
1295
1296You can try to avoid this by performing typical tasks that often will autoload
1297additional kernel modules: start a VM, establish VPN connections, loop-mount a
1298CD/DVD ISO, mount network shares (CIFS, NFS, ...), and connect all external
1299devices (2FA keys, headsets, webcams, ...) as well as storage devices with file
1300systems you otherwise do not utilize (btrfs, ext4, FAT, NTFS, XFS, ...). But it
1301is hard to think of everything that might be needed -- even kernel developers
1302often forget one thing or another at this point.
1303
1304Do not let that risk bother you, especially when compiling a kernel only for
1305testing purposes: everything typically crucial will be there. And if you forget
1306something important you can turn on a missing feature manually later and quickly
1307run the commands again to compile and install a kernel that has everything you
1308need.
1309
1310But if you plan to build and use self-built kernels regularly, you might want to
1311reduce the risk by recording which modules your system loads over the course of
1312a few weeks. You can automate this with `modprobed-db
1313<https://github.com/graysky2/modprobed-db>`_. Afterwards use ``LSMOD=<path>`` to
1314point localmodconfig to the list of modules modprobed-db noticed being used::
1315
1316  yes '' | make LSMOD='${HOME}'/.config/modprobed.db localmodconfig
1317
1318That parameter also allows you to build trimmed kernels for another machine in
1319case you copied a suitable .config over to use as base (see previous step). Just
1320run ``lsmod > lsmod_foo-machine`` on that system and copy the generated file to
1321your build's host home directory. Then run these commands instead of the one the
1322step-by-step guide mentions::
1323
1324  yes '' | make LSMOD=~/lsmod_foo-machine localmodconfig
1325
1326[:ref:`back to step-by-step guide <localmodconfig_bissbs>`]
1327
1328.. _tagging_bisref:
1329
1330Tag the kernels about to be build
1331---------------------------------
1332
1333  *Ensure all the kernels you will build are clearly identifiable using a
1334  special tag and a unique version identifier.* [:ref:`... <tagging_bissbs>`]
1335
1336This allows you to differentiate your distribution's kernels from those created
1337during this process, as the file or directories for the latter will contain
1338'-local' in the name; it also helps picking the right entry in the boot menu and
1339not lose track of you kernels, as their version numbers will look slightly
1340confusing during the bisection.
1341
1342[:ref:`back to step-by-step guide <tagging_bissbs>`]
1343
1344.. _debugsymbols_bisref:
1345
1346Decide to enable or disable debug symbols
1347-----------------------------------------
1348
1349  *Decide how to handle debug symbols.* [:ref:`... <debugsymbols_bissbs>`]
1350
1351Having debug symbols available can be important when your kernel throws a
1352'panic', 'Oops', 'warning', or 'BUG' later when running, as then you will be
1353able to find the exact place where the problem occurred in the code. But
1354collecting and embedding the needed debug information takes time and consumes
1355quite a bit of space: in late 2022 the build artifacts for a typical x86 kernel
1356trimmed with localmodconfig consumed around 5 Gigabyte of space with debug
1357symbols, but less than 1 when they were disabled. The resulting kernel image and
1358modules are bigger as well, which increases storage requirements for /boot/ and
1359load times.
1360
1361In case you want a small kernel and are unlikely to decode a stack trace later,
1362you thus might want to disable debug symbols to avoid those downsides. If it
1363later turns out that you need them, just enable them as shown and rebuild the
1364kernel.
1365
1366You on the other hand definitely want to enable them for this process, if there
1367is a decent chance that you need to decode a stack trace later. The section
1368'Decode failure messages' in Documentation/admin-guide/reporting-issues.rst
1369explains this process in more detail.
1370
1371[:ref:`back to step-by-step guide <debugsymbols_bissbs>`]
1372
1373.. _configmods_bisref:
1374
1375Adjust build configuration
1376--------------------------
1377
1378  *Check if you may want or need to adjust some other kernel configuration
1379  options:*
1380
1381Depending on your needs you at this point might want or have to adjust some
1382kernel configuration options.
1383
1384.. _configmods_distros_bisref:
1385
1386Distro specific adjustments
1387~~~~~~~~~~~~~~~~~~~~~~~~~~~
1388
1389  *Are you running* [:ref:`... <configmods_bissbs>`]
1390
1391The following sections help you to avoid build problems that are known to occur
1392when following this guide on a few commodity distributions.
1393
1394**Debian:**
1395
1396* Remove a stale reference to a certificate file that would cause your build to
1397  fail::
1398
1399   ./scripts/config --set-str SYSTEM_TRUSTED_KEYS ''
1400
1401  Alternatively, download the needed certificate and make that configuration
1402  option point to it, as `the Debian handbook explains in more detail
1403  <https://debian-handbook.info/browse/stable/sect.kernel-compilation.html>`_
1404  -- or generate your own, as explained in
1405  Documentation/admin-guide/module-signing.rst.
1406
1407[:ref:`back to step-by-step guide <configmods_bissbs>`]
1408
1409.. _configmods_individual_bisref:
1410
1411Individual adjustments
1412~~~~~~~~~~~~~~~~~~~~~~
1413
1414  *If you want to influence the other aspects of the configuration, do so
1415  now.* [:ref:`... <configmods_bissbs>`]
1416
1417At this point you can use a command like ``make menuconfig`` or ``make nconfig``
1418to enable or disable certain features using a text-based user interface; to use
1419a graphical configuration utility, run ``make xconfig`` instead. Both of them
1420require development libraries from toolkits they are rely on (ncurses
1421respectively Qt5 or Qt6); an error message will tell you if something required
1422is missing.
1423
1424[:ref:`back to step-by-step guide <configmods_bissbs>`]
1425
1426.. _saveconfig_bisref:
1427
1428Put the .config file aside
1429--------------------------
1430
1431  *Reprocess the .config after the latest changes and store it in a safe place.*
1432  [:ref:`... <saveconfig_bissbs>`]
1433
1434Put the .config you prepared aside, as you want to copy it back to the build
1435directory every time  during this guide before you start building another
1436kernel. That's because going back and forth between different versions can alter
1437.config files in odd ways; those occasionally cause side effects that could
1438confuse testing or in some cases render the result of your bisection
1439meaningless.
1440
1441[:ref:`back to step-by-step guide <saveconfig_bissbs>`]
1442
1443.. _introlatestcheck_bisref:
1444
1445Try to reproduce the regression
1446-----------------------------------------
1447
1448  *Verify the regression is not caused by some .config change and check if it
1449  still occurs with the latest codebase.* [:ref:`... <introlatestcheck_bissbs>`]
1450
1451For some readers it might seem unnecessary to check the latest codebase at this
1452point, especially if you did that already with a kernel prepared by your
1453distributor or face a regression within a stable/longterm series. But it's
1454highly recommended for these reasons:
1455
1456* You will run into any problems caused by your setup before you actually begin
1457  a bisection. That will make it a lot easier to differentiate between 'this
1458  most likely is some problem in my setup' and 'this change needs to be skipped
1459  during the bisection, as the kernel sources at that stage contain an unrelated
1460  problem that causes building or booting to fail'.
1461
1462* These steps will rule out if your problem is caused by some change in the
1463  build configuration between the 'working' and the 'broken' kernel. This for
1464  example can happen when your distributor enabled an additional security
1465  feature in the newer kernel which was disabled or not yet supported by the
1466  older kernel. That security feature might get into the way of something you
1467  do -- in which case your problem from the perspective of the Linux kernel
1468  upstream developers is not a regression, as
1469  Documentation/admin-guide/reporting-regressions.rst explains in more detail.
1470  You thus would waste your time if you'd try to bisect this.
1471
1472* If the cause for your regression was already fixed in the latest mainline
1473  codebase, you'd perform the bisection for nothing. This holds true for a
1474  regression you encountered with a stable/longterm release as well, as they are
1475  often caused by problems in mainline changes that were backported -- in which
1476  case the problem will have to be fixed in mainline first. Maybe it already was
1477  fixed there and the fix is already in the process of being backported.
1478
1479* For regressions within a stable/longterm series it's furthermore crucial to
1480  know if the issue is specific to that series or also happens in the mainline
1481  kernel, as the report needs to be sent to different people:
1482
1483  * Regressions specific to a stable/longterm series are the stable team's
1484    responsibility; mainline Linux developers might or might not care.
1485
1486  * Regressions also happening in mainline are something the regular Linux
1487    developers and maintainers have to handle; the stable team does not care
1488    and does not need to be involved in the report, they just should be told
1489    to backport the fix once it's ready.
1490
1491  Your report might be ignored if you send it to the wrong party -- and even
1492  when you get a reply there is a decent chance that developers tell you to
1493  evaluate   which of the two cases it is before they take a closer look.
1494
1495[:ref:`back to step-by-step guide <introlatestcheck_bissbs>`]
1496
1497.. _checkoutmaster_bisref:
1498
1499Check out the latest Linux codebase
1500-----------------------------------
1501
1502  *Check out the latest Linux codebase.*
1503  [:ref:`... <introlatestcheck_bissbs>`]
1504
1505In case you later want to recheck if an ever newer codebase might fix the
1506problem, remember to run that ``git fetch --shallow-exclude [...]`` command
1507again mentioned earlier to update your local Git repository.
1508
1509[:ref:`back to step-by-step guide <introlatestcheck_bissbs>`]
1510
1511.. _build_bisref:
1512
1513Build your kernel
1514-----------------
1515
1516  *Build the image and the modules of your first kernel using the config file
1517  you prepared.* [:ref:`... <build_bissbs>`]
1518
1519A lot can go wrong at this stage, but the instructions below will help you help
1520yourself. Another subsection explains how to directly package your kernel up as
1521deb, rpm or tar file.
1522
1523Dealing with build errors
1524~~~~~~~~~~~~~~~~~~~~~~~~~
1525
1526When a build error occurs, it might be caused by some aspect of your machine's
1527setup that often can be fixed quickly; other times though the problem lies in
1528the code and can only be fixed by a developer. A close examination of the
1529failure messages coupled with some research on the internet will often tell you
1530which of the two it is. To perform such investigation, restart the build
1531process like this::
1532
1533  make V=1
1534
1535The ``V=1`` activates verbose output, which might be needed to see the actual
1536error. To make it easier to spot, this command also omits the ``-j $(nproc
1537--all)`` used earlier to utilize every CPU core in the system for the job -- but
1538this parallelism also results in some clutter when failures occur.
1539
1540After a few seconds the build process should run into the error again. Now try
1541to find the most crucial line describing the problem. Then search the internet
1542for the most important and non-generic section of that line (say 4 to 8 words);
1543avoid or remove anything that looks remotely system-specific, like your username
1544or local path names like ``/home/username/linux/``. First try your regular
1545internet search engine with that string, afterwards search Linux kernel mailing
1546lists via `lore.kernel.org/all/ <https://lore.kernel.org/all/>`_.
1547
1548This most of the time will find something that will explain what is wrong; quite
1549often one of the hits will provide a solution for your problem, too. If you
1550do not find anything that matches your problem, try again from a different angle
1551by modifying your search terms or using another line from the error messages.
1552
1553In the end, most issues you run into have likely been encountered and
1554reported by others already. That includes issues where the cause is not your
1555system, but lies in the code. If you run into one of those, you might thus find a
1556solution (e.g. a patch) or workaround for your issue, too.
1557
1558Package your kernel up
1559~~~~~~~~~~~~~~~~~~~~~~
1560
1561The step-by-step guide uses the default make targets (e.g. 'bzImage' and
1562'modules' on x86) to build the image and the modules of your kernel, which later
1563steps of the guide then install. You instead can also directly build everything
1564and directly package it up by using one of the following targets:
1565
1566* ``make -j $(nproc --all) bindeb-pkg`` to generate a deb package
1567
1568* ``make -j $(nproc --all) binrpm-pkg`` to generate a rpm package
1569
1570* ``make -j $(nproc --all) tarbz2-pkg`` to generate a bz2 compressed tarball
1571
1572This is just a selection of available make targets for this purpose, see
1573``make help`` for others. You can also use these targets after running
1574``make -j $(nproc --all)``, as they will pick up everything already built.
1575
1576If you employ the targets to generate deb or rpm packages, ignore the
1577step-by-step guide's instructions on installing and removing your kernel;
1578instead install and remove the packages using the package utility for the format
1579(e.g. dpkg and rpm) or a package management utility build on top of them (apt,
1580aptitude, dnf/yum, zypper, ...). Be aware that the packages generated using
1581these two make targets are designed to work on various distributions utilizing
1582those formats, they thus will sometimes behave differently than your
1583distribution's kernel packages.
1584
1585[:ref:`back to step-by-step guide <build_bissbs>`]
1586
1587.. _install_bisref:
1588
1589Put the kernel in place
1590-----------------------
1591
1592  *Install the kernel you just built.* [:ref:`... <install_bissbs>`]
1593
1594What you need to do after executing the command in the step-by-step guide
1595depends on the existence and the implementation of ``/sbin/installkernel``
1596executable on your distribution.
1597
1598If installkernel is found, the kernel's build system will delegate the actual
1599installation of your kernel image to this executable, which then performs some
1600or all of these tasks:
1601
1602* On almost all Linux distributions installkernel will store your kernel's
1603  image in /boot/, usually as '/boot/vmlinuz-<kernelrelease_id>'; often it will
1604  put a 'System.map-<kernelrelease_id>' alongside it.
1605
1606* On most distributions installkernel will then generate an 'initramfs'
1607  (sometimes also called 'initrd'), which usually are stored as
1608  '/boot/initramfs-<kernelrelease_id>.img' or
1609  '/boot/initrd-<kernelrelease_id>'. Commodity distributions rely on this file
1610  for booting, hence ensure to execute the make target 'modules_install' first,
1611  as your distribution's initramfs generator otherwise will be unable to find
1612  the modules that go into the image.
1613
1614* On some distributions installkernel will then add an entry for your kernel
1615  to your bootloader's configuration.
1616
1617You have to take care of some or all of the tasks yourself, if your
1618distribution lacks a installkernel script or does only handle part of them.
1619Consult the distribution's documentation for details. If in doubt, install the
1620kernel manually::
1621
1622   sudo install -m 0600 $(make -s image_name) /boot/vmlinuz-$(make -s kernelrelease)
1623   sudo install -m 0600 System.map /boot/System.map-$(make -s kernelrelease)
1624
1625Now generate your initramfs using the tools your distribution provides for this
1626process. Afterwards add your kernel to your bootloader configuration and reboot.
1627
1628[:ref:`back to step-by-step guide <install_bissbs>`]
1629
1630.. _storagespace_bisref:
1631
1632Storage requirements per kernel
1633-------------------------------
1634
1635  *Check how much storage space the kernel, its modules, and other related files
1636  like the initramfs consume.* [:ref:`... <storagespace_bissbs>`]
1637
1638The kernels built during a bisection consume quite a bit of space in /boot/ and
1639/lib/modules/, especially if you enabled debug symbols. That makes it easy to
1640fill up volumes during a bisection -- and due to that even kernels which used to
1641work earlier might fail to boot. To prevent that you will need to know how much
1642space each installed kernel typically requires.
1643
1644Note, most of the time the pattern '/boot/*$(make -s kernelrelease)*' used in
1645the guide will match all files needed to boot your kernel -- but neither the
1646path nor the naming scheme are mandatory. On some distributions you thus will
1647need to look in different places.
1648
1649[:ref:`back to step-by-step guide <storagespace_bissbs>`]
1650
1651.. _tainted_bisref:
1652
1653Check if your newly built kernel considers itself 'tainted'
1654-----------------------------------------------------------
1655
1656  *Check if the kernel marked itself as 'tainted'.*
1657  [:ref:`... <tainted_bissbs>`]
1658
1659Linux marks itself as tainted when something happens that potentially leads to
1660follow-up errors that look totally unrelated. That is why developers might
1661ignore or react scantly to reports from tainted kernels -- unless of course the
1662kernel set the flag right when the reported bug occurred.
1663
1664That's why you want check why a kernel is tainted as explained in
1665Documentation/admin-guide/tainted-kernels.rst; doing so is also in your own
1666interest, as your testing might be flawed otherwise.
1667
1668[:ref:`back to step-by-step guide <tainted_bissbs>`]
1669
1670.. _recheckbroken_bisref:
1671
1672Check the kernel built from a recent mainline codebase
1673------------------------------------------------------
1674
1675  *Verify if your bug occurs with the newly built kernel.*
1676  [:ref:`... <recheckbroken_bissbs>`]
1677
1678There are a couple of reasons why your bug or regression might not show up with
1679the kernel you built from the latest codebase. These are the most frequent:
1680
1681* The bug was fixed meanwhile.
1682
1683* What you suspected to be a regression was caused by a change in the build
1684  configuration the provider of your kernel carried out.
1685
1686* Your problem might be a race condition that does not show up with your kernel;
1687  the trimmed build configuration, a different setting for debug symbols, the
1688  compiler used, and various other things can cause this.
1689
1690* In case you encountered the regression with a stable/longterm kernel it might
1691  be a problem that is specific to that series; the next step in this guide will
1692  check this.
1693
1694[:ref:`back to step-by-step guide <recheckbroken_bissbs>`]
1695
1696.. _recheckstablebroken_bisref:
1697
1698Check the kernel built from the latest stable/longterm codebase
1699---------------------------------------------------------------
1700
1701  *Are you facing a regression within a stable/longterm release, but failed to
1702  reproduce it with the kernel you just built using the latest mainline sources?
1703  Then check if the latest codebase for the particular series might already fix
1704  the problem.* [:ref:`... <recheckstablebroken_bissbs>`]
1705
1706If this kernel does not show the regression either, there most likely is no need
1707for a bisection.
1708
1709[:ref:`back to step-by-step guide <recheckstablebroken_bissbs>`]
1710
1711.. _introworkingcheck_bisref:
1712
1713Ensure the 'good' version is really working well
1714------------------------------------------------
1715
1716  *Check if the kernels you build work fine.*
1717  [:ref:`... <introworkingcheck_bissbs>`]
1718
1719This section will reestablish a known working base. Skipping it might be
1720appealing, but is usually a bad idea, as it does something important:
1721
1722It will ensure the .config file you prepared earlier actually works as expected.
1723That is in your own interest, as trimming the configuration is not foolproof --
1724and you might be building and testing ten or more kernels for nothing before
1725starting to suspect something might be wrong with the build configuration.
1726
1727That alone is reason enough to spend the time on this, but not the only reason.
1728
1729Many readers of this guide normally run kernels that are patched, use add-on
1730modules, or both. Those kernels thus are not considered 'vanilla' -- therefore
1731it's possible that the thing that regressed might never have worked in vanilla
1732builds of the 'good' version in the first place.
1733
1734There is a third reason for those that noticed a regression between
1735stable/longterm kernels of different series (e.g. 6.0.13..6.1.5): it will
1736ensure the kernel version you assumed to be 'good' earlier in the process (e.g.
17376.0) actually is working.
1738
1739[:ref:`back to step-by-step guide <introworkingcheck_bissbs>`]
1740
1741.. _recheckworking_bisref:
1742
1743Build your own version of the 'good' kernel
1744-------------------------------------------
1745
1746  *Build your own variant of the working kernel and check if the feature that
1747  regressed works as expected with it.* [:ref:`... <recheckworking_bissbs>`]
1748
1749In case the feature that broke with newer kernels does not work with your first
1750self-built kernel, find and resolve the cause before moving on. There are a
1751multitude of reasons why this might happen. Some ideas where to look:
1752
1753* Check the taint status and the output of ``dmesg``, maybe something unrelated
1754  went wrong.
1755
1756* Maybe localmodconfig did something odd and disabled the module required to
1757  test the feature? Then you might want to recreate a .config file based on the
1758  one from the last working kernel and skip trimming it down; manually disabling
1759  some features in the .config might work as well to reduce the build time.
1760
1761* Maybe it's not a kernel regression and something that is caused by some fluke,
1762  a broken initramfs (also known as initrd), new firmware files, or an updated
1763  userland software?
1764
1765* Maybe it was a feature added to your distributor's kernel which vanilla Linux
1766  at that point never supported?
1767
1768Note, if you found and fixed problems with the .config file, you want to use it
1769to build another kernel from the latest codebase, as your earlier tests with
1770mainline and the latest version from an affected stable/longterm series were most
1771likely flawed.
1772
1773[:ref:`back to step-by-step guide <recheckworking_bissbs>`]
1774
1775.. _bisectstart_bisref:
1776
1777Start the bisection
1778-------------------
1779
1780  *Start the bisection and tell Git about the versions earlier established as
1781  'good' and 'bad'.* [:ref:`... <bisectstart_bissbs>`]
1782
1783This will start the bisection process; the last of the commands will make Git
1784check out a commit round about half-way between the 'good' and the 'bad' changes
1785for you to test.
1786
1787[:ref:`back to step-by-step guide <bisectstart_bissbs>`]
1788
1789.. _bisectbuild_bisref:
1790
1791Build a kernel from the bisection point
1792---------------------------------------
1793
1794  *Build, install, and boot a kernel from the code Git checked out using the
1795  same commands you used earlier.* [:ref:`... <bisectbuild_bissbs>`]
1796
1797There are two things worth of note here:
1798
1799* Occasionally building the kernel will fail or it might not boot due some
1800  problem in the code at the bisection point. In that case run this command::
1801
1802    git bisect skip
1803
1804  Git will then check out another commit nearby which with a bit of luck should
1805  work better. Afterwards restart executing this step.
1806
1807* Those slightly odd looking version identifiers can happen during bisections,
1808  because the Linux kernel subsystems prepare their changes for a new mainline
1809  release (say 6.2) before its predecessor (e.g. 6.1) is finished. They thus
1810  base them on a somewhat earlier point like 6.1-rc1 or even 6.0 -- and then
1811  get merged for 6.2 without rebasing nor squashing them once 6.1 is out. This
1812  leads to those slightly odd looking version identifiers coming up during
1813  bisections.
1814
1815[:ref:`back to step-by-step guide <bisectbuild_bissbs>`]
1816
1817.. _bisecttest_bisref:
1818
1819Bisection checkpoint
1820--------------------
1821
1822  *Check if the feature that regressed works in the kernel you just built.*
1823  [:ref:`... <bisecttest_bissbs>`]
1824
1825Ensure what you tell Git is accurate: getting it wrong just one time will bring
1826the rest of the bisection totally off course, hence all testing after that point
1827will be for nothing.
1828
1829[:ref:`back to step-by-step guide <bisecttest_bissbs>`]
1830
1831.. _bisectlog_bisref:
1832
1833Put the bisection log away
1834--------------------------
1835
1836  *Store Git's bisection log and the current .config file in a safe place.*
1837  [:ref:`... <bisectlog_bissbs>`]
1838
1839As indicated above: declaring just one kernel wrongly as 'good' or 'bad' will
1840render the end result of a bisection useless. In that case you'd normally have
1841to restart the bisection from scratch. The log can prevent that, as it might
1842allow someone to point out where a bisection likely went sideways -- and then
1843instead of testing ten or more kernels you might only have to build a few to
1844resolve things.
1845
1846The .config file is put aside, as there is a decent chance that developers might
1847ask for it after you report the regression.
1848
1849[:ref:`back to step-by-step guide <bisectlog_bissbs>`]
1850
1851.. _revert_bisref:
1852
1853Try reverting the culprit
1854-------------------------
1855
1856  *Try reverting the culprit on top of the latest codebase to see if this fixes
1857  your regression.* [:ref:`... <revert_bissbs>`]
1858
1859This is an optional step, but whenever possible one you should try: there is a
1860decent chance that developers will ask you to perform this step when you bring
1861the bisection result up. So give it a try, you are in the flow already, building
1862one more kernel shouldn't be a big deal at this point.
1863
1864The step-by-step guide covers everything relevant already except one slightly
1865rare thing: did you bisected a regression that also happened with mainline using
1866a stable/longterm series, but Git failed to revert the commit in mainline? Then
1867try to revert the culprit in the affected stable/longterm series -- and if that
1868succeeds, test that kernel version instead.
1869
1870[:ref:`back to step-by-step guide <revert_bissbs>`]
1871
1872
1873Supplementary tasks: cleanup during and after the bisection
1874-----------------------------------------------------------
1875
1876.. _makeroom_bisref:
1877
1878Cleaning up during the bisection
1879--------------------------------
1880
1881  *To remove one of the kernels you installed, look up its 'kernelrelease'
1882  identifier.* [:ref:`... <makeroom_bissbs>`]
1883
1884The kernels you install during this process are easy to remove later, as its
1885parts are only stored in two places and clearly identifiable. You thus do not
1886need to worry to mess up your machine when you install a kernel manually (and
1887thus bypass your distribution's packaging system): all parts of your kernels are
1888relatively easy to remove later.
1889
1890One of the two places is a directory in /lib/modules/, which holds the modules
1891for each installed kernel. This directory is named after the kernel's release
1892identifier; hence, to remove all modules for one of the kernels you built,
1893simply remove its modules directory in /lib/modules/.
1894
1895The other place is /boot/, where typically two up to five files will be placed
1896during installation of a kernel. All of them usually contain the release name in
1897their file name, but how many files and their exact names depend somewhat on
1898your distribution's installkernel executable and its initramfs generator. On
1899some distributions the ``kernel-install remove...`` command mentioned in the
1900step-by-step guide will delete all of these files for you while also removing
1901the menu entry for the kernel from your bootloader configuration. On others you
1902have to take care of these two tasks yourself. The following command should
1903interactively remove the three main files of a kernel with the release name
1904'6.0-rc1-local-gcafec0cacaca0'::
1905
1906  rm -i /boot/{System.map,vmlinuz,initr}-6.0-rc1-local-gcafec0cacaca0
1907
1908Afterwards check for other files in /boot/ that have
1909'6.0-rc1-local-gcafec0cacaca0' in their name and consider deleting them as well.
1910Now remove the boot entry for the kernel from your bootloader's configuration;
1911the steps to do that vary quite a bit between Linux distributions.
1912
1913Note, be careful with wildcards like '*' when deleting files or directories
1914for kernels manually: you might accidentally remove files of a 6.0.11 kernel
1915when all you want is to remove 6.0 or 6.0.1.
1916
1917[:ref:`back to step-by-step guide <makeroom_bissbs>`]
1918
1919Cleaning up after the bisection
1920-------------------------------
1921
1922.. _finishingtouch_bisref:
1923
1924  *Once you have finished the bisection, do not immediately remove anything
1925  you set up, as you might need a few things again.*
1926  [:ref:`... <finishingtouch_bissbs>`]
1927
1928When you are really short of storage space removing the kernels as described in
1929the step-by-step guide might not free as much space as you would like. In that
1930case consider running ``rm -rf ~/linux/*`` as well now. This will remove the
1931build artifacts and the Linux sources, but will leave the Git repository
1932(~/linux/.git/) behind -- a simple ``git reset --hard`` thus will bring the
1933sources back.
1934
1935Removing the repository as well would likely be unwise at this point: there is a
1936decent chance developers will ask you to build another kernel to perform
1937additional tests. This is often required to debug an issue or check proposed
1938fixes. Before doing so you want to run the ``git fetch mainline`` command again
1939followed by ``git checkout mainline/master`` to bring your clone up to date and
1940checkout the latest codebase. Then apply the patch using ``git apply
1941<filename>`` or ``git am <filename>`` and build yet another kernel using the
1942familiar commands.
1943
1944Additional tests are also the reason why you want to keep the
1945~/kernel-config-working file around for a few weeks.
1946
1947[:ref:`back to step-by-step guide <finishingtouch_bissbs>`]
1948
1949
1950Additional reading material
1951===========================
1952
1953Further sources
1954---------------
1955
1956* The `man page for 'git bisect' <https://git-scm.com/docs/git-bisect>`_ and
1957  `fighting regressions with 'git bisect' <https://git-scm.com/docs/git-bisect-lk2009.html>`_
1958  in the Git documentation.
1959* `Working with git bisect <https://nathanchance.dev/posts/working-with-git-bisect/>`_
1960  from kernel developer Nathan Chancellor.
1961* `Using Git bisect to figure out when brokenness was introduced <http://webchick.net/node/99>`_.
1962* `Fully automated bisecting with 'git bisect run' <https://lwn.net/Articles/317154>`_.
1963
1964..
1965   end-of-content
1966..
1967   This document is maintained by Thorsten Leemhuis <linux@leemhuis.info>. If
1968   you spot a typo or small mistake, feel free to let him know directly and
1969   he'll fix it. You are free to do the same in a mostly informal way if you
1970   want to contribute changes to the text -- but for copyright reasons please CC
1971   linux-doc@vger.kernel.org and 'sign-off' your contribution as
1972   Documentation/process/submitting-patches.rst explains in the section 'Sign
1973   your work - the Developer's Certificate of Origin'.
1974..
1975   This text is available under GPL-2.0+ or CC-BY-4.0, as stated at the top
1976   of the file. If you want to distribute this text under CC-BY-4.0 only,
1977   please use 'The Linux kernel development community' for author attribution
1978   and link this as source:
1979   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/Documentation/admin-guide/verify-bugs-and-bisect-regressions.rst
1980
1981..
1982   Note: Only the content of this RST file as found in the Linux kernel sources
1983   is available under CC-BY-4.0, as versions of this text that were processed
1984   (for example by the kernel's build system) might contain content taken from
1985   files which use a more restrictive license.
1986