LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 02-17-2014, 03:01 PM   #1
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,016

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
How to keep your self compiled kernel up to date


For various reasons I decided to compile my own kernel. I chose the 3.10 LTS kernel and downloaded it directly from kernel.org.
When you compile your own kernel this obviously forces you to take care of security updates for yourself. So I put something together which I think others might benefit from, so I decided to post it here.

Essentially the instructions below will give you a setup that
1) checks on kernel.org if there is a more recent kernel available than the one you are currently running. (By more recent I mean it's checking if the current one is still available. If it's not then the assumption is that a patch was published, so the 3rd version digit was incremented). In my case e.g. when I am running 3.10.29, and 3.10.30 becomes available, I want to be notified...
2) gives you a command that leads to a fully automated download, compile and .deb packaging process of the new kernel version. All you have to do is run it and then install the new kernel with
Code:
dpkg -i newkernel.deb newlinuxheaders.deb
These instructions work on Crunchbang Waldorf, but I am assuming they should work for any debian based distro.

DISCLAIMER: I am not taking any responsibility if you are breaking your system while following the steps described below. This post is targeted at people who have compiled a kernel before. You should know what you are doing.



Step 1: Create a directory in your home that takes care of everything related to kernel compilation. (I am assuming that if you read this then you already have such a directory, so adjust as needed)
Code:
mkdir ~/kernel
mkdir ~/kernel/deb	# we will put the packages here after building
mkdir ~/kernel/src	# for kernel sources
mkdir ~/kernel/src/linux-`uname -r`  # Your current kernel. Just to put the config file
cp /path/to/your/current/kernels/.config ~/kernel/src/linux-`uname -r`
Step 2: Install needed packages (if you do not already have them).
Code:
apt-get update
apt-get install lynx fakeroot wget build-essential kernel-package
I think that's all, but to be honest I am not sure if there is anything else I had to install when I started to compile kernels.

Step 3: Create the compile script. Create a file called "compile-kernel.sh" in ~/bin and add the following content:
Code:
#!/bin/bash
if [ $# -ne 1 ]
then
        echo "Usage: compile_kernel.sh <kernel_version_string>";
        exit -1;
fi
KERNEL_VERSION=$1
cd ~/kernel/
wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-$KERNEL_VERSION.tar.xz
TARBALL=linux-$KERNEL_VERSION.tar.xz;
tar xvJf $TARBALL;
DIRNAME=${TARBALL:0:${#TARBALL}-7};
mv $DIRNAME ./src/
cd src/$DIRNAME;
CURRENT_RELEASE=`uname -r | cut -d'.' -f 1-3`;
make mrproper
cp ../linux-$CURRENT_RELEASE/.config ./.config
make oldconfig
#make menuconfig     # Uncomment this line if you want to customize the config.
make-kpkg clean

time fakeroot make-kpkg -j8 --initrd kernel_image kernel_headers   # adjust the -j parameter (number of cores) as needed 

mv ../*.deb ../../deb/
Step 4: Create the script that will go and check if you need to update your kernel - Create a file called "check_for_kernel_update.sh" in ~/bin and add the following content:
Code:
#!/bin/bash
/usr/bin/wget -q --tries=10 --timeout=3 http://www.google.com -O /tmp/google.idx &> /dev/null
if [ ! -s /tmp/google.idx ]; then
        # No internet connection found.
        exit -1;
fi
rm -f /tmp/google.idx;

BASHRC_MSG_FILE='~/kernel/message.txt'
CURRENT_RELEASE=`uname -r | cut -d'.' -f 1-3`;

SEARCH_RESULT=`lynx -nonumbers -dump https://www.kernel.org/ | grep -F $CURRENT_RELEASE | grep -F [pgp]`;

if [ $? -eq 0 ]; then
        echo $SEARCH_RESULT | grep -qsF [EOL];
        if [ $? -eq 0 ]; then
                echo "Kernel $CURRENT_RELEASE has reached EOL" > "$BASHRC_MSG_FILE";
        elif [ -s "$BASHRC_MSG_FILE" ]; then
                rm -f "$BASHRC_MSG_FILE";
        fi
else
        echo "Current kernel version string $CURRENT_RELEASE not found on kernel.org. Update required" > "$BASHRC_MSG_FILE";
        MAJOR_RELEASE=`uname -r | cut -d'.' -f 1-2`;
        MINOR_RELEASE=`uname -r | cut -d'.' -f 3`;
        NEXT_MINOR=`expr $MINOR_RELEASE + 1`;
        echo "To download and compile next version type" >> "$BASHRC_MSG_FILE";
        echo "" >> "$BASHRC_MSG_FILE";
        echo "    compile_kernel.sh $MAJOR_RELEASE.$NEXT_MINOR" >> "$BASHRC_MSG_FILE";
fi
Note that the last part which suggests a command to compile the newest kernel is quite dumb. It's not actually checking for the current version, it only increments the current minor version digit by one. For me this is fine, because I always run it directly as new kernels become available, so I did not bother to fine-tune this part, it's really just a convenience thing to be able to copy and paste the command. You may also want to run the whole process automatically instead of only being suggested to run it. Question of personal taste I guess. Anyhow. Adjust as needed.

Step 5:
Run the checking script created in step 4 when logging in. It depends on your DE how to do this. In openbox adding the following lines to the end of ~/.config/openbox/autostart does the job:
Code:
# check for kernel updates
(sleep 5s && ~/bin/check_for_kernel_update.sh) &
Alternatively you could also run this in a cronjob...


Step 6: Set up your bashrc to warn you when an update became available by adding the following lines to the bottom:

Code:
# Print message from kernel update status file 
if [ -s /home/$USER/kernel/message.txt ]; then
        cat /home/$USER/kernel/message.txt;
fi
Step 7: You should be all set.

Feel free to ask if anything is unclear. I also appreciate suggestions for improvement...


EDIT: One last thing I should mention. The kernel directory will grow pretty fast. You may want to add automatic removal of files that are no longer needed...

Last edited by joe_2000; 02-17-2014 at 04:48 PM.
 
Old 02-21-2014, 07:02 PM   #2
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
I recommend using patches instead, saves bandwidth and space. Just keep a tarball of the base version (3.10) and only download the patches. You may also want to add signature verification for extra security.

I wrote something similar for Slackware, but it only downloads the patch and sets it up for the make using your current config. You decide whether to make menuconfig or make.
http://docs.slackware.com/howtos:sla...git_repository
See the kernupd script.
 
1 members found this post helpful.
Old 02-27-2014, 09:18 AM   #3
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,016

Original Poster
Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
Hi metaschima... thanks for pointing that out. Will take a look when I get the chance. But it looks like that won't be anytime soon, last weekend my son was born so I'll be spending more time with diaper changing than with kernel compilation scripts for a while :-)
 
Old 03-24-2014, 07:55 PM   #4
mreff555
Member
 
Registered: Sep 2011
Location: Philly
Distribution: Gentoo
Posts: 473

Rep: Reputation: Disabled
Quote:
Originally Posted by joe_2000 View Post
Hi metaschima... thanks for pointing that out. Will take a look when I get the chance. But it looks like that won't be anytime soon, last weekend my son was born so I'll be spending more time with diaper changing than with kernel compilation scripts for a while :-)
Congratulations! I just had my first a few months ago. Don't worry, kids are just like compiling a kernel. Changing diapers and all that stuff is a pain the first couple times. After that, it's pretty much routine.
 
Old 03-25-2014, 05:02 PM   #5
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,016

Original Poster
Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
Quote:
Originally Posted by mreff555 View Post
Congratulations! I just had my first a few months ago. Don't worry, kids are just like compiling a kernel. Changing diapers and all that stuff is a pain the first couple times. After that, it's pretty much routine.
Haha, thanks, I'm sure you must be right. I'm still looking for the way to automate the process though...
 
Old 03-26-2014, 07:06 AM   #6
mreff555
Member
 
Registered: Sep 2011
Location: Philly
Distribution: Gentoo
Posts: 473

Rep: Reputation: Disabled
Ha! Let me know if you figure that one out.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] 'Kernel too old message' when booting a newly compiled kernel tony paul Linux - Kernel 2 01-24-2013 05:38 AM
kernel execute file is diffternet compiled from same kernel source at different time willchen Linux - Kernel 5 01-01-2010 01:04 AM
Compiled Kernel: Kernel panic Unable to mount root fs on 08:02 pobrika Linux - Software 3 05-23-2008 02:29 PM
kernel panic while booting custom compiled 2.6.24 kernel on RHEL 4 AS samkraju Red Hat 4 02-10-2008 12:55 AM
The kernel I compiled reads my sata drives as hda even though the rpm kernel read sda abefroman Linux - Software 5 07-10-2006 04:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 12:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration