下载源码
apt update
apt install linux-source
# /usr/src/linux-source-5.4.0/linux-source-5.4.0.tar.bz2 下载源码tar -jxvf linux-source-5.4.0.tar.bz2
# /usr/src/linux-source-5.4.0 解压源码
安装依赖
sudo apt -y install build-essential
sudo apt -y install libncurses-dev
sudo apt -y install flex
sudo apt -y install bison
sudo apt -y install libelf-dev
修改代码
vim init/main.c
static int __ref __init start_kernel(void)
{
printk(KERN_INFO "Custom message: Hello from my kernel!\n");
// 其他代码...
}
编译安装
make oldconfig
make -j$(nproc)
sudo make modules
sudo make modules_installmake install
重启
update-grub
先关机,在启动( 不要直接reboot -f,一直报错/dev/mapper/ubuntu--vg-ubuntu--lv does not exit )
查看cat /var/log/dmesg | more