Total Pageviews

Wednesday, 16 December 2015

用Elrepo包升级centos7/6的内核(不要用“从源码编译”的方式。“从源码编译”的方式非常难缠,还往往搞不定)



Installing Linux Kernel 3.18.4 on centos

So, we're gonna install our latest and stable release of linux kernel 3.18.4 on our CentOS 7 Linux Distribution which is based on fedora. We we'll be tutoring about 2 common ways of install linux kernel 3.18.4 on CentOS 7.
1. Using ELRepo
2. Compiling and installing from the source
Note: Please make sure to choose anyone of the above ways.
First we'll gonna go for installing using ELRepo as its the easiest way to do.

Installing using Elrepo

1. Downloading and Installing ELRepo

We'll first gonna download the GPG key of ELRepo and install the relrepo-release package. As this tutorial is for CentOS 7. We'll gonna install elrepo-release-7.0-2.el7.elrepo.noarch.rpm using the command below.
Note: If you have a secure boot enabled please see this page for more information.
# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm

Installing ELRepo release

2. Updating Kernel to version 3.18.4

Now, we'll gonna install the latest stable kernel 3.18.4 from the ELRepo repository. To do so, we'll need to enter the following commands in a shell or terminal of the CentOS 7.
# yum --enablerepo=elrepo-kernel install kernel-ml
Installing ELRepo Linux kernel
The above command will automatically install the Linux Kernel 3.18.4 for CentOS 7.
from http://linoxide.com/linux-how-to/upgrade-linux-kernel-stable-3-18-4-centos/
---------------------------------------------------

Installing Linux Kernel 4.0 on CentOS 7

We can easily install Linux Kernel 4.0 using two ways in CentOS 7 .
1. Installing from Elrepo Repository
2. Compiling and installing from the Source Code
First we'll gonna go for installing using ELRepo as its the easiest way to do.

Installing using Elrepo

1. Downloading and Installing ELRepo

We'll first gonna download the GPG key of ELRepo and install the relrepo-release package. As we're running CentOS 7, we'll gonna install elrepo-release-7.0-2.el7.elrepo.noarch.rpm using the command below.
Note: If you have a secure boot enabled please see this page for more information.
# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
Adding Elrepo Source

2. Updating Linux Kernel to version 4.0

Now, we'll gonna install the latest stable kernel 4.0 from the ELRepo repository. To do so, we'll need to enter the following commands in a shell or terminal of the CentOS 7.
# yum --enablerepo=elrepo-kernel install kernel-ml
Installing Linux Kernel 4.0 from ELRepo
The above command will automatically install the Linux Kernel 4.0 for CentOS 7.
(补充说明:
然后还要做如下操作-
cat /boot/grub2/grub.cfg |grep menu entry
显示:
...
menuentry 'CentOS Linux (4.3.3-1.el7.elrepo.x86_64) 7 (Core)' --class centos ...
menuentry 'CentOS Linux (3.10.0-229.20.1.el7.x86_64) 7 (Core)' --class centos ...
cat /boot/grub2/grubenv     //这里记录了默认启动项
显示:
# GRUB Environment Block
saved_entry=CentOS Linux (3.10.0-229.20.1.el7.x86_64) 7 (Core)

修改默认启动内核为4.3.3,即修改/boot/grub2/grubenv文件,把saved_entry的值改为:
CentOS Linux (4.3.3-1.el7.elrepo.x86_64) 7 (Core)
然后reboot.重启系统后,运行uname -a 即可看到内核已升级:
[root@ar3 ~]# uname -a
Linux 4.3.3-1.el7.elrepo.x86_64 #1 SMP Tue Dec 15 11:18:19 EST 2015 x86_64 x86_64 x86_64 GNU/Linux  )

from http://linoxide.com/how-tos/install-linux-kernel-4-0-elrepo-source/
------------------------------------------

Install Kernel 3.10 on CentOS 6.5

CentOS 6.5 ships with kernel 2.6 and it's a quite old for now(CentOS 7 already comes with 3.10), but compile a kernel on CentOS is a mess and it's not recommended. But fear no more, guys from  Elrepo took care of that for us and made a package, let's see how we can install it.

Enable ELRepo Project repository

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org  
rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm  

Install the kernel

yum --enablerepo=elrepo-kernel install kernel-lt  

Configure grub

You also need edit /etc/grub.conf to change the kernel order, change default from 1 to 0, must looks like the below:
default=0  
timeout=5  
splashimage=(hd0,0)/grub/splash.xpm.gz  
hiddenmenu  
title CentOS (3.10.55-1.el6.elrepo.x86_64)  
    root (hd0,0)
    kernel /vmlinuz-3.10.55-1.el6.elrepo.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root rd_NO_DM  KEYBOARDTYPE=pc KEYTABLE=br-abnt2 rhgb quiet
...

Reboot and profit!

reboot  
Now you have a fresh(not so much) kernel on CentOS.
from http://bicofino.io/2014/10/25/install-kernel-3-dot-10-on-centos-6-dot-5/
--------------------------------------------------------------------------------------------------
You may want to upgrade the Linux kernel for various reasons. For example, you want to try a new kernel module or device driver which requires the latest kernel feature. Or, a new vulnerability has been uncovered in an existing Linux kernel. In other times, your Linux server may be unreliable with frequent system crashes. Whatever the reason is, upgrading the Linux kernel is an essential maintenance job for every Linux user.
In this tutorial, I will describe how to upgrade the Linux kernel on CentOS system. Here I will be upgrading the Linux kernel 2.6.32, which is the stock kernel in CentOS 6.4, to the Linux kernel 3.2.48 LTS.
First, verify the current kernel version:
$ uname -r
2.6.32-358.el6.x86_64
Before you start, install all necessary prerequisite software for building a kernel:
$ sudo yum groupinstall "Development Tools"
$ sudo yum install ncurses-devel
Also, install any existing updates on your system:
$ sudo yum update
Now you are ready to upgrade the kernel from 2.6.32 to 3.2.48 LTS.
Download the new kernel source from kernel.org, and install it on your system:
$ wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.2.48.tar.xz
$ sudo tar xvfvJ linux-3.2.48.tar.xz -C /usr/src
$ cd /usr/src/linux-3.2.48
Before compiling a new kernel, you need to generate a kernel configuration.
(
if you want to use the same kernel configuration as the currently running kernel, run the following command instead. You still need to set any newly added configuration options by manually answering questions. If you do not know the meaning of each option, just press enter to accept a default answer.
$ sudo make oldconfig

If you want to use the same old kernel configuration, and automatically accept default answers to every question, run the following command instead:
$ sudo sh -c 'yes "" | make oldconfig'
After kernel configuration is done, go ahead and compile a new kernel:
$ sudo make
The above step will take 30 minutes or more, depending on your CPU speed. After compilation is completed, go ahead and install the new kernel (and all kernel modules) as follows.
$ sudo make modules_install install
To use the newly built kernel in your system, you need to choose the new kernel on grub menu upon boot-up. 
Alternatively, edit /boot/grub/grub.conf to specify the new kernel as the default kernel to load. In /boot/grub/grub.conf, change the "default" number to whichever position your new kernel information is in the kernel list (counting starts at 0).
$ sudo vi /boot/grub/grub.conf
default=1
from http://xmodulo.com/how-to-upgrade-the-kernel-on-centos.html (此文比这个
http://www.tecmint.com/kernel-3-5-released-install-compile-in-redhat-centos-and-fedora/更详细)
-----------------------

CentOS升级内核到 3.10.28


本文适用于CentOS 6.4, CentOS 6.5,亲测可行.

1. 准备工作

1.1 下载源码包

Linux内核版本有两种:稳定版和开发版 ,Linux内核版本号由3个数字组成:r.x.y
  • r: 主版本号
  • x: 次版本号,偶数表示稳定版本;奇数表示开发中版本。
  • y: 修订版本号 , 表示修改的次数
去 http://www.kernel.org 首页,可以看到有stable, longterm等版本,longterm是比stable更稳定的版本,会长时间更新,因此我选择 3.10.28,
wget  https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.28.tar.xz

1.2 解压

tar -xf linux-3.10.28.tar.xz

1.3 更新当前系统

sudo yum update
sudo yum upgrade

1.4 安装编译内核所需要的软件包

sudo yum groupinstall "Development Tools" # 一口气安装编译时所需的一切工具
sudo yum install ncurses-devel #必须这样才能让 make *config 这个指令正确地执行。
sudo yum install qt-devel #如果你没有 X 环境,这一条可以不用
sudo yum install hmaccalc zlib-devel binutils-devel elfutils-libelf-devel #创建 CentOS-6 内核时需要它们

2 配置文件

2.1 查看当前系统内核

uname -r
2.6.32-358.11.1.el6.x86_64

2.2 将当前系统的配置文件拷贝到当前目录

cp /boot/config-2.6.32-358.11.1.el6.x86_64 .config

2.3 使用旧内核配置,并自动接受每个新增选项的默认设置

sh -c 'yes "" | make oldconfig'
make oldconfig会读取当前目录下的.config文件,在.config文件里没有找到的选项则提示用户填写,然后备份.config文件为.config.old,并生成新的.config文件,参考 http://stackoverflow.com/questions/4178526/what-does-make-oldconfig-do-exactly-linux-kernel-makefile

3 编译

sudo make bzImage #生成内核文件
sudo make modules #编译模块
sudo make modules_install #编译安装模块
要严格按照这个顺序进行编译,不能合并成一句。

4 安装

sudo make install
如果出现了 ERROR: modinfo: could not find module xxx,数量少的话,可以忽略。

5 修改Grub引导顺序

安装完成后,需要修改Grub引导顺序,让新安装的内核作为默认内核。
编辑 grub.conf文件,
sudo vim /etc/grub.conf
数一下刚刚新安装的内核在哪个位置,从0开始,然后设置default为那个数字,一般新安装的内核在第一个位置,所以设置default=0

6 重启

sudo reboot
重启后,看一下当前内核版本号,
uname -r
3.10.28
成功啦!!

7 如果失败,则重新循环

如果失败,重新开始的话,要清理上次编译的现场 
make mrproper #清理上次编译的现场 
然后转到第2步,重新开始。
from http://cn.soulmachine.me/blog/20140123/
参考:
http://winotes.net/centos-64-upgrade-to-kernel-3x.html
http://my.oschina.net/qichang/blog/101542?fromerr=ewgiRPkT
------------------------------------
一、查看当前内核版本
uname -a #查看当前内核版本
2.6.32-220.13.1.el6.x86_64 #1 SMP Tue Apr 17 23:56:34 BST 2012 x86_64 x86_64 x86_64 GNU/Linux 
二、下载待安装的kernel并解压
wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.6.8.tar.bz2
tar -jxf linux-3.6.8.tar.bz2
mv linux-3.6.8 /usr/src/kernels/
cd /usr/src/kernels/linux-3.6.8/
三、安装编译内核所需的工具
yum install ncurses-devel
yum -y install gcc automake autoconf libtool make 
四、内核编译安装过程
#make mrproper #首次编译可以省略该步,如果之前在此目录编译过,该命令可以删除之前编译所生成的文件和配置文件
备份文件
cp /boot/config-2.6.32-220.13.1.el6.x86_64 /usr/src/kernels/linux-3.6.8/.config
#在当前内核参数的基础上来,选择我们想要增删的参数进行编译,这点很重要,否则可能有各种奇怪的问题。
(make menuconfig 不建议运行此步骤)
#在菜单模式下选择需要编译的内核模块,可以参考内核编译配置选项:http://lamp.linux.gov.cn/Linux/kernel_options.html )
make bzImage #生成内核文件(漫长等待,我用了20分钟) 
make modules #编译模块(非常慢,耐心等待) 
make modules_install #安装模块 
make install #安装 
五、设置从新内核启动
vi /boot/grub/grub.conf
将 default=1 改为 default=0 
六、重启系统并查看内核版本
shutdown –f -r now
正常登录后,查看内核版本
uname –r 
OK,内核升级成功。
http://bbs.aliyun.com/read/130332.html
http://www.vfeelit.com/492.html
-------------
newest kernel version:
https://www.kernel.org/pub/linux/kernel/v3.0/linux-3.19.8.tar.gz
--------------------