Thursday, February 5, 2015

Building Linux Kernel from Source

1. Download the Latest Stable Kernel

The first step is to download the latest stable kernel from kernel.org.

# cd /usr/src/

# wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.9.3.tar.xz



2. Untar the Kernel Source

The second step is to untar the kernel source file for compilation.

# tar -xvJf linux-3.9.3.tar.xz


3. Configure the Kernel
# cd linux-3.9.3

# make menuconfig



4) Compile the Linux Kernel

Compile the main kernel: # 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.9.3/ in your system.

5. Install the new kernel on the system:

# make install

6. Boot Linux to the new Kernel
# reboot

2 comments:

  1. How to build a linux kernel deb package ( output files in diff folder)
    mkdir build ( outside linux source folder)
    cp .config ../build/.config
    cd linux ( linux source code)
    make O=../build menuconfig
    make O=../build dep-pkg -j 24 => will generate deb package and all build files are generated in build folder outside kernel source.

    ReplyDelete
  2. How to build a kernel module :
    Make sure we have build a full kernel build once and later need to build a specific module rather than building full kernel.

    make O=../build M=drivers/gpu/drm/ttm

    This will generate ttm.ko at build/drivers/gpu/drm/ttm/ttm.ko

    Need to copy this file to /lib/modules/'uname -r'/kernel/drivers/gpu/drm/ttm/ttm.ko

    Later need to update initramfs saying

    sudo update-initramfs -c -k 'uname -r'

    ReplyDelete