Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在QEMU上构建和运行Linux内核模块?_Linux_Linux Kernel_Kernel Module_Qemu - Fatal编程技术网

如何在QEMU上构建和运行Linux内核模块?

如何在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

我的老师给了我一个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,它在没有任何提示的情况下退出 还有echo$?返回0
但是,我在dmesg或/var/log/messages中看不到任何内容 有什么问题吗?我该怎么办? 当我成功运行rmmod hello.ko时,也没有要打印的内容

我的日志级别是7417

我向你问好如下:

#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调试模块:
在Ubuntu 16.04上测试