• Linux换源+编译内核总结


    换源:

    我用的是CentOS,所以下面以其为例,其它OS做法类似,可作参考;

    在主机能联网的情况下

    进入存放源配置的文件夹
    cd /etc/yum.repos.d
    备份默认源
    mv ./CentOS-Base.repo ./CentOS-Base.repo.bak
    使用wget下载163的源 http://mirrors.163.com/.help/centos.html
    wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
    把下载下来的文件CentOS-Base-163.repo设置为默认源
    mv CentOS6-Base-163.repo CentOS-Base.repo
    通过上述操作就把默认源修改为163的了。当然上述的第三、四步可以合并为如下:
    wget http://mirrors.163.com/.help/CentOS6-Base-163.repo -O CentOS-Base.repo
    运行yum makecache生成缓存
    yum makecache
    全部更新
    yum update
     
    在主机不能联网的情况下
    现在windows上下载好源设置
     
    进入存放源配置的文件夹
    cd /etc/yum.repos.d
    上传下载下来的源
    rz
    删除原来的源
    rm CentOS-Base.repo
    把下载下来的文件CentOS-Base-163.repo设置为默认源
    mv CentOS6-Base-163.repo CentOS-Base.repo
    运行yum makecache生成缓存
    yum makecache
    全部更新
    yum update
     
    编译升级内核:
    从www.kernel.org下载所需版本的内核文件:下面以文件linux-3.19.3.tar.xz为例
     
    使用xshell连接linux主机,或登录linux主机
     
    使用rz命令上传内核文件
    rz
    解压内核文件
    xz -dk linux-3.19.3.tar.xz
    //如果提示xz not found,请帮yum换源,再用yum install xz安装
    继续解压,得到文件夹:linux-3.19.3
    tar xvf linux-3.19.3.tar
    进入刚得到的文件夹
    cd linux-3.19.3
    使用yum安装编译需要的编译环境
    yum install -y gcc make bison ncurses-devel rpm-build
    复制现有内核编译的配置文件
    cp /boot/config-`uname -r` .config
    如果想使用旧内核配置,并自动接收每个新增选项的默认设置
    sh -c 'yes "" | make oldconfig'
    进入菜单配置
    make menuconfig
    根据需求,设置选项“[ ] 64-bit kernel" 是否选择,按‘y’选择,‘n’取消
     
    进入General setup, 勾选 "Enable deprected sysfs features to support old userspace tools"
     
    生成内核文件,通常生成在/usr/src/arch/x86/boot目录下 
    make bzImage
    编译内核模块
    make modules
    安装新内核模块,即把它们放到相应的位置
    make modules_install
    //上面三步也可以写成这样:
    //make bzImage && make modules && make modules_install
    安装内核
    make install
    设置系统引导管理器,以便从新的内核启动
    vi /etc/grub.conf   
    //将default=1改为default=0,保存退出
    重启系统
    reboot
    验证内核版本
    uname -a
     
    !!!以上任一编译过程出现错误需重新编译!!!
     
    先执行!清除安装过程中的临时文件
    make mrproper
    //make clean
    再重复编译步骤。
     
    PS:下面的错误只遇到了两个,其它是在解决过程中收集的,如若侵犯了你的权益,请劳烦告知删除,谢谢~
     
    错误一:
    In file included from /usr/include/sys/time.h:31,
    from /usr/include/linux/input.h:12,
    from samples/hidraw/hid-example.c:14:
    /usr/include/sys/select.h:78: 错误:与 ‘fd_set’ 类型冲突
    /usr/include/linux/types.h:12: 错误:‘fd_set’ 的上一个声明在此
    In file included from /usr/include/linux/input.h:14,
    from samples/hidraw/hid-example.c:14:
    /usr/include/sys/types.h:62: 错误:与 ‘dev_t’ 类型冲突
    /usr/include/linux/types.h:13: 错误:‘dev_t’ 的上一个声明在此
    /usr/include/sys/types.h:67: 错误:与 ‘gid_t’ 类型冲突
    /usr/include/linux/types.h:27: 错误:‘gid_t’ 的上一个声明在此
    /usr/include/sys/types.h:72: 错误:与 ‘mode_t’ 类型冲突
    /usr/include/linux/types.h:15: 错误:‘mode_t’ 的上一个声明在此
    /usr/include/sys/types.h:77: 错误:与 ‘nlink_t’ 类型冲突
    /usr/include/linux/types.h:16: 错误:‘nlink_t’ 的上一个声明在此
    /usr/include/sys/types.h:82: 错误:与 ‘uid_t’ 类型冲突
    /usr/include/linux/types.h:26: 错误:‘uid_t’ 的上一个声明在此
    In file included from /usr/include/sys/types.h:133,
    from /usr/include/linux/input.h:14,
    from samples/hidraw/hid-example.c:14:
    /usr/include/time.h:105: 错误:与 ‘timer_t’ 类型冲突
    /usr/include/linux/types.h:22: 错误:‘timer_t’ 的上一个声明在此
    In file included from /usr/include/linux/input.h:14,
    from samples/hidraw/hid-example.c:14:
    /usr/include/sys/types.h:235: 错误:与 ‘blkcnt_t’ 类型冲突
    /usr/include/linux/types.h:114: 错误:‘blkcnt_t’ 的上一个声明在此
    samples/hidraw/hid-example.c:15:26: 错误:linux/hidraw.h:没有那个文件或目录
    samples/hidraw/hid-example.c: In function ‘main’:
    samples/hidraw/hid-example.c:48: 错误:‘rpt_desc’ 的存储大小未知
    samples/hidraw/hid-example.c:49: 错误:‘info’ 的存储大小未知
    samples/hidraw/hid-example.c:65: 错误:‘HIDIOCGRDESCSIZE’ 未声明 (在此函数内第一次使 用)
    samples/hidraw/hid-example.c:65: 错误:(即使在一个函数内多次出现,每个未声明的标识符 在其
    samples/hidraw/hid-example.c:65: 错误:所在的函数内只报告一次。)
    samples/hidraw/hid-example.c:73: 错误:‘HIDIOCGRDESC’ 未声明 (在此函数内第一次使用)
    samples/hidraw/hid-example.c:84: 警告:隐式声明函数 ‘HIDIOCGRAWNAME’
    samples/hidraw/hid-example.c:91: 警告:隐式声明函数 ‘HIDIOCGRAWPHYS’
    samples/hidraw/hid-example.c:98: 错误:‘HIDIOCGRAWINFO’ 未声明 (在此函数内第一次使用)
    samples/hidraw/hid-example.c:49: 警告:未使用的变量 ‘info’
    samples/hidraw/hid-example.c:48: 警告:未使用的变量 ‘rpt_desc’
    samples/hidraw/hid-example.c: In function ‘bus_str’:
    samples/hidraw/hid-example.c:171: 错误:‘BUS_VIRTUAL’ 未声明 (在此函数内第一次使用)
    make[2]: *** [samples/hidraw/hid-example] 错误 1
    make[1]: *** [samples/hidraw] 错误 2
    make: *** [vmlinux] 错误 2
     
    解决方法:
    cp include/linux/hidraw.h /usr/include/linux/
    
    cp include/linux/hid.h /usr/include/linux/
    
    vi samples/hidraw/hid-example.c
    将13-15行的如下3行移动到33行以后。 
     
         13 #include <linux/types.h>
         14 #include <linux/input.h>
         15 #include <linux/hidraw.h> 
     
         29 #include <sys/ioctl.h>
         30 #include <sys/types.h>
         31 #include <sys/stat.h>
         32 #include <fcntl.h>
         33 #include <unistd.h>
     接下来继续修改
    vi /usr/include/linux/input.h
     
    定位到647行
     
    #define BUS_PCI                 0x01
    #define BUS_ISAPNP              0x02
    #define BUS_USB                 0x03
    #define BUS_HIL                 0x04
    #define BUS_BLUETOOTH           0x05
    /*新增以下这一行*/
    #define BUS_VIRTUAL             0x06 
    #define BUS_ISA                 0x10
    #define BUS_I8042               0x11
    #define BUS_XTKBD               0x12
    #define BUS_RS232               0x13
    #define BUS_GAMEPORT            0x14
    #define BUS_PARPORT             0x15
    #define BUS_AMIGA               0x16
    #define BUS_ADB                 0x17
    #define BUS_I2C                 0x18
    #define BUS_HOST                0x19
    #define BUS_GSC                 0x1A
    /*再新增两行---声明*/
    #define BUS_ATARI               0x1B
    #define BUS_SPI                 0x1C
    或者进入设置菜单
    make menuconfig
    进入选项"kernel hacking"
    取消勾选:"sameple kernel code"
    因为它默认引用了include的头文件,不编译即可!
     
    错误二:
    错误提示:编译错误,未知存储大小
    解决办法:这两个头文件可以把错误与警告消除
    vi samples/hidraw/hid-example.c
    新增
    #include <arpa/inet.h>
    #include <netinet/in.h> 
     
    错误三:
    错误提示:Kernel panic—not syncing :vfs:unable to mount root fs on unkown—block (0,0)
    错误分析:initrd-*.*.img文件有问题;未能成功挂载真正的根文件系统。
    解决方法:请你确认执行了make install 命令
     
    错误四:
    错误提示:Create root device  mkrootdev: label / not found 
                         Mountingrootfilesystem 
                         mount :error2 mounting ext3
                         mount :error 2mountingnone 
                         switch root mount failed:22
                         umount  /initrd/dev failed :2
                         kernel panic-not synicncing :Attempted to kill  init .
    错误分析:
    1、根文件系统找不到挂载点 ,修改grub.conf文件为 root=/dev/ * 
    2、硬盘驱动未能找到,请看看你机器的硬盘是都是 SATA盘,是的话同样恭喜你本文对你有帮助。

    错误解决:
    1.、修改grub.conf文件试试,具体修改点
    root=/dev/*
    // * 指的是原系统中/分区的挂载点。
    修改后,重启进入新内核系统,很有会遇到如下错误提示:
    Mounting root filesystem 
    mount :error6 mounting ext3
    mount :error 2 mountingnone 
    switchroot mount failed:22
    umount  /initrd/dev failed :2
    kernel panic-not synicncing :Attempted tokil  linit .
    如果真的跪了,继续看好了~
     
    2、硬盘驱动未能成功找到,SCSI驱动有问题。
    内核选项是这样的
    Device Drivers--------SCSI
    device support------SCSI
    low-level drivers----Serial ATA(SATA)support 选为 M

    然后再选择相应的子选项Intel PIIX/ICH  SATA support (new)
    设置后机器就成功启动了。

    错误五:
    错误提示:Enforcing mode requested but no policy loaded. Halting now.
    kernel panic - not syncing: Attenpted to kill init!
    错误分析:原内核中启用了selinux,新内核未选择selinux的选项,不能成功启动。
    解决方法:修改grub.conf文件,在root=LABEL=/ 后加入 enforcing=0 

    错误六:
    编译完重启后出现:
    switchroot:   mount   failed:   22 
    umount   /initrd/dev   failed:   2 
    kernel   panic   -   not   symcing:   Attempted   to   kill   init! 
    的错误,

    解决办法:
    重新make menuconfig, 使CONFIG_SYSFS_DEPRECATED_V2=y
    也可以打开文件.config做修改和验证;

    再执行:
    # make bzImage
    # make modules
    # make modules_install
    # make install
    # shutdown -r "now"
     
    本文由AnnsShadoW发布于http://www.cnblogs.com/annsshadow/p/5003801.html ,如需转载,请保留,谢谢~
  • 相关阅读:
    tensorflow源码资源,github
    数据挖掘实战
    Ansible--快速入门
    gRPC C#学习
    Linq之Expression高级篇(常用表达式类型)
    十大经典排序算法(动图演示)
    ASP.NET Web API 管道模型
    docker面试题和解答(一)
    浅谈委托和事件(一)
    面试题三
  • 原文地址:https://www.cnblogs.com/annsshadow/p/5003801.html
Copyright © 2020-2023  润新知