Douglas Winslow's internet home page updates | tech | games | art | community | parodies | e-mail | index

Compiling the Linux Kernel

September 5, 2023 at 4:00 PM Eastern Time

If you've ever wondered how to compile your own Linux kernel to impress your computer and its hardware, then wonder no more. However, you may still want to compile the Linux kernel. Such is the problem of Linux now that it's corporate and acceptable to be complicated, as we talked about in the post before this one. It's obviously not a fun whim-based system anymore. That's unexpected.

It's not like it was in 1995, when potential users had to upgrade what was probably a hobby-based computer setup into an i386-compatible computer to be able to run Linux, only to need to wait hours to see if their new kernel would compile, link, and boot, if the boot loader could even find the kernel, if the memory timing or another hardware concern didn't crash the build. All you wanted to do was get audio support working. What a mess. When the distribution crowd started to become more popular than the trial-run crowd (the developers), it was a sign that there was professional backing, which gave the hobbyist volunteer path even more credibility. Time versus money versus education it was, for sure.

When you get tired of McAuthority throwing you a bone at school, with all that entry-level data entry work trapezing you back into entering the Microsoft ecosystem (maybe because the MacAuthority was out for the day), shuffle on home past all the advertising, say "aw shucks", and note the fact: in a world of McAuthority and MacAuthority, at least there's McDonald's: the place you knew public school was hinting at all along as where to spend or maybe even earn your paycheck, if only computers weren't at home to make you stay in and wonder why 8.3 filenames and expensive resource forks made money instead of free software. And here you thought McAuthority was from McDonald's. The restaurant, not the person. Or persons. (About here is where Mr. Linux Torvalds, who is probably Linus pretending to be a college student with a need to make an interface work, shows up and makes bank. McAuthority.)

Linux. As confusing and really standardatious as it is, it could be that it only was able to conquer the operating system landscape because UNIX™ has long file names and you need to eat something made by whoever aren't the old-school grocery store stalwarts running Microsoft and Apple Computers. Also it's expensive somehow (which investors like) resulting in multiple purchases to justify to yourself how cool you are.

You can try to install any kernel onto your running system, but it's not necessary if it's already functioning properly. There's no guarantee that your system will reload properly for any reason, including if you use a different kernel or boot loader, or if your custom configuration is different from what's already running, or if there are updated compiler or library complexities which are developer statements that prohibit a functional result, as I've pointed out in other places. You should have a best interoperability result with the same kernel version and the configuration that created the kernel you are currently running. Note that most Linux distributions have proprietary kernels because they do not prompt the user for source code installation; you could stay within the same major version and patchlevel (e.g. Linux 5.10.0-25 at Debian could suggest Linux 5.10.194 from

 $ export PS1="\n "               # you can try this; it's a professionally-designed prompt. 'pwd' for the current directory path.
 $ export PS1="\[\e];\w\a\]\n "  # separately, this works for certain extended xterms that hold information in the window manager.
 $ uname -a
Linux linux 6.1.51 #1 SMP PREEMPT_DYNAMIC Mon Sep  4 03:55:55 EDT 2023 x86_64 GNU/Linux

 $ tar -xf linux-6.1.51.tar.xz
 $ ls -ld linux*
drwxr-xr-x 26 drw drw 4096 Sep  2 03:16 linux-6.1.51
 $ cd linux-6.1.51
 $ mkdir ../mrkernel
 $ make O=../mrkernel/ oldconfig
make[1]: Entering directory '/home/drw/proj/src/mrkernel'
  GEN     Makefile
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/confdata.o
  HOSTCC  scripts/kconfig/expr.o
  LEX     scripts/kconfig/lexer.lex.c
  YACC    scripts/kconfig/[ch]
  HOSTCC  scripts/kconfig/lexer.lex.o
  HOSTCC  scripts/kconfig/menu.o
  HOSTCC  scripts/kconfig/
  HOSTCC  scripts/kconfig/preprocess.o
  HOSTCC  scripts/kconfig/symbol.o
  HOSTCC  scripts/kconfig/util.o
  HOSTLD  scripts/kconfig/conf
# using defaults found in /boot/config-6.1.51
# configuration written to .config
make[1]: Leaving directory '/home/drw/proj/src/mrkernel'
 $ cd ../mrkernel/
 $ ls -l .config
-rw-r--r-- 1 drw drw 156835 Sep  5 17:17 .config
 $ wc .config
  5770  17995 156835 .config
 $ make
 $ ls -l arch/x86/boot/bzImage
-rw-r--r-- 1 drw drw 8273952 Sep  5 19:30 arch/x86/boot/bzImage
 $ file arch/x86/boot/bzImage
arch/x86/boot/bzImage: Linux kernel x86 boot executable bzImage, version
	6.1.51 (drw@linux) #1 SMP PREEMPT_DYNAMIC Tue Sep  5 19:29:37 EDT
	2023, RO-rootFS, swap_dev 0x7, Normal VGA
 $ su root
 # make modules_install INSTALL_MOD_STRIP=1
 # make install
 # time sync
 # reboot

Copyright © 1996-2024 Douglas Rice Winslow III. All Rights Reserved. E-mail Address: <>