如何在QEMU上构建和运行Linux内核模块?
我的老师给了我一个linux内核vmlinuz-3.17.2和一个rootfs.ext2,可以加载到qemu。他让我构建一个最简单的内核模块,打印一个hello world作为家庭作业如何在QEMU上构建和运行Linux内核模块?,linux,linux-kernel,kernel-module,qemu,Linux,Linux Kernel,Kernel Module,Qemu,我的老师给了我一个linux内核vmlinuz-3.17.2和一个rootfs.ext2,可以加载到qemu。他让我构建一个最简单的内核模块,打印一个hello world作为家庭作业 首先,我下载内核源代码并运行makeoldconfig 其次,我将配置设置为抢占,并且没有modversions (根据qemu中运行的vmlinuz的uname-a),然后进行准备 第三,我编译内核mod并在rootfs.ext2中复制hello.ko 最后,在qemu中,我运行insmod hello.ko
- 首先,我下载内核源代码并运行makeoldconfig
- 其次,我将配置设置为抢占,并且没有modversions (根据qemu中运行的vmlinuz的uname-a),然后进行准备
- 第三,我编译内核mod并在rootfs.ext2中复制hello.ko
- 最后,在qemu中,我运行insmod hello.ko,它在没有任何提示的情况下退出 还有echo$?返回0
#include <linux/init.h>
#include <linux/module.h>
static int __init hello_init(void)
{
pr_info("Hello World");
return -1;
// I changed this to -1 deliberately, Because It seems that the code is not executed.
}
static void __exit hello_exit(void)
{
printk(KERN_ERR "Goodbye, cruel world\n");
}
MODULE_LICENSE("GPL");
module_init(hello_init);
module_exit(hello_exit);
#包括
#包括
静态int\uu init hello\u init(void)
{
公关信息(“你好世界”);
返回-1;
//我故意将其更改为-1,因为代码似乎没有执行。
}
静态无效\uuu退出你好\u退出(无效)
{
printk(KERN_ERR“再见,残酷的世界”);
}
模块许可证(“GPL”);
模块_init(hello_init);
模块退出(你好退出);
Buildroot
Buildroot是最简单的方法:
- 最小树外示例:
- 树中最小值示例:
- 如何使用GDB调试模块: