Ubuntu linux kernel source

Ubuntu Wiki

There are a number of different ways of getting the kernel sources. The two main ways will be documented here.

If you have installed a version of Ubuntu and you want to make changes to the kernel that is installed on your system, use the apt-get method (described below) to obtain the sources.

However, if you wish to get the most up to date sources for the Ubuntu release you are running and make changes to that, use the git method (described below) to obtain the sources.

Obtaining the kernel sources for an Ubuntu release using apt-get

apt-get source linux-image-unsigned-$(uname -r)
apt-get source linux-image-$(uname -r)

Obtaining the kernel sources for an Ubuntu release using git

The source for each release is maintained in its own git repository on Launchpad.

git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source//+git/

git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/cosmic
groovy git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/groovy
focal git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/focal
bionic git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/bionic

Replace your intended OS series in the above, and pull the source for the kernels you need.

The distro kernel is always on the master branch in these repositories. Each release also has a master-next branch containing the commits that will go onto the master branch and become the next release for that release.

A number of releases also have other source packages which represent other related but divergent kernels for other purposes. For example, there is a specialized AWS kernel available in the linux-aws source package. (Previously these sorts of things were done in Topic Branches and some older kernels and projects still use them.)

Obtaining a copy

To obtain a local copy you can simply git clone the repository for the release you are interested. The git command is part of the git package.

git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/bionic
git clone git://kernel.ubuntu.com/ubuntu/linux.git git clone --reference linux git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/groovy

In each case you will end up with a new directory ubuntu- containing the source and the full history which can be manipulated using the git command from within each directory.

$ git tag -l Ubuntu-* Ubuntu-5.4.0-47.51 Ubuntu-5.4.0-48.52 Ubuntu-5.4.0-49.53 Ubuntu-5.4.0-51.56 Ubuntu-5.4.0-52.57 $
git checkout -b temp Ubuntu-5.4.0-52.57

You may then manipulate the release - for example, by adding new commits.

Applying Patches

Apply patches using git cherry-pick

To apply individual patches from an upstream kernel tree to your current Ubuntu kernel tree use the following command:

Where, SHAID is the commit ID of the patch you want to apply.

Set up chroot build environment

Get the automated chroot build scripts

  • buildscripts: Scripts used to farm out the kernel builds to very fast remote
  • chroot-setup: Scripts to setup jailed kernel compilation enviroments.
  • daily-test-isos: Scripts and support files to produce daily, custom test isos.
  • git-hooks: Optional hooks to help you commit patches
  • maintscripts: Scripts used for general / stable kernel maintenance
  • mainline-build: Scripts to produce .debs for mainline kernels
  • misc: Everything else.
Читайте также:  Vt100 terminal emulator linux

Download them using the following command.

git clone git://kernel.ubuntu.com/ubuntu/kteam-tools.git kteam-tools

Create the chroot environment

To automatically create the chroot environment use:

sudo mkdir -p /usr3/chroots # prep environment sudo chroot-setup/make_chroot precise amd64 http://archive.ubuntu.com/ubuntu
  • arch stands for different arch supported by the CPU, for example i386 on AMD64 or LPIA on i386 etc.
  • suite stands for release name such as hardy, gutsy, intrepid etc.
  • mirror stands for the http location to download environment from, http://host[:port]/dir/

Note: You don't need to specify a mirror when using the LPIA arch

Packages required on a build system

  • ccache
  • devscripts
  • xmlto
  • docbook-utils
  • gs
  • transfig
  • sharutils

Install build system package requisites

Certain packages are required to be installed on the build system. You can install these packages using the following command:

sudo apt-get install git-core debhelper build-essential fakeroot kernel-wedge makedumpfile

Optionally you may also install the following packages that might help debuild to function flawlessly.

sudo apt-get install ccache devscripts xmlto docbook-utils gs transfig sharutils libdw-dev libdw1 libelf-dev

Building the kernel packages

chroot into the build environment

Depending on what may be installed on your system you may use "dchroot" or "schroot" to chroot into the build environment.

You should chroot into a 64bit build environment to build 64bit kernel package, 32bit build environemt to build 32bit kernel package.

Setup the build tree

This step generates the debian control files required to build the kernel. The clean target is a bit of a misnomer here since we moved the generated files (control.stub, control) out of version control. The clean target actually creates these files. It is a known drawback, and unavoidable.

fakeroot debian/rules clean

Modify debian/changelog

Modify the debian/changelog file to reflect something unique about this build, for example, you may use a launchpad bug number that you might be building this kernel for.

Modify the the first line, for example:

linux (2.6.27-12.28) UNRELEASED; urgency=low
linux (2.6.27-12.28~lpNNNNNNUSERNAME1) UNRELEASED; urgency=low

Build the kernel package

fakeroot debian/rules binary-generic
fakeroot debian/rules binary-arch

Build the kernel header, source, doc packages

The following will build the header, source, doc packages.

fakeroot debian/rules binary-indep

Kernel/Dev/QuickBuildLocal (последним исправлял пользователь 193 2010-07-20 10:29:33)

The material on this wiki is available under a free license, see Copyright / License for details.

Источник

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?

Читайте также:  Конфигурация компьютера для linux

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

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.

Читайте также:  Debian gnu linux 10 buster

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

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.

Источник

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