How to quickly customize the binary kernel RPM package in CentOS

Source: Internet
Author: User
Tags rpmbuild

How to quickly customize the binary kernel RPM package in CentOS

As the number of Linux servers increases, a dedicated binary installation package must be customized for easy upgrade and management to ensure the consistency of the underlying system kernel versions. RedHat system, of course, is to use rpmbuild for customized management.

Today, we will explain how to create a binary rpm package for the kernel in two parts (root and common users.

Building host system environment conventions:
  • OS: CentOS release 6.6

  • Arch: i686

I. Simple customization of rpm packages

Note: We need to reserve at least 20 GB of temporary file space.

1. Preparations for the rpm production environment:
  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 # verify and update the configuration. config configuration file (if you only want to modify some minor points based on the original Kernel configuration)
  7. Make menuconfig # simple Graphical Kernel configuration management
3. Now, we can start to compile the new kernel rpm package.
  1. Make rpm # automatically generates the rpmtree and kernel. spec files and automatically compiles them. All rpm package components, including the debug package, are generated.

Let's just wait, or have a cup of afternoon tea or something.

Now, let's look for the compiled kernel rpm package.

  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. Restart and verify the kernel version.
  1. uname -a
Ii. Deep customization of rpm Packages 1. We first created the rpm production workshop (I think this may be more vivid ).
  1. Yum install rpmdevtools # rpm workshop quick creation tool
  2. Useradd-m builder # create a temporary user to create an RPM package. If an error occurs, the build program will not damage the existing system environment.
  3. su - builder
  4. Rpmdev-setuptree # create a workshop

The following directory structure will be generated under the Home Directory of the builder User:

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

In this case, we need to package the new kernel source code package to 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. # Note: rpmbuild uses gzipto decompress the source code package of buildingand converts the package into .tar.gz format.
  5. # No record is recorded here.
  6. Cp/boot/config-'uname-R'. # copy the existing Kernel configuration file config-'uname-R' to the SOURCES directory.

Switch to the SPECS directory to generate 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. # Here we need to manually generate the kernel. spec file using the script provided in the source code package
  5. # Remember to clean up the linux-3.19.1 folder after generating kernel. spec
  6. Vim kernel. spec # Deep customization based on individual situations

At this point, our preparation is basically complete. 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. Now, we officially start to compile the binary rpm package of the kernel:
  1. rpmbuild -bb --with baseonly --without debug --without debuginfo --target=`uname -m` kernel.spec

Rpmbuild parameter description:

(1) -- with <option> indicates to compile a certain kind of kernel. Optional options include baseonly, smponly, and xenonly.

(2) -- without <option> indicates removing some functional modules. Optional options include xen, smp, up, pae, kdump, debug, and debuginfo. Among them, the debug option will remove the debugging code in the kernel, and the debuginfo option will disable the establishment of the kernel-debuginfo package.

After completion, go ~ /Rpmbuild/RPMS/'uname-m'/directory to obtain the rpm installation package.

Getting started with creating an RPM package

In Linux, how does one create an RPM package?

Create your own rpm package

Directory structure and configuration after rpm installation in Linux

Brief Introduction and demo of rpm and yum

Redhat Linux --- rpm command details

Use FPM to easily create an RPM package

Rpm package building Reference documents:
  • 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

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.