Linux kernel source dir

How do I get the kernel source code?

I am planning to write some device drivers and I need to get the Linux kernel source. My Linux kernel version is 3.2.0-23-generic-pae and I downloaded the image from this. In many of the articles I have read, it tells me that I need to have the entire kernel tree to start inserting new modules. Is it enough if I download this image and paste it into the usr/src/ folder or do I have to do something else?

I usually just install the ‘linux-source’ package from synaptic when I’m custom compiling for one of my machines, but given you’re doing development you might need the most recent version. This link might be useful to you: help.ubuntu.com/community/Kernel/Compile

5 Answers 5

This will get the source of the stock kernel:

apt-get source linux-source 

You can check what version of the kernel is running like this:

Which will print something like:

You can find a list of current source package versions available on your system via:

apt-cache search linux-source 

To get the upstream version of the kernel:

git clone git://kernel.ubuntu.com/ubuntu/ubuntu-trusty.git 

In the above link, ‘trusty’ is the codename for the version of Ubuntu. You can find out the codename for the version of Ubuntu you have installed via:

If I use git to clone how do i specify the version. Also If i Clone it is it enough if a I copy pate it into the usr/src folder

That git repository is kept to 3.2.0 specifically; it follows what’s in Ubuntu Precise (12.04). If you want a different version change ubuntu-precise.git to ubuntu-quantal.git or whatever. It should be fine to just copy into usr/src.

And where should I be able to find the source tree when installing with. Damn, I should read better. The answer says apt-get source not apt-get install . Than the source tree will end up in your current path.

sudo apt install linux-source # downloads into system directory sudo apt source linux-source # downloads into working directory 

If you’re told to give some ‘sources’ URLs in your sources.list , go edit your /etc/apt/sources.list file and uncomment the desired deb-src line, for example (if you’re running Xenial):

deb http://fr.archive.ubuntu.com/ubuntu/ xenial main restricted # deb-src http://fr.archive.ubuntu.com/ubuntu/ xenial main restricted 

Removing the # on this last line enables sources repositories for download, including kernel sources.

  • Use modern tools; avoid apt-get .
  • These commands download the source code for your current kernel (in my case 4.4.0-75-generic for example).
  • When downloaded into system directory, files are stored in /usr/src/linux-source-4.4.0/ (for example).
Читайте также:  Linux set variable in command line

Doesn’t work for me (but neither does the apt-get version). I’m running Ubuntu 16.04.4, kernel 4.4.0-98-generic. It says, «You must put some ‘source’ URIs in your sources.list». I have no idea how to do that.

Yes thanks. It was a stupid comment from me. I only needed to google the error message. Anyway, have an upvote for your effort.

is the easiest way. It will download the source from your repository — and it’ll be the same as the version you’re running (assuming you haven’t already customised it).

But if you want to find where the source is maintained you can run:

Look for the ‘Vcs-‘ attribute (Version control system). It’ll usually be a git (Vcs-Git) or mercurial repository.

Note — these commands work with any package. Just substitute ‘linux’ with the package you’re interested in. And also note that ‘apt-get source’ doesn’t need sudo access and will dump the source in your current directory.

This requires the machine you are downloading on to match the target machine. Really only works if you have a network. Most of the readers landing on this page won’t have a network (hence why they suddenly need the source). I need it as a tarball on a thumb drive and I don’t have a working apt.

This downloading the src into the CURRENT DIRECTORY on Ubuntu 20.04 LTS, but it downloaded the wrong version of the kernel?? linux-5.4.0 when uname -r = 5.8.0-55-generic

Download source directly from Launchpad

Strangely enough everyone recommends apt-get source which doesn’t work most of the time if you’re looking for a specific kernel version:

Say you need kernel source for 3.19.0-58 :
apt-get source linux-image-3.19.0-58-generic will get the source for the latest kernel in the series: 3.19.0-80 in this case, which is not what you asked for.

1) Give up, install kernel 3.19.0-80 and use apt-get source

2) Get source directly from launchpad:

  • Google site:launchpad.net «linux-image-3.19.0-58-generic»
  • That should give you the Launchpad Package Page for that version.
  • Scroll down, click the «Source:» link, you’re on the Package Source Page now.
  • Scroll down and download .tar.gz , .diff.gz , .dsc files:

links

  • There must be a better way.
  • You can get the version you want from git, but you’re in for a big download. See «Obtaining the kernel sources for an Ubuntu release using git» in Ubuntu Wiki Kernel Source Code.

Thank you for explaining this so clearly. However, I am still unable to find the source for linux-image-4.15.0-39-generic. This process is needlessly complicated. I’ve tried googling for it but I keep finding packages that are a few kilobytes only. Any tips?

This is the only option on this page that worked for Ubuntu 20.04 LTS to get something that claims to be a similar kernel version linux-5.8.0 to the one returned but uname -r

Читайте также:  How to create directories and files in linux

There are cases where it is simply more practical to download the linux kernel source and headers for the version you’re interested in directly from http://kernel.org (a pretty reliable URL/site that isn’t going away [e.g. standard stackoverflow concern about stale links isn’t not an issue])

Reason? For example, you might be interested in debugging an older/defunct no-longer-supported version of linux where package repository points to dead areas, where in some cases there are either no viable current alternatives, or the repos has are expired keys that won’t let you get the stuff, requiring unmemorable difficult to search out arcane techniques to get those repositories to work anyway.

Or maybe Internet networking might be broken on Linux machine (or VM) you’re using, but file sharing or NFS works, where the source can be downloaded onto another machine and accessed via the filesystem.

If you’re working with a relatively obsolete version of Linux, chances are you’ll have to build a number of things from source and get them the hard way.

Источник

kernel source code location in linux

I am working in Windows and running fedora through VMware. By default, the kernel source tree should be in usr/src/ directory. Instead I could find only an empty directory called kernels. The actual source code is missing there. When browsing I thought it might be in other directories like /boot . But I couldn’t find source tree there as well. I need to modify system call tables for which I should be able to access those source codes.

3 Answers 3

Kernel source is not installed by default. You can follow e.g. the instructions here to install the source and build your kernel.

You probably need to install the kernel-devel package.

On Fedora, all of the software is managed through a system called the Red Hat Package Manager (RPM). Every file (other than user data and other transient files like logs and such) is «owned» by a package. The ls command is from coreutils , the kernel is probably from kernel and BZFlag (the greatest Linux game ever) is provided by the bzflag package.

In the good old days, you would try to install software by using the rpm command (type » man rpm » for more information) and giving it the path to an RPM file that you had downloaded. The rpm command would then dutifully respond by informing you that you first need to satisfy 33 prerequisites. Then you would go download those 33 prerequisites and try to install them, only to find that each of those had their own prerequisites. And so on.

Читайте также:  Linux grep исключить строки содержащие

These days, Fedora has a nice set of online repositories of packages (and you can add others for third party software), and a program called yum that can download databases of all the packages, and you tell yum «install package foo for me» (by typing something like » yum install kernel-devel «) and it goes and figures out that in order to install that package, you need a bunch of other prerequisite packages, and so on. It then automatically downloads and installs everything you need, and away you go. For more information on the various incantations that make yum go, see » man yum «).

Источник

Linux kernel source dir

All of the source code for the Linux kernel can be found on one of the kernel.org sites, a worldwide network of servers that mirror the Linux source code, enabling everyone to find a local server close to him. This allows the main kernel servers to be responsive to the mirror sites, and lets users download the needed files as quickly as possible.

The main https://www.kernel.org. site shows all of the current kernel versions for the various different kernel trees, as shown in Figure 4.2, “The main kernel.org web site”.

Figure 4.2. The main kernel.org web site

The main kernel.org web site

To download the latest stable kernel version, click on the F character on the line for the kernel version. This will download the full source tree. Or you can navigate to the proper subdirectory for all of the 2.6 kernel versions, https://www.us.kernel.org/pub/linux/kernel/v2.6/, shown in Figure 4.3, “The 2.6 kernel source directory”.

Figure 4.3. The 2.6 kernel source directory

The 2.6 kernel source directory

It is also possible to download the kernel source from the command line, using the wget or curl utilities, both of which should come with your Linux distribution.

To download the 2.6.17.8 kernel version using wget , enter:

$ wget https://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.17.8.tar.gz  --17:44:55-- https://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.17.8.tar.gz => `linux-2.6.17.8.tar.gz' Resolving www.kernel.org. 204.152.191.5, 204.152.191.37 Connecting to www.kernel.org|204.152.191.5|:80. connected. HTTP request sent, awaiting response. 200 OK Length: 51,707,742 (49M) [application/x-gzip] 100%[=============================================>] 51,707,742 35.25K/s ETA 00:00 18:02:48 (47.12 KB/s) - `linux-2.6.17.8.tar.gz' saved [51707742/51707742]

To download it using curl :

$ curl https://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.17.8.tar.gz -o linux-2.6.17.8.tar.gz  % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 49.3M 100 49.3M 0 0 50298 0 0:17:08 0:17:08 --:--:-- 100k

For a quick and easy way to determine the latest kernel versions, use the information available at https://www.kernel.org/kdist/finger_banner, illustrated by Figure 4.4, “Latest kernel version”.

Figure 4.4. Latest kernel version

Latest kernel version

Источник

Оцените статью
Adblock
detector