CentOS source code and compilation process
Source code of Centos
Http://vault.centos.org//7.0.1406/ OS /Source/SPackages/
Standard Linux Kernel
Https://www.kernel.org/
Download source code:
Wgethttp: // vault.centos.org//7.0.1406/ OS /Source/SPackages/kernel-3.10.0-123.el7.src.rpm
Decompress:
Rpm2cpi kernel-3.10.0-123.el7.src.rpm | cpio-div
By default,/usr/src contains a kernel header file, so that you can compile your own kernel module without downloading the entire kernel source code.
Obtain the current system config
Cp/boot/config-3.10.0-123.el7.x86_64. config and make oldconfig produce the same config
You can also make menuconfig for configuration.
Patch
Patch-p1 <scst_exec_req_fifo-3.10.patch
Compile and install
Make-j8; make modules; make modules_install; make install;
Make modules_install puts the compiled ko under/lib/modules/3.10.0-123. el7.x86 _ 64 /.
View the path of a module:
[Root @ bogon 2.6.32-358.18.1.el6.x86 _ 64] # modinfo qla2xxx
Filename:/lib/modules/2.6.32-131.0.15.el6.x86 _ 64/kernel/drivers/scsi/qla2xxx/qla2xxx. ko
Put the compiled ko in/lib/modules/2.6.32-131.0.15.el6.x86 _ 64/kernel/drivers/scsi/qla2xxx/qla2xxx. ko;
Make install output
[Root @ localhost linux-3.10.0-123.el7] # make install
Sh/root/SCST/linux-3.10.0-123.el7/arch/x86/boot/install. sh 3.10.0 arch/x86/boot/bzImage \
System. map "/boot
/Root/SCST/linux-3.10.0-123.el7/arch/x86/boot/install. sh the script is very simple, put bzImage and System. map under boot.
The kernel installation process mainly completes the following tasks:
1. Copy the kernel image bzImage generated during kernel compilation to the/boot directory and name it vmlinuz-3.0.4. If you use an x86 cpu, the image is located in the arch/x86/boot/directory (under the kernel source code being compiled ).
2. Change ~ Copy System. map under the/linux-3.0.4/directory to the/boot/directory and rename it System. map-3.0.4. This file contains the symbol table of the kernel.
3. Change ~ The. config under the/linux-3.0.4/directory is copied to the/boot/directory and renamed as a config-3.0.4.
4. Install the kernel modules under/lib/modules.
5. Create initrd. img
Initrd. img is the initial ramdisk file. It is an image file that packs some basic drivers and command tools into the image file. This image file is used to release the initrd file to the memory before the system has mounted the root partition, as a virtual root partition, execute related scripts and run the insmod command to load the required modules.
Mkinitramfs 3.0.4-o/boot/initrd. img-3.0.4
6. Update grub
Update-grub2
About GRUB
Grub is updated by default.
/Etc/grub2.cfg-> ../boot/grub2/grub. cfg
The linux image is determined by GRUB_DEFAULT = saved of/etc/default/grub;
It indicates the value used last time;
Modify default startup items of the kernel
Grub2-set-default 0
Note: The default number of newly installed kernels is 0th.
Clear compiled configurations and files
# Make clean Delete most generated filesLeave enough to build external modules
# Make mrproper Delete the current configuration, and all generated files
# Make distclean Remove editor backup files, patch leftover files and the like
Check whether the large patch is successfully started. You can view the kernel symbol table.
Cat/proc/kallsyms | grep blk_rq_map_kern_sg
Compile some kernel code
Make driver/usb/serial
Make M = driver/usb/serial
Make drivers/usb/serial/visor. ko
Or specify the kernel path.
Make-C/home/user/rpmbuild/BUILD/kernel-3.10.0-123.el7/linux-3.10.0-123.el7.x86_64/M = 'pwd' modules
# Include <linux/kernel. h>
# Include <linux/init. h>
# Include <linux/module. h>
MODULE_LICENSE ("Dual BSD/GPL ");
Static int _ init hello_init (void ){
Printk (KERN_ALERT "hello from hello world/n ");
Return 0;
}
Static void _ exit hello_exit (void ){
Printk (KERN_ALERT "goodbye from hello world/n ");
}
Module_init (hello_init );
Module_exit (hello_exit );
--------------------------------------------------------
Compile a Makefile with the following content:
------------------- Makefile -----------------------
Obj-m: = hello. o
----------------------------------------------------
Use the following command to compile
$ Make-C $ HOME/Software/linux-kernel-2.6.31 M = 'pwd' modules
This article is from the Storage blog, please be sure to keep this source http://9899672.blog.51cto.com/9889672/1611578