Essential for Kernel programmers In Debian/Ubuntu Linux

Source: Internet
Author: User

If you want to upgrade your Debian/Ubuntu Linux kernel, or you want to develop a new module for the kernel, or you want to write a new driver for a hardware ...... All of this involves Debian/Ubuntu Linux kernel programming.

As a kernel programmer, there are several pieces of software that you must have. As a magic weapon for Kernel programming, I will list them one by one:

1. GCC

Well-known GCC, I don't know? It is a weapon that any programmer must install first. However, if you are installing the Debian system, it should have been installed by default. If Ubuntu is used, install it. The installation method is as follows:

 

apt-get install gcc

2. Make

If you have actually written useful programs, you must have entered make clean, make, and make
For commands such as install, make is a source code maintenance tool that can automatically detect the source files to be re-compiled and recompile the program according to the compilation rules you set. It is not mentioned here. If
If you are not familiar with it, Google it. However, if you are installing the Debian system, it should have been installed by default. If Ubuntu is used, install it. The installation method is the same.
Inbound:

 

apt-get install make

3. kernel-Source

We can see from the package name that this is the kernel source code package. You can use apt-cache search
Kernel-Source: Find the kernel source code package and run the uname-R command to view the kernel version of the current system. Then run apt-Get install
Kernel-source-xxxx to install the kernel source code package with the same kernel version.

But I do not recommend that you do this, because most of the Linux kernel source code packages of the release version are not from
The download from kernel.org is exactly the same. It should be the packages modified and optimized by the publishers. Although the producers of the release have spent their effort on it, but this is not a good thing for our programmers,
Most of the source code packages of the release version lack some necessary header files and some useful script programs, which causes us to encounter troubles when writing the kernel module, for example, an error may be reported during compilation that a header file cannot be found,
An error may be reported that a script program does not exist.

If you directly download a new kernel from kernel.org to compile and upgrade your kernel, and perform kernel programming on this basis, it may save some trouble, at least you don't need to install these packages as I will talk about later. It is enough to set the kernel_dir variable to the location of your kernel source code package.

Here we will teach you how to prepare the kernel programming environment based on Debian 3.1 and kernel 2.6.8-2-386. Use these commands to install the kernel-source package in sequence.

 

apt-cache search kernel-source
uname -r

Apt-Get install kernel-source-xxxx

Note: If you do not want to re-compile the kernel, the kernel-source package can be downloaded.

4. kernel-headers

This is the kernel source code header file package. Whether you want to develop the kernel module or driver, this package is required
To install. As a kernel module writer, it usually calls something in the kernel, such as the kernel header file and kernel data structure declaration. It contains some key kernel header files. Otherwise
An error similar to the following is reported during kernel Translation:

 

Hostcc scripts/basic/fixdep
Scripts/basic/fixdep. C: 105: 23: Error: SYS/types. H: No file or directory

Run the following command to install the SDK:

 

apt-cache search kernel-headers
uname -r
apt-get instakk kernel-headers-xxxx

Note: In ubuntu, it seems that the package is prefixed with "Linux-" to change to "Linux-kernel-headers.

If you have not installed the kernel-kbuild package before, the kernel-kbuild package will be installed during the installation process. This package is described below.

5. kernel-kbuild

This package is used to compile the kernel module. After downloading and installing this package, you will find that a directory starting with kernel-kbuild-XXXX is added under the/usr/src directory, there is only one scripts directory. Obviously, this is a script program used to compile the kernel module. The installation method is the same:

 

apt-cache search kernel-kbuild
uname -r
apt-get install kernel-kbuild-xxxx

Note: You will also find that after the kernel-headers package is installed on it, there is a scripts directory under the/usr/src/kernel-headers-XXXX directory, it is actually a link to the scripts under the/usr/src/kernel-kbuild-XXXX directory.

6. Build-essential

This package contains a list of packages that play a key role in the Deb package creation process. If you do not want to create a deb package, you do not need to install this table, if you need to generate a deb package, you 'd better install this package. Installation Method:

 

apt-get install build-essential

7. kernel-Package

If you want to use the kernel image as a deb package, you must install this package. That is to say, the make-kpkg command is available only when this software package is installed. The installation method is the same:

 

apt-get install kernel-package

8. initrd-Tools

If you want to create an initrd image during the startup process, this package is essential. The mkinitrd command is available only after this package is installed. Installation Method:

 

apt-get instakk initrd-tools

Let's end with a kernel module programming example!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.