I’m a tinkerer at heart, after my father, who’s an electronics engineer. When I was still a toddler, he showed me everything – how to clean computers, how to turn them inside-out, how to exchange hard drives, do upgrades, etc. Those were valuable lessons that I unconsciously stored in the depths of my memory pockets for years. Now they’re finally starting to blossom. They just needed a trigger, I guess. Anyhow, my latest fancy is Gentoo. Though it’s considered a fully fledged GNU/Linux distribution, I feel it’s more of a framework since many things are optional and most of the system utilities have to be compiled from source code. Honestly, it’s a great learning experience, a “rite of passage” of sorts in the GNU/Linux world. Therefore, I decided to document my trials – fortunes and mishaps alike. Might be of value to the future “me” and many others who struggle with similar dilemmas or issues. Let’s get down to business then, shall we?
Entry 1# – Oct 1st 2016:
Every operating system has a kernel. Windows uses the NT kernel, MacOS X relies on the Mach kernel, GNU/Linux has the Linux kernel (surprise, surprise) and various BSDs have their own BSD kernels (FreeBSD, DragonflyBSD, OpenBSD, NetBSD, etc.). Finally, Illumos and OpenIndiana utilize the Illumos kernel. However, only the Illumos-based, BSDs and Linux-based operating systems allow the user to configure and compile the kernel from source code. It’s a non-trivial and oftentimes daunting undertaking. However, knowing what hardware the kernel supports pays off in the long-run. Not to mention the lower resource usage of a kernel that has been trimmed down and tailored to a specific machine. As long as one has the time and will to learn, the benefits are substantial. However, there are certain limitations that cannot be easily circumvented:
- Because GNU/Linux covers only ~1% of the consumers computer market, many hardware vendors don’t give a flying wardrobe about providing drivers for the Linux kernel.
- Per above, if GNU/Linux compatible drivers are actually provided, they tend to be poorly documented.
- Lacking documentation makes it difficult to know which kernel features need to be ON for external drivers to load and function.
- Computer and device vendors seldom provide information on the make and version of the internals (chips).
The one and only solution is to do proper data mining on the piece of hardware in question, prior to buying it. Then, seriously consider whether building a kernel from scratch is worth the effort. Regardless, Gentoo Linux recommends compiling one’s own kernel as that way we’re sure that every computer internal is fully operational (or not!) when booting the operating system afterwards. Kernel configuration and compilation is fully manual and typically proceeds according to the respective Handbook chapter. Since I don’t like running too many commands by hand, I wrote a simple shell script to do the kernel upgrades for me:
#!/bin/bash # a simple script to rebuild the kernel, regenerate initramfs with genkernel # and GRUB2 bootloader config. read -p "State the kernel version: " KERNEL_VERSION if [ -e /usr/src/linux-$KERNEL_VERSION-gentoo ] ; then cd /usr/src/linux-$KERNEL_VERSION-gentoo make silentoldconfig make && make modules_install make install genkernel --install initramfs grub-mkconfig -o /boot/grub/grub.cfg else echo "Sorry mate/lass, kernel sources for this version don't exist!" fi
“Genkernel” is a handy Gentoo tool that allows building of the initial RAM disc (initramfs) and the kernel also if we’re not interested in working with the .config file. It’s especially useful for non-standard setups like LVM, RAID or disc encryption. Additional details are available in the genkernel manpage. My first kernel compilation took ~1 hour, though together with reading through the configuration file I spent around 3 hours on it in total. On modern hardware the compilation would take 30-60 min and obviously the time devoted to learning about supported hardware is time well-spent. The gained knowledge can be applied to any GNU/Linux distribution. As I said earlier, it pays off in the long-run. To elaborate, running “make silentoldconfig” will ask for confirmation on new features (changed since last configuration) and “make oldconfig” will assume the default responses for them (“Yes”, “No”, “build as module”). If one has multiple versions of the Gentoo kernel, the primary version can be easily selected via the “eselect” tool (“eselect kernel list” to show available kernels and “eselect kernel set <number>” to choose the kernel). I will mention eselect many more times still as it is used for other selections, too.