- Kernel/Traditional compilation
- Contents
- Preparation
- Install the core packages
- Create a kernel compilation directory
- Download the kernel source
- Unpack the kernel source
- Kernel configuration
- Default Arch configuration
- Advanced configuration
- Compilation
- Installation
- Install the modules
- Copy the kernel to /boot directory
- Make initial RAM disk
- Automated preset method
- Manual method
- Copy System.map
- Bootloader configuration
- Compile kernel module
- Contents
- Build environment
- Traditional compilation
- Arch Build System
- Source configuration
- Module compilation
- out-of-tree module compilation
- Module installation
- possible errors
- How to: Compile Linux kernel modules
- Example: hello.c module
- See also:
Kernel/Traditional compilation
This article is an introduction to building custom kernels from kernel.org sources. This method of compiling kernels is the traditional method common to all distributions. It can be, depending on your background, more complicated than using the Kernels/Arch Build System. Consider the Arch Build System tools are developed and maintained to make repeatable compilation tasks efficient and safe.
Contents
Preparation
It is not necessary (or recommended) to use the root account or root privileges (i.e. via Sudo) for kernel preparation.
Install the core packages
Install the base-devel package group, which contains necessary packages such as make and gcc . It is also recommended to install the following packages, as listed in the default Arch kernel PKGBUILD: xmlto , kmod , inetutils , bc , libelf , git , cpio , perl , tar , xz .
Create a kernel compilation directory
It is recommended to create a separate build directory for your kernel(s). In this example, the directory kernelbuild will be created in the home directory:
Download the kernel source
Download the kernel source from https://www.kernel.org. This should be the tarball ( tar.xz ) file for your chosen kernel.
It can be downloaded by simply right-clicking the tar.xz link in your browser and selecting Save Link As. , or any other number of ways via alternative graphical or command-line tools that utilise HTTP, TFTP, Rsync, or Git.
In the following command-line example, wget has been installed and is used inside the
/kernelbuild directory to obtain kernel 4.8.6:
You should also verify the correctness of the download before trusting it. First grab the signature, then use that to grab the fingerprint of the signing key, then use the fingerprint to obtain the actual signing key:
Note the signature was generated for the tar archive (i.e. extension .tar ), not the compressed .tar.xz file that you have downloaded. You need to decompress the latter without untarring it. Verify that you have xz installed, then you can proceed like so:
Do not proceed if this does not result in output that includes the string «Good signature».
If wget was not used inside the build directory, it will be necessary to move the tarball into it, e.g.
Unpack the kernel source
Within the build directory, unpack the kernel tarball:
To finalise the preparation, ensure that the kernel tree is absolutely clean; do not rely on the source tree being clean after unpacking. To do so, first change into the new kernel source directory created, and then run the make mrproper command:
Kernel configuration
This is the most crucial step in customizing the default kernel to reflect your computer’s precise specifications. Kernel configuration is set in its .config file, which includes the use of Kernel modules. By setting the options in .config properly, your kernel and computer will function most efficiently.
You can do a mixture of two things:
- Use the default Arch settings from an official kernel (recommended)
- Manually configure the kernel options (optional, advanced and not recommended)
Default Arch configuration
This method will create a .config file for the custom kernel using the default Arch kernel settings. If a stock Arch kernel is running, you can use the following command inside the custom kernel source directory:
Otherwise, the default configuration can be found online in the official Arch Linux kernel package.
Advanced configuration
There are several tools available to fine-tune the kernel configuration, which provide an alternative to otherwise spending hours manually configuring each and every one of the options available during compilation.
Those tools are:
- make menuconfig : Command-line ncurses interface superseded by nconfig
- make nconfig : Newer ncurses interface for the command-line
- make xconfig : User-friendly graphical interface that requires packagekit-qt5 to be installed as a dependency. This is the recommended method — especially for less experienced users — as it is easier to navigate, and information about each option is also displayed.
- make gconfig : Graphical configuration similar to xconfig but using gtk. This requires gtk2 , glib2 and libgladeAUR .
The chosen method should be run inside the kernel source directory, and all will either create a new .config file, or overwrite an existing one where present. All optional configurations will be automatically enabled, although any newer configuration options (i.e. with an older kernel .config ) may not be automatically selected.
Once the changes have been made save the .config file. It is a good idea to make a backup copy outside the source directory. You may need to do this multiple times before you get all the options right.
If unsure, only change a few options between compilations. If you cannot boot your newly built kernel, see the list of necessary config items here.
Running lspci -k # from liveCD lists names of kernel modules in use. Most importantly, you must maintain cgroups support. This is necessary for systemd. For more detailed information, see Gentoo:Kernel/Gentoo Kernel Configuration Guide and Gentoo:Intel#Kernel or Gentoo:Ryzen#Kernel for Intel or AMD Ryzen processors.
Compilation
Compilation time will vary from as little as fifteen minutes to over an hour, depending on your kernel configuration and processor capability. Once the .config file has been set for the custom kernel, within the source directory run the following command to compile:
Installation
Install the modules
Once the kernel has been compiled, the modules for it must follow. First build the modules:
Then install the modules. As root or with root privileges, run the following command to do so:
This will copy the compiled modules into /lib/modules/ — . For example, for kernel version 4.8 installed above, they would be copied to /lib/modules/4.8.6-ARCH . This keeps the modules for individual kernels used separated.
Copy the kernel to /boot directory
The kernel compilation process will generate a compressed bzImage (big zImage) of that kernel, which must be copied to the /boot directory and renamed in the process. Provided the name is prefixed with vmlinuz- , you may name the kernel as you wish. In the examples below, the installed and compiled 4.8 kernel has been copied over and renamed to vmlinuz-linux48 :
Make initial RAM disk
If you do not know what making an initial RAM disk is, see Initramfs on Wikipedia and mkinitcpio.
Automated preset method
An existing mkinitcpio preset can be copied and modified so that the custom kernel initramfs images can be generated in the same way as for an official kernel. This is useful where intending to recompile the kernel (e.g. where updated). In the example below, the preset file for the stock Arch kernel will be copied and modified for kernel 4.8, installed above.
First, copy the existing preset file, renaming it to match the name of the custom kernel specified as a suffix to /boot/vmlinuz- when copying the bzImage (in this case, linux48 ):
Second, edit the file and amend for the custom kernel. Note (again) that the ALL_kver= parameter also matches the name of the custom kernel specified when copying the bzImage :
Finally, generate the initramfs images for the custom kernel in the same way as for an official kernel:
Manual method
Rather than use a preset file, mkinitcpio can also be used to generate an initramfs file manually. The syntax of the command is:
- -k ( —kernel ): Specifies the modules to use when generating the initramfs image. The name will be the same as the name of the custom kernel source directory (and the modules directory for it, located in /usr/lib/modules/ ).
- -g ( —generate ): Specifies the name of the initramfs file to generate in the /boot directory. Again, using the naming convention mentioned above is recommended.
For example, the command for the 4.8 custom kernel installed above would be:
Copy System.map
The System.map file is not required for booting Linux. It is a type of «phone directory» list of functions in a particular build of a kernel. The System.map contains a list of kernel symbols (i.e function names, variable names etc) and their corresponding addresses. This «symbol-name to address mapping» is used by:
- Some processes like klogd, ksymoops, etc.
- By OOPS handler when information has to be dumped to the screen during a kernel crash (i.e info like in which function it has crashed).
If your /boot is on a filesystem which supports symlinks (i.e., not FAT32), copy System.map to /boot , appending your kernel’s name to the destination file. Then create a symlink from /boot/System.map to point to /boot/System.map- :
After completing all steps above, you should have the following 3 files and 1 soft symlink in your /boot directory along with any other previously existing files:
- Kernel: vmlinuz-
- Initramfs: Initramfs- .img
- System Map: System.map-
- System Map kernel symlink
Bootloader configuration
Add an entry for your new kernel in your bootloader’s configuration file. See Arch boot process#Feature comparison for possible boot loaders, their wiki articles and other information.
Источник
Compile kernel module
Sometimes you may wish to compile Linux’s Kernel module without recompiling the whole kernel.
Contents
Build environment
Firstly you will need to install build dependencies such as compiler ( base-devel ) and linux-headers .
Next you will need to get the source code for the kernel version the module is intended to run on. You may try use newer kernel sources but most likely compiled module will not load.
In case the intended kernel version is the installed kernel, find its version with
There are two main options to acquire the required source. Each option has slightly different usage methods and directory structure.
Traditional compilation
See Kernels/Traditional compilation#Download the kernel source. If you fetch latest source using Git you will need to checkout needed version using tag (eg. v4.1).
Arch Build System
For a general overview on Arch Build System read ABS. See Kernel/Arch Build System for acquiring the kernel source, as well as the directory structure, and other details.
Source configuration
When you have the source code, enter its directory. For the #Arch Build System case, that directory would be src/archlinux-linux/ down from where the PKGBUILD is.
The output from make help is beneficial here. Start by cleaning with
An appropriate .config file is now required. If no config file is to be seen nearby, perhaps from a saved .config , and the intended kernel version is the running kernel, you can use its configuration file:
Next ensure the .config file is adjusted for the kernel version. If you are using kernel sources for the exact current version then it should not ask anything. But for another version than the current kernel you might be asked about some options. In any case, for the #Arch Build System option, you might want to examine the PKGBUILD::prepare() function.
If the module you want to compile have some compilation options such as debug build, or it was not compiled before, you can also, possibly must, adjust the kernel configuration. You can do this with one of the many configuration targets mentioned by make help.
Module compilation
In order to compile and load our module cleanly, we must find the value of the EXTRAVERSION component of the current kernel version number so we can match the version number exactly in our kernel source. EXTRAVERSION is a variable set in the kernel top-level Makefile, but the Makefile in a vanilla kernel source will have EXTRAVERSION empty; it is set only as part of the Arch kernel build process. If relevant, the value of the current kernel’s EXTRAVERSION can be found by looking at the output of the uname -r command. In general, the kernel version is the concatenation of three components. Namely, the numeric version, the EXTRAVERSION, and the LOCALVERSION. The numeric version itself is a concatenation of three numbers. If built by a PKGBUILD file, the LOCALVERSION will be taken from the pkgrel variable, prefixed by a hyphen. And the EXTRAVERSION will be the suffix of the pkgver variable, where the period character to the right of the third numeric number of the numeric version is replaced by a hyphen. For example, with the linux package linux 5.5.8.arch1-1 , the LOCALVERSION is -1 . The EXTRAVERSION is -arch1 . The output of uname -r will be 5.5.8-arch1-1 in that example.
Once the EXTRAVERSION value is known, we prepare the source for module compilation:
Alternatively, if you are happy to load modules with modprobe using the —force-vermagic option to ignore mismatches in the kernel version number, you can simply run:
Finally, compile wanted module by specifying its directory name. You can find the module location, thus also its directory name, with modinfo or find.
As a last resort, if nothing else has worked, you can
Which will build all the modules from the kernel configuration.
out-of-tree module compilation
get the official source code of the current running linux kernel as described in Kernel/Arch Build System:
then point to the checked out source when compiling the module:
Module installation
Now after successful compilation you just need to gzip and copy it over for your current kernel.
If you are replacing some existing module you will need to overwrite it (and remember that reinstalling linux will replace it with default module)
Or alternatively, you can place the updated module in the updates folder (create it if it does not already exist).
However if you are adding a new module you can just copy it to extramodules (note, this is just example as btrfs will not get loaded from here)
You need to rebuild the module dependency tree with «depmod» to use installed modules.
If you are compiling a module for early boot (e.g. updated module) which is copied to Initramfs then you must remember to regenerate it with (otherwise your compiled module will not be loaded).
possible errors
If EXTRAVERSION is not set correctly the following errors may occur
adding force-vermagic makes it ignore the version mismatch
Источник
How to: Compile Linux kernel modules
This is one the essential and important task. Many time we upgrade our kernel and some precompiled drivers won’t work with Linux. Especially if you have weird hardware; then vendor may send you driver code aka C files to compile. Or even you can write your own Linux kernel driver. Compiling kernel driver is easy. Kernel 2.6.xx makes it even much more easier. Following steps are required to compile driver as module:
1) You need running kernel source code; if you don’t have a source code download it from kernel.org. Untar kernel source code (tar ball) in /usr/src using tar command:
$ tar -zxvf kernel* -C /usr/src
To be frank kernel headers are more than sufficient to compile kernel modules / drivers. See how to install kernel headers under Debian / Ubuntu Linux or RHEL / CentOS / Fedora Linux.
2) Next go to your kernel module source code directory and simply create the Makefile file as follows (assuming your kernel module name is foo):
$ vi Makefile
3) Add following text to it:
4) Compile module using make command (module build can be done by any user) :
$ make
It will finally creates the foo.ko module in current directory. You can see all actual compile command stored in .foo* files in same directory.
5) Once module compiled successfully, load it using insmod or modprobe command. You need to be root user or privileged user to run insmod:
# insmod foo.ko
Example: hello.c module
1) hello.c C source code. Copy following code and save to hello.c
$ mkdir demo; cd demo
$ vi hello.c
2)Add following c source code to it:
This is an example modified from original source for demonstration purpose.
3) Save the file. Create new Makefile as follows:
$ vi Makefile
Append following make commands:
4) Save and close the file.
5) Compile hello.c module:
$ make
6) Become a root user (use su or sudo) and load the module:
$ su —
# insmod hello.ko
Note you can see message on screen if you are logged in as root under run level 3.
7) Verify that module loaded:
# lsmod | less
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
8) See message in /var/log/message file:
# tail -f /var/log/message
9) Unload the module:
# rmmod hello
10) Load module when Linux system comes up. File /etc/modules use to load kernel boot time. This file should contain the names of kernel modules that are to be loaded at boot time, one per line. First copy your module to /lib/modules/$(uname -r)/kernel/drivers. Following are suggested steps:
(a) Create directory for hello module:
# mkdir -p /lib/modules/$(uname -r)/kernel/drivers/hello
(b) Copy module:
# cp hello.ko /lib/modules/$(uname -r)/kernel/drivers/hello/
(c) Edit /etc/modules file under Debian Linux:
# vi /etc/modules
(d) Add following line to it:
hello
(e) Reboot to see changes. Use lsmod or dmesg command to verify module loaded or not.
# cat /proc/modules
OR
# lsmod | less
See also:
- Read man pages of lsmod, rmmod, modprobe, modules
- Documentation located in your kernel source directory (for example /usr/src/linux-2.6.xx.xx/Documentation/) and README file located under kernel source code tree /usr/src/linux-2.6.xx.xx/README
- Read TLDP.org tutorial online.
Category | List of Unix and Linux commands |
---|---|
Documentation | help • mandb • man • pinfo |
Disk space analyzers | df • duf • ncdu • pydf |
File Management | cat • cp • less • mkdir • more • tree |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Linux Desktop Apps | Skype • Spotify • VLC 3 |
Modern utilities | bat • exa |
Network Utilities | NetHogs • dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop |
Searching | ag • grep • whereis • which |
Shell builtins | compgen • echo • printf |
Text processing | cut • rev |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Comments on this entry are closed.
Aha … intresting gone try this.
hi when i compile this by running make file this type of erro occcur …what to do
make -f make
make -C /lib/modules/2.6.18-1.2798.fc6/build M=/home/mclamna modules
make[1]: Entering directory `/usr/src/kernels/2.6.18-1.2798.fc6-i686′
scripts/Makefile.build:17: /home/mclamna/Makefile: No such file or directory
make[2]: *** No rule to make target `/home/mclamna/Makefile’. Stop.
make[1]: *** [_module_/home/mclamna] Error 2
make[1]: Leaving directory `/usr/src/kernels/2.6.18-1.2798.fc6-i686′
make: *** [all] Error 2
dis s wat i encountered wen using
CHK include/linux/version.h
CHK include/linux/utsrelease.h
HOSTCC scripts/basic/fixdep
In file included from /usr/include/bits/posix1_lim.h:153,
from /usr/include/limits.h:145,
from /usr/lib/gcc/i486-linux-gnu/4.1.2/include/limits.h:122,
from /usr/lib/gcc/i486-linux-gnu/4.1.2/include/syslimits.h:7,
from /usr/lib/gcc/i486-linux-gnu/4.1.2/include/limits.h:11,
from scripts/basic/fixdep.c:113:
/usr/include/bits/local_lim.h:36:26: error: linux/limits.h: No such file or directory
In file included from /usr/include/sys/socket.h:35,
from /usr/include/netinet/in.h:24,
from /usr/include/arpa/inet.h:23,
from scripts/basic/fixdep.c:115:
/usr/include/bits/socket.h:310:24: error: asm/socket.h: No such file or directory
scripts/basic/fixdep.c: In function ‘use_config’:
scripts/basic/fixdep.c:204: error: ‘PATH_MAX’ undeclared (first use in this function)
scripts/basic/fixdep.c:204: error: (Each undeclared identifier is reported only once
scripts/basic/fixdep.c:204: error: for each function it appears in.)
scripts/basic/fixdep.c:204: warning: unused variable ‘s’
scripts/basic/fixdep.c: In function ‘parse_dep_file’:
scripts/basic/fixdep.c:300: error: ‘PATH_MAX’ undeclared (first use in this function)
scripts/basic/fixdep.c:300: warning: unused variable ‘s’
make[1]: *** [scripts/basic/fixdep] Error 1
make: *** [scripts_basic] Error 2
Hi swift, I guess u have not created Makefile in ur present directory, plz make sure that makefile name is correct and its case sensitive, it should be ‘Makefile’.
Hi, This was very much helpful but now I’m stuck because i didn’t understand how this particular makefile is working, so i’m not able to write it for multiple files. Please could anyone explain how this makefile works with a example for multiple files.
Thanks,
Nitin.
how to cross compile lkm for arm?
Dear Vivek ,
Thanks alots for yr teaching.
i compile a new module on fedora core 6 and make it very good. but in fedora i dont know how to submit for when linux start up , can load automaticly. i didnot find /etc/modules in fedora.
I followed the instructions as written even copying and pasting the code, I got nada.
I was able to install the headers using
apt-get install linux-headers-$(uname -r)
then I copied and pasted the hello.c text and the Makefile from this page but I got nothing.
make: Nothing to be done for ‘all’.
I must be missing something
this is in Ubuntu 8.04
ok I got it somehow, honestly I am not sure how but I patched my install (now running kernel-headers 2.6.24-21 generic) and rebooted, sudo -i, just tried running make and it worked.
before I was getting “can’t find target ‘make’ error that seems so common. It now is working.
how do I cross compile a module using kbuild. Please help
The reason that make: Nothing to be done for ‘all’ is you should modify the Makefile, replace the space in each make command with tab.
i am getting the same error and replacing spaces with tab is not working.
some other solution.
After executing the insmod the message is not being displayed…Can u pls guide me on whats goin wrong?
try looking for messages in dmesg i.e., after #insmod hello.ko
try #dmesg
u will be able to see the messages
hello: disagrees about version of symbol module_layout
i can’t install module to my system
uname –all
Linux debian-vir1 3.2.0-4-486 #1 Debian 3.2.60-1+deb7u3 i686 GNU/Linux
OS is installed on virtualbox.
what’s wrong in here?
Oh, big thanks, source of Makefile is very helpful.
I’m trying to compile your hello.c module in a Fedora Core 9 with a 2.6.27.21-78.2.41.fc9.i686 kernel. My gcc compiler is 4.3.0 20080428 (Red Hat 4.3.0-8) (GCC). My kernel-devel package is installed with my current kernel version.
When I try to compile I get the following:
/pruebas-modulos]$ make
make -C /lib/modules/2.6.27.21-78.2.41.fc9.i686/build M=/root/pruebas-modulos modules
make[1]: se ingresa al directorio `/usr/src/kernels/2.6.27.21-78.2.41.fc9.i686′
Building modules, stage 2.
MODPOST 0 modules
make[1]: se sale del directorio `/usr/src/kernels/2.6.27.21-78.2.41.fc9.i686′
/pruebas-modulos]$ ls
hello.c hello.o Makefile Module.markers modules.order Module.symvers
root@leela:[
As you can see I do not obtain the .ko file. I have searched across the web in order to understand why I am not getting my .ko file, but I am not able to find anything useful. I would appreciate if you could help me to find why the makefile is not working
Thanks in advance,
VÃctor.
Hey, check that you makefile if you make a mistake with “obj-m” with “obj_m”, I have the same problem as you do.
When I write “obj-m” instead of “obj_m”, everything goes good.
Be sure you have tabs instead of spaces in the Makefile. Obvious and common mistake but took me a few minutes to figure this out after copy-pasting.
hi,
could u please tell me how can i install the kernel updates as I despirately need linux source code.
Thank you for posting this. It is very hard to figure out how to just make a single module manually. This post should be ranked higher when searching “How to compile a single kernel module”. Self fulfilling prophecy, perhaps?
Thanks, this ended a few hours of frustration.
Hi
I have tried load module when Linux system comes up but it’s not displaying in
#cat /proc/modules
I have done these things successfully.
# mkdir -p /lib/modules/$(uname -r)/kernel/drivers/hello
# cp hello.ko /lib/modules/$(uname -r)/kernel/drivers/hello/
# vi /etc/modules
and Added “hello” word in next line.
any suggestion would be welcome
with regards
Alok
I am also facing the same problem. Have your query been solved ?
If solved, tell me the procedure, it will be a great help to me.
Thanks & Regards,
Devang
Thanks a lot. Found this article v. useful
I found the article very helpful. Unlike many other linux tutorials, this one worked (with me) within the first few attempts! Just one minor point:
I had to change
tail -f /var/log/message
to
tail -f /var/log/messages
Be sure , tabs instead of spaces in the Makefile.
Please can anybody help me out, I need to add the pktgen module, but I’m finding it difficult
Thanks in advance
hi
thanks for that article. I try to compile a helloworld.c against the sources of my running kernel now quite a while without success. First the distro-kernel, and then also the kernel.org kernel. It all looks good to me. make enters the right directories. the error is _always_ “No Rule for target ….. ” like in the first comment above.
I don’t really understand all about the makefile. make is called from inside the kernel tree through the makefile right? Still, it really should be fine, but it doesnt work. Does anybody have a hint?
Hi guys… I’m getting really desperate, I need to program a network device drivers for one of my projects, and I can’t even get the hello world done properly !
I followed the protocol above, and when it comes to the make command, here is what I get:
make -C /lib/modules/2.6.31-20-generic/build M=/usr/src/linux-source-2.6.31/include modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.31-20-generic’
Building modules, stage 2.
MODPOST 0 modules
make[1]: Leaving directory `/usr/src/linux-headers-2.6.31-20-generic’
So no hello.ko file generated ! I already spent so many hours on this, checked that I have tabs instead of spaces in the makefile, and nothing changed…
Thanks for your help guys !
I found an error in Makefile you have:
$(PWD) should be $(shell pwd)
Since PWD is not defined, I think it attempts to compile the entire kernel source.
It solved this error I got:
“make[2]: *** No rule to make target `kernel/bounds.c’, needed by `kernel/bounds.s’. Stop.”
Thanks a lot to mix and reveil for pointing out the tabs in place of spaces. I spent like 3 hrs trying to build a module from another site, and had no clue what was wrong. It all boiled down to tabs.
Also thanks to whoever made this tut. 🙂
One thing I learned from this exercise is to always start from a working example.
Checked it.
Following is my program
#include
#include
#include
extern void *sys_table[];
asmlinkage int(*main_sys_exit)(int);
asmlinkage int alt_exit_function(int err_code)
<
printk(“Sys_exit called with err_code=%dn”,err_code);
return main_sys_exit(err_code);
>
int init_module()
<
main_sys_exit=sys_table[__NR_exit];
sys_table[__NR_exit]=alt_exit_function;
>
void cleanup_module()
<
sys_table[__NR_exit]=main_sys_exit;
>
and following is make file
obj-m = sample2.o
all:
make -C /lib/modules/$(uname -r)/build/M=$(PWD) modules
clean:
make -C /lib/modules/$(uname -r)/build/M=$(PWD) clean
but I got error
make -C /lib/modules//build/M=/home/tapas/LKP/pandora/temp/sample2 modules
make: *** /lib/modules//build/M=/home/tapas/LKP/pandora/temp/sample2: No such file or directory. Stop.
make: *** [all] Error 2
where as I had installed Kernel headers.
START WITH THE EXAMPLE, WHICH HAS BEEN DEBUGGED & TESTED FOR YOU.
If you cannot get that to work that is one thing.
If you can get THAT to work but you cannot get YOUR code to work then
for chrissakes
figure out what you have done different that doesn’t work and fix it l.
hello,
my system is ubuntu 10.04 kernel 2.6.32-25-generic, i did everything as described in article and.. when i do(as root: sudo -i ):
# insmod hello.ko
i get answer :
# insmod: error inserting ‘hello.ko’: -1 Invalid module format
And I’ve no idea what can be wrong.. or what I do wrong… would be gratefull for help
Cool! 🙂
I compiled my first module in Linux.
Thanks for your instructions.
I made a hello-1.c and Makefile in the same directory.
when is issue “make” command, it gives error:
make −C /lib/modules/2.6.32-25-generic/build M=/home/prashant modules
make[1]: Entering directory `/home/prashant’
make[1]: *** No rule to make target `−C’. Stop.
make[1]: Leaving directory `/home/prashant’
make: *** [all] Error 2
I am getting this error from so long. I even changed my working directory to root.
How did you fix this problem Prashanth? I’m getting exactly same error make[1]: *** No rule to make target `−C’. Stop. Please help me if you have some info on this.
I have trouble with my custom kernel for the last tow days, it does not boot due [b]ahci[/b] module, can I compile it as module and then make initrd image or I have to add it to kernel configuration, if so where I have to activate it, I tried to go to:
Device drivers-> Serial ATA Drivers and Parelle ATA Drivers-> AHCI SATA Support
But it seems does not compile it according to this message when I install modules:
[code]
WARNING: No module ahci found for kernel 2.6.37-rc4, continuing anyway
[/code]
I have trouble with my custom kernel for the last tow days, it does not boot due ahci module, can I compile it as module and then make initrd image or I have to add it to kernel configuration, if so where I have to activate it, I tried to go to:
Device drivers-> Serial ATA Drivers and Parelle ATA Drivers-> AHCI SATA Support
But it seems does not compile it according to this message when I install modules:
WARNING: No module ahci found for kernel 2.6.37-rc4, continuing anyway
Cool article. My first module programming is running successfully. Thanks a lot.
– Prabhu
Really Thankful…..A great note for Beginners
Источник