Get kernel source linux

Ubuntu Wiki

The majority of users that are interested in building their own kernel are doing so because they have installed Ubuntu on their system and they wish to make a small change to the kernel for that system. In many cases the user just wants to make a kernel configuration change.

The purpose of this page is to give that user a minimum amount of information for them to meet the goal of making a simple change to the kernel, building it and installing their kernel. It is not intended to be the definitive guide to doing Ubuntu kernel development.

Build Environment

sudo apt-get build-dep linux linux-image-$(uname -r)
sudo apt-get install libncurses-dev gawk flex bison openssl libssl-dev dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf llvm
deb-src http://archive.ubuntu.com/ubuntu disco main deb-src http://archive.ubuntu.com/ubuntu disco-updates main

Obtaining the source for an Ubuntu release

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.

apt-get

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

git

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

Modifying the configuration

chmod a+x debian/rules chmod a+x debian/scripts/* chmod a+x debian/scripts/misc/* LANG=C fakeroot debian/rules clean LANG=C fakeroot debian/rules editconfigs # you need to go through each (Y, Exit, Y, Exit..) or get a complaint about config later

This takes the current configuration for each architecture/flavour supported and calls menuconfig to edit its config file. The chmod is needed because the way the source package is created, it loses the executable bits on the scripts.

In order to make your kernel «newer» than the stock Ubuntu kernel from which you are based you should add a local version modifier. Add something like «+test1» to the end of the first version number in the debian.master/changelog file, before building. This will help identify your kernel when running as it also appears in uname -a. Note that when a new Ubuntu kernel is released that will be newer than your kernel (which needs regenerating), so care is needed when upgrading. NOTE: do not attempt to use CONFIG_LOCALVERSION as this _will_ break the build.

Читайте также:  Linux for core 2 duo

Building the kernel

LANG=C fakeroot debian/rules clean # quicker build: LANG=C fakeroot debian/rules binary-headers binary-generic binary-perarch # if you need linux-tools or lowlatency kernel, run instead: LANG=C fakeroot debian/rules binary
cd .. ls *.deb linux-headers-4.8.0-17_4.8.0-17.19_all.deb linux-headers-4.8.0-17-generic_4.8.0-17.19_amd64.deb linux-image-4.8.0-17-generic_4.8.0-17.19_amd64.deb

on later releases you will also find a linux-extra- package which you should also install if present.

Testing the new kernel

sudo dpkg -i linux*4.8.0-17.19*.deb sudo reboot

Debug Symbols

sudo apt-get install pkg-config-dbgsym LANG=C fakeroot debian/rules clean LANG=C fakeroot debian/rules binary-headers binary-generic binary-perarch skipdbg=false

See also

Kernel Git Guide More information about using git to pull down the kernel sources.
ARM Cross Compile For more info about ARM and cross compilation.

Kernel/BuildYourOwnKernel (последним исправлял пользователь b-stolk 2022-09-08 00:38:14)

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

Источник

Getting kernel source code (ubuntu)

I want to try my hand at writing a linux driver. I am trying to set up my environment. My current kernel:

$ apt-get source linux-image-$(uname -r) Reading package lists. Done Picking 'linux' as source package instead of 'linux-image-4.10.0-37-generic' . 
version magic '4.10.17 SMP mod_unload ' should be '4.10.0-37-generic SMP mod_unload ' 
$ uname -r 4.10.17-041017-generic 
version magic '4.10.17 SMP mod_unload ' should be '4.10.17-041017-generic SMP mod_unload 

So maybe someone can help: what is the best and correct way for me to get a working kernel and matching source on ubuntu (well, xubuntu, but I don’t think it should matter)? Do I need to get the code from kernel.org and build it from scratch? I kinda want to match the shipping Ubuntu kernel.

The linux-source-VERSION where VERSION is 4.10.17 in your case is probably the package you want to install.

@ivan seems like linux-source defaults to linux-source-4.10.17 but it doesn’t match 4.10.17-041017-generic

I pulled the code from kernel.org and I’m going to try to match it that way. @sebasth I didn’t see any mention of debuild on any of the guides at ubuntu.com. I’d need a little more help, though for now I’m compiling the kernel.org code.

Читайте также:  Linux and rar files

1 Answer 1

There are a number of approaches.

    If you’re trying to build an external module (including one you’re developing), you only need the kernel headers:

apt install linux-header-$(uname -r) 

This will provide the necessary files so that the /lib/modules/$(uname -r)/ symlinks point to something meaningful. Then you can build a module in another directory by running

make -C /lib/modules/$(uname -r)/build SUBDIRS="/path/to/your/module" modules 
apt install linux-source-4.10.0 cd /usr/src tar xf linux-source-4.10.0.tar.bz2 

This will include the Ubuntu kernel patches, allowing you to build a kernel with the same features as your current kernel. Note however the caveat from the package description:

This package is mainly meant for other packages to use, in order to build custom flavours. If you wish to use this package to create a custom Linux kernel, then it is suggested that you investigate the package kernel-package, which has been designed to ease the task of creating kernel image packages. If you are simply trying to build third-party modules for your kernel, you do not want this package. Install the appropriate linux-headers package instead.

In any case it’s not a good idea to use the linux source package itself (as obtained using apt-get source ), since that’s really designed for building all the kernels used in Ubuntu. If you blindly debuild using that source package, you’ll wait for many hours before the build finishes. (There are circumstances where this is appropriate, and the Ubuntu kernel documentation will explain what to do; but this is very likely not one of them.)

Источник

How to install full kernel source on Debian or Ubuntu

Question: I need to download and install a full kernel source tree to compile a custom kernel for my Debian or Ubuntu system. What is a proper way to download full kernel source on Debian or Ubuntu?

Before installing full kernel source on your Linux system, ask yourself whether you really need the full kernel source. If you are trying to compile a kernel module or a custom driver for your kernel, you do not need the full kernel source. You only need to install matching kernel header files, and that’s it.

You need the full kernel source tree only if you want to build a custom kernel after modifying the kernel code in any way and/or tweaking default kernel options.

Читайте также:  Scp linux указание порта

Here is how to download and install full kernel source tree from Debian or Ubuntu repositories. While you can download the official kernel source code from https://www.kernel.org/pub/linux/kernel/, using distro’s repositories allows you to download a kernel source with the maintainer’s patches applied to it.

Install Full Kernel Source on Debian

Before downloading kernel source, install dpkg-dev , which contains a suite of development tools needed to build Debian source packages. Among other things, dpkg-dev contains dpgk-source tool which can extract a Debian source package and automatically apply patches.

$ sudo apt-get install dpkg-dev

Next, run the following command to download full kernel source.

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

Along with the full kernel source ( linux_X.X.XX.orig.tar.xz ), any available kernel patches ( linux_X.X.X+XXX.debian.tar.xz ) and source control file ( linux_XXXX.dsc ) will also be downloaded and stored in the current directory. The .dsc file instructs how the patches are applied to the kernel sources.

Upon the completion of download, the above command will automatically invoke dpkg-source tool, which will unpack the downloaded kernel source in the current directory, and apply downloaded patches according to .dsc file.

The final full kernel source tree will be available in the current directory as linux-X.X.XX .

Install Full Kernel Source on Ubuntu

If you want to install full kernel source, the Debian way described above should work on Ubuntu as well.

There is another way to download full kernel source on Ubuntu. You can actually check out the kernel source tree maintained by Canonical for different Ubuntu releases.

$ sudo apt-get install git $ git clone git://kernel.ubuntu.com/ubuntu/ubuntu-$(lsb_release --codename | cut -f2).git

For example, if you are using Ubuntu 14.04, the above command will check out code from » ubuntu-trusty » Git repository.

Once you check out the Git repository, use the following command to install necessary development packages to meet the build dependencies for the kernel source tree.

$ sudo apt-get build-dep linux-image-$(uname -r)

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Источник

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