Wednesday 27 November 2013

COMPILE LINUX KERNEL

COMPILE LINUX KERNEL STEP BY SETP

1. Switch to "src" directory
# cd /usr/src

2. Download any latest stable version of kernel
# wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.12.1.tar.xz

3. untar the kernel
# tar -xzJf linux-3.12.1.tar.xz

4. Configure the Kernel
The kernel contains nearly 3000 configuration options. To make the kernel used by most people on most hardware, the Linux distro like Ubuntu, Fedora, Debian, RedHat, CentOS, etc, will generally include support for most common hardware. You can take any one of configuration from the distro, and on top of that you can add your own configuration, or you can configure the kernel from scratch, or you can use the default config provided by the kernel

# cd linux-3.12.1

# make menuconfig

NOTE: You should have installed “libncurses and libncurses-devel” packages for this command to work


We will use the default config provided by the kernel. So select “Save” and save the config in the file name “.config”.


Press "ok" to save .config

Press "exit" to exit the utility


This will save .config file in current directory. The file looks like below.
#
# Automatically generated file; DO NOT EDIT.
# Linux/x86 3.12.1 Kernel Configuration
#
CONFIG_64BIT=y
CONFIG_X86_64=y
CONFIG_X86=y
CONFIG_INSTRUCTION_DECODER=y
CONFIG_OUTPUT_FORMAT="elf64-x86-64"
CONFIG_ARCH_DEFCONFIG="arch/x86/configs/x86_64_defconfig"
CONFIG_LOCKDEP_SUPPORT=y
CONFIG_STACKTRACE_SUPPORT=y
CONFIG_HAVE_LATENCYTOP_SUPPORT=y
CONFIG_MMU=y
CONFIG_NEED_DMA_MAP_STATE=y
CONFIG_NEED_SG_DMA_LENGTH=y
CONFIG_GENERIC_ISA_DMA=y
CONFIG_GENERIC_BUG=y
CONFIG_GENERIC_BUG_RELATIVE_POINTERS=y
CONFIG_GENERIC_HWEIGHT=y
CONFIG_ARCH_MAY_HAVE_PC_FDC=y
CONFIG_RWSEM_XCHGADD_ALGORITHM=y
CONFIG_GENERIC_CALIBRATE_DELAY=y
CONFIG_ARCH_HAS_CPU_RELAX=y
CONFIG_ARCH_HAS_CACHE_LINE_SIZE=y
CONFIG_ARCH_HAS_CPU_AUTOPROBE=y
CONFIG_HAVE_SETUP_PER_CPU_AREA=y
CONFIG_NEED_PER_CPU_EMBED_FIRST_CHUNK=y
CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK=y
CONFIG_ARCH_HIBERNATION_POSSIBLE=y
CONFIG_ARCH_SUSPEND_POSSIBLE=y
CONFIG_ARCH_WANT_HUGE_PMD_SHARE=y
CONFIG_ARCH_WANT_GENERAL_HUGETLB=y
CONFIG_ZONE_DMA32=y
CONFIG_AUDIT_ARCH=y
CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING=y
CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC=y
CONFIG_HAVE_INTEL_TXT=y
CONFIG_X86_64_SMP=y
CONFIG_X86_HT=y
CONFIG_ARCH_HWEIGHT_CFLAGS="-fcall-saved-rdi -fcall-saved-rsi -fcall-saved-rdx -fcall-saved-rcx -fcall-saved-r8 -fcall-saved-r9 -fcall-saved-r10 -fcall-saved-r11"
CONFIG_ARCH_CPU_PROBE_RELEASE=y
CONFIG_ARCH_SUPPORTS_UPROBES=y
CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
CONFIG_IRQ_WORK=y
CONFIG_BUILDTIME_EXTABLE_SORT=y

......................


5. Compile linux kernel (it will take almost 40Min)
# make

compile the kernel modules
# make modules

install the kernel modules
# make modules_install

At this point, you should see a directory named /lib/modules/3.12.1/ in your system

6. Install the kernel

install the kernel on your system
# make install


The make install command will create the following files in the /boot directory.


vmlinuz-3.12.1 – The actual kernel
System.map-3.12.1 – The symbols exported by the kernel
initrd.img-3.12.1 – initrd image is temporary root file system used during boot process
config-3.12.1 – The kernel configuration file

The command “make install” will also update the grub.cfg by default. So we don’t need to manually edit the grub.cfg file.


7. Boot Linux to the new Kernel


To use the new kernel that you just compiled, reboot the system.

# reboot  | init 6

After reboot you can check the kernel version

# uname -r
3.12.1

No comments:

Post a Comment