How to Download, Extract and update the Linux Kernel source
 

How to Download, Extract and update the Linux Kernel source

 

This post was last updated on December 1st, 2020 at 05:38 pm

When you are starting to learn Linux development or Device driver development, then the first thing you need is the Linux Kernel which is available in a zipped archive format from kernel.org. Sometimes I just download the kernel to browse source code of some modules.

How to download the Linux kernel source?

You just go to kernel.org and download the desired kernel required to you. You can download the latest stable Linux kernel which will be highlighted in big on the website or else you can download any other earlier long term Linux kernel version.
Have a look on the below image where I have highlighted the latest stable and older long term kernel download links.

Linux kernel download link

Basically this will download the kernel archive file into the local storage. Sometimes you may be working on a remote machine using a command line where you don’t have the browser access immediately. So, in that case you need to copy the linux kernel download link by right clicking on the download button on the web page. See the below image:

copy kernel tarball download link

So, if you want to download the kernel into a remote system then use the following command in the remote machine:

$ wget <paste the download link>

The command should look something like this:

$ wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.4.tar.xz

Use the [shift + insert] key combination to paste the copied text into the console.

The download may take several minutes depending on the system’s internet connection where you are downloading.

How to Unpack the linux kernel archive:

Now that you have downloaded the linux kernel archive which is in a zip format and needs to be extracted or unpacked. Lets say if the downloaded file is at ~/Downloads/linux-4.4.tar.xz (I am taking an example of the latest 4.4 kernel). We will make a new directory (say kernel-src-4.4) inside /usr/src and move the new kernel archive file to the new location and start unpacking.

$ cd /usr/src
$ mkdir kernel-src-<version>  (use another name if already have a kernel version installed)
# cp ~/Downloads/linux.<version>.tar.xz /usr/src/kernel-src-<version>
# cd /usr/src/kernel-src-<version>
# tar xfv linux.<version>.tar.xz

NOTE:
Mostly the above mentioned tar command will unpack the linux kernel archive file. If it did not work then try with the following command:
# tar xjvf linux.<version>.tar.bz2

After executing all the commands successfully a new directory (linux-4.4) would have already created in the /usr/src/kerenl-src-4.4 location.
If you are only planning to browse the latest source code then

How to point to the new kernel:

We have done unpacking the kernel and now we need to point the default linux kernel source to our newly copied kernel source which the other packages should be pointing or using from. I am assuming that the current kernel source code is pointed by /usr/src/linux symbolic link (or the current kernel source directory). Follow the below commands to do that:

$ cd /usr/src/kernel-src-<version>
# rm /usr/src/linux (assuming that's a link to your old kernel)
# ln -s /usr/src/kernel-src-<version>/linux-<version> linux

Now the /usr/src/linux symbolic link will point to /usr/src/kernel-src-<version>/linux-<version>

Previous What's an Operating system & why do we need one?
Next [SHELL] How to know in which shell you are working in Linux or FreeBSD
 

About author

shibaa987
shibaa987 269 posts

Linux kernel developer and a firmware developer with an experience of 10+ years.

View all posts by this author →

You might also like

Linux Topics 0 Comments

How To Setup Xfce Desktop Environment On CentOS 8?

Xfce is a free and opensource desktop environment that aims to be lightweight, fast, and low on system resources while still being visually appealing and easy to use. Like GNOME,

Linux Topics 0 Comments

How To Install And Use Linux Containers (LXC) On Ubuntu?

LXC (Linux containers) is the operating system-level virtualization which is used for running multiple isolated Linux systems called containers on a host machine. Unlike a virtual machine that requires dedicated

Linux Topics 0 Comments

Process Management In Linux/Unix

This post was last updated on August 3rd, 2020 at 03:06 pmA process is an instance of a computer program that is currently running. A program can have multiple instances

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply