安裝核心源碼
apt-cache search kernel-source
uname -r
核心源檔案:
apt-get install linux-tree-xxxx
apt-get install linux-source-xxxx
核心標頭檔:
apt-get install linux-headers-xxxx
核心編譯器:
apt-get install linux-kbuild-xxxx
核心鏡像做成deb的工具
apt-get install kernel-package
製做initrd鏡像
apt-get install initrd-tools
編譯核心:
make-kpkg --initrd --revision=custom.1.0 kernel_image
Debian kernel-image檔案的名字格式如下:
kernel-image-(kernel-version)(--append-to-version)_(--revision)_(architecture).deb
如果我們使用了--append-to-version,我們就不需要擔心apt-get會試著更新我們的核心了
安裝核心:
dpkg -i ../linux-image-2.6.18-subarchitecture_custom.1.0_s390.deb
kernel-tree-x.x.x (或2.6.12以後是linux-tree-x.x.x)
這個包依賴兩個包:kernel-source-x.x.x 和 kernel-patch-debian-x.x.x
這兩個包就分別是原始碼和debian的補丁。
編寫核心模組
編寫了一個核心模組程式,原始碼如下:
/* hello.c */
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
static int hello_init(void)
{
printk(KERN_ALERT "Hello, linux kernel module\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, I've created a linux kernel module sucessfully\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
你需要這此來源程式編寫一個makefile,內容如下:
#Makefile for hello.c file
#
KERNEL_DIR:=/usr/src/linux
obj-m:=hello.o
default:
$(MAKE) -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules
clean:
$(RM) .*.cmd *.mod.c *.o *.ko -r .tmp
KERNEL_DIR是指核心原始碼標頭檔所在目錄的上一級目錄,通常就是指核心原始碼目錄。
編寫好makefile後就可以輸入make命令產生hello.ko核心模組了,然後你可以用:
insmode hello.ko
命令來加入核心模組,然後用:
rmmod hello
來刪除核心模組。
刪除舊的核心
1. 對著/boot/grub/menu.lst裡的內容刪去你不要的。最後再把/boot/grub/menu.lst裡相應的項目刪掉。 包括
/lib/modules/2.6.24-xxxx
/boot/vmlinuz-2.6.24-xxxx
/boot/initrd-2.6.24-xxxx
/boot/System.map-2.6.24-xxxx
2. dpkg --get-selections | grep linux 查看自己系統安裝了多少核心
sudo apt-get remove linux-image-2.6.24-XXX
sudo apt-get remove linux-headers-2.6.24-XXX