实验一:openEuler安装与内核编译
使用华为云进行实验
一、系统备份
cd ~
yum install lrzsz # rz和sz可以在终端下很方便的传输文件
tar czvf boot_origin.tgz /boot/
sz boot_origin.tgz # 将备份文件发送到本地
二、内核源码下载
wget https://gitee.com/openeuler/kernel/repository/archive/5.10.0-13.0.0.zip
解压:
unzip 5.10.0-13.0.0.zip
进入源码根目录:
三、编译内核
- 进入解压好的源码文件夹执行命令,清理过去内核编译产生的文件,第一次编译时可不执行此命令
cd kernel-5.10.0-8.0.0
make mrproper
- 生成内核配置文件.config
cp -v /boot/config-$(uname -r) .config
执行依赖安装
yum install ncurses-devel
然后使用make menuconfig 对配置进行需要的更改,决定将内核的各个功能系统编译进内核还是编译为模块还是不编译
make menuconfig
首先载入原始数据:
之后save保存配置文件:
-
make 开始安装
产生错误:
可以在makefile中将date-time的error提示去除即可:
make modules_install #编译完成后安装模块
make install #安装内核
-
重启系统
reboot # 查看内核版本信息 uname -a #查看内核版本信息可分析出内核是否更新成功
四、内核模块编程
1 创建文件夹task1
mkdir task1
2 创建文件helloworld.c
#include<linux/module.h>
MODULE_LICENSE("GPL");
int __init hello_init(void)
{
printk("hello init\n");
printk("hello,world!\n");
return 0;
}
void __exit hello_exit(void)
{
printk("hello exit\n");
}
module_init(hello_init);
module_exit(hello_exit);
3 编写makefile
ifneq ($(KERNELRELEASE),)
obj-m := helloword.o
else
KERNELDIR ?=/root/kernel-5.10.0-13.0.0
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
.PHONY:clean
clean:
-rm *.mod.c *.o *.order *.symvers *.ko
4 编译make指令
make
5 加载模块
insmod helloword.ko
查看加载的内容
dmesg | tail -n 2 #可以看到打印的信息:
lsmod | grep main #可以查看所有名字中包含main的内核模块:
6 模块的卸载及查看
rmmod helloword #卸载helloworld模块
dmesg | tail -n 1 #查看卸载内容
遇到问题
dnf 指令找不到
使用 yum 代替: