38

Is there a resource to download a specific kernel version source? For example, I want to get 2.6.36.2 sources to compare with this package and see what changes were introduced?

RaoulDuke
  • 381

6 Answers6

39

The easiest and most bandwidth-friendly way, if you expect to do this more than once, would be to clone the kernel's git repository and check out the version you want based on its tag. It's probably best to clone the linux-stable repo, since that will include tags for all of the stable releases:

git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
cd linux
git checkout v2.6.36.2

To later switch to another version, it's easy:

git checkout v3.5.2

To update your repository to include all of the latest tags and commits:

git fetch
Jim Paris
  • 14,337
  • 3
    Any clue why minor tags don't show on GitHub? E.g. https://github.com/torvalds/linux/releases/tag/v3.5.2 vs https://github.com/torvalds/linux/releases/tag/v3.5 Nor on https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/refs/ – Ciro Santilli OurBigBook.com Jun 13 '17 at 22:26
  • 1
    --depth and --branch can also drastically reduce the clone size: https://unix.stackexchange.com/a/473373/32558 – Ciro Santilli OurBigBook.com Oct 05 '18 at 05:43
  • Ah.. Thanks. That repository is one of hundreds of the addresses in https://git.kernel.org/. Why should it be so difficult to find it? linux people are keeping it as a secret?? – Chan Kim Jun 28 '21 at 03:05
  • While the git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git remote still works, it appears to be deprecated, as kernel/git/stable/linux-stable.git is no longer listed on the official list of Kernel.org git repositories at https://git.kernel.org/. It has been replaced by kernel/git/stable/linux.git instead. So, the new recommended clone command is git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git instead. – Gabriel Staples Dec 09 '22 at 23:25
19

Yes, kernel.org has all released versions, including 2.6.36.2. Note, however, that most Linux distributions apply own patches to the vanilla kernel source.

scai
  • 10,793
13

If you do not want to download whole kernel commit history (which is well above 1 GiB), you can download only such part of the kernel Git repo that leads to your desired branch. E.g. to locally checkout the Ubuntu kernel in version 4.5, you'd do:

git clone --depth 1 --single-branch --branch v4.5  git://git.launchpad.net/~ubuntu-kernel-test/ubuntu/+source/linux/+git/mainline-crack

This way, the clone is about 150 MiB.

Martin Pecka
  • 407
  • 7
  • 17
9

If you just want to get one tag for quick compilation, do:

git clone --depth 1 --branch v4.18 \
  git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git

--depth 1 does a shallow clone, which drastically reduces the clone time and disk usage.

It only works for tags currently unfortunately, not arbitrary commits, due to how the cgit git server works and is configured. See also: https://stackoverflow.com/questions/3489173/how-to-clone-git-repository-with-specific-revision-changeset

See also: Why is the git clone of the Linux kernel source code much larger than the extracted tar.xz?

Ciro Santilli OurBigBook.com
  • 18,092
  • 4
  • 117
  • 102
2

I've been struggling to figure out where and how to get the various Linux kernel branches, so I wanted to expound upon that and show where I learned it. This research also allowed me to fix and update the link in the most-upvoted answer, which I recently did.

Where and how to get the official Linux kernel source code

Quick summary

The official code location for the Linux kernel source is https://kernel.org/.

Option 1: manually download just the kernel version tar file of interest

Go here to navigate and download just your version of interest: https://mirrors.edge.kernel.org/pub/linux/kernel/.

Ex: the OP's v2.6.32.2 is on this page here: https://mirrors.edge.kernel.org/pub/linux/kernel/v2.6/. I recommend downloading the .tar.xz version of the file, since it is the smallest: linux-2.6.36.2.tar.xz. The .sign file next to it contains the cryptographic PGP signature to verify the downloaded file's authenticity and integrity. Read more about that here, including seeing commands to verify the signature: https://kernel.org/category/signatures.html.

It's also really easy to download the files from the command-line. Here's what that might look like:

# Download the file, showing a progress bar; this file is 56 MB
wget https://mirrors.edge.kernel.org/pub/linux/kernel/v2.6/linux-2.6.36.2.tar.xz
# extract it; on a fast computer this takes ~4 sec.; the extracted 
# "linux-2.6.36.2" dir is ~400 MB when done
time tar -xvf linux-2.6.36.2.tar.xz

Option 2 (recommended): use git to download all versions and check out any version

