从 Linux 中的内核模块调用 C 文件中的内核函数的正确方法是什么?
我想打电话给exit_task_namespaces在linux/nsproxy.c从我第一次内核模块
我正在这样做:
#include <linux/nsproxy.h>
…
static ssize_t device_read(struct file *flip, char *buffer, size_t len, loff_t *offset)
{
struct task_struct *task = current;
…
exit_task_namespaces(task);
…
}
Run Code Online (Sandbox Code Playgroud)
当我尝试时,make出现以下错误:
ERROR: "exit_task_namespaces" [/home/.../lkm_example.ko] undefined!
make[2]: *** [scripts/Makefile.modpost:94: __modpost] Error 1
make[1]: *** [Makefile:1673: modules] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-73-generic'
make: *** [Makefile:3: all] Error 2
Run Code Online (Sandbox Code Playgroud)
我可以在文件中看到/usr/src/linux-headers-5.4.0-73-generic/include/linux/nsproxy.h该方法存在。
这是我的 Makefile:
obj-m += lkm_example.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
Run Code Online (Sandbox Code Playgroud) 根据“编写伟大的代码”,几乎所有操作系统运行时内存都被组织成以下区域:
操作系统 | 堆栈 | 堆 | 文字 | 静态 | 存储/BSS
[以增加地址方式]
用户空间进程为其不同类型的数据对象使用更高的内存区域。
内核空间进程也有不同类型的数据对象。这些对象是否共享用户空间内存区域(堆栈、堆等),或者它们是否在操作系统区域中有自己的独立子部分(堆、堆栈等)。如果是,它们的排列顺序是什么? . 谢谢,
我已经从源代码(没有问题)编译了 Linux 内核 2.6.24.6 并尝试安装它。具体来说,在解压 Linux 源代码后,我做了
make && make modules
Run Code Online (Sandbox Code Playgroud)
编译。然后经过一些配置,我简单地使用了
sudo make modules_install install
Run Code Online (Sandbox Code Playgroud)
安装新构建的二进制文件。在此过程中,出现定位文件错误/sys/class/net/eth0/device/bus。它还会抛出肮脏的致命错误。详细错误堆栈如下:
sh /mnt/factor/myProj3/linux-2.6.24.6/arch/x86/boot/install.sh 2.6.24.6 arch/x86/boot/bzImage System.map "/boot"
unable to stat /sys/class/net/eth0/device/bus: No such file or directory
WARNING: No module xenblk found for kernel 2.6.24.6, continuing anyway
grubby fatal error: unable to find a suitable template
Run Code Online (Sandbox Code Playgroud)
源代码应该没问题。这个致命错误的原因可能是什么?如果不修复它,我就无法安装 Linux。请指教。
我一直在按照这些说明为 arch linux 安装来宾软件包。
不幸modprobe返回:
[snooc@archfire ~]$ modprobe -a vboxguest vboxsf vboxvideo
modprobe: WARNING: Module vboxguest not found.
modprobe: WARNING: Module vboxsf not found.
modprobe: WARNING: Module vboxvideo not found.
Run Code Online (Sandbox Code Playgroud)
pacman -Ss virtualbox 显示:
[snooc@archfire ~]$ pacman -Ss virtualbox
...
community/virtualbox-guest-modules 4.3.12-1 [installed]
Guest kernel modules for VirtualBox
...
community/virtualbox-guest-utils 4.3.12-1 [installed]
VirtualBox Guest userspace utilities
...
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?我不知道从哪里开始。
Arch Linux 是在 Win7 下运行的 VirtualBox 上的来宾。
为了运行虚拟机,VirtualBox 告诉我禁用 KVM 内核模块。我搜索了一下,发现 KVM 包含在qemu-*-packages 中,但是我的系统(Debian Wheezy)上没有安装/安装它们。
之后我只是尝试卸载模块,但这不想工作,因为它正在使用中:
# modprobe -r kvm_intel
FATAL: Module kvm_intel is in use.
# modprobe -r kvm
FATAL: Module kvm is in use.
Run Code Online (Sandbox Code Playgroud)
我不知道什么程序正在使用它,我真的不知道那可能是什么。我也尝试过使用该-f选项,但得到了相同的结果。
我的问题是:如何删除或禁用 KVM 内核模块?
更新:
这是lsmod命令的输出:
# lsmod | grep kvm
kvm_intel 138825 3
kvm 404853 1 kvm_intel
Run Code Online (Sandbox Code Playgroud) 我已经根据debian wiki上的说明在 Debian Jessie 上安装了 vitualbox 。
通过运行:
apt-get install linux-headers-$(uname -r|sed 's,[^-]*-[^-]*-,,') virtualbox
Run Code Online (Sandbox Code Playgroud)
在安装过程中报告了一些错误。
现在我想重新配置 virtualbox-dkms 但我收到此错误:
Loading new virtualbox-4.3.18 DKMS files...
Building only for 3.16-3-amd64
Module build for the currently running kernel was skipped since the
kernel source for this kernel does not seem to be installed.
Run Code Online (Sandbox Code Playgroud)
注意:uname -r显示3.16-3-amd64但我在 /usr/src 中的源文件夹被命名为:
linux-headers-3.16.0-4-amd64.
我不知道该怎么办!
debian kernel-modules software-installation linux-kernel dkms
我重新介绍了它们,发现它们都在启动时处理模块加载。
那么,这两种不同的配置方式有什么区别呢?
我正在寻找一种无需 initramfs 即可启动现有 linux 内核的方法。根据此链接,只需编辑/boot/grub2/grub.cfg. 但是如果我尝试这个配置
menuentry 'Fedora Linux, no initramfs' {
set root='hd0,msdos1'
linux /vmlinuz-3.3.4-5.fc17.i686.PAE rootfstype=ext4 root=/dev/sda2 rd.md=0 rd.lvm=0 rd.dm=0 SYSFONT=True KEYTABLE=us rd.luks=0 LANG=en_US.UTF-8
}
Run Code Online (Sandbox Code Playgroud)
引导过程在内核尝试挂载 initramfs 时因内核崩溃而停止。我是否必须在编译过程中告诉我不需要 initramfs?我发现的唯一配置选项CONFIG_INITRAMFS_SOURCE是已经设置为CONFIG_INITRAMFS_SOURCE="".
我知道有一个类似的问题,但它缺乏如何在实践中做到这一点的解释。
我有这个嵌入式 Linux 设备。我想向它添加内核级功能,但非常不想编译我自己的内核来这样做。(如果内核未加载并进入用户空间,则设备变砖;我无法访问引导加载程序来恢复它。当前内核没有 kexec 支持,因此我无法使用它来测试内核映像我自己的。)
设备的内核支持模块,但我没有相应 Module.symvers 文件的副本。
我的问题:如果我没有 Linux 内核的 Module.symvers 文件,但有内核映像和为其编译的模块,我是否可以编译更多可以插入该内核的模块,也许是通过生成缺少的模块。 symvers 文件?
该设备正在运行 Linux 内核版本 3.10。
内核图像(在其的uImage容器):https://www.olio.watch/olio-firmware-1.10.220/olio-firmware/uImage
:配置(从上方图像由于CONFIG_IKCONFIG中提取)的https://www.olio .watch/3.10.0-g2ae2f33-config
我拥有的一个与该内核匹配的内核模块:https : //www.olio.watch/olio-firmware-1.10.220/olio-firmware/drv2605.ko
我用 AMD Ryzen 5700G 构建了一台新计算机,令我惊讶的是,没有获取任何传感器信息。我认为也许新的 AMD 芯片还不会被 Linux 识别,但文档却另有说法。
\n这是sudo sensors-detect:
# sensors-detect version 3.6.0+git\n# System: Gigabyte Technology Co., Ltd. B550I AORUS PRO AX [Default string]\n# Kernel: 5.14.6-arch1-1 x86_64\n# Processor: AMD Ryzen 7 5700G with Radeon Graphics (25/80/0)\n\nThis program will help you determine which kernel modules you need\nto load to use lm_sensors most effectively. It is generally safe\nand recommended to accept the default answers to all questions,\nunless you know what you're doing.\n\nSome south bridges, CPUs or …Run Code Online (Sandbox Code Playgroud) kernel-modules ×10
debian ×2
kernel ×2
linux ×2
linux-kernel ×2
amd ×1
arch-linux ×1
boot ×1
c ×1
compiling ×1
dkms ×1
etc ×1
grub2 ×1
kvm ×1
memory ×1
modprobe ×1
sensors ×1
startup ×1
virtualbox ×1