Improving your Framework Desktop or any other machine

In yesterday’s thread Framework Desktop:- amdgpu unable to locate a BIOS ROM the community helped me to fix a really bad issue. So, now I feel like giving something back to the community.

If you feel the following stuff it’s unwarranted advice or too much trouble, then skip this post and go on with your life.

If, on the other hand you’re willing to suffer a bit of short term pain (which is actually not as bad as they say!) for a big long term gain, then keep reading.

All this comes up from James comment of what most distros do.

Essentially, most distros cater to the necessities of all, so they work on the majority, if not all, machines. All that is fine and make a lot of people happy.

Distributions’ kernels are made to boot on every possible machine, so they are compiled for a generic CPU. That does not take advantage of the instruction set of the specific CPU in your machine. That’s why kernel 6.16 added this.

But distros don’t do that and also, they include in the kernel as modules the drivers for most everything. Because by doing otherwise, they won’t work on every possible machine under the sun.

If you want to make your life a little bit better, then tailor your distro to your specific machine. That means, among other things, compiling your own custom kernel.

It’s a process that can take a few hours at first, but in the end you get a lean, fast kernel made just for your machine, instead of the bloated kernel that your distribution gives you. Plus, once done, you can reuse that configuration for future kernel releases.

To do that, follow this steps:

  1. Find out what is the process to build a custom kernel for your distro. At some point, that involves installing the kernel sources, which go into /usr/src.
  2. Copy /proc/config.gz from your running system somewhere on your disc and gunzip it.
  3. lspci -nnk will tell you the drivers/modules that the distribution kernel uses for your machine. You are essentially concerned about the graphics driver (Framework Desktop’s is amdgpu), network driver (FD is Realtek RTL8126) and wireless driver (FD is Mediatek MT7925). YMMV, for example your machine could have a another AMD/ATI driver or a NVIDIA/nouveau driver. Make note of all these modules.
  4. Go to the specific kernel source in /usr/src that you downloaded in (1).
  5. make distclean or make mrproper
  6. copy your unzipped config as /usr/src/kernel-x.x.x/.config
  7. make oldconfig. Answer N or Y to any new options as you feel like.
  8. make menuconfig
  9. Make sure your disc driver is static not module, that means [*]. FD’s is NVME, your machine could have NVME or SATA.
  10. Start with your graphics adapter. For that go to Device Drivers, Graphics support, Direct Rendering Manager and from everything there only keep your driver as module, turning off all the other drivers.
  11. Do not touch/change anything else. Exit menuconfig and build the kernel per instructions you found out in (1).
  12. Make the necessary changes to add your new kernel to GRUB’s the boot list and reboot your machine into the new kernel.
  13. If everything goes well (it should), you’re running your new custom kernel.
  14. Repeat (10) to (12) for your network (Device Drivers, Network Device Support, Ethernet driver support) and wireless drivers (Device Drivers, Network Device Support, Wireless LAN).
  15. After each successfull step, make a backup copy of your .config, just in case.
  16. Now you have a lean kernel containing only the necessary modules for your machine and disabling hundreds of unneeded drivers.
  17. If you feel like it, you can try removing other things from Device Drivers, like Multimedia, Sound or other stuff you don’t need (that means they don’t come up in lspci -nnk).
  18. As a final touch, after everything is working, run make menuconfig, go to Processor type and features and turn on Build and optimize for local/native CPU. Exit, rebuild, reboot.
  19. With that done, if your machine has an AMD CPU, disable all Intel and other CPUs options. If it has an Intel CPU, disable all AMD options and so on. Exit, rebuild, reboot.

At the end of all this, you end up with the lean and fast kernel specifically built for your machine.

Make sure you save a copy of your last functioning .config so you can reuse it in future kernel releases. You just copy it to a clean new kernel source and run make oldconfig.

All this does not only make your kernel leaner and faster, but also eliminates any possible security issues that may come up in the drivers that you disabled.

That’s it! If you managed to go through all this, enjoy your faster machine.

Now, if you really feel adventurous check this.

4 Likes

Faster how? Did you do any benchmarks if that actually does something? I don’t really see how unloaded kernel drivers have any significant performance impact apart from taking up a bit more storage.

The security angle is a valid point but for unloaded modules to become a problem the attacker would have to be able to load modules and that usually means they already have quite a bit of access.

There is also the major downside of loosing the ability to just take your ssd and plug it into a different computer and keep going if there is a physical issue with the current one unless the other computer has close enough hardware.

Faster how? Did you do any benchmarks if that actually does something? I don’t really see how unloaded kernel drivers have any significant performance impact apart from taking up a bit more storage.

This an an old trope that’s been out there forever, usually by lazy people wanting to have stuff served to them on a silver platter and not doing much work themselves.

Did not do any benchmark on the Framework Desktop, but I remember that years ago, when machines where not as fast as today, my Ubuntu system took 23 seconds to boot and I got it down to 7 seconds with a custom kernel.

Unless you do them yourself, all benchmarks are always biased to give you the impression that the author wants you to have. For example storage manufacturers will push stuff and situations that show you that their thing is the fastest of them all. It’s real life that counts.

The security angle is a valid point but for unloaded modules to become a problem the attacker would have to be able to load modules and that usually means they already have quite a bit of access.

Why keep in your system potential points of failure? Vulnerabilities are found everywhere on a regular basis. With today’s AI tools it’s going to be even easier to discover them. Who knows, maybe the AI that you’re running on your Framework Desktop will find the next one if you’re training it and ask nice enough.

No this is a genuine question, I have seen a recent increase in people doing device specific kernels (some concerningly even only distributing binaries which is very sketchy) but very few of them actually deliver any concrete number or even arguments why that would be better (you at least have the argument bit covered). I am just wondering what is going on there.

That must have been a while ago or ubuntu is doing something awful to the kernel. Kernel only boot times been very fast for a while now.

Even when you do it yourself you are the author, but even then we would at least know more about what the impression you want was.

Ultimately yeah but you also did not provide much info on how it impacts that.

Portability and compatibility but this is a valid argument to make. Of course removing bits may also expose other surface are that may not otherwise have been there but I concede that is less likely than there being an issue with an ancient wifi driver. However again to take advantage of issues in unloaded kernel drivers (or hell intel microcode) does require quite a bit of access to begin with.

This also reminds me of the whole x86-64-v4 thing, but in that case at least they also compiled all the packages for it which tends to have a bigger impact.

Adrian, unless you’re paying Redhat or similar, your distribution is giving you something for free. If you’re happy with what you’re getting, then so be it.

I’m also giving something for free, but I’m not forcing anybody to do anything. If you doubt it, don’t like or have worries or concerns about it, please follow my advice in the first post and move on with your life. It’s a free world anyway.