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...