Linux Kernel Compiling



Download 53.28 Kb.
Date28.01.2017
Size53.28 Kb.
#10228


Linux Kernel Compiling


  • What is the Kernel?

The kernel is the lowest functional level of Linux.

It is the part of Linux that is common for every distribution.

It is also the single part of Linux that Linus retains control over.

It is typically a single file (/vmlinuz or /boot/vmlinuz) plus any modules it loads (/lib/modules/).


  • Overview of version numbering system

Vmajor.stability.minor-patch_level

The stability value is even for a stable and odd for a development release.

Development releases are not for the faint of heart, they often break without warning!


V2.0.39 Old stable version.

V2.2.20 Previous stable version.

V2.4.18 Current stable version

V2.4.19-pre6 Current stable version pre release.

V2.5.8-pre3 Current development version.
The current kernel can be obtained by finger @ftp.kernel.org or finger @linux.cs.helsinki.fi | more.


  • Kernel version identification, within 5 lines of the top (dmesg | more).

It is also displayed during boot if you scroll back to read it on the first console.
Linux version 2.4.18 (root@Mitton) (gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)) #8 Mon Feb 25 18:55:06 EST 2002


  • Linux distributions.

Do not confuse the Kernel version numbering with the distribution numbering.

Mandrake 6.0

Slackware 4.0

Slackware 8.0

Mandrake 8.1

Debian 2.2r6 (Potato)


  • What will be covered

- Generic kernel compiling and any “gotchas” to look out for.

- Differences between Slackware and RedHat/Mandrake.

- Some example configuration files that I use (LILO, etc.).




  • What will NOT be covered

- Details of any particular kernel option, help is available for each.

- Details of module usage. Compiling only will be covered.

- Rescue or Repair operations if the new kernel doesn't work, back ups will be emphasised.

- Since I have no experience with other distributions I will not cover those; only Slackware and Mandrake.

PreRequisites


  • Must have ROOT access to install a kernel




  • Development Environment Installed




  • Source Tree Installed




  • Sufficient Hard Drive Space

  • for source tree and compiled objects

  • V2.4.18 source required 162 Meg, 13 Meg for compiled objects and 3 Meg for modules. (178 Meg total)

(It took 50 minutes on my AMD K6-2 450 to compile completely.)


  • Linux Boot Method (which you understand)

  • I.e. LILO, LoadLin, Floppy (Boot and/or Rescue), bootable CD, DOS floppy or LoadLin

  • It can actually be a combination for normal and emergency use.




  • Know WHY you want to compile the kernel.

  • All distributions come with a working kernel.

  • If you installed OK and started up Linux you have a working kernel.

  • A major kernel upgrade (i.e. V2.2.x to V2.4.x) can make your system unusable if you don’t update the required applications, utilities and libraries first. Always read the new /usr/src/linux/Documentation/Changes file (as well as the others) for details on the new kernel version.


Why?

  • Customise/simplify/compact/speed-up/cleanup of a kernel.

  • Utilise new or development hardware or features.

  • Install third-party drivers and patches.

  • Update a kernel (patches or install a whole new source tree)


Why Not?

  • If you utilise the RedHat/Mandrake GUI configuration features for new hardware:

  • Use the RPM method of kernel upgrade.

  • Unless you compile all the modules in the correct configuration the GUI utilities may not work properly.




  • RedHat/Mandrake uses a LOT of modules. If you decide to re-compile anyway:

  • Use "lsmod" to get a list so you know what to re-compile.

(i.e. sound, network card, ppp, modem, etc.)

  • If you don't re-compile ALL the modules, "linuxconf" will not be as useful as it is now.



Note!


  • For distribution like Mandrake which supply a customised kernel make sure you obtain the original /usr/src/linux/.config file to maintain compatibility. It is usually found in:

/usr/share/doc/kernel-2.4.8/kernel-2.4.8-26mdk-i586.config

(The cooker version put it in the normal /usr/src/linux/.config location though.)




  • Some of the How-To’s are quite dated and often tell you to re-compile the kernel. Major distributions like Mandrake now include many of the added kernel functionality pre-compiled. In particular the ide-scsi functionality to allow IDE CD-RW’s to be used has been included in the last few Mandrake distributions.


Overview


  1. Make sure of the pre-requisites.




  1. Make a backup copy of your "old" kernel source tree prior to updating (if required).

(Also make a backup copy of your modules, if you are simply re-compiling the old kernel.)


  1. Install kernel source tree (if required).




  1. Apply patches (if required)




  1. Configure/Customise the kernel; one of the following.

make config, make menuconfig, make xconfig or make oldconfig






  1. Compile the kernel and modules.

make dep ; make clean ; make bzImage ; make modules ; make modules_install


  1. Make a backup copy of the old kernel image.




  1. Make the new kernel bootable (via lilo, loadlin, floppy, etc)




  1. Reboot the computer to activate the new kernel.




  1. House clean your computer once the new kernel is proven. Boot floppy, source, modules, etc.




  1. Enjoy your customised system.


Details
Note: You must be logged in as ROOT to perform most of these operations.

These steps must be followed in order so that you are in the correct directory for each step.

You are not re-compiling an old kernel but installing and compiling a new or updated one.
Mandrake: On a Mandrake system the boot files are in the /boot/ directory instead of in “/”.

Beware that the non-standard mandrake source tree may break standard kernel patches.




  1. Make copy of "old" linux to New Linux; this is so you can back up if things don't work out (if required).

cd /usr/src

cp -av linux-old linux-new

rm linux (Remove old symbolic link.)

ln -s linux-new linux (Create new linux symbolic link.)


  1. Install full source tree (if required)



cp linux-x.y.z.tar.gz /usr/src

cd /usr/src

gzip linux-x.y.z.tar.gz

tar -xvf linux-x.y.z.tar

ln -s linux-x.y.z linux (If required.)


  1. Apply patches (if required), patch should be in /usr/src, a copy in /usr/src/linux-new.

Remember, if applying multiple patches, they must be installed in order.

gzip -cd patch-x.y.z.gz | patch -p0


  1. Configure the new kernel via XConfig; this is more graphic and shows dependencies better than pure text.

cd linux

startx





make xconfig










  1. Compile the kernel; on my AMD K6-2 450 with version 2.4.18 this takes 30 min for the kernel and 20 min for the modules, depending on options.

make dep ; make clean ; make bzImage ; make modules ; make modules_install




  1. Make a backup copy of the old kernel.

Make sure that /etc/lilo.conf has a "Linux" and "Old" section. Just in case the new kernel doesn't work.

cd /usr/src/linux/arch/i386/boot/

cp /vmlinuz /vmlinuz.old [Different name and location for standard Mandrake.]

cp bzImage /vmlinuz [Different name and location for standard Mandrake.]


  1. Make the new kernel bootable; (you could always just make a boot floppy as well)

(This assumes /etc/lilo.conf is already configured.)

lilo




  1. Log out of all windows and re-boot the system ... Ctrl-Alt-Del




  1. Verify the new kernel boots and is the correct version.




  1. If the new kernel doesn’t boot here is how you boot using the old (previous) version. This only works in this manner if you have preserved your old kernel and have an entry for it in /etc/lilo.conf as it is in the enclosed examples.

- prompt LILO

- press (Must be completed before ‘delay’ expires.)

- prompt LILO boot:

- press

- prompt LILO boot:

Linux Old DOS (If my /etc/lilo.conf example is used.)

boot:

- press old




  1. Once you are sure the new kernel is ok: (This is optional cleanup.)

  • Remove the old kernel (if required)

cd /usr/src

rm -r linux-

  • Clean up and conserve space in the new kernel

cd /usr/src/linux

make dep ; make clean

  • Remove the installed patch file (if required)

cd /usr/src

rm patch-x.y.z.gz

  • Remove the old source archive (if required)

cd /usr/src

rm linux-x.y.z.tar

  • Remove the old modules (if required)

cd /lib/modules

rm –r x.y.z.old

  • Copy the new kernel to the LoadLin location (hard drive or floppy drive) for emergency use.

  • Make a new emergency boot floppy(?):

  • Start with a DOS (?) formatted floppy.

(Only do this after ‘lilo’ has been successfully run on /vmlinuz.)

fdformat /dev/fd0h1440

dd if=/vmlinuz of=/dev/fd0

Boot Disk



  • Compile a kernel with required support

