The Linux Kernel: Configuring the Kernel (Part 1)

Discussion in 'Linux Kernel' started by DevynCJohnson, Jul 15, 2013.

  1. DevynCJohnson

    DevynCJohnson Super Moderator Staff Member Staff Writer

    Messages:
    973
    Likes Received:
    857
    Trophy Points:
    93
    Index
    NOTE: To better understand this article, check out the previous articles in this series.
    Introduction
    Source Code
    Drivers
    Security
    Configuration Part 1
    Configuration Part 2
    Configuration Part 3
    Configuration Part 4
    Configuration Part 5
    Configuration Part 6
    Configuration Part 7
    Configuration Part 8
    Configuration Part 9
    Configuration Part 10
    Configuration Part 11
    Configuration Part 12
    Configuration Part 13
    Configuration Part 14
    Configuration Part 15
    Configuration Part 16
    Configuration Part 17
    Configuration Part 18
    Configuration Part 19
    Configuration Part 20
    Configuration Part 21
    Configuration Part 22
    Configuration Part 23
    Compiling and Installing
    Modules
    Patches
    Types of Kernels

    List of Kernel Topics on Linux.org

    Now that we understand the Linux kernel, we can move on to the main event - configuring and compiling the code. Configuring code for the kernel does take a lot of time. The configuration tool asks many questions and allows developers to configure every aspect of the kernel. If unsure about any question or feature, it is best to pick the default value provided by the configuration tool. This tutorial series will walk readers through the whole process of configuring the kernel.

    To configure the code, open a terminal in the main source code folder. Once a terminal is up, there are a few ways to configure the code based on the preferred configuration interface.

    make config - Plain text interface (most commonly used choice)
    make menuconfig - Text-based with colored menus and radiolists. This options allows developers to save their progress. ncurses must be installed (sudo apt-get install libncurses5-dev).
    make nconfig - Text-based colored menus - curses (libcdk5-dev) must be installed
    make xconfig - QT/X-windows interface – QT is required
    make gconfig - Gtk/X-windows interface – GTK is required
    make oldconfig - Plain text interface that defaults questions based on the local config file
    make silentoldconfig - This is the same as oldconfig except the questions answered by the config file will not be shown
    make olddefconfig - This is like silentoldconfig except some questions are answered by their defaults
    make defconfig - This option creates a config file that uses default settings based on the current system's architecture.
    make ${PLATFORM}_defconfig - Creates a config file using values from arch/$ARCH/configs/${PLATFORM}_defconfig.
    make allyesconfig - This option creates a config file that will answer yes to as many questions as possible.
    make allmodconfig - This option creates a config file that will make as many parts of the kernel a module as possible

    NOTE: Code in the Linux kernel can be put in the kernel itself or made as a module. For instance, users can add Bluetooth drivers as a module (separate from the kernel), add to the kernel itself, or not add at all. When code is added to the kernel itself, the kernel requires more RAM space and boot-up time may take longer. However, the kernel will perform better. If code is added as modules, the code will remain on the hard-drive until the code is needed. Then, the module is loaded to RAM. This will reduce the kernel's RAM usage and decrease boot time. However, the kernel's performance may suffer because the kernel and the modules will be spread throughout the RAM. The other choice is to not add some code. For illustration, a kernel developer may know that a system will never use Bluetooth devices. As a result, the drivers are not added to the kernel. This improves the kernel's performance. However, if users later need Bluetooth devices, they will need to install Bluetooth modules or update the whole kernel.

    make allnoconfig - This option creates a config file that will only add essential code to the kernel; this answers no to as many questions as possible. This can sometimes make a kernel that does not work on the hardware it was compiled on.
    make randconfig - This option makes random choices for the kernel
    make localmodconfig - This option creates a config file based on the current list of loaded modules and system configuration.
    make localyesconfig - This will set all module options to yes - most (or all) of the kernel will not be in modules

    TIP: It is best to use “make menuconfig” because users can save their progress. “make config” does not offer this luxury. Because the configuration process takes a lot of time,

    Configuration:

    Most developers choose "make menuconfig" or one of the other graphical menus. After typing the desired command, the first question asks whether the kernel to be built is going to be a 64-bit kernel or not. The choices are "Y", "n", and "?". The question mark explains the question, "n" answers no to the question, and "Y" answers yes to the question. For this tutorial, I will choose yes. To do this I type "Y" (this is case-insensitive) and hit enter.

    UPDATED NOTE: At first, I used "make config" as I wrote this series. I later used "make menuconfig" (ncurses). "make config" is linear, that is, each question is asked one after another while the ncurses interface is a branching menu. If you are using any of the configuration interfaces that use menus, start at the top of the first (main) menu and work your way down going into each menu and sub-menu. This will allow you to follow this series easily as you configure your own kernel.

    NOTE: If the kernel is compiled on a 32-bit system, then the configuration tool would ask if the kernel should be 32-bit. The first question is different on other processors.

    The next line shows "Cross-compiler tool prefix (CROSS_COMPILE) []". If you are not cross-compiling, hit enter. If you are cross-compiling, type something like "arm-unknown-linux-gnu-" for ARM systems or "x86_64-pc-linux-gnu-" for 64-bit PC systems. There are many other possible commands for other processor types, but the list can be quite large. Once a developer knows what processor they want to support, it is easy to research the command needed for that processor.

    NOTE: Cross-compiling is compiling code to be used on other processors. For illustration, an Intel system that is cross-compiling code is making applications for processors other than Intel. So, this system may be compiling code for ARM or AMD processors.

    NOTE: Each choice will change which questions come up and when they are displayed. I will include my choices so readers can follow the configuration process on their own system.

    Next, users will see "Local version - append to kernel release (LOCALVERSION) []". This is where developers can give a special version number or name to their customized kernel. I will type "LinuxDotOrg". The kernel version is now “3.9.4-LinuxDotOrg”. Next, the configuration tool asks "Automatically append version information to the version string (LOCALVERSION_AUTO) [N/y/?]". If a git tree is found, the revision number will be appended. This example is not using git, so I will answer no. Other wise the git revision number will be appended to the version. Remember vmlinuz and similar files? Well, the next question asks which compression format should be used. The developer can choose one through five. The choices are

    1. Gzip (KERNEL_GZIP)
    2. Bzip2 (KERNEL_BZIP2)
    3. LZMA (KERNEL_LZMA)
    4. XZ (KERNEL_XZ)
    5. LZO (KERNEL_LZO)

    Gzip is the default, so I will press “1” and hit enter. Each compression format has greater or less compression ratios compared to the other formats. A better compression ratio means a smaller file, but more time is needed to uncompress the file while the opposite applies to lower compression ratios.

    Now, this line is displayed - “Default hostname (DEFAULT_HOSTNAME) [(none)]”. The default hostname can be configured. Usually, developers leave this blank (I left it blank) so that Linux users can set up their own hostname.

    Next, developers can enable or disable the use of swap space. Linux uses a separate partition called “swap space” to use as virtual memory. This is equivalent to Windows' paging file. Typically, developers answer yes for the line “Support for paging of anonymous memory (swap) (SWAP) [Y/n/?]”.


    The next line (System V IPC (SYSVIPC) [Y/n/?]) asks if the kernel should support IPC. Inter Process Communication allows processes to communicate and sync. It is best to enable IPC, otherwise, many applications will not work. Answering yes to this question will cause the configuration tool to ask “POSIX Message Queues (POSIX_MQUEUE) [Y/n/?]”. This question will only be seen if IPC is enabled. POSIX message queues is a messaging queue (a form of interprocess communication) where each message is given a priority. The default choice is yes. Hit enter to choose the default choice (indicated by the capitalized choice).

    The next question (open by fhandle syscalls (FHANDLE) [Y/n/?]) is asking if programs will be permitted to use file handles instead of filenames when performing filesystem operations if needed. By default, the answer is yes.

    Sometimes, when a developer has made certain choices, some questions will automatically be answered. For instance, the next question (Auditing support (AUDIT) [Y/?]) is answered yes without prompting because previous choices require this feature. Auditing-support logs the accesses and modifications of all files. The next question relates to auditing (Enable system-call auditing support (AUDITSYSCALL) [Y/n/?]). If enabled, all system calls are logged. If the developer wants performance, then as much auditing features as possible should be disabled and not added to the kernel. Some developers may enable auditing for security monitoring. I will select “no” for this question. The next audit question (Make audit loginuid immutable (AUDIT_LOGINUID_IMMUTABLE) [N/y/?]) is asking if processes can change their loginuid (LOGIN User ID). If enabled, processes in userspace will not be able to change their own loginuids. For better performance, we will disable this feature.

    NOTE: When configuring via “make config”, the questions that are answered by the configuration tool are displayed, but the user does not have a way to change the answer. When configuring via “make menuconfig”, the user cannot change the option no matter what button is pressed. Developers should not want to change options like that anyway because a previous choice requires another question to be answered a certain way.

    In the next article, we can configure the IRQ subsystem and all of the following choices.

    Attached Files:

    • slide.JPG
      slide.JPG
      File size:
      177.1 KB
      Views:
      105,853
    Last edited: Dec 29, 2013
    Haider92, lin.and.phi, VP9KS and 3 others like this.
  2. ilAli

    ilAli New Member

    Messages:
    1
    Likes Received:
    1
    Trophy Points:
    3
    this guide is fantastic. please explain how to save config file in the middle of its process to be able continue rest of it in future.
    DevynCJohnson likes this.
  3. DevynCJohnson

    DevynCJohnson Super Moderator Staff Member Staff Writer

    Messages:
    973
    Likes Received:
    857
    Trophy Points:
    93
    Not all interfaces allow you to save the progress. Near the top of the article, you will see different make commands. "make menuconfig" is one that allows you to save your progress. The standard "make config" cannot save its progress.

    Thank you for your interest in my article. I have written a whole series on the Linux kernel. Look for articles whose name begins with "The Linux Kernel: ". I am currently writing about the configuration process. This series is going to get more detailed. This series is far from over. There is a lot to configure in the Linux kernel.

    If you have any suggestions for other topics, email me at DevynCJohnson@Gmail.com, find me on Google+, contact me via Launchpad, or contact me through Linux.org.
    Haider92 likes this.
  4. ryanvade

    ryanvade Administrator Staff Member Staff Writer

    Messages:
    910
    Likes Received:
    290
    Trophy Points:
    63
    Configuring the kernel is the best part of Linux. Every time a new kernel comes out I have something to mess around with. :)
    DevynCJohnson likes this.
  5. CubeGod

    CubeGod New Member

    Messages:
    6
    Likes Received:
    4
    Trophy Points:
    3
    Well, I'll be sure to read this through more thoroughly later, there's bound to be options not even I understand (although I am currently developing my own distro, the second one in my list (first was based on opensuse with a kernel upgrade and some specific configuration, the second one, still being built is made from scratch) and I already configured many kernels some options I've never touched because I never quite understood them)

    Can't wait for part 2, never really researched the IRQ options ^^;
  6. DevynCJohnson

    DevynCJohnson Super Moderator Staff Member Staff Writer

    Messages:
    973
    Likes Received:
    857
    Trophy Points:
    93
    I will be getting in great depth, so watch the main page for the site for the next ones. I expect to have more than eight of these tutorials. I plan to be a thorough as possible. Keep reading and liking the series. If any questions arise, feel free to ask and I will clarify.
    Haider92 likes this.
  7. CubeGod

    CubeGod New Member

    Messages:
    6
    Likes Received:
    4
    Trophy Points:
    3
    Well, truth is that the options I don't get I never bothered looking up (mostly due to lack of time) and the ones I get I mostly figured out using common sense and the comments on each entry in menuconfig.
  8. VP9KS

    VP9KS New Member

    Messages:
    18
    Likes Received:
    13
    Trophy Points:
    3
    Devyn,
    Thanks for the series, I will be sure to check them all out as time permits.
    Paul
    DevynCJohnson likes this.
  9. DevynCJohnson

    DevynCJohnson Super Moderator Staff Member Staff Writer

    Messages:
    973
    Likes Received:
    857
    Trophy Points:
    93
    Thanks for the compliments!
    Haider92 likes this.
  10. supergeek1000

    supergeek1000 New Member

    Messages:
    3
    Likes Received:
    3
    Trophy Points:
    3
    I sure wish these resources were available back in the nineties. Linux was way more dificult then. Thank you for your fine work, I will be reading all in the coming days.
    DevynCJohnson likes this.
  11. DevynCJohnson

    DevynCJohnson Super Moderator Staff Member Staff Writer

    Messages:
    973
    Likes Received:
    857
    Trophy Points:
    93
    Thanks for your compliments! Readers like you give me motivation to write more cool articles that you like to read. I release about one Linux kernel article a week. I also post one "random Linux topic" article per week. If you have any ideas for topics, feel free to let me know.
    kenshuri and Haider92 like this.
  12. flunwyc

    flunwyc Member

    Messages:
    99
    Likes Received:
    60
    Trophy Points:
    18
    It actually does the opposite - it turns all LKMs to built in (it turns all incidences of 'm' to 'y' in kernel config).
    DevynCJohnson likes this.
  13. DevynCJohnson

    DevynCJohnson Super Moderator Staff Member Staff Writer

    Messages:
    973
    Likes Received:
    857
    Trophy Points:
    93
    Thanks! I see that I do contradict myself by saying all modules will be set to "yes" and then in the same sentence say "most of the kernel will be in modules".
    Haider92 likes this.
  14. Ivaylo Krumov

    Ivaylo Krumov New Member

    Messages:
    7
    Likes Received:
    7
    Trophy Points:
    3
    Absolutely outstanding article from a technical standpoint and from a standpoint of the content it is talking about. This is what I call an article that is worthy to be categorized as THE DOCUMENTATION BIBLE!!!
    Thank You Sir.
    Keep doing what you are doing and always look for a way to make it better and more efficient !!!!
    DevynCJohnson likes this.
  15. DevynCJohnson

    DevynCJohnson Super Moderator Staff Member Staff Writer

    Messages:
    973
    Likes Received:
    857
    Trophy Points:
    93
    Thank you for the compliments! I love posters like you.

    Feel free to give me any ideas on future topics for this series or other articles or topics in general. All three of the main authors on this site (me, Jarret Buse, and Eric Hansen) are open to ideas and suggestions. Enjoy the site!

    I am thinking about starting a second article series on Python3 scripting. What do you think about that?
    Haider92 likes this.
  16. Ivaylo Krumov

    Ivaylo Krumov New Member

    Messages:
    7
    Likes Received:
    7
    Trophy Points:
    3
    Thank you Sir,
    As I said before, what you are doing, the way you are doing it is Great. Maybe one very small recommendation for an improvement of your articles would be to include some screenshots of the key steps during the course of the action you are doing. As you know , a single picture is bringing as much information as 100 words.
    I don't know what your interests are therefore my ideas might not be necessary the ideas of you guys and the ideology of the web site.
    I would be interesting to see articles related to architectural, design and implementation of SOA technologies with all the SOA related layers, databases, IPv6 etc. Python and Ruby would be interesting as well. There are some other ideas I have in my mind which could be interesting.
    DevynCJohnson likes this.
  17. DevynCJohnson

    DevynCJohnson Super Moderator Staff Member Staff Writer

    Messages:
    973
    Likes Received:
    857
    Trophy Points:
    93

    Thanks for the suggestions. I will do what I can. I will include more screenshots in my future articles. Thanks!

    I am currently working on a Python3 tutorial (I will release it in a week or two). If I see that enough people enjoyed it, then I will write a whole tutorial series.

    Last I knew, one of the authors plan to write an article on IPv6. I do not know when he will write and release it.

    Later, I will create a thread for people to post article topic requests for the authors.
    Haider92 likes this.
  18. lin.and.phi

    lin.and.phi New Member

    Messages:
    4
    Likes Received:
    5
    Trophy Points:
    3
    Hello,

    Maybe you should also explain shortly how ncurses can be installed. For Ubuntu it is:
    sudo apt-get install libncurses5-dev
    The name "libncurses5-dev" is not self-explanatory, so you should mention it I think.
    (or maybe there is a better way after all, I just googled it now)

    Other than that, great article :)
    DevynCJohnson likes this.
  19. DevynCJohnson

    DevynCJohnson Super Moderator Staff Member Staff Writer

    Messages:
    973
    Likes Received:
    857
    Trophy Points:
    93
    libncurses5-dev -
    • lib - LIBrary
    • ncurses - the terminal-based GUI
    • 5 - version
    • dev - for developers (contains headers, links, etc.)
    Thanks for the compliment.
    Haider92 and lin.and.phi like this.
  20. Waqar

    Waqar New Member

    Messages:
    5
    Likes Received:
    4
    Trophy Points:
    3
    make gconfig never works on ubuntu 12.04 LTS whatever I do. Has anyone tried it?
    I have also asked a question Trouble using `make gconfig` in ubuntu linux in 'Unix and Linux' on StackExchange website with details of my problem. No working answers so far :(
    DevynCJohnson likes this.

Share This Page