SUSE Conversations


Compiling the Linux Kernel, the SUSE way

debianized

By: debianized

September 4, 2013 9:37 am

Reads:4779

Comments:6

Rating:4.8

Today Linus Torvalds announced the release of the Linux Kernel 3.11 “Linux for Workgroups” (is not it funny?).

Let’s get straight to the point:

How to compile the kernel manually, SUSE style!.

For this example, I’ll use the new kernel 3.11 (obviously) on a SLES11 SP3 server.

1. After all we need to install: ncurses-devel

# zypper install ncurses-devel

2. Get the source:

# wget "https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.11.tar.xz"

3. Unpack the source:

# tar -Jxvf linux-3.11.tar.xz -C /usr/src/

4. Configure the kernel:

# cd /usr/src/linux-3.11/

Make sure you are in the path from the source

# make mrproper

If this is your first time, you really do not need this step, this only cleans .o files and other temporary

In the next step there are several ways to configure the kernel, I prefer to make menuconfig, but if you don’t have experience or want to play it safe, I recommend you use an existing configuration, to do this copy your old config file to the new source path:

# cp /boot/config-`uname -r` .config

If you still want to change or add something, at this point you can run: make menuconfig

HINT: After configuration you can further customize the kernel, adding a “extraversion” value. In the Makefile, edit the “EXTRAVERSION =” field, for (this) example:

VERSION = 3
PATCHLEVEL = 11
SUBLEVEL = 0
EXTRAVERSION = -w00t
NAME = Linux for Workgroup

5. Build the Kernel:

# make rpm

Because we copy the old configuration in this step we ask about the new kernel features, read carefully before responding.

Now, take a break, this step will take a bit depending on the performance of your hardware.

6. Install the Kernel:

If all went well, you will see output similar to this:

[...]
Wrote: /usr/src/packages/SRPMS/kernel-3.11.0_w00t_0.11_default-1.src.rpm
Wrote: /usr/src/packages/RPMS/x86_64/kernel-3.11.0_w00t_0.11_default-1.x86_64.rpm
Wrote: /usr/src/packages/RPMS/x86_64/kernel-headers-3.11.0_w00t_0.11_default-1.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.13989
+ umask 022
+ cd /usr/src/packages/BUILD
+ cd kernel-3.11.0_w00t_0.11_default
+ rm -rf /var/tmp/kernel-3.11.0_w00t_0.11_default-root
+ exit 0
rm kernel-3.11.0_w00t_0.11_default.tar.gz kernel.spec

Install the new Kernel package under /usr/src/packages/RPMS/x86_64/:

# cd /usr/src/packages/RPMS/x86_64/
sp3-lab:/usr/src/packages/RPMS/x86_64 # ls
kernel-3.11.0_w00t_0.11_default-1.x86_64.rpm
kernel-headers-3.11.0_w00t_0.11_default-1.x86_64.rpm
sp3-lab:/usr/src/packages/RPMS/x86_64 #
# rpm -ivh kernel-3.11.0_w00t_0.11_default-1.x86_64.rpm

And build the initrd

# mkinitrd

Now it only remains to edit the grub menu:

# vim /boot/grub/menu.lst

And add these lines, obviously putting the right disk to your existing system:

title SUSE Linux Enterprise Server 11 SP3 - 3.11 Linux for Workgroups
root (hdX,X)
kernel /boot/vmlinuz-3.11.0-w00t-0.11-default root=/dev/XXX resume=/dev/disk/XXX splash=silent crashkernel=256M-:128M showopts vga=0x314
initrd /boot/initrd-3.11.0-w00t-0.11-default

Basically, what we do here is copy the current grub entry in your system and just change the title and the image of the new Kernel.

Now, reboot!

We should see the new option in the grub.

K311SLES11SP3-01

K311SLES11SP3-02

w00t!

Happy Hacking!

VN:D [1.9.22_1171]
Rating: 4.8/5 (5 votes cast)
Compiling the Linux Kernel, the SUSE way, 4.8 out of 5 based on 5 ratings

Tags: , , ,
Categories: Enterprise Linux, Server, SUSE Linux Enterprise, Technical Solutions

Disclaimer: As with everything else at SUSE Conversations, this content is definitely not supported by SUSE (so don't even think of calling Support if you try something and it blows up).  It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.

6 Comments

  1. By:mikewillis

    You appear to be doing everything as root. I’d advise doing steps 2-5 as a regular user. Step 3 would fail because writing to /usr/src can only be done by root, but the source can be unpacked somewhere else instead.

    I was taught never build rpms as root. All it takes is one error in the spec file and you end up with files all over the place and/or bits of your system overwritten. (One would expect a spec file provided in Kernel source to be free from such errors, but even so). Also it’s just generally good practice not to do things as root unless they actually need to be done as root.

    • By:debianized

      Indeed, step 5 can be done as a normal user (the best practice) but nothing happens as root, I build all my packages as regular user too.
      In step 3, yes I agree that anyone can unpack the source, it’s just a way to simplify.

  2. By:thelastblack

    Hi
    Thanks for a nice guide.
    I tried building the kernel for openSUSE thumbleweed using this guide, but in step 5 it says something like “rpm : invalid option –target” and I can see that a command like `rpm –target x86_64` is being executed (but failed).
    I just ran `make` and now it is compiling, but how to get rpm packages after that?
    Also I didn’t find anything like VERSION in .config, so I didn’t add an EXTRAVERSION. I think that is ok, isn’t it?

    BTW, I installed sources using zypper and I am just compiling kernel to make ps/2 mouse module not a built-in module, because my ALPS touchpad is not recognized and I have to compile it myself and enable the module.

    • By:thelastblack

      I found all the answers.
      Don’t do ‘make rpm’, instead first run ‘make’ then ‘make install_modules’ and ‘make install’ then if you are using grub2 run `grub2-mkconfig` to add boot entry. Done!

  3. By:abonilla

    edit and set allow_unsupported_modules 1 in
    /etc/modprobe.d/10-unsupported-modules.conf

Comment

RSS