# clone the latest Stable and Longterm release tree (git repo)
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
# cd into it
cd linux
# view all tags, which contain the many many version numbers
# - see my answer here: https://stackoverflow.com/a/69275540/4561887
git log --no-walk --tags --oneline
# Once you identify the one of interest (ex: 2.6.36.2), check out the commit
# with that tag
git checkout v2.6.36.2

Details

The official Linux kernel source code is at The Linux Kernel Archives at https://kernel.org/.

Choose the git repository "tree" you wish to clone:

These quotes just below are from this page: https://kernel.org/category/releases.html. I've also added my words in square brackets ([]).

Prepatch
Prepatch or "RC" [Release Candidate] kernels are mainline kernel pre-releases that are mostly aimed at other kernel developers and Linux enthusiasts. They must be compiled from source and usually contain new features that must be tested before they can be put into a stable release. Prepatch kernels are maintained and released by Linus Torvalds. [Their versions end in -rcX, where X is a number.]

Mainline
Mainline tree is maintained by Linus Torvalds. It's the tree where all new features are introduced and where all the exciting new development happens. New mainline kernels are released every 9-10 weeks.

Stable
After each mainline kernel is released, it is considered "stable." Any bug fixes for a stable kernel are backported from the mainline tree and applied by a designated stable kernel maintainer. There are usually only a few bugfix kernel releases until next mainline kernel becomes available -- unless it is designated a "longterm maintenance kernel." Stable kernel updates are released on as-needed basis, usually once a week.

Longterm
There are usually several "longterm maintenance" kernel releases provided for the purposes of backporting bugfixes for older kernel trees. Only important bugfixes are applied to such kernels and they don't usually see very frequent releases, especially for older trees. [See a table of all of the long-term releases here: https://kernel.org/category/releases.html. Most of them are supported for up to 6 years.]

git clone URLs

Clone the repo you want. Note that if there are multiple clone URLs, any are usable, but I prefer the first one in each list below:

  1. For Prepatch ("Release Candidate", or -rc) and Mainline (the main working tree) releases:
    # From kernel.org directly
    # See: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
    git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
    git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
    git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux.git
    

    Or, an exact mirror on GitHub

    See: https://github.com/torvalds/linux

    git clone https://github.com/torvalds/linux

  2. For Stable and Longterm releases:
    # From kernel.org directly
    # See: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/
    git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
    git clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
    git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/stable/linux.git
    

    Note: This URL still works as of Dec. 2022, and has the exact same content

    as the URLs above, but is no longer listed in the list of all

    repos/trees here (https://git.kernel.org/), and so it appears to be

    deprecated. Use the URLs above instead.

    git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git

  3. For "Linux-Next" (I'm not sure what this means) releases:
    # From kernel.org directly
    # See: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/
    git clone git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
    git clone https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
    git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/next/linux-next.git
    

If you're developing in the kernel or want to see the latest, you'll probably want the Mainline git tree:

git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
# or on GitHub
git clone https://github.com/torvalds/linux

If you're just trying to download a given stable or longterm release number, such as in the question (v2.6.36.2), then clone the Stable and Longterm release tree instead, and cd into it:

git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
cd linux  # cd into the newly-cloned dir

You can then view all version number tags (see my answer for details and more commands), and check out the one of interest:

git log --no-walk --tags --oneline
git checkout v2.6.36.2

How did I find the kernel.org git clone URLs above?

Go to the main page at https://kernel.org/ and click the "browse" links:

enter image description here

Then click the "summary" column header at the top, and look for the "Clone" links at the bottom:

enter image description here

References

  1. https://kernel.org/category/signatures.html - I learned how to verify the PGP signatures and find the download URLs for individual tar files from this page.
  2. My answer: show all tags in git log
  3. https://linuxize.com/post/how-to-extract-unzip-tar-xz-file/
0
  1. Go to https://github.com/torvalds/linux
  2. Tap on "commits" enter image description here
  3. Click on branch selector ("master" most probably) enter image description here
  4. Select "tags" and specify linux version (I selected 5.8) enter image description here
  5. Click on in the right <> enter image description here
  6. Profit enter image description here
  • 1
    This seems rather roundabout. If you want to download the code for a particular tag, you can search for the tag in the branch selector in the first screenshot, there's no need to go to the list of commits. If you want to download it for a particular commit, you can click the <> directly, again, no need to search for tags. – muru Aug 14 '23 at 15:00