Debian編譯核心源碼

來源:互聯網
上載者:User
安裝核心源碼

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.