Get the corresponding kernel source command under Ubuntu

Source: Internet
Author: User

Input: Apt-cache Search Linux-source//view kernel version

Input: Apt-get install linux-source-3.0.0//get the corresponding version of the kernel, by default installed in the/USR/SRC directory

See:

How to build the kernel source tree under Ubuntu

Does the translation machine module of Ubuntu need to download the kernel source code?

The answer is yes.

DMESG | The TAIL-1 command is used to view the data that is printed after the kernel is loaded.

In Ubuntu, can also be downloaded according to the source code to compile the module, to enable the module to run in this machine, download the kernel source version of the best and the same machine. Of course, you can also develop embedded system modules based on the cross compiler.

Makefile Version 1:

Obj-m: = MOD_TEST.O
Kernelbuild: =/lib/modules/$ (shell uname-r)/build
Default
Make-c $ (kernelbuild) m=$ (shell pwd)
Modulesclean:
RM-RF *.o *.ko *.mod.c *.cmd *.markers *.order *.symvers. tmp_versions

In the case of a source, makefile version 2:

Obj-m: = MOD_TEST.O

Command Line Input:

Make-c/usr/src/linux26/subdirs= $PWD Modules
can produce modules. If the kernel version is different, there will be problems that cannot be loaded. Can be viewed with modinfo Mod_test.ko.

vi/lib/modules/' uname-r '/build/makefile can view the kernel version number in Makefile

http://blog.csdn.net/sabalol/article/details/2076610

Makefile for,
PWD = $ (Shell PWD)
KERNEL_SRC =/usr/src/linux-source-2.6.15/

Obj-m: = TEST.O
MODULE-OBJS: = TEST.O

All
$ (make)-C $ (KERNEL_SRC) m=$ (PWD) modules


Clean
RM *.ko
RM *.O
Run make in the directory where test.c and makefile are located, and if you see similar output
Make-c/usr/src/linux-source-2.6.15/m=/home/vmeth Modules

MAKE[1]: Entering directory '/usr/src/linux-source-2.6.15 '
CC [M]/home/vmeth/hello.o
Building modules, Stage 2.
Modpost
cc/home/vmeth/hello.mod.o
LD [M]/home/vmeth/hello.ko
MAKE[1]: Leaving directory '/usr/src/linux-source-2.6.15 '

Generally with the following makefile,
# Makefile2.6
Ifneq ($ (kernelrelease),)
#kbuild syntax. Dependency Relationshsip of files and target modules are
Listed here.

MYMODULE-OBJS: = hello.o
Obj-m: = hello.o

Else
PWD: = $ (Shell PWD)

Kver? = $ (Shell uname-r)
Kdir: =/lib/modules/$ (kver)/build
All
$ (make)-C $ (Kdir) m=$ (PWD)

Clean
Rm-rf. *.cmd *.o *.mod.c *.ko. tmp_versions

endif
Kernelrelease is a variable defined in the top-level makefile of the kernel source code, which executes this on the first read
Makefile, the kernelrelease is not defined, so make reads the contents after the Execute else.
When make's target is all, the-C $ (kdir) indicates the jump to the kernel source directory to read the makefile;m=
$ (PWD) indicates that it is then returned to the current directory to continue reading and execute the current makefile.
When returned from the kernel source directory, Kernelrelease has been defined and Kbuild is also started to parse Kbuild
syntax, make will continue to read the contents before else. Else before the content is kbuild syntax of the statement,
Indicates the dependencies of the files in the module source code and the name of the target module to be generated.
The name of each kernel contains its version number, which is also the value displayed by the Uname-r command.

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.