Gentoo-sources: How to build your kernel without dying trying

Well, this is one more of those points that I cannot ignore before starting the Gentoo installation guide 🙂 I know that many will already be looking forward to this post, and sorry for making you wait, but I also consider that I do not explain this carefully against my Gentoo user status 😛 Without further ado, let's get started.

What is the kernel?

The kernel is properly the Linux part of any distribution, it is the program that allows us to communicate each piece of hardware on our computer with the programs that we run on it. Its creator, Linus Torvalds, decided to release it under the GPL license and thanks to him, and the GNU project, we can now enjoy so many distributions and varieties to choose from. It is mostly written in C, with a bit of Assembly here and there, and today it is the largest free software project, with thousands of developers working on it, both hobbyists and professionals, and maintains a line constant accelerated growth for several years now. Here is the kernel official page so they can take an in-depth look.

How are you on Gentoo?

Well, as is to be expected in Gentoo, there are many kernel options, I leave here a small list for you to see better what I mean:

  • gentoo-sources: Kernel 4.12 with special patches for Gentoo Linux.
  • git-sources: Kernel directly downloaded from the Linus Git repository.
  • vanilla-sources: Full kernel without any patch.
  • xbox-sources: Full kernel for Xbox Linux.
  • zen-sources: Zen's living kernel
  • ...

For a complete list I leave you the wiki link where you can find all the kernels Gentoo maintains in their repositories. (everything ending with -sources)

I have the code, now what?

Well, unlike all other Linux packages, the kernel DO NOT it is updated, it is installed. This allows us to have multiple kernels in our system at the same time, of course, you can always run only one at a time. In order to compile it, it is necessary to use the tools that we have already discussed in a previous post. But since in Gentoo the community does 80% of your work, let's do it the simplest way 😉

genkernel-next:

Let me introduce you to a tool that is just great 🙂 it's called genkernel-next, you can find it in the Gentoo repositories.

Own. Christopher Diaz Riveros

The list of options is even bigger, but here are some of my favorite options. One of the most important steps when installing Gentoo is setting of your kernel, this will allow you to get the most out of your computer and at the same time avoid all that extra weight that many pre-compiled kernels have.

CLI and GUI:

As you might expect, the kernel configuration also has various ways of being made 🙂 choices all over the place, just awesome. Here are some of the photos of what the options look like:

genkernel --xconfig all

Own. Christopher Diaz Riveros

genkernel –qconfig all

Own. Christopher Diaz Riveros

genkernel --nconfig all

Own. Christopher Diaz Riveros

genkernel –menuconfig all (my favorite)

Own. Christopher Diaz Riveros

Great, but how do I find things?

A wise question that everyone is surely asking themselves right now. If you don't want to have to search line by line, remember that «/ » Y "They are your friends on this mission. But since it is better to see than to read, I show you what I mean by this.

Suppose we need to check our processor, the kernel supports both intel and amd, and ours is intel. If you press / (slash), it will take us to the following menu:

Own. Christopher Diaz Riveros

Great, now let's see the magic in action 🙂

Own. Christopher Diaz Riveros

Great! Now we have a drop-down list with all the information we may need, the technical name of the module, the path, the type of value, etc. And now the question ... how do I get to the location? Also very simple! if we look at the left part, we have numbers inside parentheses. Press one of them and you will see the magic happen again.

Own. Christopher Diaz Riveros

As fast as this! We are already in the location we need. But ... wait, I told you that is your friend, do you remember? Well let's see what happens if we press? right now.

Own. Christopher Diaz Riveros

A short description of the module, its options and dependencies 🙂 all at your fingertips. Once your search is finished, you can exit. You will notice that the top bar has returned to the Search (intel) line, if you exit again, it will return you to the main menu where you can start a new search.

What to move and what not?

At this point you should already feel totally powerful, because you have achieved something that few humans do in their life, compile a kernel. Congratulations! But now the question arises… what should I modify? That my friend, is something that only you can discover, but of course I can give you a couple of recommendations that help me a lot:

The default works

As with all programs, Linux is configured to work with the default settings. This guarantees that even if you don't want to configure anything, when compiling you will have a working kernel.

If you don't know it, don't move it

This is something that perhaps the most adventurous will overlook. It's great to be able to quickly navigate through the options, but if you're interested in really getting to know how your machine thinks, a read of each option is a great way to get used to the idea. Always remembering what you change and searching or comparing with a browser is highly recommended as well.

The biggest weight is on the drivers

