Linux – A Custom RPM based on Source Tar file patched with LIDS

>Steps for creating LIDS based kernel RPM from source .tar.gz file.

1) Download the linux kernel i.e linux-2.6.31.11.gz from kernel.org website.

2) Download required LIDS source file i.e lidstools-2.2.7.2.tar.gz & lids-2.2.3rc9-2.6.31.patch

3) Extract the linux kernel
tar -zvxf linux-2.6.31.11.gz

4) Patch the linux kernel with LIDS support. Go to linux kernel extract directory
[root@vmlinux linux-2.6.31.11]# patch -p1 < ../lids-2.2.3rc9-2.6.31.patch Note: Lids version i.e 2.6.31 must match with kernel version.

5) Patch the kernel extracted ‘mkspec’ file in order to create mkinitrd file and putting the entry inside /etc/grub.conf file to avoid human error.

Note: mkspec location is ‘/usr/src/redhat/BUILD/linux-2.6.31.11/scripts/package’. This is customised path. you can get it on extracted linux source rpm file.

6) mkspec file should look like this i.e /usr/src/linux-kernel_level/scripts/mkspec file:

#!/bin/sh
#
# Output a simple RPM spec file that uses no fancy features requring
# RPM v4. This is intended to work with any RPM distro.
#
# The only gothic bit here is redefining install_post to avoid
# stripping the symbols from files in the kernel which we want
#
# Patched for non-x86 by Opencon (L) 2002
#

# how we were called determines which rpms we build and how we build them

if [ “$1” = “prebuilt” ]; then
PREBUILT=true
else
PREBUILT=false
fi

# starting to output the spec
if [ “`grep CONFIG_DRM=y .config | cut -f2 -d=`” = “y” ]; then
PROVIDES=kernel-drm
fi

PROVIDES=”$PROVIDES kernel-$KERNELRELEASE”
__KERNELRELEASE=`echo $KERNELRELEASE | sed -e “s/-//g”`

echo “Name: kernel”
echo “Summary: The Linux Kernel”
echo “Version: $__KERNELRELEASE”
# we need to determine the NEXT version number so that uname and
# rpm -q will agree
echo “Release: `. $srctree/scripts/mkversion`”
echo “License: GPL”
echo “Group: System Environment/Kernel”
echo “Vendor: The Linux Community”
echo “URL: http://www.kernel.org&#8221;

if ! $PREBUILT; then
echo “Source: kernel-$__KERNELRELEASE.tar.gz”
fi

echo “BuildRoot: /var/tmp/%{name}-%{PACKAGE_VERSION}-root”
echo “Provides: $PROVIDES”
echo “%define __spec_install_post /usr/lib/rpm/brp-compress || :”
echo “%define debug_package %{nil}”
echo “”
echo “Provides: kernel-devel-%{_target_cpu} = %{version}-%{release}”
echo “Prereq: /usr/bin/find”
echo “”
echo “%description”
echo “The Linux Kernel, the operating system core itself”
echo “”

if ! $PREBUILT; then
echo “%prep”
echo “%setup -q”
echo “”
fi

echo “%build”

if ! $PREBUILT; then
echo “make clean && make %{?_smp_mflags}”
echo “”
fi

echo “%install”
echo “%ifarch ia64”
echo ‘mkdir -p $RPM_BUILD_ROOT/boot/efi $RPM_BUILD_ROOT/lib/modules’
echo ‘mkdir -p $RPM_BUILD_ROOT/lib/firmware’
echo “%else”
echo ‘mkdir -p $RPM_BUILD_ROOT/boot $RPM_BUILD_ROOT/lib/modules’
echo ‘mkdir -p $RPM_BUILD_ROOT/lib/firmware’
echo “%endif”

