This post is about how to install a new kernel from source.
The latest source code for the Linux kernel is kept on kernel.org. You can either download the full source code as a tar ball (not recommended and will take forever to download), or you can check out the code from the read-only git repositories.
First let’s install some packages using:
sudo apt-get install vim libncurses5-dev gcc make git exuberant-ctags
I was working on the staging-next, so this post will take that as an example.
git clone -b staging-next git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git
Basically above command clones staging-next branch of Greg’s tree. Obviously as the size is big so this clone is going to take some time.
Now let’s set up the configuration.
When you download the source tree, it doesn’t come with a .config file. You have several options on generating a .config file. The easiest is to duplicate your current config.
Duplicate your current config using:
cp /boot/config-`uname -r`* .config
If you want to make some change in your configuration, run the following command, to to silently update any new configuration values to their default:
If you want to make changes, you can run
This will popup something like this:
If you simply want to use the default just save and exit out of the above menu.
Now let’s build the kernel:
or if you have a multi-core processor (run nproc), run
Now let’s install new kernel
Save the following script in a file where your code is present.
echo " " && echo "This script will attempt to install Linux Kernel 3.9 on this machine." && echo "Typically, your current version will be kept, and you will be able to ustilise it again later if Kernel 3.9 does not work." && echo " " && read -p "Press Enter to continue, or abort by pressing CTRL+C" nothing && echo " " && echo "Downloading Kernel 3.9 Packages" && echo "3 Files, 55 MB to Download" && echo " " && echo "Creating Kernel Directory in Home folder" && echo " " && mkdir -p $HOME/kernel-htu && cd $HOME/kernel-htu && echo " " && echo "Downloading File 1 of 3, 12 MB" && echo " " && wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.9-raring/linux-headers-3.9.0-030900_3.9.0-030900.201304291257_all.deb && echo " " && if [ $(getconf LONG_BIT) = "64" ] then echo "64bit Detected" && echo " " && echo "Downloading File 2 of 3, 1 MB" && echo " " && wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.9-raring/linux-headers-3.9.0-030900-generic_3.9.0-030900.201304291257_i386.deb && echo " " && echo "Downloading File 3 of 3, 12 MB" && echo " " && wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.9-raring/linux-image-3.9.0-030900-generic_3.9.0-030900.201304291257_i386.deb else echo "32bit Detected" && echo " " && echo "Downloading File 2 of 3, 1 MB" && echo " " && wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.9-raring/linux-headers-3.9.0-030900-generic_3.9.0-030900.201304291257_amd64.deb && echo " " && echo "Downloading File 3 of 3, 12 MB" && wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.9-raring/linux-image-3.9.0-030900-generic_3.9.0-030900.201304291257_amd64.deb fi && echo " " && echo "Installing Kernel" && echo "This step will require you password." && echo "This is the last step you can safely cancel at." && echo "Use Ctrl+C to cancel." && echo " " && sudo dpkg -i *.deb && echo " " && echo "Installation Complete" && echo " " && read -p "Press Enter to Delete the Downloads, or CTRL+C to keep them." nothing && echo " " && sudo rm -rf $HOME/kernel-htu
Set execute permissions:
sudo chmod +x kernelinstall.sh
Execute the script :
Running your kernel
You need the grub menu at the time of boot, to make it always appear at the time of boot, do the following
#Open grub file using vim, you can use any editor vim /etc/default/grub #Either comment or remove the following line GRUB_HIDDEN_TIMEOUT_QUIET GRUB_HIDDEN_TIMEOUT=0 #Change GRUB_TIMEOUT to something &amp;gt; 0
This portion of my grub file looks something like this:
GRUB_DEFAULT=0 #GRUB_HIDDEN_TIMEOUT=0 #GRUB_HIDDEN_TIMEOUT_QUIET=true GRUB_TIMEOUT=10 #how long grub shows the menu before it choses the kernel at the top of the list
Now after editing the file, update it using
Now you are done. You just need to reboot.
load the kernel which you installed.