编译一个linux内核模块
看源代码。
#include <linux/kernel.h>
#include <linux/module.h>
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif
int init_module()
{
printk("Hello, I'm kernel\n");
return 0;
}
void cleanup_module()
{
printk("I'm kernel, bye\n");
}
再来看 makefile的写法
TARGET = hello
OBJS = hello.o
MDIR = drivers/misc
EXTRA_CFLAGS = -DEXPORT_SYMTAB
CURRENT = $(shell uname -r)
KDIR = /lib/modules/$(CURRENT)/build
PWD = $(shell pwd)
DEST = /lib/modules/$(CURRENT)/kernel/$(MDIR)
obj-m := $(TARGET).o
default:
make -C $(KDIR) SUBDIRS=$(PWD) modules
$(TARGET).o: $(OBJS)
$(LD) $(LD_RFLAG) -r -o $@ $(OBJS)
ifneq (,$(findstring 2.4.,$(CURRENT)))
install:
echo $(DEST) $(LD_RFLAG)
su -c "cp -v $(TARGET).o $(DEST) && /sbin/depmod -a"
else
install:
su -c "cp -v $(TARGET).ko $(DEST) && /sbin/depmod -a"
endif
clean:
-rm -f *.o *.ko .*.cmd .*.flags *.mod.c
-include $(KDIR)/Rules.make
好了 放入到位置运行makefile即可
插入模块的命令是这样的
$insmod hello.ko(PS:尽管你看不到有.ko这样的文件,但是的确是这么来做的)
用 dmesg 就可以看到 输出啦。。。。
补充一个错误:
./linux/include/asm/elf.h: In function `start_ia32_thread':
./linux/include/asm/elf.h:153: warning: implicit declaration of function `load_g
s_index'
./linux/include/asm/elf.h: In function `elf_common_init':
./linux/include/asm/elf.h:166: error: structure has no member named `r8'
./linux/include/asm/elf.h:166: error: structure has no member named `r9'
./linux/include/asm/elf.h:166: error: structure has no member named `r10'
./linux/include/asm/elf.h:166: error: structure has no member named `r11'
./linux/include/asm/elf.h:167: error: structure has no member named `r12'
./linux/include/asm/elf.h:167: error: structure has no member named `r13'
./linux/include/asm/elf.h:167: error: structure has no member named `r14'
./linux/include/asm/elf.h:167: erro
相关文档:
本文记录一下本人安装LAMP的全过程
本人使用的Linux为RedHat Enterprise 5 X64
第一步:安装Mysql
Mysql的安装比较简单,为了避免出现文件找不到的情况,我依次下载安装了以下4个RPM包
MySQL-server-community-5.1.46-1.rhel5.x86_64.rpm
MySQL-client-community-5.1.46-1.rhel5.x86_64.rpm
MySQL-devel-commu ......
经常需要Kill多个进程,这些进程包含共同的关键字,可以用一条命令Kill掉它们。 ps aux | grep "common" | cut –c 9-15 | xargs kill –9 管道符“|”用来隔开两个命令,管道符左边命令的输出会作为管道符右边命令的输入。下面说说用管道符联接起来的几个命令: "ps aux" 查看所有进程的命令。这时检索出的 ......
昨天晚上准备装subversion 结果碰到一个很恼火的问题
[root@rhel6beta Packages]# rpm -ivh libproxy-0.3.0-1.el6.i686.rpm
warning:
libproxy-0.3.0-1.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID
f21541eb: NOKEY
error: Failed dependencies:
libproxy-b ......
将联网方式设置为NAT
第一步:
cd到/etc/sysconfig/network-scripts系的ifcfg-eth0
第二步:
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0
#BOOTPROTO=static
BOOTPROTO=none
BROADCAST=192.168.174.255
HWADDR=00:0C:29:F2:BB:A9
IPADDR=192.168.174.11
......
一、下载ubuntu操作系统
http://www.ubuntu.com.cn/
我在这个网站下载ubuntu 10.04 LTS版本的,并写成光盘格式。
二、安装ubuntu linux
(1)设置bios从光盘引导
(2)启动计算机之后会出现一个install窗口,并显示了欢迎信息,选择语言:中文(简体),他提供了试用和安装两个选项,我选择了“试用Ubuntu 10.04 ......