Friday, August 12, 2016

Easy First Time Kernel Compilation for Arch Linux

If you have a deep understanding of kernel compilation and the necessary steps to take to support your hardware from scratch using a kernel straight from kernel.org, then this article is not for you. If you've never compiled the Linux kernel before and want a safe and straightforward way to do so, keep reading. Will this significantly speed up your system? Not particularly. But if you're itching to compile your own kernel just for the sake of doing so, this is definitely the place to start.

All of these steps can be found on the Arch Wiki Kernel Compilation page. It is really clear and easy to follow but sometimes, step-by-step guides that don't show you a bunch of different methods of accomplishing each task are helpful. This guide will be aimed specifically at the Dell XPS 13 Developer Edition but is applicable to all computers running Arch Linux.

Set-up:

The first step is to make and enter a directory to work in while compiling the kernel, as per the Arch Wiki.


mkdir ~/kernelbuild && cd ~/kernelbuild

The next step is to download the kernel you wish to compile. This guide will be using the mainline kernel, which at the time of writing this article, is 4.7.0. If you wish to work with a different kernel, simply right-click the tar.xz link next to the one you wish to use and click Copy Link Address and place it after wget.


wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.7.tar.xz

Now, extract the tarball and change directory to the unpacked tarball


tar -xvJf linux-4.7.tar.xz && cd linux-4.7

Even though its a freshly unpacked tarball, the Arch wiki recommends making sure the directory is clean anyways.


make clean && make mrproper

As an easy starting point, copy over your config from your current Arch installation.


zcat /proc/config.gz > .config

Arch is known for their kernel stability so it will be sure to include you need for your system to boot as a starting point. Instead of adding to what you will be compiling, you will be taking unnecessary options out. This way, if you are unsure about anything, DO NOT REMOVE IT.

Configuration:

Now, you have a couple of tools for going about setting options. I chose to go with 'make gconfig' since I'm running GNOME and like that it automatically describes what each option does at the bottom of the interface. So, go ahead and run your preferred configuration.


make gconfig

There are three states for the boxes. Blank means the option is not chosen, a check-mark means it will be compiled into the kernel, and a dash means it will be compiled as a module. Double click the box to cycle through these options. NOTE: I'm not sure if double-clicking is standard or only the case for my system so it may take some playing around to see how changing options works.

1. Processor Types and Features:
Since the XPS 13 uses a 6th generation Intel processor, I removed all other processors. Expand 'Processor Types and Features' and uncheck the AMD processors. If your running an AMD processor, this can be done inversely. Under the same menu, expand 'Processor Family' and chose your processor, in my case this was 'Core2/newer Xeon'. Also, as it currently stands, my processor doesn't support 'Hibernation', so I also disabled this. Also, when it comes to CPU frequency scaling, my processor only supports 'powersave' and 'performance'. I changed these from modules to enabled options and disabled the others, such as 'ondemand'.

2. General Options:
Expand 'General Options'. The only things I touched in this section was the 'Default Hostname' and 'Local Version' since I wanted to feel cool and put my own hostname into the kernel. Click on the option then single click on the text to the right. For example: click 'Local Version' and move over to where it says '-ARCH' and click it once. Double clicking will enable and disable editing the text rapidly and make it seem like you can't change this option. I changed mine to '-CUSTOM'.

3. Device Drivers:
Expand 'Device Drivers' then expand 'Graphics Support'. Disable all options that you KNOW aren't your graphics card. If you're unsure about anything, DO NOT DISABLE it. But things you are sure about, such as support for NVIDIA cards, disable.

4. Security Options:
The only thing I added here was 'Restrict unprivileged access to the kernel syslog'.


These are only a few of many options. As I mentioned earlier, you can read about each option at the bottom of the interface so go through and do some research to see what each one is/does and if you should disable/enable it. THIS WILL TAKE SOME TIME! But, it can end up being one of the most rewarding parts of learning about how the kernel operates. Once you have finished, click the save button at the top and kill gconfig.

Compiling:

This part is easy but takes quite some time so be prepared for that:


make

And wait. Then keep waiting. Then wait a little more. Now its done!

From this point on all commands MUST be run as root in order to work.


sudo su

then


make modules_install


Now, you'll copy over the image you just made to your boot partition and name it as you so desire.


cp -v arch/x86_64/boot/bzImage /boot/vmlinuz-[YOURKERNELNAME]

Finally, you'll generate the initramfs files. I chose the manual method of accomplishing this task. It is structured like so:


mkinitcpio -k <kernelversion> -g /boot/initramfs-<file name>.img

Replace file name with your kernel name and if you are unsure about what to put for the kernel version, check the output of:


ls /lib/modules/

This will list all available module directories and you should see the one that you created earlier in this process. If you don't go back and make sure 'make modules_install' ran correctly. This is crucial! Without the proper modules, you system will not boot!

The final step is to edit you boot settings to boot your new kernel! Check the documentation for your specific boot process, or if you are using systemd boot, continue reading.

Simply edit your '/boot/loader/entries/arch.conf' file to include both your new vmlinuz file and your new initramfs file. If for some reason your system doesn't boot, you can boot with a LiveUSB and edit this file back to its original state. For this reason, do not remove your old kernel files from the boot partition!

And there you have it! A simple guide to compiling your own kernel. Now that wasn't so hard, was it? Of course, there is a lot more to kernel compilation than this guide covers but like I said earlier, this can help you feel more comfortable with the overall process. If you follow this guide, please don't let this be the "end all" for your experiences with kernel compilation! There is still a lot more left to learn, such as making a PKGBUILD so that future updates don't accidentally change your system state to using the old kernel. Look out for a simple PKGBUILD guide here in the future!

Questions/comments/hate mail? Please feel free to use the comment box below this post! I'd love to hear from you, even if it is just about how much you hate me and everything I stand for!





StumbleUpon

No comments :

Post a Comment