Rebuild the kernel (complie kernel) from Kernel source.

Written on October 27, 2008 – 2:08 am | by Tum. |

การ compile kernel ของ linux นั้นบางคนได้ยินชื่อถึงกับส่ายหน้ากันเลยทีเดียวเพราะว่าชื่อก็บอกอยู่แล้วว่าคงจะยากน่าดู แต่จริงๆแล้วการ compile kernel นั้นไม่ยากอย่างที่คิดเลย และก็ทำไม่กี่ขั้นตอนก็เสร็จแล้ว เพียงแต่เราจะต้องเตรียมเครื่องให้พร้อมกับการ compile ในครั้งนี้และทำตามขั้นตอนด้านล่างนี้ก็จะไม่มีปัญหาแต่อย่างใด

สิ่งที่ต้องเตรียมก่อนการ compile kernel คือ develop tools ต่างๆ ไม่ว่าจะเป็น c compiler, library ต่างๆ

เมื่อเตรียมเครื่องพร้อมแล้วเราก็มาเริ่มการ compile kernel กันเลยครับ

1. download kernel source จาก kernel.org
2. ใช้คำสั่ง tar -xvjf <kernel source>
3. เข้าไปที่ directory ที่ทำการแตกไฟล์ออกมาเมื่อกี้
4. รัน make clean
5. รัน make mrproper
6. รัน make menuconfig หรือ make xconfig (ทำการเปิด feature ต่างๆ)
7. รัน make dep (ถ้า kernel version 2.6 ขึ้นไปไม่ต้องรันคำสั่งนี้ก็ได้)
8. รัน make
9. รัน make modules 

เมื่อ compile kernel เป็นที่เรียบร้อยแล้วก็ kernel ที่ build มาจะเก็บอยู่ที่ directory <kernel source>/arch/<system’s architecture>/
จากนั้นให้ทำการ copy มาไว้ที่ /boot ดังตัวอย่าง

#cp /usr/src/linux-2.6.5-1.358/arch/i386/boot/bzImage /boot/vmlinuz-2.6.5-1.358-custom

ต่อมาแก้ไขไฟล์ /etc/grub.conf เพื่อเพิ่มบรรทัดด้านล่างนี้ลงไป

   title Custom Kernel (2.6.5-1.358)
   root (hd0,0)
   kernel /vmlinuz-2.6.5-1.358-custom ro root=LABEL=/
   initrd /initrd-2.6.5-1.358.img       

ขั้นตอนสุดท้านคือการ reboot เครื่องเพื่อทำให้ระบบโหลด kernel ตัวใหม่นี้ขึ้นมา

Tags: compile Kernel, compile Linux Kernel, Rebuild kernel

Post a Comment

Sponsor Links

Find entries :