How to quickly customize the binary kernel rpm package in Centos

Source: Internet
Author: User
Tags rpmbuild

With more and more Linux servers, the underlying system kernel wants to keep the version unified and needs to customize a dedicated binary installation package for easy upgrade and management. Redhat is of course the use of Rpmbuild to do custom management.

Today we have two sections (root and normal user) to explain how to make a kernel binary RPM package.

Building host system Environment conventions:
    • Os:centos Release 6.6

    • arch:i686

One, RPM package simple customization

Note: Here we first have to reserve at least 20GB of temporary file space.

1, RPM pre-production environment preparation:
  1. yum -y groupinstall "Development Tools"
  2. yum -y install ncurses-devel qt-devel
  3. yum -y install rpm-build redhat-rpm-config asciidoc hmaccalc perl-ExtUtils-Embed xmlto
  4. yum -y install audit-libs-devel binutils-devel elfutils-devel elfutils-libelf-devel
  5. yum -y install newt-devel python-devel zlib-devel bc
2. Prepare the source code component of the kernel
  1. cd /usr/src
  2. wget -c https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.19.1.tar.xz
  3. tar -Jxvf linux-3.19.1.tar.xz
  4. ln -s linux-3.19.1 linux
  5. cd linux
  6. make oldconfig # 验证和更新配置.config配置文件(如果只想在原来内核配置的基础上修改一些小地方)
  7. make menuconfig # 简单图形化的内核配置管理
3. At this point, we can start compiling the new kernel RPM package.
    1. make rpm # 自动生成rpmtree,kernel.spec文件,自动编译, 会生成debug包在内的所有rpm包组件。

This time we'll wait, or have a cup of afternoon tea or something.

OK, let's find the kernel RPM package that has been compiled.

  1. cd /root/rpmbuild/RPMS/`uname -m`/
  2. tree RPMS/
  3. RPMS/
  4. └── i386
  5. ├── kernel-3.19.1-2.i386.rpm
  6. ├── kernel-devel-3.19.1-2.i386.rpm
  7. └── kernel-headers-3.19.1-2.i386.rpm
  8. 1 directory, 3 files
4. Install the new kernel
    1. rpm -Uvh kernel-*-.rpm
5. Reboot to verify kernel version
    1. uname -a
Second, RPM package depth customization 1, we first create a good rpm "Production workshop" (I think this may be more image).
    1. yum install rpmdevtools # rpm 制作车间快速创建工具
    2. useradd -m builder # 新建一个临时用户以便创建 RPM 包,如果有错误发生,构建程序不会破坏现有的系统环境。
    3. su - builder
    4. rpmdev-setuptree # 创建”制作车间“

The following directory structure will be generated in the builder user's home directory:

    1. tree -L 1 ~/rpmbuild/
    2. rpmbuild/
    3. ├── BUILD
    4. ├── RPMS
    5. ├── SOURCES
    6. ├── SPECS
    7. └── SRPMS
2. Prepare before compiling

At this point we need to collect the new kernel source package to put in the/home/builder/rpmbuild/sources directory

  1. su - builder
  2. cd ~/rpmbuild/SOURCES
  3. wget -c https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.19.1.tar.xz
  4. # 注意: rpmbuild 是通过gzip来做building前源码包解压工作的,所以需要把这个压缩包转换成.tar.gz格式。
  5. # 这里就不做记录了
  6. cp /boot/config-`uname -r` . # 将现有的内核配置文件 config-`uname -r` 拷贝到 SOURCES 目录下

To switch to the specs directory, generate the Kernel.spec:

  1. tar Jxvf ../SOURCES/linux-3.19.1.tar.xz -C .
  2. bash ../linux-3.19.1/scripts/package/mkspec >./kernel.spec
  3. rm -rf linux-3.19.1
  4. # 这里需要我们手动利用源码包中提供的脚本生成 kernel.spec 文件
  5. # 记得生成kernel.spec完之后,清理掉 linux-3.19.1 文件夹
  6. vim kernel.spec # 可以根据个人情况做深度定制化

To this, our preparations are basically completed, the directory structure and content are as follows:

  1. tree rpmbuild/ -a
  2. rpmbuild/
  3. ├── BUILD
  4. ├── RPMS
  5. ├── SOURCES
  6. │   ├── config-`uname -r`
  7. │   └── linux-3.19.1.tar.gz
  8. ├── SPECS
  9. │   └── kernel.spec
  10. └── SRPMS
  11. 5 directories, 3 files
3, OK, now we officially start compiling the kernel binary RPM package:
    1. rpmbuild -bb --with baseonly --without debug --without debuginfo --target=`uname -m` kernel.spec

Rpmbuild parameter Description:

(1)--with <option> Specifies that a kernel is compiled, and option options are baseonly, Smponly, and Xenonly.

(2)--without <option> Specify the removal of some function modules, optional option has Xen, SMP, Up, PAE, Kdump, Debug and Debuginfo, etc. Where the debug option rejects the debug code in the kernel, the Debuginfo option disables the creation of the Kernel-debuginfo package.

When you are finished, get the RPM installation package in the ~/rpmbuild/rpms/' uname-m '/directory.

RPM Package Building Reference Documentation:
    • Http://fedoraproject.org/wiki/How_to_create_an_RPM_package/zh-cn
    • Http://fedoraproject.org/wiki/Building_a_custom_kernel
    • http://wiki.centos.org/zh/HowTos/Custom_Kernel#head-981e27f326384c58516d3b2051b225526bb0a50a

How to quickly customize the binary kernel rpm package in Centos

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.