vineri, 4 octombrie 2013

Building a custom kernel

This example is for Fedora Core 18

I. Install necessary packages:

#su -c 'yum install rpmdevtools yum-utils'
#su -c 'yum install ncurses-devel'
#su -c 'yum install qt3-devel libXi-devel'

II. Get the Source
OBS. Do not build packages as root

1. Prepare a RPM package building environment in your home directory. Run the following command: 

rpmdev-setuptree

2.Download the kernel-<version>.src.rpm file. Enable the appropriate source repositories with the --enablerepo switch. (yumdownloader --enablerepo=repo_to_enable --source kernel)

 
yumdownloader --source kernel

3.Install build dependencies for the kernel source with the yum-builddep command (root is required to install these packages):

su -c 'yum-builddep kernel-<version>.src.rpm'

4. Install kernel-<version>.src.rpm with the following command

rpm -Uvh kernel-<version>.src.rpm


Prepare the Kernel Source Tree

cd ~/rpmbuild/SPECS
rpmbuild -bp --target=$(uname -m) kernel.spec


Preserve the original tree :

export arch=x86_64 # replace x86_64 with your arch
export ver=3.7 # replace 3.1 with your kernel version
export subver=4-204
export fedver=fc16 # replace fc16 with your fedora version
cp -r ~/rpmbuild/BUILD/kernel-$ver.$fedver ~/rpmbuild/BUILD/kernel-$ver.$fedver.orig
cp -al ~/rpmbuild/BUILD/kernel-$ver.$fedver ~/rpmbuild/BUILD/kernel-$ver.$fedver.new



cd ~/rpmbuild/BUILD/kernel-$ver.$subver.$fedver/linux-$ver.$arch/
cp configs/<desired-config-file> .config
make menuconfig

Copy the config file to ~/rpmbuild/SOURCES/:

cp .config ~/rpmbuild/SOURCES/config-`uname -m`-generic
cd ~/rpmbuild/SPECS
%define buildid .<custom_text>
rpmbuild -bb --with baseonly --with firmware --without debuginfo \
--target=`uname -m` kernel.spec


Install the new kernel
su -c "rpm -ivh $HOME/rpmbuild/RPMS/<arch>/kernel-<version>.<arch>.rpm"