Ubuntu14.04升级内核3.14.25

Ubuntu14.04升级内核3.14.25


linux kernel官方网站:
https://www.kernel.org/
https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.14.25.tar.xz

ubuntu二进制内核官方网站:
http://kernel.ubuntu.com/~kernel-ppa/mainline/?C=N;O=D
http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.14.25-utopic/linux-headers-3.14.25-031425-generic_3.14.25-031425.201411211235_amd64.deb
http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.14.25-utopic/linux-headers-3.14.25-031425_3.14.25-031425.201411211235_all.deb
http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.14.25-utopic/linux-image-3.14.25-031425-generic_3.14.25-031425.201411211235_amd64.deb


我们知道,ubuntu14.04正式版发行时采用的是3.13.0内核,但3.13.0并不是长期LTS内核,2014-12-04时最新的LTS kernel是3.14.25所以这里简单介绍下如何升级到最新LTS内核。


以ubuntu14.04.1 x64为例,
一.二进制内核deb包
1.查看原始版本及内核信息
root@KVM:~# lsb_release -a
No LSB modules are available.
Distributor ID:    Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:    14.04
Codename:    trusty
root@KVM:~# uname -a
Linux KVM 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
2.下载上面链接中的3个内核deb包并安装
我装的是64bit位ubuntu,所以下载的是64位版本。
root@KVM:~# ls
linux-headers-3.14.25-031425_3.14.25-031425.201411211235_all.deb
linux-headers-3.14.25-031425-generic_3.14.25-031425.201411211235_amd64.deb
linux-image-3.14.25-031425-generic_3.14.25-031425.201411211235_amd64.deb
root@KVM:~# dpkg -i *
Selecting previously unselected package linux-headers-3.14.25-031425.
(Reading database ... 160580 files and directories currently installed.)
Preparing to unpack linux-headers-3.14.25-031425_3.14.25-031425.201411211235_all.deb ...
Unpacking linux-headers-3.14.25-031425 (3.14.25-031425.201411211235) ...
Selecting previously unselected package linux-headers-3.14.25-031425-generic.
Preparing to unpack linux-headers-3.14.25-031425-generic_3.14.25-031425.201411211235_amd64.deb ...
Unpacking linux-headers-3.14.25-031425-generic (3.14.25-031425.201411211235) ...
Selecting previously unselected package linux-image-3.14.25-031425-generic.
Preparing to unpack linux-image-3.14.25-031425-generic_3.14.25-031425.201411211235_amd64.deb ...
Done.
Unpacking linux-image-3.14.25-031425-generic (3.14.25-031425.201411211235) ...
Setting up linux-headers-3.14.25-031425 (3.14.25-031425.201411211235) ...
Setting up linux-headers-3.14.25-031425-generic (3.14.25-031425.201411211235) ...
Setting up linux-image-3.14.25-031425-generic (3.14.25-031425.201411211235) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.14.25-031425-generic /boot/vmlinuz-3.14.25-031425-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.14.25-031425-generic /boot/vmlinuz-3.14.25-031425-generic
update-initramfs: Generating /boot/initrd.img-3.14.25-031425-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 3.14.25-031425-generic /boot/vmlinuz-3.14.25-031425-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 3.14.25-031425-generic /boot/vmlinuz-3.14.25-031425-generic
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-3.14.25-031425-generic
Found initrd image: /boot/initrd.img-3.14.25-031425-generic

Found linux image: /boot/vmlinuz-3.13.0-32-generic
Found initrd image: /boot/initrd.img-3.13.0-32-generic

Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done
安装完成后重启,默认会从新内核启动。

ubuntu@KVM:~$ uname -a
Linux KVM 3.14.25-031425-generic #201411211235 SMP Fri Nov 21 17:37:23 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
可以看到,内核己升级为3.14.25,并且grub2默认从新内核启动,原内核仍然保留启动项。
没错,这种更新方法高效快捷。


