Linux Kernel
Posted on July 2, 2014
Tags: operatingsys
boot directory
cd /boot
uname -r
#>5.16.0-kali7-amd64
#>vmlinuz-5.16.0-kali7-amd64 is the kernel we are booted in
“vmlinuz-5.16.0-kali7-amd64” kernel will be loaded into memory by GRUB bootloader and then GRUB will transfer control to it
1 Listing hardware
lspci | more #lists all devices connected to pci
lsusb #lists usb devices
2 Kernel
#include <linux/init.h>
#include <linux/module.h>
("Dual BSD/GPL");
MODULE_LICENSEstatic int hello_init(void)
{
(KERN_ALERT "Hello, world\n");
printkreturn 0;
}
static void hello_exit(void)
{
(KERN_ALERT "Goodbye, cruel world\n");
printk}
(hello_init);
module_init(hello_exit); module_exit
obj-m=kmain.o
EXTRA_CFLAGS += $(CFLAGS_EXTRA) -fno-pie
all:
make -C /lib/modules/`uname -r`/build/ M=$(PWD) modules
clean:
make -C /lib/modules/`uname -r`/build M=$(PWD) clean
sudo insmod kmain.ko #load kernel file
modinfo kmain.ko
sudo cat /var/log/kern.log | grep "Hello, world"
sudo dmesg | grep "Hello, world"
sudo rmmod kmain.ko #unload kernel file
Note the only way you can “see” the output is by grepping the kernel logs.