1. download and install the required tool: $ apt-getinstallkernel-packagelibncurses5-devbzip22. download the new linux-kernel source code: kernel
1. download and install the required tools:
$ Apt-get install kernel-package libncurses5-dev bzip2
2. download the new linux-kernel source code:
Http://www.kernel.org/
Download the complete source code, that isF
Here I downloadLinux-2.6.29.4.tar.bz2
3. decompress the source code:
$ Tar xvjf linux-2.6.29.4.tar.bz2
4. Create a compilation configuration file
$ Linux-2.6.29.4 cd
$ Vi Makefile
ModifyEXTRAVERSION =. 4IsEXTRAVERSION =-4-generic
$ Sudo cp/boot/config-2.6.28-11-generic./. config
$ Make menuconfig
Configure your own options or optionsLoad an Alternate Configuration FileUse System Configurations
5. Compile the deb installation package
$ Make-kpkg clean
$ Sudo make-kpkg -- initrd kernel_image kernel_headers modules_ Image
After the compilation is complete, it will be generated in the previous level directory
Linux-headers-2.6.29-4-generic_2.6.29-4-generic-10.00.Custom_i386.debAndLinux-image-2.6.29-4-generic_2.6.29-4-generic-10.00.Custom_i386.deb
6. Install the kernel mirror and the module package
$ Cd ..
$ Sudo dpkg-I linux-image-2.6.29-4-generic_2.6.29-4-generic-10.00.Custom_i386.deb
After the installation is complete, we can
/Lib/modulesThe directory contains more2.6.29-4-genericDirectory
/BootThe directory contains moreConfig-2.6.29-4-generic, System. map-2.6.29-4-generic, initrd. img-2.6.29-4-generic, vmlinuz-2.6.29-4-genericThese files.
/Boot/grub/menu. lstThe file contains more content.
Title Ubuntu 9.04, kernel 2.6.29-4-generic
Uuid 11213c36-058e-4933-a2b3-81f3df0acb38
Kernel/boot/vmlinuz-2.6.29-4-generic root = UUID = 41513c36-058e-4933-a2b3-81f3df0acb38 ro locale = zh_CN quiet splash
Initrd/boot/initrd. img-2.6.29-4-generic
Quiet
Title Ubuntu 9.04, kernel 2.6.29-4-generic (recovery mode)
Uuid 11213c36-058e-4933-a2b3-81f3df0acb38
Kernel/boot/vmlinuz-2.6.29-4-generic root = UUID = 41513c36-058e-4933-a2b3-81f3df0acb38 ro locale = zh_CN single
Initrd/boot/initrd. img-2.6.29-4-generic
7. Install the kernel header file:
$ Sudo dpkg-I linux-headers-2.6.29-4-generic_2.6.29-4-generic-10.00.Custom_i386.deb
After completion
/Usr/srcThe directory contains moreLinux-headers-2.6.29-4-genericHeader file directory
Restart your computer.
Run the sample driver
// ----- Hello. c -----
# Include
# Include
MODULE_LICENSE ("Dual BSD/GPL ");
Static int hello_init (void)
{
Printk (KERN_ALERT "Hello, world! /N ");
Return 0;
}
Static void hello_exit (void)
{
Printk (KERN_ALERT "Goodbye, cruel world! /N ");
}
Module_init (hello_init );
Module_exit (hello_exit );
Corresponding Makefile:
Ifneq ($ (KERNELRELEASE ),)
Obj-m: = hello. o
Else
KERNELDIR? =/Usr/src/linux-source-2.6.29.4/
PWD: = $ (shell pwd)
Default:
$ (MAKE)-C $ (KERNELDIR) M = $ (PWD) modules
Endif
Running result: