Updating your Linux Kernel

So you want to update your kernel, eh? Hopefully that means you got some shiny new cutting-edge hardware you want to play with. Alternatively, it means that something is broken or not working in an older kernel and you’re hoping the updating to a new one fixes the problem.

Well, there is good news and bad news. The good news is that if you are using Ubuntu or any of its derivatives, like Linux Mint, the Ubuntu team has literally done 99% of the work for you. The bad news is that if you are using a different distro, you have a bit more work to do.

Lets start with the easy route: those people using Ubuntu or Linux Mint. In that case, Ubuntu has all the kernels pre-configured and available on their website, ~kernel-ppa/mainline.

In this example, I’m going to use the linux kernel version 3.18.1, available at ~kernel-ppa/mainline/v3.18.1-vivid.

Step 1 is to download the files you need. Here are the commands for a 64 bit computer

wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.18.1-vivid/linux-headers-3.18.1-031801-generic_3.18.1-031801.201412170637_amd64.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.18.1-vivid/linux-headers-3.18.1-031801_3.18.1-031801.201412170637_all.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.18.1-vivid/linux-image-3.18.1-031801-generic_3.18.1-031801.201412170637_amd64.deb

And for a 32 bit computer

wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.18.1-vivid/linux-headers-3.18.1-031801-generic_3.18.1-031801.201412170637_i386.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.18.1-vivid/linux-headers-3.18.1-031801_3.18.1-031801.201412170637_all.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.18.1-vivid/linux-image-3.18.1-031801-generic_3.18.1-031801.201412170637_i386.deb

The next question you’ll inevitably ask is if you need the low latency kernel. The answer is most likely “no.” If you need the low latency kernel, changes are pretty good you’ll know it. That specific version is helpful for people doing encoding/decoding and in general, processing where your program cannot be suspended and shuffled off in a round-robin fashion so a lower priority process (such as that web page you have open in the background) can use the cpu.

Next, you install the .deb packages:

sudo dpkg -i linux-headers-3.18.1*.deb linux-image-3.18.1*.deb

Then reboot into your new kernel and enjoy!

Note that you may have to run the following commands to update grub to see the new kernel, though you most likely won’t have to.

grub-mkconfig -o /boot/grub/grub.cfg

Compiling from source

Now that the easy version is done, lets talk about updating the kernel if you aren’t on Ubuntu or one of its derivatives, like Linux Mint.

Step one, download the kernel source.

wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.18.1.tar.xz

Extract via the traditional tar method and change into the new directory.

tar -xvJf linux-3.18.1.tar.xz
cd linux-3.18.1

Next, always prepare for compilation by running the following to ensure the kernel tree is absolutely clean.

make mrproper

A good place to start is by issuing:

make defconfig

to have the kerne take into account your system hardware and architecture defaults.

Either way, you should really spend some time browsing through, reading, and selecting the options you need after issuing:

make menuconfig

A newer option to the above is:

make nconfig

Once you have all your options set, save and exit. Backup this saved config file by copying it to /boot.

cp -v .config /boot/config-3.18.1

Compiling the kernel comes next, issued here to utilize 8 processor cores.

make -j8

If you have selected any modules (the “M” when browsing the kernel features), you’ll need to build those too

make modules_install

Now you can copy the kernel to /boot

cp -v arch/x86/boot/bzImage /boot/vmlinuz-3.18.1

The next step is to make the initial ramdisk for your computer, which is the temporary root file system loaded into memory during the linux boot process.

mkinitcpio -k linux-3.18.1 -c /etc/mkinitcpio.conf -g /boot/initramfs-linux-3.18.1.img

If needed, you can utilize preset files found in /etc/mkinitcpio.d by using the -p switch.

mkinitcpio -p /etc/mkinitcpio.d/linux.preset

Copy the file System.map, which maps the entry points of every function in the kernel among other things, to /boot.

cp -v System.map /boot/System.map-linux-3.18.1

As needed, copy documentation for the linux kernel

install -d /usr/share/doc/linux-3.18.1
cp -rv Documentation/* /usr/share/doc/linux-3.18.1

Finally, add new entries to GRUB for the kernel you just finished compiling.

grub-mkconfig -o /boot/grub/grub.cfg

Note that you shouldn’t have to use the command grub-mkconfig unless this is your initial installation or the file grub.vfg does not exist for some reason.

And you’re finished! Boot up in your new kernel and make sure you selected all the correct options that your hardware requires :)

Tagged , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.

Protected by WP Anti Spam