二.编译kernel源码包
利用快照还原ubuntu的初始状态
编译内核的一般步骤:

1.清除旧目标文件和配置(make mrproper
2.配置内核选项 
a.文本交互y|n|m"问答"界面(make config
b.文本菜单界面(make menuconfig)#libncures5-dev
c.图形界面 (make xconfig|gconfig #需要qt或gtk开发库支持
d.应答文件(make oldconfig) #.config
推荐使用:文本菜单方式(make menuconfig)
菜单选项功能,根据生产环境进行配置:
                 General setup  --->                          # 普通安装                                                        
             [*] Enable loadable module support  --->         # 是否支持外挂模块的功能                                
             -*- Enable the block layer  --->                 #块设备                                  
                 Processor type and features  --->            #cpu的类型和功能(主要修改选项)
Processor type and features:子菜单:
                                     Processor family (Generic-x86-64):选择cpu的类型
                 Power management and ACPI options  --->      #电源管理                                  
                 Bus options (PCI etc.)  --->                 #pci总线的配置                                  
                 Executable file formats / Emulations  --->   #可执行二进制文件格式                                   
             -*- Networking support  --->                     #网络配置                                  
                 Device Drivers  --->                         #驱动                                 
                 Firmware Drivers  --->                       #固件驱动
                 File systems  --->                           #文件系统                                  
                 Kernel hacking  --->                         #内核debug                                 
                 Security options  --->                       #安全相关选项                                 
             -*- Cryptographic API  --->                      #加密api                                  
             [*] Virtualization  --->                         #校验码选项                                  
                 Library routines  --->                                                         
                 Load an Alternate Configuration File                                           
                 Save an Alternate Configuration File
3.编译内核(make bzImage
4.编译内核模块(make modules
5.安装内核模块(make modules_install
6.安装新内核(make install

更详细的说明,请参看源码中的README
root@KVM:/usr/local/src/linux-3.14.25# make help
Cleaning targets:
  clean          - Remove most generated files but keep the config and
                    enough build support to build external modules
  mrproper      - Remove all generated files + config + various backup files
  distclean      - mrproper + remove editor backup and patch files

Configuration targets:
  config      - Update current config utilising a line-oriented program
  nconfig         - Update current config utilising a ncurses menu based program
  menuconfig      - Update current config utilising a menu based program
  xconfig      - Update current config utilising a QT based front-end
  gconfig      - Update current config utilising a GTK based front-end
  oldconfig      - Update current config utilising a provided .config as base
  localmodconfig  - Update current config disabling modules not loaded
  localyesconfig  - Update current config converting local mods to core
  silentoldconfig - Same as oldconfig, but quietly, additionally update deps
  defconfig      - New config with default from ARCH supplied defconfig
  savedefconfig   - Save current config as ./defconfig (minimal config)
  allnoconfig      - New config where all options are answered with no
  allyesconfig      - New config where all options are accepted with yes
  allmodconfig      - New config selecting modules when possible
  alldefconfig    - New config with all symbols set to default
  randconfig      - New config with random answer to all options
  listnewconfig   - List new options
  olddefconfig      - Same as silentoldconfig but sets new symbols to their default value

Other generic targets:
  all          - Build all targets marked with [*]
* vmlinux      - Build the bare kernel
* modules      - Build all modules
  modules_install - Install all modules to INSTALL_MOD_PATH (default: /)
  firmware_install- Install all firmware to INSTALL_FW_PATH
                    (default: $(INSTALL_MOD_PATH)/lib/firmware)
  dir/            - Build all files in dir and below
  dir/file.[oisS] - Build specified target only
  dir/file.lst    - Build specified mixed source/assembly target only
                    (requires a recent binutils and recent build (System.map))
  dir/file.ko     - Build module including final link
  modules_prepare - Set up for building external modules
  tags/TAGS      - Generate tags file for editors
  cscope      - Generate cscope index
  gtags           - Generate GNU GLOBAL index
  kernelrelease      - Output the release version string
  kernelversion      - Output the version stored in Makefile
  image_name      - Output the image name
  headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH
                    (default: /usr/local/src/linux-3.14.25/usr)

Static analysers
  checkstack      - Generate a list of stack hogs
  namespacecheck  - Name space analysis on compiled kernel
  versioncheck    - Sanity check on version.h usage
  includecheck    - Check for duplicate included header files
  export_report   - List the usages of all exported symbols
  headers_check   - Sanity check on exported headers
  headerdep       - Detect inclusion cycles in headers
  coccicheck      - Check with Coccinelle.

Kernel packaging:
  rpm-pkg             - Build both source and binary RPM kernel packages
  binrpm-pkg          - Build only the binary kernel package
  deb-pkg             - Build the kernel as a deb package
  tar-pkg             - Build the kernel as an uncompressed tarball
  targz-pkg           - Build the kernel as a gzip compressed tarball
  tarbz2-pkg          - Build the kernel as a bzip2 compressed tarball
  tarxz-pkg           - Build the kernel as a xz compressed tarball
  perf-tar-src-pkg    - Build perf-3.14.25.tar source tarball
  perf-targz-src-pkg  - Build perf-3.14.25.tar.gz source tarball
  perf-tarbz2-src-pkg - Build perf-3.14.25.tar.bz2 source tarball
  perf-tarxz-src-pkg  - Build perf-3.14.25.tar.xz source tarball

Documentation targets:
 Linux kernel internal documentation in different formats:
  htmldocs        - HTML
  pdfdocs         - PDF
  psdocs          - Postscript
  xmldocs         - XML DocBook
  mandocs         - man pages
  installmandocs  - install man pages generated by mandocs
  cleandocs       - clean all generated DocBook files

Architecture specific targets (x86):
* bzImage      - Compressed kernel image (arch/x86/boot/bzImage)
  install      - Install kernel using
                  (your) ~/bin/installkernel or
                  (distribution) /sbin/installkernel or
                  install to $(INSTALL_PATH) and run lilo
  fdimage      - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)
  fdimage144   - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)
  fdimage288   - Create 2.8MB boot floppy image (arch/x86/boot/fdimage)
  isoimage     - Create a boot CD-ROM image (arch/x86/boot/image.iso)
                  bzdisk/fdimage*/isoimage also accept:
                  FDARGS="..."  arguments for the booted kernel
                  FDINITRD=file initrd for the booted kernel
  kvmconfig    - Enable additional options for guest kernel support

  i386_defconfig           - Build for i386
  x86_64_defconfig         - Build for x86_64

  make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build
  make V=2   [targets] 2 => give reason for rebuild of target
  make O=dir [targets] Locate all output files in "dir", including .config
  make C=1   [targets] Check all c source with $CHECK (sparse by default)
  make C=2   [targets] Force check of all c source with $CHECK
  make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections
  make W=n   [targets] Enable extra gcc checks, n=1,2,3 where
        1: warnings which may be relevant and do not occur too often
        2: warnings which occur quite often but may still be relevant
        3: more obscure warnings, can most likely be ignored
        Multiple levels can be combined with W=12 or W=123

Execute "make" or "make all" to build all targets marked with [*]
For further info see the ./README file



root@KVM:~# uname  -a
Linux KVM 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
root@KVM:~# ls
linux-3.14.25.tar.xz
root@KVM:~# tar -xvf linux-3.14.25.tar.xz -C /usr/local/src/
root@KVM:~# cd /usr/local/src/linux-3.14.25/
menuconfig需要ncurses库支持,以文本菜单的方式显示编译内容,并且可以随时保存及调用己存在的.config文件,非常方便,强烈推荐。所以,先安装编译必须库及ncurses支持。如果没有ncurse支持就会报如下错误。
HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
 *** Unable to find the ncurses libraries or the
 *** required header files.
 *** 'make menuconfig' requires the ncurses libraries.
 ***
 *** Install ncurses (ncurses-devel) and try again.
 ***
make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1
make: *** [menuconfig] Error 2

root@KVM:/usr/local/src/linux-3.14.25# apt-get install build-essential libncurses5-dev
root@KVM:/usr/local/src/linux-3.14.25# make mrproper
root@KVM:/usr/local/src/linux-3.14.25# make menuconfig
如果还是闲选择功能模块太麻烦且不够优化,可以偷懒借用ubuntu己编好的config文件,可以的话稍加以修改再来编译,这样会省很多事,毕竟官方出的内核配置文件应该说是比较优化和足够稳定的。
我这里就直接借用/boot/config-3.13.0-32-generic.config这个文件,通过menuconfig load功能加载并保存,然后开始编译。
root@KVM:/usr/local/src/linux-3.14.25# cp /boot/config-3.13.0-32-generic .config
Ubuntu14.04升级内核3.14.25
Ubuntu14.04升级内核3.14.25
Ubuntu14.04升级内核3.14.25
Ubuntu14.04升级内核3.14.25
开始编译
提示:可以修改Makefile中的相关变量来个性化内核,如EXTRAVERSION = 20141204-generic,指定编译版本号。
root@KVM:/usr/local/src/linux-3.14.25# make bzImage
... ...
  OBJCOPY arch/x86/boot/setup.bin
  OBJCOPY arch/x86/boot/vmlinux.bin
  HOSTCC  arch/x86/boot/tools/build
  BUILD   arch/x86/boot/bzImage
Setup is 16944 bytes (padded to 17408 bytes).
System is 5706 kB
CRC 36e8068
Kernel: arch/x86/boot/bzImage is ready  (#1)
root@KVM:/usr/local/src/linux-3.14.25# make modules
make[1]: Nothing to be done for `all'.
make[1]: Nothing to be done for `relocs'.
  CHK     include/config/kernel.release
  ... ...
IHEX2FW firmware/keyspan_pda/xircom_pgs.fw
IHEX    firmware/cpia2/stv0672_vp4.bin
IHEX    firmware/yam/1200.bin
IHEX    firmware/yam/9600.bin
root@KVM:/usr/local/src/linux-3.14.25# make modules_install
  INSTALL arch/x86/crypto/aes-x86_64.ko
  INSTALL arch/x86/crypto/aesni-intel.ko
  INSTALL arch/x86/crypto/blowfish-x86_64.ko
 ... ...
  INSTALL /lib/firmware/keyspan_pda/xircom_pgs.fw
  INSTALL /lib/firmware/cpia2/stv0672_vp4.bin
  INSTALL /lib/firmware/yam/1200.bin
  INSTALL /lib/firmware/yam/9600.bin
  DEPMOD  3.14.25
root@KVM:/usr/local/src/linux-3.14.25# make install
sh /usr/local/src/linux-3.14.25/arch/x86/boot/install.sh 3.14.25 arch/x86/boot/bzImage System.map "/boot"
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.14.25 /boot/vmlinuz-3.14.25
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.14.25 /boot/vmlinuz-3.14.25
update-initramfs: Generating /boot/initrd.img-3.14.25
run-parts: executing /etc/kernel/postinst.d/update-notifier 3.14.25 /boot/vmlinuz-3.14.25
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 3.14.25 /boot/vmlinuz-3.14.25
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-3.14.25
Found initrd image: /boot/initrd.img-3.14.25

Found linux image: /boot/vmlinuz-3.13.0-32-generic
Found initrd image: /boot/initrd.img-3.13.0-32-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
done
至此,内核编译安装完成。重启查看效果。
root@KVM:~# uname -a
Linux KVM 3.14.25 #1 SMP Thu Dec 4 10:08:33 CST 2014 x86_64 x86_64 x86_64 GNU/Linux
没问题,己成功从新内核启动。
原文地址:https://www.cnblogs.com/lixuebin/p/10814463.html