echo ‘INSTALL_MOD_PATH=$RPM_BUILD_ROOT make %{_smp_mflags} modules_install’
echo “%ifarch ia64”
echo ‘cp $KBUILD_IMAGE $RPM_BUILD_ROOT'”/boot/efi/vmlinuz-$KERNELRELEASE”
echo ‘ln -s ‘”efi/vmlinuz-$KERNELRELEASE” ‘$RPM_BUILD_ROOT'”/boot/”
echo “%else”
echo “%ifarch ppc64”
echo “cp vmlinux arch/powerpc/boot”
echo “cp arch/powerpc/boot/”‘$KBUILD_IMAGE $RPM_BUILD_ROOT'”/boot/vmlinuz-$KERNELRELEASE”
echo “%else”
echo ‘cp $KBUILD_IMAGE $RPM_BUILD_ROOT'”/boot/vmlinuz-$KERNELRELEASE”
echo “%endif”
echo “%endif”

echo “%ifnarch ppc64”
echo ‘cp vmlinux vmlinux.orig’
echo ‘bzip2 -9 vmlinux’
echo ‘mv vmlinux.bz2 $RPM_BUILD_ROOT'”/boot/vmlinux-$KERNELRELEASE.bz2″
echo ‘mv vmlinux.orig vmlinux’
echo “%endif”
#############################################################################################
#Added By Satyendra
echo ‘gzip -c9 $RPM_BUILD_ROOT'”/boot/symvers-$KERNELRELEASE.gz”
echo ‘cp System.map $RPM_BUILD_ROOT'”/boot/System.map-$KERNELRELEASE”
echo ‘cp .config $RPM_BUILD_ROOT'”/boot/config-$KERNELRELEASE”
echo ‘touch $RPM_BUILD_ROOT'”/boot/initrd-$KERNELRELEASE.img”

echo ‘rm -f $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build’
echo ‘rm -f $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/source’
echo ‘mkdir -p $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build’
echo ‘(cd $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE ; ln -s build source)’
echo ‘mkdir -p $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/extra’
echo ‘mkdir -p $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/updates’
echo ‘mkdir -p $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/weak-updates’
echo ‘# first copy everything’
echo ‘cp –parents `find -type f -name Makefile -o -name “Kconfig*”` $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build’
echo ‘cp Module.symvers $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build’
echo “# then drop all but the needed Makefiles/Kconfig file”
echo ‘rm -rf $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build/Documentation’
echo ‘rm -rf $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build/scripts’
echo ‘rm -rf $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build/include’
echo ‘cp .config $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build’
echo ‘cp -a scripts $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build’
echo “if [ -d arch/%{_arch}/scripts ]; then”
echo ‘cp -a arch/%{_arch}/scripts $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build/arch/%{_arch} || :’
echo “fi”
echo ‘if [ -f arch/%{_arch}/*lds ]; then’
echo ‘cp -a arch/%{_arch}/*lds $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build/arch/%{_arch}/ || :’
echo “fi”
echo ‘rm -f $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build/scripts/*.o’
echo ‘rm -f $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build/scripts/*/*.o’
echo ‘mkdir -p $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build/include’
echo ‘cd include’
echo ‘cp -a `ls` $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build/include/’
# Make sure the Makefile and version.h have a matching timestamp so that
# external modules can be built
touch -r $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build/Makefile $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build/include/linux/version.h’
touch -r $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build/.config $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build/include/linux/autoconf.h’
echo ‘# Copy .config to include/config/auto.conf so “make prepare” is unnecessary.’
echo ‘cp $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build/.config $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build/include/config/auto.conf’
echo “cd ..”

echo ‘find $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE -name “*.ko” -type f >modnames’
echo “# mark modules executable so that strip-to-file can strip them”
echo “cat modnames | xargs chmod 755”
echo “rm -f modnames”
echo “# remove files that will be auto generated by depmod at rpm -i time”
echo ‘rm -f $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/modules.*’
echo “”
echo “# Move the devel headers out of the root file system”
echo “DevelDir=/usr/src/kernels/$KERNELRELEASE-%{_target_cpu}”
echo ‘mkdir -p $RPM_BUILD_ROOT/usr/src/kernels’
echo ‘mv $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build $RPM_BUILD_ROOT/$DevelDir’
echo ‘ln -sf ../../..$DevelDir $RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build’
echo “”
####################################################################################################################
echo “”
echo “%clean”
#echo ‘rm -rf $RPM_BUILD_ROOT’
#echo “%{__rm} -rf %{buildroot}”
echo “”
#############################################################################################################
#Added by Satyendra
echo “%post”
echo “cd /boot”
echo “if [ `uname -i` == “x86_64” -o `uname -i` == “i386″ ]; then”
echo “if [ -f /etc/sysconfig/kernel ]; then”
echo “/bin/sed -i -e ‘s/^DEFAULTKERNEL=kernel-smp$/DEFAULTKERNEL=kernel/’ /etc/sysconfig/kernel || exit $?”
echo “fi”
echo “fi”
echo “/sbin/new-kernel-pkg –package kernel –mkinitrd –depmod –install $KERNELRELEASE || exit $?”
echo “”
echo “%preun”
echo “/sbin/new-kernel-pkg –rminitrd –rmmoddep –remove $KERNELRELEASE || exit $?”
echo “”
###############################################################################################################
echo “%files”
echo ‘%defattr (-, root, root)’
echo “%dir /lib/modules”
echo “/lib/modules/$KERNELRELEASE”
echo “/lib/firmware”
echo “$RPM_BUILD_ROOT/$DevelDir”
echo “/boot/*”
echo “”
Note: Comment Added by Satyendra are only changes incorporated on existing mkspec file on i386 plateform.

# Go to the /usr/src/linux-kernel_level directory.
7) Run ‘make menuconfig’ commands to include LIDS support on Kernel
8) Edit your .config file to incorporate the following to avoid ‘setuproot /dev/root error + kernel panic while booting system
CONFIG_SYSFS_DEPRECATED_V2=y
9) make the changes in ‘Makefile’ for required parameter i.e
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 31
EXTRAVERSION = .11Non-SMP-LIDS-Complied_Kernel_i386
SMP = 0
NAME = Non-SMP-LIDS-Complied_Kernel_i386

Note: SMP = 0 means non-smp support ‘1’ means SMP-support

10) Run “make binrpm-pkg” commands to create LIDS based kernel RPM
Note: It will create the rpm ( a few lines from my owned complied kernel)
/usr/lib/rpm/brp-compress
Processing files: kernel-2.6.31.11-1
Provides: kernel-2.6.31.11
Requires(rpmlib): rpmlib(CompressedFileNames) < = 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/kernel-2.6.31.11-root Wrote: /usr/src/redhat/SRPMS/kernel-2.6.31.11-1.src.rpm Wrote: /usr/src/redhat/RPMS/i386/kernel-2.6.31.11-1.i386.rpm Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.23781 + umask 022 + cd /usr/src/redhat/BUILD + cd kernel-2.6.31.11 + rm -rf /var/tmp/kernel-2.6.31.11-root + exit 0 12) RPM kernel installation [root@vmlinux i386]# rpm -ivh kernel-2.6.31.11-1.i386.rpm Preparing… ########################################### [100%] 1:kernel ########################################### [100%] [root@vmlinux i386]# TroubleShooting.

Sometimes it may be that after installing LIDS enabled kernel rpm. you are getting the following error.

cann’t open /proc/sys/lids/lock file
Reason :Illigle seek

It mean LIDS modules is not loaded on kernel

Solution

modprobe lids

Advertisements

3 thoughts on “Linux – A Custom RPM based on Source Tar file patched with LIDS

  1. Donte November 20, 2011 at 10:31 am Reply

    People nrolmlay pay me for this and you are giving it away!

    • Zaiya December 1, 2011 at 3:54 pm Reply

      Pin my tail and call me a dnoeky, that really helped.

    • Victory December 3, 2011 at 6:27 am Reply

      Just what the doctor ordreed, thankity you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: