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:
yum -y groupinstall "Development Tools"
yum -y install ncurses-devel qt-devel
yum -y install rpm-build redhat-rpm-config asciidoc hmaccalc perl-ExtUtils-Embed xmlto
yum -y install audit-libs-devel binutils-devel elfutils-devel elfutils-libelf-devel
yum -y install newt-devel python-devel zlib-devel bc
2. Prepare the source code component of the kernel.
cd /usr/src
wget -c https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.19.1.tar.xz
tar -Jxvf linux-3.19.1.tar.xz
ln -s linux-3.19.1 linux
cd linux
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)
Make menuconfig # simple Graphical Kernel configuration management
3. Now, we can start to compile the new kernel rpm package.
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.
cd /root/rpmbuild/RPMS/`uname -m`/
tree RPMS/
RPMS/
└── i386
├── kernel-3.19.1-2.i386.rpm
├── kernel-devel-3.19.1-2.i386.rpm
└── kernel-headers-3.19.1-2.i386.rpm
1 directory,3 files
4. Install the new kernel
rpm -Uvh kernel-*-.rpm
5. Restart and verify the kernel version.
uname -a
Ii. Deep customization of rpm Packages 1. We first created the rpm production workshop (I think this may be more vivid ).
Yum install rpmdevtools # rpm workshop quick creation tool
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.
su - builder
Rpmdev-setuptree # create a workshop
The following directory structure will be generated under the Home Directory of the builder User:
tree -L 1~/rpmbuild/
rpmbuild/
├── BUILD
├── RPMS
├── SOURCES
├── SPECS
└── 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.
su - builder
cd ~/rpmbuild/SOURCES
wget -c https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.19.1.tar.xz
# Note: rpmbuild uses gzipto decompress the source code package of buildingand converts the package into .tar.gz format.
# No record is recorded here.
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:
tar Jxvf../SOURCES/linux-3.19.1.tar.xz -C .
bash ../linux-3.19.1/scripts/package/mkspec >./kernel.spec
rm -rf linux-3.19.1
# Here we need to manually generate the kernel. spec file using the script provided in the source code package
# Remember to clean up the linux-3.19.1 folder after generating kernel. spec
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:
tree rpmbuild/-a
rpmbuild/
├── BUILD
├── RPMS
├── SOURCES
│ ├── config-`uname -r`
│ └── linux-3.19.1.tar.gz
├── SPECS
│ └── kernel.spec
└── SRPMS
5 directories,3 files
3. Now, we officially start to compile the binary rpm package of the kernel:
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