Найти в Дзене
Linux Pages

Создание модуля ядра

sudo apt install linux-source
sudo tar jxf /usr/src/linux-source-5.15.0.tar.bz2
sudo make menuconfig sudo apt-get install libc6-devsudo apt-get install build-essential
sudo make menuconfig
ps -ax
smod
tail -f /var/log/kern.log
вывод модуля - sudo insmod ./hello.ko
удаление модуля - sudo rmmod ./hello.ko
ДЗ: 1. вывод числовое значение - на экран ?
2. вывод hello в лог содержимое файла //hello.c *********************** #include <linux/module.h> MODULE_LICENSE("GPL"); MODULE_AUTHOR("IVS <a@a.ru>"); static int __init hello_init(void) { printk(KERN_ALERT "Hello from kernel module!\n"); return 0; } static void __exit hello_exit(void) { printk(KERN_ALERT "Module 'hello' has exited!\n"); return; } module_init(hello_init); module_exit(hello_exit); //Makefile ************************* CURRENT = $(shell uname -r) KERNEL_DIR = /lib/modules/$(CURRENT)/build PWD = $(shell pwd) obj-m := hello.o default: $(MAKE) -C $(KERNEL_DIR) M=$(PWD) modules

sudo apt install linux-source


sudo tar jxf /usr/src/linux-source-5.15.0.tar.bz2


sudo make menuconfig

sudo apt-get install libc6-devsudo

apt-get install build-essential


sudo make menuconfig

ps -ax


smod

tail -f /var/log/kern.log

вывод модуля - sudo insmod ./hello.ko

удаление модуля - sudo rmmod ./hello.ko


ДЗ: 1. вывод числовое значение - на экран ?

2. вывод hello в лог содержимое файла

//hello.c

***********************

#include <linux/module.h>

MODULE_LICENSE("GPL");

MODULE_AUTHOR("IVS <a@a.ru>");

static int __init hello_init(void)

{

printk(KERN_ALERT "Hello from kernel module!\n");

return 0;

}

static void __exit hello_exit(void)

{

printk(KERN_ALERT "Module 'hello' has exited!\n");

return;

}

module_init(hello_init);

module_exit(hello_exit);

//Makefile

*************************

CURRENT = $(shell uname -r)

KERNEL_DIR = /lib/modules/$(CURRENT)/build

PWD = $(shell pwd)

obj-m := hello.o

default:

$(MAKE) -C $(KERNEL_DIR) M=$(PWD) modules