Many drivers are loaded by default, this makes the kernel heavy. For example, only for network cards, there are about 10 official drivers in the kernel, and many distributions compile all 10, or more, but in reality you will only use one on your computer (note that for Wi-Fi there is another separate section). If you want to reduce the weight of your kernel considerably, your first option is there. For this, your best friends will be lspci, lsusb, Google. With this you can have a fairly clear idea of ​​what your system has and only leave the necessary drivers to make it work. For example I leave my lspci output:

Own. Christopher Diaz Riveros

With this I can have quite clear critical information, such as my network controller, the Wi-Fi controller, my SATA hard drive, and many other things that help me reduce the weight of my kernel.

Check well that you are compiling what is necessary with *

Thanks again to our partner njord, an important point that I forgot to mention because of the emotion 🙂

It should also be mentioned that there are features of the kernel that should be included within it (*), and others can be handled as modules (M). I remember my first compiled kernel, wanting to leave my root reiserfs support as a module, when in life was it going to work?!?! xD ...

Certainly, if your kernel needs something to work, it cannot be a module. By default, modules load after the kernel has done all the startup process. If your kernel needs something to start, it better be compiled into instead of as module … Which brings us to the first point again "?"  is our friend 😉

In summary:

Well now that you've dived into the kernel world a bit, I think I've already met another milestone needed to be able to generate a ~ 20-step Gentoo install guide 🙂 but if I find anything else out there I'll try to explain before just let loose in the air.

Greetings and I leave you other of my posts in case you miss them:

Gentoo Linux: The Story of a Journey

Gentoo: Why did I choose to compile my own programs?

Gentoo: Heart of the Beast

 


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   njord said

    Very good post as always.

    And here is my grain of sand: For our kernel to work correctly we have to adapt it to our hardware, so we must know it extremely well. For this purpose we have to see 'lspci' and 'lsusb' as the main sources of information. And if we need something more specific, I leave you this page, which has gotten me out of trouble on more than one occasion https://kmuto.jp/debian/hcl/

    It should also be mentioned that there are features of the kernel that should be included within it (*), and others can be handled as modules (M). I remember my first compiled kernel, wanting to leave my root reiserfs support as a module, when in life was it going to work?!?! xD ...

    Regards!

    1.    Juan Pablo Garcia Rivera placeholder image said

      Exactly njord, so this post will not be descriptive enough if you do not know the HW you have, as a recommendation it is important to visit the manufacturer's page as well as read with the help of the kernel itself about the modules that can serve you, under these comments I have added a link to my blog where you can download an advanced config file for a Hp Pavilion 23-p132la, I hope it will be helpful and hopefully more and more users share these files with different applications in HW.

  2.   I javilondo said

    Hello friend, I love your articles, that is why I have subscribed to your page for a long time. I also share the video into the unknown of getting into gentoo, but I'm excited to follow this series of articles.
    Congratulations on your website.
    I just ask you a favor: Do not upload images in * .bmp, since my connection is somewhat slow and my browser takes a long time to load heavy images, so I recommend that you convert the images into * .png or * .jpg.
    Greetings.

    1.    ChrisADR said

      Oops, sorry 🙂 but thank you very much for pointing out, I had not thought about it and although somewhat experienced in Gentoo, I still do not master this topic of blogs very well 😛 but from now on I will try to change the format, normally I only take cuts with Shutter and I upload them directly, so as not to make too much weight on my team, but I will also consider the weight for you 😉 Greetings and thank you very much for your comments, they encourage me to continue writing, I already have the weekend gift 🙂

  3.   gnarlf said

    I find the series of articles you are writing super interesting. I've ever installed Gentoo as a hobby, but always with a thousand and one problems, not really controlling much of what I did and tricking things to get out of trouble. Even so, I have managed to see in my multiple attempts that this would be the distribution in which I would stay if I managed to have an optimal and correct installation and master it. Right now I'm on Fedora, although I'm not a convinced Fedorian. I'm a bit like Gentoo's mascot: «Larry the cow was a bit frustrated
    at the current state of Linux distributions…
    … Until I've tried Gentoo Linux. »
    I leave you a couple of «tips» for your future articles, in case you find it interesting to touch them specifically and that derive from my own doubts:
    - Gentoo has a fairly extensive repository, but even so there are specificities that are not in it; be it some scientific programs or other very specific things. It would be interesting to know firsthand how we can install what we cannot find in your repos. I know but do not understand well the existence of "overlays". Debian has an official and recommended way to install software that is not in their repositories, is there something similar in Gentoo? What would be the best way to install without the classic ./configure && make && make install?
    - Finally, my biggest problem when installing Gentoo comes after the first restart in which I face a console without having the network configured. It is a point of frustration, since I don't quite understand how to get the Wi-Fi up from there. It would be very interesting to know the tutorial mode which are the exact steps to do it and to be able to continue the installation of the desktop and other utilities. In my previous installations what I did was install Gnome and everything from the chroot of the base system installation; a fix, come on.
    Nothing else. Thanks to you already DesdeLinux for these articles about a distribution that is so non-mainstream and yet so interesting.
    By the way, and I already abuse you a little more: I always read about Gentoo from the perspective of IT professionals like you, programmers, systems or network engineers, etc. But I've never seen an opinion from an end user using the distro; Is Gentoo a good idea for that end user, who, I don't know, is a photographer, or studies environmental science or mechatronics, or just wants Steam,…? (I guess you understand what I mean)
    Thank you very much ChrisADR and a warm greeting

    1.    ChrisADR said

      Well, your requests have been written down 🙂 now that I have finally finished the step-by-step installation guide, you will have to give me a couple of days because I have a certification exam this Saturday (LFSC of the Linux Foundation) and I have to prepare for these remaining days. As for the Overlays, they come to be like AUR in Arch, a place where users can create their own ebuild, another topic that remains pending for a full post. And at the same time there are also the normal installation processes, which are as varied as there are grains of sand on the beach ... but that's also for another post 😉 As for users, in Gentoo there is a bit of everything, there are people who are gamer (old style, because I'm not 100% if Steam is in our main repository), there are Hackers who have their own Gentoo derivative for Pentesting, Pentoo ... I know some colleagues in the community who are not necessarily engineers, or mathematicians, and Well, they do well 🙂 There are also more scientific people and projects on geosciences, or even religion ... in short, there is a bit of everything in Gentoo, for all tastes, since philosophy allows us to choose 🙂 I will soon be writing more articles and I will try to cover your doubts 🙂 Greetings

      . As a good Gentoo user that I am, over time you will notice, many times we have to think “out of the box” and if that includes one or another skill out there, then great 😉 you will see it in my Gentoo installation guide that will come out soon 🙂

  4.   Juan Pablo Garcia Rivera placeholder image said

    How about partner ... supporting your movement ... here is the config ... for the "Hp Pavilion 23-p132la + AMD A10-7800 Radeon R7"
    http://jgarcia.my-place.us/?page_id=585

    I am currently investigating the governor configuration… all help is welcome…

    1.    ChrisADR said

      Excellent! Thank you very much for sharing your experiences with the rest of the community, without a doubt my post is not 100% exact or perfect, because I think that in that case it is better to write a complete book 😛 but at least I hope this will awaken the curiosity of more of one and thus be able to leave some homework for each one in their free time 😉 Greetings and thanks

  5.   fernan said

    Hello:
    Do you notice much difference between compiling a kirnel or binary kernels?
    For example in an overlay there is this ebuild:
    http://gpo.zugaina.org/Overlays/betagarden/sys-kernel/debian-sources-bin
    Greetings.

    1.    ChrisADR said

      To give you a little idea, Our friends at Linux From Scratch have this to say about building.

      «We installed a system that was just enough to run the Apache web server; total disk space usage was approximately 8 MB. With further stripping, that can be brought down to 5 MB or less. »[1]

      Translated into Spanish it says that they have managed to run an embedded Apache server in only 8MB, which could even have been 5MB. Much of that space is kernel only, so if you want a system that does one thing specifically, or uses only your hardware. 10M kernel allow you to have the rest of RAM available (remember that the kernel runs in RAM all the time you use your computer). In addition to the security and other benefits of having a custom kernel, you can see a significant improvement in space. Which may affect speed as well.

      regards

      [1] http://wiki.linuxfromscratch.org/lfs/

  6.   fernan said

    Hello:
    I have downloaded stage 3 into a folder and after synchronizing portage I have tried emerge gentoo-sources but does the process take hours? after half an hour, messages like
    / usr / linux / gentoo-sources 4.12.12 / arch / arm / *
    Should it decompress so much and stay the same hours or is there an option to do it faster? since this emerge only leaves the sources to later compile them with the options.
    greetings.

    1.    ChrisADR said

      Hi Fernan, well I have never tried to install an arm processor. I understand that depending on the version of RPi (in case you are using one) the USB and internet buses are connected, so the download time may be much longer than normal. (Even on my i7 laptop the kernel download time in the git repository is about 4 to 5 minutes)
      Well, I don't know how familiar you are with the subject, but you could compile everything on a much more powerful laptop and pass it already compiled to the final device, that would help a lot with the timing issue.
      regards