How to tune the kernel

Although I use Linux Mint 17 (version 17.2 is the latest, as I type) and I am tinkering with Ubuntu (15 is the latest, but 14.xx seems to be the latest stable version), the linux kernel is the one unique part amongst all Linux systems and hardware possibilities. You can choose which version you want to download from kernel.org. It's the same kernel as is on your distro. (Just match up the version numbers)

When you install Linux from your distro DVD, it will install a perfectly working copy of the latest (well, reasonably latest and stable) version of the kernel. If you don't need to investigate further - then don't. Your kernel will work. If you don't add on any new hardware, then leave your kernel alone. It will carry on working ad infinitum.

Kernels advance in versions as new hardware is developed and linux drivers are created for that new hardware.

I recently bought a new laptop. It was pre-installed with Windows 10, which I didn't even bother booting btw. However, this laptop came with a touchpad, which could be pressed, but no buttons. So, from the default installion of Linux Mint 17.2, I needed to update my kernel from 3.13 to 3.16, which is where Linux caught up with touchpads. At the time of writing, m$ windows hadn't caught up and also had problems with touchpad drivers.

Tuning the kernel is a lot of fun. The system will run slightly faster, in theory, sleeker, and you'll have the satisfaction of knowing exactly what is in your system. If you have a specialist piece of hardware of course, then tuning the kernel is essential. If you're a serious systems administrator, perhaps NASA or NSA, then it's critical. Otherwise, assuming you're an average user with a printer, the distro is usually quite good in selecting default kernel settings. If you choose to tune it, then it's usually because you want to learn.

The steps, in summary , are quite simple :

1. Download the latest stable kernel from kernel.org, and unzip it into your home directory. For today's example, I downloaded linux-4.2.5.tar.xz, about 80 Mb in size. My distro kernel is 3.13.smething, and I run 3.16.something
2. Get a .config file. This is easier than you might think.
3. Run either "make menuconfig", "make xconfig" or "make gconfig" to run a GUI, and make the changes.
4. Run "time make -j3" to compile the new kernel. (this is still in your home directory, remember.) This will take between 30 minutes and 90 minutes, depending on your processor speed and the kernel options that you chose.
the '-j3' parameter. If you have a single core processor, just type 'make'. Dual core processor - 'make -j3'. Quad core processor - 'make -j5'. And so on. The 'time' command gives you a good sense of how long you have waited for the kernel to compile, so you can decide how many cups of tea you are likely to need during the next compile.
4 and a bit. ==>> Take a Backup :-) !
5. LOGIN AS ROOT ! (su - root)
6. Run "make modules_install"
7. Run "make install".
8. ========== Your new kernel is now installed - reboot ===========
9. You may need to boot into single user mode, to re-install Graphics drivers (eg nVidia drivers).

The steps in more detail.

Create the build environment

Since my username is 'sheldon', and I named my system 'mint', I will use this throughout. Substitute your own username.
These commands create the correct kernel build environment in your home directory, and create the correct .config file. (ie. the .config file that your system used to create your current kernel).

Code:
sheldon@mint:~> mkdir build
sheldon@mint:~> cd build
sheldon@mint:~/build> 
sheldon@mint:~/build> mv /home/sheldon/Downloads/linux-4.2.5.tar.xz .
sheldon@mint:~/build> < I then used my file manager to go open this file, and extract the files from the archive. >
sheldon@mint:~/build> cd linux-4.2.5
sheldon@mint:~/build/linux-4.2.5>  
sheldon@mint:~/build/linux-4.2.5> make oldconfig
sheldon@mint:~/build/linux-4.2.5> make gconfig	

Notes on make oldconfig

Because you are upgrading your kernel, your .config is going to have a few more options in it, that weren't in your existing kernel options. At this stage, accept all the default suggestion given to you.

Run the GUI

- make menuconfig runs the GUI as a text-based system.
- make xconfig, my personal favourite because it has a 'search' option, runs the GUI using qt.
- make gconfig runs the GUI using GTK.

