Debian install linux source

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.

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.

Читайте также:  Linux no templates installed

Источник

Debian install linux source

Why would someone want to compile a new kernel? It is often not necessary since the default kernel shipped with Debian handles most configurations. Also, Debian often offers several alternative kernels. So you may want to check first if there is an alternative kernel image package that better corresponds to your hardware. However, it can be useful to compile a new kernel in order to:

  • handle special hardware needs, or hardware conflicts with the pre-supplied kernels
  • use options of the kernel which are not supported in the pre-supplied kernels (such as high memory support)
  • optimize the kernel by removing useless drivers to speed up boot time
  • create a monolithic instead of a modularized kernel
  • run an updated or development kernel
  • learn more about linux kernels

8.6.1. Kernel Image Management

Don’t be afraid to try compiling the kernel. It’s fun and profitable.

To compile a kernel the Debian way, you need some packages: fakeroot , kernel-package , linux-source-2.6 and a few others which are probably already installed (see /usr/share/doc/kernel-package/README.gz for the complete list).

This method will make a .deb of your kernel source, and, if you have non-standard modules, make a synchronized dependent .deb of those too. It’s a better way to manage kernel images; /boot will hold the kernel, the System.map, and a log of the active config file for the build.

Note that you don’t have to compile your kernel the “ Debian way ” ; but we find that using the packaging system to manage your kernel is actually safer and easier. In fact, you can get your kernel sources right from Linus instead of linux-source-2.6 , yet still use the kernel-package compilation method.

Note that you’ll find complete documentation on using kernel-package under /usr/share/doc/kernel-package . This section just contains a brief tutorial.

Hereafter, we’ll assume you have free rein over your machine and will extract your kernel source to somewhere in your home directory [22] . We’ll also assume that your kernel version is 3.16. Make sure you are in the directory to where you want to unpack the kernel sources, extract them using tar xf /usr/src/linux-source-3.16.tar.xz and change to the directory linux-source-3.16 that will have been created.

Now, you can configure your kernel. Run make xconfig if X11 is installed, configured and being run; run make menuconfig otherwise (you’ll need libncurses5-dev installed). Take the time to read the online help and choose carefully. When in doubt, it is typically better to include the device driver (the software which manages hardware peripherals, such as Ethernet cards, SCSI controllers, and so on) you are unsure about. Be careful: other options, not related to a specific hardware, should be left at the default value if you do not understand them. Do not forget to select “ Kernel module loader ” in “ Loadable module support ” (it is not selected by default). If not included, your Debian installation will experience problems.

Читайте также:  Фишинг инструменты кали линукс

Clean the source tree and reset the kernel-package parameters. To do that, do make-kpkg clean .

Now, compile the kernel: fakeroot make-kpkg —initrd —revision=1.0.custom kernel_image . The version number of “ 1.0 ” can be changed at will; this is just a version number that you will use to track your kernel builds. Likewise, you can put any word you like in place of “ custom ” (e.g., a host name). Kernel compilation may take quite a while, depending on the power of your machine.

Once the compilation is complete, you can install your custom kernel like any package. As root, do dpkg -i ../linux-image-3.16- subarchitecture _1.0.custom_i386.deb . The subarchitecture part is an optional sub-architecture, such as “ 686 ” , depending on what kernel options you set. dpkg -i will install the kernel, along with some other nice supporting files. For instance, the System.map will be properly installed (helpful for debugging kernel problems), and /boot/config-3.16 will be installed, containing your current configuration set. Your new kernel package is also clever enough to automatically update your boot loader to use the new kernel. If you have created a modules package, you’ll need to install that package as well.

It is time to reboot the system: read carefully any warning that the above step may have produced, then shutdown -r now .

For more information on Debian kernels and kernel compilation, see the Debian Linux Kernel Handbook. For more information on kernel-package , read the fine documentation in /usr/share/doc/kernel-package .

[22] There are other locations where you can extract kernel sources and build your custom kernel, but this is easiest as it does not require special permissions.

