<?xml version="1.0" encoding="UTF-8"?>
//我添加系统调用步骤,仅供参考,尤其是系统调用的实现部分,建议大家自己写,除了我这种好像还可以用sys_open系列来写 #define 内核版本 linux-2.6.34.14 #define 操作系统 CentOS-6.4-x86_64 int main() { 下载内核并解压到任意位置 if ( 你当前的系统是x86_32系统 ) { 32位系统的步骤() } else if ( 你当前的系统是x86_64系统 ){ 64位系统的步骤() } else { //??? } 共同操作1() 共同操作2() //共同操作3() //make install似乎已经完成了该步骤 reboot } 32位系统的步骤(){ 解压后在linux-2.6.34.14/arch/x86/kernel中的syscall_table_32.S文件中, 添加一行 .long sys_filecopy 然后进入linux-2.6.34.14/arch/x86/include/asm文件夹,打开unistd_32.h,将 #define NR_syscalls 338 改为 #define NR_syscalls 339 然后加上一行: #define __NR_filecopy 338 } 64位系统的步骤(){ 然后打开linux-2.6.34.14/arch/x86/include/asm/unistd_64.h,加上下面两行: #define __NR_filecopy 300 __SYSCALL(__NR_filecopy, sys_filecopy) 再打开linux-2.6.34.14/include/linux/syscalls.h添加声明: asmlinkage long sys_filecopy( char *in , char *out ); } 共同操作1(){ 再打开linux-2.6.34.14/kernel下的sys.c并在末尾插入如下代码: asmlinkage long sys_filecopy( char *in , char *out ) { struct file* filpin = NULL; struct file* filpout = NULL; const int BUF_SIZE = 2048; char buf[BUF_SIZE]; int num; mm_segment_t oldfs; oldfs = get_fs(); set_fs(get_ds()); filpin = filp_open(in, O_RDONLY, 0); filpout = filp_open(out, O_CREAT|O_WRONLY, 0644); printk( "<0>""start writing in kernel !...\n" ); do{ num = vfs_read( filpin , buf , BUF_SIZE , &filpin->f_pos ); vfs_write( filpout , buf , num , &filpout->f_pos ); }while( num == BUF_SIZE ); filp_close( filpin , NULL ); filp_close( filpout , NULL ); printk( "<0>""done writing in kernel !...\n" ); set_fs(oldfs); return 0; } } 共同操作2(){ 打开终端,cd到linux-2.6.34.14目录下,输入以下命令: make xconfig // 使用Qt的图形界面进行配置 make -j4 bzImage // j for jobs,现在主流的双核心四线程处理器 make -j4 modules // 使用该选项可以让四个核心同时以超过90%的使用率工作 make modules_install make install } //以下已经无需执行 共同操作3(){ if ( 你使用的是基于Debian的系统 ) // 如ubuntu和Mint mkinitramfs -o /boot/initrd-2.6.34.14.img 2.6.34.14 else if ( 你是用的是基于RedHat的系统 ) // 如CentOS和Fedora mkinitrd -v /boot/initramfs-2.6.34.14.img 2.6.34.14 else //??? 在grub.conf内添加 title CentOS (2.6.34.14) root (hd0,8) kernel /vmlinuz-2.6.34.14 ro root=LABEL=/ rhgb quiet initrd /initramfs-2.6.34.14.img }