- Network card, RAMDisk, etc.


  • Copy kernel to new floppy

This will boot whichever root device was configured when lilo was run without any ‘rdev’ changes.

- 'fdformat /dev/fd0h1440' (format the floppy disk)

- 'dd if=/vmlinuz of=/dev/fd0' (copy the image from hard drive to floppy)


  • Set default video mode (vga=mode); this is my preference, 132x43 console (not required, optional)

- ‘rdev –v /dev/fd0 8’


  • Configure new floppy to boot the floppy and use a RAMDisk (Only for Boot/Root disks)

- 'rdev /dev/fd0 /dev/fd0' (look for root on floppy)

- 'rdev -r /dev/fd0 49152' (turn on RamDisk support)

- 'rdev -R /dev/fd0 0' (make RamDisk root read/write)


  • Write protect floppy (just a safety precaution)



Root Disk




  • Use an existing Slackware Root disk.

- 'color.gz' or 'rescue.gz'
The Boot/Root disk idea is a Slackware convention BUT is very handy as it provides an emergency Linux system that runs out of a ram disk instead of from a floppy or hard drive. This has some great applications such as the Linux Router Project.

Bootable CD

All the newer distributions come on bootable CD’s which offer more than enough emergency repair and boot options. Just boot the CD and select the Rescue option or continue the process to the first installation screen and switch to another virtual console and use the rescue options manually.


If you are offered a LILO prompt at the first stage of the boot process you can provide an alternate root filesystem to allow access to a previously installed Linux that has lost its ability to boot normally then repair it. It is usually something like:

LILO: linux root=/dev/hda2 single



Windows/Dos LoadLin

The Windows harddrive partition or a DOS bootable floppy can be used as an emergency boot option as well. Just create a linux directory on the device and include the following files from the distribution CD and/or your installed Linux:

[dmitton@Portable dmitton]$ ls -l /mnt/windows/linux/

-rwxrwxrwx 1 root root 137 Jan 30 18:06 linux.bat*

-rwxrwxrwx 1 root root 32177 Jan 30 17:41 loadlin.exe*

-rwxrwxrwx 1 root root 665029 Jan 30 17:42 vmlinuz*


The linux.bat file looks like this:

[dmitton@Portable dmitton]$ cat /mnt/windows/linux/linux.bat

c:\linux\loadlin c:\linux\vmlinuz root=/dev/hda2 ro vga=788
Slackware LILO Configuration
<12>root:~# cat /etc/lilo.conf

# LILO configuration file

# Start LILO global section

boot = /dev/hda

linear

delay = 150



ramdisk = 0 # paranoia setting

lba32


password=xxxxx

restricted

# End LILO global section

# Linux bootable partition config begins

image = /vmlinuz

root = /dev/hdb1

label = Linux

vga = 8 # force sane state

read-only # Non-UMSDOS filesystems should be mounted read-only for checking

# Linux bootable partition config ends

# Linux alternate bootable partition config begins

image = /vmlinuz.old

root = /dev/hdb1

label = Old

vga = 8 # force sane state

read-only # Non-UMSDOS filesystems should be mounted read-only for checking

# Linux bootable partition config ends



# DOS bootable partition config begins

other = /dev/hda1

label = DOS

table = /dev/hda

# DOS bootable partition config ends
Mandrake LILO Configuration
<12>root:~# cat /etc/lilo.conf

# LILO configuration file

# Start LILO global section

boot = /dev/hda

linear

delay = 150



ramdisk = 0 # paranoia setting

lba32


password=xxxxx

restricted

# End LILO global section

# Linux bootable partition config begins

image = /boot/vmlinuz

root = /dev/hdb1

label = Linux

vga = 8 # force sane state

read-only # Non-UMSDOS filesystems should be mounted read-only for checking

# Linux bootable partition config ends

# Linux alternate bootable partition config begins

image = /boot/vmlinuz.old

root = /dev/hdb1

label = Old

vga = 8 # force sane state

read-only # Non-UMSDOS filesystems should be mounted read-only for checking

# Linux bootable partition config ends



# DOS bootable partition config begins

other = /dev/hda1

label = DOS

table = /dev/hda

# DOS bootable partition config ends


Kingston Linux Users Group (KLUG)

May 2002





Download 53.28 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page