20 votes

Have you ever compiled a custom Linux kernel?

Tags: linux

I was stubbornly determined to get my new Yubikeys working for FIDO2 SSH on WSL, which led me down the road to compiling my own custom Linux kernel for WSL with HIDDEV and HIDRAW enabled.

This was my first time ever trying anything like this, and by the end of it I realized that it's not actually so scary to compile your own custom Linux kernel!

Have you ever compiled a custom kernel before? What was the sequence of events that led you to do it?

22 comments

  1. [3]
    Notcoffeetable
    (edited )
    Link
    It's been about 20 years, but when I was 13-14 I ran some small webservers out of my room. Pretty much just toy projects. I definitely compiled Gentoo and some other distros, mostly as a hobby and...

    It's been about 20 years, but when I was 13-14 I ran some small webservers out of my room. Pretty much just toy projects. I definitely compiled Gentoo and some other distros, mostly as a hobby and also because at the time it was more or less necessary depending on the functionality you wanted. It wasn't hard, just slow at the time :).

    15 votes
    1. [2]
      UP8
      Link Parent
      Back in the slackware days I would compile a new kernel whenever a new version came out which was every few days. Back then I almost never used the package manager for software I cared about, I...

      Back in the slackware days I would compile a new kernel whenever a new version came out which was every few days.

      Back then I almost never used the package manager for software I cared about, I thought

      ./configure
      make
      sudo make install

      was really user friendly (it is!) but installing from rpm really is 100x faster.

      5 votes
      1. asciipip
        Link Parent
        I used to go through all the kernel configuration menus to look at each option and decide whether I wanted it in my kernel or not. But I haven't done that in a couple decades now; as long as my...

        I used to go through all the kernel configuration menus to look at each option and decide whether I wanted it in my kernel or not. But I haven't done that in a couple decades now; as long as my distro's packaged kernel works for me, I feel like it'd be wasting my time to keep chasing that level of granularity. And with DKMS now, I don't even need to worry about hand-compiling out-of-kernel modules when I need them.

        2 votes
  2. Nemoder
    Link
    I started building my own kernel sometime in the late 2000s when I needed to get a mouse driver fully functional. Then I never stopped doing it. It's a great way to learn about all the new...

    I started building my own kernel sometime in the late 2000s when I needed to get a mouse driver fully functional. Then I never stopped doing it. It's a great way to learn about all the new features that are being added and to trim off excess modules you know you'll never need (or to learn about why you actually DID need them. oops.)

    8 votes
  3. Akir
    Link
    It's been a while but it's actually pretty easy. The last time I checked it was just a matter of grabbing the sources, answering some detailed questions about your machine, and running make. The...

    It's been a while but it's actually pretty easy. The last time I checked it was just a matter of grabbing the sources, answering some detailed questions about your machine, and running make. The hardest part was getting the bootloader to use the new one safely without getting rid of the old kernel in case you messed up the configuration.

    My early experiences with Linux were well before Ubuntu made it easy, so I took the time to understand the system from inside out. For a time I was running a scratch-built somewhat barebones Linux system. I tried to do Gentoo for a while but their tools that were supposed to simplify everything actually seemed to make things more complicated, so I don't remember if I ever managed to make it self-hosting.

    With all that in mind, I had a lot more knowledge about the inner workings of a PC before I started, so while I say "it's easy", that's not accounting for the knowledge I had acquired beforehand. For most people it's going to be something of a research project.

    7 votes
  4. nosewings
    Link
    Over the summer I bought a Libre Computer "Le Potato", essentially as a cheaper alternative to a Raspberry Pi. They do provide their own images, but my preferred distro (NixOS) doesn't have their...

    Over the summer I bought a Libre Computer "Le Potato", essentially as a cheaper alternative to a Raspberry Pi. They do provide their own images, but my preferred distro (NixOS) doesn't have their kernel in the central repository, so I ended up writing a little recipe to build it. Fortunately, NixOS makes that sort of thing easy (once you've gotten past the hardest thing in Nix: the documentation).

    5 votes
  5. [4]
    KneeFingers
    Link
    Somewhat tangentially related, but I've used a DevOps pipeline process to automate the build of a custom Linux ISO image off of a virtual machine. It was a complicated process that required a lot...

    Somewhat tangentially related, but I've used a DevOps pipeline process to automate the build of a custom Linux ISO image off of a virtual machine. It was a complicated process that required a lot of trial and error; calling chroot presented some challenges and introduced unexpected behaviors. But looking back, this project really established my love of working with Linux and becoming comfortable with the command line.

    4 votes
    1. [3]
      LGUG2Z
      Link Parent
      I'm actually in the process of doing this right now! I'm setting up a GitHub Actions build of the custom WSL2 Linux kernel I'm using to easily be able to distribute it to others (and to have a...

      I'm actually in the process of doing this right now! I'm setting up a GitHub Actions build of the custom WSL2 Linux kernel I'm using to easily be able to distribute it to others (and to have a pre-built copy handy if I'm ever in a bind!)

      5 votes
      1. [2]
        KneeFingers
        Link Parent
        It's so cool to hear about others exploring pipeline integration for image/kernal distribution! I was having to do my work on a cloud platform, but did take a peak at GitHub's tools when working...

        It's so cool to hear about others exploring pipeline integration for image/kernal distribution! I was having to do my work on a cloud platform, but did take a peak at GitHub's tools when working elsewhere. It's been a few years since I've touched it and my career has been adventurous to say the least, but feel free to shoot me a DM if you would like to hear more. Every once and while it comes up in professional discussions on my past experience, but I haven't had another position that has really allowed me to dive into that again.

        I remember Ubuntu's site had some great guides that I relied upon as my dev Bible of sorts, but mashing that with cloud documentation felt like uncharted territory at the time. But it's very cool hear about this topic being expanded upon more since I last worked on it!

        2 votes
        1. LGUG2Z
          Link Parent
          I actually just managed to push something working before I went to bed last night for anyone that wants to try building their own custom WSL Linux kernel via GitHub Actions!...

          I actually just managed to push something working before I went to bed last night for anyone that wants to try building their own custom WSL Linux kernel via GitHub Actions! https://github.com/LGUG2Z/custom-wsl2-linux-kernel

          2 votes
  6. Happy_Shredder
    Link
    I run funtoo, a derivative of gentoo, and routinely compile my own kernels. The standard tool for this family of distros is genkernel, which makes everything super easy. I also use dracut to...

    I run funtoo, a derivative of gentoo, and routinely compile my own kernels. The standard tool for this family of distros is genkernel, which makes everything super easy. I also use dracut to generate my initramfs, because it has some nice tools for handling encrypted partitions.

    Without starting a flamewar, I was on Debian for a long time, had a looooot of issues with the switch to systemd, switched to gentoo cos it seemed the best supported non-systemd distro, and quickly jumped to funtoo cos it has some nicer utils. Kinda fell in love with how the whole os is designed and haven't looked back. While you don't need to compile your own kernel for Funtoo it's a very natural step to take

    3 votes
  7. [2]
    Pistos
    Link
    Been using Gentoo for many years. I don't even know or remember what it's like to just accept and use a stock kernel blob from a distro provider. If all you're doing is changing kernel config and...

    Been using Gentoo for many years. I don't even know or remember what it's like to just accept and use a stock kernel blob from a distro provider. If all you're doing is changing kernel config and compiling, that's actually pretty easy, assuming you know which config vars you want or need to change -- and there's a lot of documentation out there to help you find those out.

    In a sense, what's actually harder in practice than rolling a custom kernel is getting it to load smoothly with a boot loader. I actually have had more UX friction dealing with LILO and GRUB than with the kernel. Not to mention BIOS, UEFI, dual booting, telling the computer which disk to boot from. Those are the trickier things.

    2 votes
    1. Pavouk106
      Link Parent
      As a fellow Gentoo user I have only recently learned that on UEFI it doesn't just need the EFI partition, but actually installing the bootloader (info) into the UEFI (BIOS). Simply put - I got SSD...

      As a fellow Gentoo user I have only recently learned that on UEFI it doesn't just need the EFI partition, but actually installing the bootloader (info) into the UEFI (BIOS).

      Simply put - I got SSD from one PC, threw it in another (both UEFI and OS too) and couldn't get it to boot.

      I had to make bootable UEFI flashdrive with UEFI image (used dd to just throw Ubuntu Live ISO on the /dev/sdX), biot into that, chroot into my Gentoo install and run grub-install again so the new motherboard knows I have a system on that SSD...

      BIOS was much much easier, you just had bootale partition, bootlader there and it picked it up by itself.

      Oh man, so many things still waiting for me to learn...

      1 vote
  8. Pavouk106
    Link
    I run Gentoo Linux on almost all my machines, I have compiled al he kernels myself. I also set them up myself. I don't use initramfs, I boot kernel straight up. Every kernel is made for the...

    I run Gentoo Linux on almost all my machines, I have compiled al he kernels myself. I also set them up myself. I don't use initramfs, I boot kernel straight up.

    Every kernel is made for the concrete mchine it runs on, which means it has only the driver for that one ethernet device that is present in the computer, for that one hardware monitoring (temps, voltages, fan speeds), for that one wifi card...

    It is part of Gentoo Linux and I do it since around 2010, so it is just kinda no-brainer for me.

    I also setup my own GRUB config file, as the generazed one seems too convoluted for me. I have my boot parameters on literally four lines, two of those are name to show on boot screen and closing parentheses ( } ). The other two are just pointing on the partition with /boot and then calling out the specified kernel.

    2 votes
  9. whbboyd
    Link
    Compiling a kernel is easy, verging on trivial. Documentation is good, the build tools are very robust, and the process is well-tested (across multiple C compilers, even). The kernel very possibly...

    Compiling a kernel is easy, verging on trivial. Documentation is good, the build tools are very robust, and the process is well-tested (across multiple C compilers, even). The kernel very possibly accounts for a plurality of C compilation time since the 2000s or so, so you would expect it to be well hammered-out.

    Configuring a kernel is a whole different story. I have never successfully configured a working kernel from scratch. There are a lot of obscure options that you have to get "right", that may depend on details of your hardware or desired kernel functionality that no one who's not a kernel developer has enough context for to know. I've compiled working kernels, but only by starting from a pre-existing configuration (typically a distro's).

    2 votes
  10. xvnz
    (edited )
    Link
    Far too long ago, at the beginning of my time with Unix and Unix-like systems, I spent a fair amount of time recompiling the NetBSD kernel in the hopes of squeezing a little more performance out...

    Far too long ago, at the beginning of my time with Unix and Unix-like systems, I spent a fair amount of time recompiling the NetBSD kernel in the hopes of squeezing a little more performance out of a DEC Multia. (I'm aware OP asked specifically about the Linux kernel, but the question was about motivations, not OS choices.) While the idea sounded scary when suggested to me by more experienced geeks, the process turned out to be little more than editing a text file to comment out unused drivers, running a couple of prep commands, then firing off the compile. Oh yeah, and then waiting until the next morning, because if there was one thing you could say about Multias, it's that they were SLOOOOWWWWWW.

    1 vote
  11. andrewhudson
    Link
    I haven’t, but it’s sort of on my bucket list to do so. I’ve had the Building Linux from Scratch guide in my bookmarks forever and someday I’ll see it through.

    I haven’t, but it’s sort of on my bucket list to do so. I’ve had the Building Linux from Scratch guide in my bookmarks forever and someday I’ll see it through.

  12. chris-evelyn
    Link
    Yes, back when I started I had only a very old PC (Pentium II, I think) built with whatever other parts I could scrounge together. Leaving out everything I didn‘t use made a small but noticeable...

    Yes, back when I started I had only a very old PC (Pentium II, I think) built with whatever other parts I could scrounge together.

    Leaving out everything I didn‘t use made a small but noticeable performance difference and I had to customize things to get my graphics and sound card working.

    It was kinda fun but these days I have better uses for my time. And money for supported hardware.

  13. JXM
    Link
    Technically, yes. I used to run custom kernels on my Android phones way back when that was more possible. A lot of them had to be compiled from scratch.

    Technically, yes. I used to run custom kernels on my Android phones way back when that was more possible. A lot of them had to be compiled from scratch.

  14. ulkesh
    Link
    Yes, in 1999 when I was first learning Linux and had a very crappy PCI 56kbps winmodem that Linux just didn't like. I attempted to get it to work by so many various attempts at changing flags/etc...

    Yes, in 1999 when I was first learning Linux and had a very crappy PCI 56kbps winmodem that Linux just didn't like. I attempted to get it to work by so many various attempts at changing flags/etc and recompiling the kernel.

    I ended up getting an ISA 33.6kbps modem that just worked with Linux and I never bothered with a winmodem again.

  15. tech10
    Link
    Sort of, while making a postmarketOS port to an old phone of mine (real linux for phones) i had to get a kernel for my device, so i speciefied the kernel (which is basically the android kernel)...

    Sort of, while making a postmarketOS port to an old phone of mine (real linux for phones) i had to get a kernel for my device, so i speciefied the kernel (which is basically the android kernel) and the program to make a port automatically took care of compiling it, i just had to put some patch files to make the kernel compile.

  16. UntouchedWagons
    Link
    I ran gentoo for a while maybe 12 to 13 years ago which my nature required me to compile my own kernel but I don't remember much about it.

    I ran gentoo for a while maybe 12 to 13 years ago which my nature required me to compile my own kernel but I don't remember much about it.