I work as System Specialist. During my work I often came to point that normal kernel from distribution doesn't work. Whole or part of server was unusable because one of these common reasons:
- Virtualization support with combination of new HW
- Missing driver for some Raid Controllers
- Missing driver for network cards
- Security hardening patches for specific systems
I don't remember which of the reason was the first when I must build my own kernel to be able use server or computer with all it's hardware. In few next years another big reason appear.
- New kernel have fixed some performance issues
Now we can talk about how to do it.
Kernel Build
1. Install dependencies
You will need some additional SW to configure and build your kernel
- make
- gcc
- ncurses-dev
2. Download sources
First of all you must download source of the kernel from Kernel Home page.
Version depends on your needs. In most cases best option is to download latest stable or latest stable longterm supported version.
So we download and unzip kernel source
cd /usr/src/
wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.11.bz2
tar -jxf linux-3.10.11.bz2
ln -s linux-3.10.11 linux
Best practice is to link sources to /usr/src/linux .
3. Configure new kernel
One of the most importand part :)
There are several options how to do that. Enter directory /usr/local/src and type one of the following commands
- make config - run simple text interface
- make menuconfig - Text based colored ncurses interface
- make nconfig - Text based colored curses interface (you must install libcdk5-dev)
- make xconfig - Graphical QT/X window interface (QT library required)
- make gconfig - Graphical GTK/X window interface (GTK is required)
- make allmodconfig - Enable as many modules and parts of the kernel as possible
I prefer "make menuconfig". Run command and wait until ncurses interface starts.
Here you can change settings and enable/disable parts of the kernel. If you enable some part, it can be desplayed in two ways
- "*" sign - means feature will be enabled and part of kernel itself
- "M" sign - means feature will be enabled but compiled in separate loadable file called kernel module.
When you go throught all kernel parts it's time to save configuration file. It's saved by default to ".config" file.
4. Build your new kernel
Now in order run following commands
- "make clean" - clean sources from object files and previous build mess
- "make bzImage" - build kernel and compress it with bzip
- "make modules" - build kernel modules files, parts of kernel you marked with "M" sign
- or "make vmlinux" to build bare kernel
- or "make fdimage" to build bootable 1.44 MB floppy
- or "make isoimage" to build bootable iso image
- or "make help" for more options
Now if no error ocured we have our kernel build.
5. Install kernel image
First we install modules, firmware and kernel binary from our new kernel
- "make modules_install" - install kernel modules to /lib/modules/<kernel_version/
- "make firmware_install" - install firmware files to /lib/firmware/
- "make install" - install kernel to /boot/ using /sbin/installkernel
Post install things
To successfully boot your new kernel, you must add it to your grub.
Create /etc/grub.d/09_mykernel file with following contents
#!/bin/sh
exec tail -n +3 $0
menuentry "My new kernel"{
set root=(hd0,1)
linux /boot/vmlinuz-<yourkernelversion> root=/dev/sda1 ro
}
This propably boot only if you mark all modules with "*" sign. If you mark filesystems, sata controllers with "M"sign your kernel won't boot with this configuration.
You will need initrd image, which contain all modules to successfully boot your kernel
InitRD image
mkinitramfs -o /boot/inird.img-<yourkernelversion> <yourkernelversion>
Your grub.d config file should look like this
#!/bin/sh
exec tail -n +3 $0
menuentry "My new kernel"{
set root=(hd0,1)
inird /boot/inird.img-<yourkernelversion>
linux /boot/vmlinuz-<yourkernelversion> root=/dev/sda1 ro
}
This is only example. How to properly configure grub for your system is not part of this article.
Finaly run "update-grub" to apply your new configuration and reboot your system.
System specific
Many linux distribution like ubuntu/debian, centos, fedora have utilities to build proper kernel package. You need only unpack and configure your kernel and then you should run some command to create installation package which install kernel properly to your system.
Debian/Ubuntu example
apt-get install fakeroot kernel-package
cd /usr/src/linux
<configure your kernel>
fakeroot make-kpkg --initrd --revision=custom.1.0 kernel_image
cd ..
dpkg -i ./linux-image-3<....>.deb
As you can see, first we must install some dependencies and then configure and build our kernel. After it using dpkg we install regular deb package.
No comments:
Post a Comment