Find the answer to your Linux question:
Results 1 to 5 of 5
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Tutorial for Linux kernel modification?

    Hi friends,

    I'm new to linux and wanting to learn how to hacking Linux kernel. Could you please point some useful links on how to modify Linux Kernel?


  2. #2
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    (I thought I posted this elsewhere on the forum but can't find it now.)

    The author of Linux Kernel in a Nutshell has generously made his book available for free online:

    It's a pretty quick read and contains lots of useful info for you to get started with. Happy hacking.

  3. #3
    Thanks a lot!

  4. $spacer_open
  5. #4

    Kernel Modifications

    The installation of the kernel sources creates a file called README in the /usr/src/linux directory
    that briefly outlines the steps needed to create a new kernel. Take a look at a more detailed explanation
    of the required steps.
    Make Sure Your Source Files Are In Order
    Cleaning up the various source files is the first step. This isn't so important for a first time rebuild,
    but it is vital for subsequent attempts. You use the make mrproper command to do this; it must be
    executed in the root directory of the Linux kernel sources tree. In our case, the subdirectory's name
    is /usr/src/linux which has already been symbolically linked to the
    /usr/src/linux/ subdirectory.
    [root@bigboy tmp]# cd /usr/src/linux
    [root@bigboy linux]# make mrproper
    [root@bigboy linux]#
    The ".config" File
    You next need to run scripts to create a kernel configuration file called
    /usr/src/linux/.config. This file lists all the kernel options you wish to use.
    132 Chapter 33: Modifying the Linux Kernel to Improve Performance
    Backup Your Configuration
    The .config file won't exist if you've never created a custom kernel on your system before,
    but fortunately, RedHat stores a number of default .config files in the
    /usr/src/linux/configs directory. You can automatically copy the .config file that
    matches your installed kernel by running the make oldconfig command in the
    /usr/src/linux directory.
    [root@bigboy tmp]# cd /usr/src/linux
    [root@bigboy linux]# ls .config
    ls: .config: No such file or directory
    [root@bigboy linux]# make oldconfig
    [root@bigboy linux]#
    If you've created a custom kernel before, the .config file that the previous custom kernel
    build used will already exist. Copy it to a safe location before proceeding.
    Customizing The ".config" File
    Table 33-2 lists three commands that you can run in the /usr/src/linux-2.6.5-1.358
    directory to update the .config file.
    Table 33-2 Scripts For Modifying The .config File
    Command Description
    make config Text based utility that prompts you line by line. This
    method can become laborious.
    make menuconfig Text menu based utility.
    make gconfig X-Windows based utility.
    Each command prompts you in different ways for each kernel option, each of which generally
    provides you with the three choices shown in Table 33-3. A brief description of each kernel option is
    given in Table 33-4. / Forums 133
    Table 33-3 Kernel Option Choices
    Kernel Option
    M The kernel will load the drivers for this option on an as needed
    basis. Only the code required to load the driver on demand will
    be included in the kernel.
    Y Include all the code for the drivers needed for this option into
    the kernel itself. This will generally make the kernel larger and
    slower but will make it more self sufficient. The "Y" option is
    frequently used in cases in which a stripped down kernel is one
    of the only programs Linux will run, such as purpose built home
    firewall appliances you can buy in a store.
    There is a limit to the overall size of a kernel. It will fail to
    compile if you select parameters that will make it too big.
    N Don't make the kernel support this option at all.
    134 Chapter 33: Modifying the Linux Kernel to Improve Performance
    Table 33-4 Kernel Configuration Options
    Option Description
    Code maturity level options Determines whether Linux prompts you for certain types of
    development code or drivers.
    Loadable module support Support for loadable modules versus a monolithic kernel. Most of
    the remaining kernel options use loadable modules by default. It is
    best to leave this alone in most cases.
    Processor type and features SMP, Large memory, BIOS and CPU type settings.
    General setup Support for power management, networking, and systems buses
    such as PCI, PCMCIA, EISA, ISA
    Memory technology devices Linux subsystem for memory devices, especially Flash devices
    Parallel port support Self explanatory
    Plug and Play configuration Support of the automatic new hardware detection method called
    plug and play
    Block devices Support for a number of parallel-port-based and ATAPI type
    devices. Support for your loopback interface and RAM disks can be
    found here too.
    Multidevice support (RAID, LVM) Support for RAID, 0, 1, and 5, as well as LVM.
    Cryptography support (CryptoAPI) Support for various types of encryption
    Networking options TCP/IP, DECnet, Appletalk, IPX, ATM/LANE
    Telephony support Support for voice to data I/O cards
    ATA/IDE/MFM/RLL support Support for a variety of disk controller chipsets
    SCSI support Support for a variety of disk controller chipsets. Also sets limits on
    the maximum number of supported SCSI disks and CDROMs.
    Fusion MPT support High speed SCSI chipset support.
    I2O device support Support for specialized Intelligent I/O cards
    Network device support Support for Ethernet, Fibre Channel, FDDI, SLIP, PPP, ARCnet,
    Token Ring, ATM, PCMCIA networking, and specialized WAN
    Amateur Radio support Support for packet radio
    IrDA subsystem support Infrared wireless network support
    ISDN subsystem Support for ISDN
    Old CD-ROM drivers (not SCSI, not
    Support for non-SCSI, non-IDE, non ATAPI CDROMs
    Input core support Keyboard, mouse, and joystick support in addition to the default
    VGA resolution.
    Character devices Support for virtual terminals and various serial cards for modems,
    joysticks and basic parallel port printing. / Forums 135
    Option Description
    Multimedia devices Streaming video and radio I/O card support
    Crypto Hardware support Web-based SSL hardware accelerator card support
    Console drivers Support for various console video cards
    Filesystems Support for all the various filesystems and strangely, the native
    languages supported by Linux.
    Sound Support for a variety of sound cards
    USB support Support for a variety of USB devices
    Additional device driver support Miscellaneous driver support
    Bluetooth support Support for a variety of Bluetooth devices
    Kernel hacking Support for detailed error messages for persons writing device
    Configure Dependencies
    As I mentioned before, the .config file you just created lists the options you'll need in your kernel.
    In version 2.4 of the kernel and older, the make dep command was needed at this step to prepare
    the needed source files for compiling. This step has been eliminated as of version 2.6 of the kernel.
    Edit The Makefile To Give The Kernel A Unique Name
    Edit the file Makefile and change the line "EXTRAVERSION =" to create a unique suffix at the
    end of the default name of the kernel.
    For example, if your current kernel version is 2.6.5-1.358, and your EXTRAVERSION is set to -6-
    new, your new additional kernel will have the name vmlinuz-2.6.5-6-new.
    Remember to change this for each new version of the kernel you create.
    Compile A New Kernel
    You can now use the make command to create a compressed version of your new kernel and its
    companion .img RAM disk file. This could take several hours on a 386 or 486 system. It will take
    about 20 minutes on a 400MHz Celeron running in text mode.
    [root@bigboy linux]# make
    [root@bigboy linux]#
    Note: In older versions of Fedora the command to do this would have been make bzImage.
    136 Chapter 33: Modifying the Linux Kernel to Improve Performance
    Build The Kernel's Modules
    You can now use the make modules_install command to copy all the modules created in the
    previous step to the conventional module locations.
    [root@bigboy linux]# make modules_install
    [root@bigboy linux]#
    Note: In versions of Fedora before Core 3, this was a two step process. The make modules
    command would compile the modules, but locate them within the Linux kernel source directory tree
    under the directory /usr/src/. The make modules_install command would then relocates
    them to where they should finally reside under the /lib/modules/
    Copy The New Kernel To The /boot Partition
    The kernel and the .img you just created needs to be copied to the /boot partition where all your
    systems active kernel files normally reside. This is done with the make install command.
    This partition has a default size of 100MB, which is enough to hold a number of kernels. You may
    have to delete some older kernels to create enough space.
    [root@bigboy linux]# make install
    [root@bigboy linux]#
    Here you can see that the new kernel vmlinuz-2.6.5-1.358-new is installed in the /boot
    [root@bigboy linux]# ls -l /boot/vmlinuz*
    lrwxrwxrwx 1 root root 22 Nov 28 01:20 /boot/vmlinuz -> vmlinuz-2.6.5-1.358-new
    -rw-r--r-- 1 root root 1122363 Feb 27 2003 /boot/vmlinuz-2.6.5-1.358
    -rw-r--r-- 1 root root 1122291 Nov 28 01:20 /boot/vmlinuz-2.6.5-1.358-new
    [root@bigboy linux]#
    Updating GRUB
    You should now update your /etc/grub.conf file to include an option to boot the new kernel. The
    make install command does this for you automatically.
    In this example, default is set to 1, which means the system boots the second kernel entry, which
    happens to be that of the original kernel 2.6.5-1.358. You can set this value to 0, which makes it boot
    your newly compiled kernel (the first entry).
    timeout=10 / Forums 137
    title Red Hat Linux (2.6.5-1.358-new)
    root (hd0,0)
    kernel /vmlinuz-2.6.5-1.358-new ro root=LABEL=/
    initrd /initrd-2.6.5-1.358-new.img
    title Red Hat Linux (2.6.5-1.35
    root (hd0,0)
    kernel /vmlinuz-2.6.5-1.358 ro root=LABEL=/
    initrd /initrd-2.6.5-1.358.img
    Kernel Crash Recovery
    Sometimes the new default kernel will fail to boot or work correctly with the new kernel. A simple
    way of recovering from this is to reboot your system, selecting the old version of the kernel from the
    Fedora splash screen. Once the system has booted with this stable version, edit the grub.conf
    file and set the default parameter to point to the older version instead. If this fails, you may want
    to boot from a CD with the original kernel. You can then try to either reinstall a good kernel RPM or
    rebuild the failed one over again after fixing the configuration problem that caused the trouble in the
    first place.

  6. #5
    I refuse to let fear and fear of others rule my life. It puts my humanity at risk.
    Accepting Death is the only way to stay alive.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts