换源:

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

在主机能联网的情况下

进入存放源配置的文件夹
  1. cd /etc/yum.repos.d
备份默认源
  1. mv ./CentOS-Base.repo ./CentOS-Base.repo.bak
使用wget下载163的源 http://mirrors.163.com/.help/centos.html
  1. wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
把下载下来的文件CentOS-Base-163.repo设置为默认源
  1. mv CentOS6-Base-.repo CentOS-Base.repo
通过上述操作就把默认源修改为163的了。当然上述的第三、四步可以合并为如下:
  1. wget http://mirrors.163.com/.help/CentOS6-Base-163.repo -O CentOS-Base.repo
运行yum makecache生成缓存
  1. yum makecache
全部更新
  1. yum update
 
在主机不能联网的情况下
现在windows上下载好源设置
 
进入存放源配置的文件夹
  1. cd /etc/yum.repos.d
上传下载下来的源
  1. rz
删除原来的源
  1. rm CentOS-Base.repo
把下载下来的文件CentOS-Base-163.repo设置为默认源
  1. mv CentOS6-Base-.repo CentOS-Base.repo
运行yum makecache生成缓存
  1. yum makecache
全部更新
  1. yum update
 
编译升级内核:
从www.kernel.org下载所需版本的内核文件:下面以文件linux-3.19.3.tar.xz为例
 
使用xshell连接linux主机,或登录linux主机
 
使用rz命令上传内核文件
  1. rz
解压内核文件
  1. xz -dk linux-3.19..tar.xz
  2. //如果提示xz not found,请帮yum换源,再用yum install xz安装
继续解压,得到文件夹:linux-3.19.3
  1. tar xvf linux-3.19..tar
进入刚得到的文件夹
  1. cd linux-3.19.
使用yum安装编译需要的编译环境
  1. yum install -y gcc make bison ncurses-devel rpm-build
复制现有内核编译的配置文件
  1. cp /boot/config-`uname -r` .config
如果想使用旧内核配置,并自动接收每个新增选项的默认设置
  1. sh -c 'yes "" | make oldconfig'
进入菜单配置
  1. make menuconfig
根据需求,设置选项“[ ] 64-bit kernel" 是否选择,按‘y’选择,‘n’取消
 
进入General setup, 勾选 "Enable deprected sysfs features to support old userspace tools"
 
生成内核文件,通常生成在/usr/src/arch/x86/boot目录下 
  1. make bzImage
编译内核模块
  1. make modules
安装新内核模块,即把它们放到相应的位置
  1. make modules_install
  2. //上面三步也可以写成这样:
  3. //make bzImage && make modules && make modules_install
安装内核
  1. make install
设置系统引导管理器,以便从新的内核启动
  1. vi /etc/grub.conf
  2. //将default=1改为default=0,保存退出
重启系统
  1. reboot
验证内核版本
  1. uname -a
 
!!!以上任一编译过程出现错误需重新编译!!!
 
先执行!清除安装过程中的临时文件
  1. make mrproper
  2. //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
 
解决方法:
  1. cp include/linux/hidraw.h /usr/include/linux/
  2.  
  3. cp include/linux/hid.h /usr/include/linux/
  4.  
  5. vi samples/hidraw/hid-example.c
将13-15行的如下3行移动到33行以后。 
 
  1. #include <linux/types.h>
  2. #include <linux/input.h>
  3. #include <linux/hidraw.h>
  4.  
  5. #include <sys/ioctl.h>
  6. #include <sys/types.h>
  7. #include <sys/stat.h>
  8. #include <fcntl.h>
  9. #include <unistd.h>
 接下来继续修改
  1. 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
/*新增以下这一行*/
  1. #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
/*再新增两行---声明*/
  1. #define BUS_ATARI 0x1B
  2. #define BUS_SPI 0x1C
或者进入设置菜单
  1. make menuconfig
进入选项"kernel hacking"
取消勾选:"sameple kernel code"
因为它默认引用了include的头文件,不编译即可!
 
错误二:
错误提示:编译错误,未知存储大小
解决办法:这两个头文件可以把错误与警告消除
  1. vi samples/hidraw/hid-example.c
