Ch11 Kernel

Embed Size (px)

Citation preview

  • 8/9/2019 Ch11 Kernel

    1/24

  • 8/9/2019 Ch11 Kernel

    2/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Objectives

    Define kernel properties

    Demonstrate new kernel preparation

    Identify and use kernel configuration tools

    Recompile and install a kernel

    Identify kernel modules

    Configure LILO to use a new kernel

  • 8/9/2019 Ch11 Kernel

    3/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    The Linux Kernel

    Its loaded at initial bootup of Linux system,manages activities : I/O, memory, processes, networkinterface,

    Why would you want to build a new kernel ?(newer hardware, faster, more stable, )

    Kernel can be built with 2 basic options :

    D

    evice drivers can be built directly into thekernel binary itself (monolithic)

    Device drivers can be built as external modulesto the kernel (modular)

  • 8/9/2019 Ch11 Kernel

    4/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102

    SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Kernel Version Numbering

    Kernel version numbers are made by three basiccomponents:

    The major number

    The minor number

    The micro number (patch number)

    There is the fourth number, sometimes appliedafter a dash is genarally the patch level, applied bykernel maintainers

    Ex : 2 . 4 . 7 - 10

  • 8/9/2019 Ch11 Kernel

    5/24

  • 8/9/2019 Ch11 Kernel

    6/24

  • 8/9/2019 Ch11 Kernel

    7/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Preparing For The New Kernel

    See

    /usr/src/linux/Documentation/Changes

    Software tools

    The source tree (source code)

    Apply patches to the kernel source code

  • 8/9/2019 Ch11 Kernel

    8/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Software Tools

    make : determines which pieces of a large program

    need to be recompiled and compile them. It executescommands in Makefile (sometime named makefile)to update programs or module components

    C/gcc : C compiler integrated into gcc

    binutils: a collection of binary utilities :gas(assembler), ld(likner), nm, ranlib, objdump,

  • 8/9/2019 Ch11 Kernel

    9/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    The Source Tree

    Kernel source released as a zipped tar file,

    extension of .tar.gz or .tar.bz2Ex: linux-2.4.19-16.tar.gz

    You should NEVER unpack your kernel sourcesdirectly into /usr/src/linux

    # tar xzfv linux-2.4.19-16.tar.gz C /usr/src

  • 8/9/2019 Ch11 Kernel

    10/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Apply patches to kernel source

    A patch file is editing instructions to change one setof files into new version of the files Ex: patch-2.4.19-

    16-1-acl.gzSteps to patch :

    # ln s /usr/src/linux-2.4.19-16 /usr/src/linux

    # cp patch-2.4.19-16-1-acl /usr/src/linux

    # cd /usr/src/linux

    # cat patch-2.4.19-16-1-acl | patch p1

  • 8/9/2019 Ch11 Kernel

    11/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Customize & Install New Kernel

    There are many possible make targets in the Linuxkernel Makefile that can be used to build kernel :

    make depB

    uild a list of all kernel depsmake clean Remove old binaries and .o files

    make zlilo Make a compressed vmlinuz

    image and update LILOmake zImage Make a simple compressed image

    make bzImage Build an image compressed with gzip

  • 8/9/2019 Ch11 Kernel

    12/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    General Procedure to build kernel

    Step 1: Configure kernels parameters and build it

    make config or make menuconfig or makexconfig

    make dep, make clean, make bzImage

  • 8/9/2019 Ch11 Kernel

    13/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    General Procedure to build kernel

    Step 2: Compile modules

    make modules

    Step 3: Install modulesmake modules_install

    Step 4: Install kernel

    make installStep 5: Check boot loader configuration

    Step 6: Backup file .config

  • 8/9/2019 Ch11 Kernel

    14/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    make menuconfig Interface

  • 8/9/2019 Ch11 Kernel

    15/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    make xconfig Interface

  • 8/9/2019 Ch11 Kernel

    16/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    KernelDefault Option with rdev

    With rdev or its new name rootflags , you can setdefault option appended to your new kernel imagewithout add them to /etc/lilo.conf

    ( See #man rdev for more information )

  • 8/9/2019 Ch11 Kernel

    17/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Kernel Modules

    insmod Install & binding a module to kernel.You can customizemodule loadtime parameters in /etc/modules.conf or /etc/conf.modules

    rmmod Unload a module from kernel

    lsmod List currently loaded modules in kernelmodinfo Details about a modules description

    genksyms Generates symbol version information

    modprobe Load a set of modules either a single module, a stack of

    dependent modules or all modules that are marked with a specified tagdepmod Build a relationship table for modules that are required ofrunning kernel.You can put it in start-up script and run depmod a

    ( Package : modutils )

  • 8/9/2019 Ch11 Kernel

    18/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Building a Monolithic Kernel

    If you build all supports directly into kernel, thenew kernel referred monolithic kernel

    In kernel configuration, a Y answer for anoption means to build that option into the kernel(monolithic); a N means exclude and M meansto build as a module.

    You can omit make modules and makemodules_install when building a new kernel

  • 8/9/2019 Ch11 Kernel

    19/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Boot Loader Features & Config

    LILO (Linux Loader)How to install ?

    Install LILO manually from the packet

    Let your Linux automatically install LILOWhere to install ? first 1024 logical cylinders

    On a diskette

    In the boot sectorof a primary or logical Linuxpartition on thefirstharddisk

    In the Master Boot Record

    You must run /sbin/lilo to update the configurationin file /etc/lilo.conf

  • 8/9/2019 Ch11 Kernel

    20/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    LILO Configuration File

    [root@lpi linux-2.4]# more /etc/lilo.conf

    timeout=50

    default=linux

    boot=/dev/hda

    root=/dev/hda1

    message=/boot/message

    image=/boot/vmlinuz-2.4.7-10

    label=linux

    read-only

  • 8/9/2019 Ch11 Kernel

    21/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    Using LILO to Test a New Kernel

    Make new entry in /etc/lilo.conf for your newkernel :

    image=/boot/vmlinuz-2.4.19-16

    label=My New Kernel

    read-onlyRun /sbin/lilo v command *

    Boot with new kernel and observe

  • 8/9/2019 Ch11 Kernel

    22/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    LILO and Boot Options

    LILO command options

    See #man lilo

    Boot options

    See #man lilo.conf and go to

    KERNEL OPTIONS category

  • 8/9/2019 Ch11 Kernel

    23/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    GRUB (GRand and Unified nified Bootloader)

    GRUB can boot multiple OS and quickly gaining popularity, maysoon replace LILO

    How to install ?

    Install GRUB manually

    Let your Linux automatically install GRUB

    Where to install ? first 1024 logical cylinders

    On a diskette

    In the boot sector of a primary or logical Linux partition onthe first harddisk

    In the Master Boot Record

    You DONT need to run /sbin/grub to update the configurationin file /etc/grub.conf

  • 8/9/2019 Ch11 Kernel

    24/24

    SAIGONLAB 69-3 Nguyen Thi Nho, P9, Q.TBinh, Tp. HCM LPI 102SAIGONLAB 83 Nguyn Th Nh, P9, Q.Tn Bnh, Tp. HCM LPI 102

    LOADLIN

    Its a MS-DOS program that can launch a Linuxkernel from DOS prompt.This is very useful if youhave hardware that relies on MS-DOS driver.