Источник

Debian install linux source

Why would someone want to compile a new kernel? It is often not necessary since the default kernel shipped with Debian handles most configurations. Also, Debian often offers several alternative kernels. So you may want to check first if there is an alternative kernel image package that better corresponds to your hardware. However, it can be useful to compile a new kernel in order to:

  • handle special hardware needs, or hardware conflicts with the pre-supplied kernels
  • use options of the kernel which are not supported in the pre-supplied kernels (such as high memory support)
  • optimize the kernel by removing useless drivers to speed up boot time
  • create a monolithic instead of a modularized kernel
  • run an updated or development kernel
  • learn more about linux kernels

8.6.1. Kernel Image Management

Don’t be afraid to try compiling the kernel. It’s fun and profitable.

To compile a kernel the Debian way, you need some packages: fakeroot , kernel-package , linux-source-2.6 and a few others which are probably already installed (see /usr/share/doc/kernel-package/README.gz for the complete list).

This method will make a .deb of your kernel source, and, if you have non-standard modules, make a synchronized dependent .deb of those too. It’s a better way to manage kernel images; /boot will hold the kernel, the System.map, and a log of the active config file for the build.

Note that you don’t have to compile your kernel the “ Debian way ” ; but we find that using the packaging system to manage your kernel is actually safer and easier. In fact, you can get your kernel sources right from Linus instead of linux-source-2.6 , yet still use the kernel-package compilation method.

Читайте также:  Linux debian fedora ubuntu

Note that you’ll find complete documentation on using kernel-package under /usr/share/doc/kernel-package . This section just contains a brief tutorial.

Hereafter, we’ll assume you have free rein over your machine and will extract your kernel source to somewhere in your home directory [22] . We’ll also assume that your kernel version is 3.16. Make sure you are in the directory to where you want to unpack the kernel sources, extract them using tar xf /usr/src/linux-source-3.16.tar.xz and change to the directory linux-source-3.16 that will have been created.

Now, you can configure your kernel. Run make xconfig if X11 is installed, configured and being run; run make menuconfig otherwise (you’ll need libncurses5-dev installed). Take the time to read the online help and choose carefully. When in doubt, it is typically better to include the device driver (the software which manages hardware peripherals, such as Ethernet cards, SCSI controllers, and so on) you are unsure about. Be careful: other options, not related to a specific hardware, should be left at the default value if you do not understand them. Do not forget to select “ Kernel module loader ” in “ Loadable module support ” (it is not selected by default). If not included, your Debian installation will experience problems.

Clean the source tree and reset the kernel-package parameters. To do that, do make-kpkg clean .

Now, compile the kernel: fakeroot make-kpkg —initrd —revision=1.0.custom kernel_image . The version number of “ 1.0 ” can be changed at will; this is just a version number that you will use to track your kernel builds. Likewise, you can put any word you like in place of “ custom ” (e.g., a host name). Kernel compilation may take quite a while, depending on the power of your machine.

Once the compilation is complete, you can install your custom kernel like any package. As root, do dpkg -i ../linux-image-3.16- subarchitecture _1.0.custom_amd64.deb . The subarchitecture part is an optional sub-architecture, depending on what kernel options you set. dpkg -i will install the kernel, along with some other nice supporting files. For instance, the System.map will be properly installed (helpful for debugging kernel problems), and /boot/config-3.16 will be installed, containing your current configuration set. Your new kernel package is also clever enough to automatically update your boot loader to use the new kernel. If you have created a modules package, you’ll need to install that package as well.

It is time to reboot the system: read carefully any warning that the above step may have produced, then shutdown -r now .

For more information on Debian kernels and kernel compilation, see the Debian Linux Kernel Handbook. For more information on kernel-package , read the fine documentation in /usr/share/doc/kernel-package .

[22] There are other locations where you can extract kernel sources and build your custom kernel, but this is easiest as it does not require special permissions.

Источник

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