You will probably find that gconfig and xconfig don't work until you install the correct packages. You don't want to use menuconfig, believe me. The correct packages to install are a bit of a mystery. using xconfig worked for me.)

Making the changes

This is the complicated and time consuming bit. The essential bits to get correct are the disk drivers and the graphics drivers. Without those, your system will hang on boot. Don't panic - your previous version is easily bootable instead __providing you renamed your kernel__.

Essential 1 : Rename your kernel. I chose "-minimal1" to start with, and after a few more changes I am on "-minimal3". My kernel is now named 3.11.3-minimal3.

Rename the kernel

Essential 2 : Get the correct processor, and enable Generic X86. Core 2/Newer Xeon is correct for my system.

Correct processor

Essential 3 : The penguins.

If you choose to enable the "bootup logo" (last entry under the graphics drivers) then you will a penguin at the top left of the screen on bootup; One penguin for every processor core you have. I have a dual core processor, so I get two penguins.

Pnguins :-)

Any other changes

There are too many other changes for me to sensibly list. Here are some guidelines :
- There are hundreds of options for hardware you do not have. Deselect them.
- The help text in the window below has a very useful hint: "If in doubt, say Y". (Or No, as the case may be). Use it.
- Providing you rename the kernel, you will _not_ overwrite your existing kernel - meaning you can choose to reboot your old kernel if the new kernel fails to boot.
- Use the log files in /var/log to review boot errors.
- If in doubt, make it a module. If the system needs it, it will install a module automatically.
- Use lsmod to review which modules are currently loaded (and therefore needed).
- Avoid the temptation to modify the .config file manually ! - Make a frequent backup of working .config files !!! They are deleted in the next step, so you NEED a backup.
- The ACPI options in the kernel need ACPI packages to be installed in Yast as well. Search in Yast for them.
- The PWM options seem unneccessary at first glance - in fact, they control the fans (thermal sensors) in your PC. Include them !

My own config file, for an Acer Aspire 5551 laptop (dual-boot production machine, not many changes)) is here.

My own config file, for an intel motherboard with dual core processor, on board intel HDA sound, 3 SATA disks and 1 PATA disk (controlled by jmicron) )and separate nvidia 9600 graphics card is here. This machine is my sandpit; I make whatever changes I want, and swap in different hard disks, accepting that sometimes I will need to rebuild starting with that SuSE 12.3 installation DVD.

Rebuilding a second time

If you make only a few changes to the configuration, you need not start from scratch. Make the changes in the GUI, and then re-run 'make'. The Makefile is clever enough to work out what else needs to be compiled, or removed. Do NOT change the kernel name in this case.

If you make several changes, or if the Makefile is unable to work it out for you, then you will need to start over. Rename the new kernel and start over ...

To start over :

You need to run 'make clean' then 'make mrproper' (as your own user, not as root). 'make mrproper' will even delete the .config file, which is why you _must_ have copied it somewhere. When 'make mrproper' has cleaned up, copy .config file back and start the process again :

Code to rerun the kernel build :
paul@sheldon:~/> cd /home/paul/build/linux-3.11.3
paul@sheldon:~/build/linux-3.11.3> 
paul@sheldon:~/build/linux-3.11.3> cp .config BACKUP_config_minimal3.txt
paul@sheldon:~/build/linux-3.11.3> make clean
paul@sheldon:~/build/linux-3.11.3> make mrproper
paul@sheldon:~/build/linux-3.11.3> cp BACKUP_config_minimal3.txt .config
paul@sheldon:~/build/linux-3.11.3> 
paul@sheldon:~/build/linux-3.11.3> time make -j3
paul@sheldon:~/build/linux-3.11.3> su - root
sheldon:~ # 
sheldon:~ # cd /home/paul/build/linux-3.11.3/
sheldon:/home/paul/build/linux-3.11.3 # make modules_intall
sheldon:/home/paul/build/linux-3.11.3 # make install