新增

  1. #include <arpa/inet.h>
  2. #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文件试试,具体修改点

  1. root=/dev/*
  2. // * 指的是原系统中/分区的挂载点。
修改后,重启进入新内核系统,很有会遇到如下错误提示:
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 ,如需转载,请保留,谢谢~

Linux换源+编译内核总结的更多相关文章

  1. Linux换源

    Linux换源 前言 最近学校的ipv6坏了,导致从deepin本身获取的源速度极慢,笔者实在忍无可忍,随后在同学指导下换了清华大学ipv4的源 步骤 sudo gedit /etc/apt/sour ...

  2. linux 解决Ubuntu编译内核uImage出现问题“mkimage” command not found - U-Boot images will not be built问题

    解决Ubuntu编译内核uImage出现问题“mkimage” command not found - U-Boot images will not be built问题 http://www.lin ...

  3. linux 换源

    Ubuntu换源 ubuntu 的默认源是美国的,所以下载起来特别慢.更换国内源:用vi和gedit 打开 /etc/apt/sources.list 将其中的us.archive 全部替换为 cn. ...

  4. LInux 2.6 编译内核出现Question

    问:在make menuconfig配置完之后(选的默认配置),然后就make出现如下错误:root@org:/usr/src/linux-2.6.32.27# make CHK include/li ...

  5. python pip 升级 或者换源

    1. 临时换源python -m pip install --upgrade pip -i https://pypi.douban.com/simple pip国内的一些镜像   阿里云  https ...

  6. Ubuntu 编译安装 Linux 4.0.5 内核,并修复 vmware 网络内核模块编译错误

    . . . . . 今天把 Ubuntu 14.04 升级到了最新的 4.0.5 的内核版本,本来不打算记录下来的,但是升级的过程中确实遇到了一些问题,所以还是记录下来,分享给遇到同样问题的猿友. 先 ...

  7. Linux下编译内核配置选项简介

    Code maturity level options代码成熟度选项 Prompt for development and/or incomplete code/drivers 显示尚在开发中或尚未完 ...

  8. linux内核编译,内核参数修改

    核心(kernel):/boot/vmlinuz-version version 带发行包版本,本地版本内核模块(kernel object): /lib/modules/version/ 内核设计: ...

  9. linux内核学习之二:编译内核

    在linux内核学习系列的第一课中讲述了搭建学习环境的过程(http://www.cnblogs.com/xiongyuanxiong/p/3523306.html),环境搭好后,马上就进入到下一环节 ...

随机推荐

  1. PHP mongodb AR

    <?php /** * @author xiaojiang */ abstract class MongoAr{ private $db = null; public function __co ...

  2. PowerDesigner

    .PowerDesigner使用MySQL的auto_increment  ◇问题描述:  PD怎样能使主键id使用MySQL的auto_increment呢?  ◇解决方法:   打开table p ...

  3. Java经典实例:正则表达式,替换匹配的文本

    import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Created by Frank * 替换匹配的文本 */ ...

  4. 2013年最新流行的响应式 WordPress 主题【下篇】

    在这篇文章中,我们收集了一些在2013年发布的最好的免费的响应式 WordPress 主题.这些主题包括高级功能,如自定义模板.自定义窗口小部件.自定义菜单主题选项等.让我们来看看下面的清单,并希望你 ...

  5. 原生JS:Math对象详解

    Math对象 本文参考MDN做的详细整理,方便大家参考MDN Math 也是一个内置对象, 为数学常量和数学函数提供了属性和方法,而不是一个函数对象. 与其它全局对象不同的是, Math 不是一个构造 ...

  6. (转)高性能JavaScript:加载和运行(动态加载JS代码)

    浏览器是如何加载JS的 当浏览器遇到一个<script>标签时,浏览器首先根据标签src属性下载JavaScript代码,然后运行JavaScript代码,继而继续解析和翻译页面.如果需要 ...

  7. JavaScript学习笔记-面向对象的模块化编程

    面向对象的模块化编程 模块是一个独立的JS文件,模块文件可以包含一个类定义.一组相关的类.一个实用函数库.一些待执行的代码 模块化的目标:支持大规模的程序开发,处理分散源代码的组装,并能让代码正确执行 ...

  8. 【Leafletjs】4.L.Map 中文API

    L.Map API各种类中的核心部分,用来在页面中创建地图并操纵地图. 使用 example // initialize the map on the "map" div with ...

  9. 让你的APK瘦成一道闪电

    APK瘦身是长久以来的难题,我们需要通过一些工具和技巧才能让它瘦下去,下面我来分享一下我在apk瘦身方面的经验. 一.apk中有哪些东西 1.代码 2.lib 3.so本地库 4.资源文件(图片,音频 ...

  10. [Android]使用RecyclerView替代ListView(二)

    以下内容为原创,转载请注明: 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/4242541.html 以前写过一篇“[Android]使用Adapte ...