OSDN: Open Source Development NetworkNewsletters - Jobs - US Disaster Support SEARCH:   
LiNUX.COM Linux.com Live! presents: Installfest Week; October 22 - 26
homelearnenhancedevelopinteractopinion
Depth Gauge: Linux.com :: Learn :: HOWTOs
Monday October 15th, 2001 - Printable :: About
Search Our Site

OSDN Advertisement

Cool Tools
hardware jobs howtos tuneup lugs links

Comments

User Account
username:

password:

Community Ad

The Linux Kernel HOWTO: Quick Steps - Kernel Compile

Next Previous Contents


2. Quick Steps - Kernel Compile

This section is written by Al Dev (alavoor@yahoo.com)

The latest version of this section is at http://www.aldev.8m.com and click on "Quick Steps to recompile linux kernel". Mirror sites are at - http://aldev0.webjump.com, angelfire, geocities, virtualave, 50megs, theglobe, NBCi, Terrashare, Fortunecity, Freewebsites, Tripod, Spree, Escalix, Httpcity, Freeservers.

These sites have lots of linux goodies and tips.

Kernel re-compile is required in order to make the kernel very lean and which will result in FASTER operating system . It is also required to support any new devices. Note: Below 'bash#' denotes the bash prompt, you should type the commands that appear after the 'bash#' prompt. Below are commands tested on Redhat Linux, but it should work for other distributions with very minor changes.

  1. Note: You can have many kernel images on your system. By following the steps below you do not overwrite or damage your existing kernel. These steps are very safe and your current kernel will be intact and will not be touched.

  2. Login in as 'root' throughout all these steps. Mount Redhat linux cdrom and install the linux kernel source rpm
    bash$ su - root
    bash# cd /mnt/cdrom/RedHat/RPMS 
    bash# rpm -i    kernel-headers*.rpm 
    bash# rpm -i    kernel-source*.rpm 
    bash# rpm -i dev86*.rpm   
    bash# rpm -i bin86*.rpm   
    

    (The bin86*.rpm and 'as86' is required only for OLDER Linux systems like redhat 5.x. Get Intel assembler 'as86' command from dev86*.rpm on cdrom or from bin86-mandrake , bin86-kondara ).

    • Start X-windows with 'startx'. If you are not able to start X-window then see next step below.
              bash# man startx
              bash# startx
              bash# cd /usr/src/linux 
              bash# make xconfig 
      

    • If you are not able to start X-window above then try -
              bash# make menuconfig
      If the above command fails then try -
              bash# make config
      

    The "make xconfig" or "make menuconfig" brings up a user friendly GUI interface. You can load the configuration file from /usr/src/linux/.config (dot config file. Note the dot before config).

  3. Within 'make xconfig' you must do these to avoid problems -
    • Select proper CPU type - Pentium 3, AMD K6, Cyrix, Pentium 4, Intel 386, DEC Alpha, PowerPC otherwise kernel will not boot!!
    • Select SMP support - whether single CPU or multiple CPUs
    • Filesystems - Select Windows95 Vfat, MSDOS, NTFS as part of kernel and not as loadable modules.
    • Enable the Loadable kernel modules support! With this option you can load/unload the device drivers dynamically on running linux system on the fly. See these man pages
      bash# rpm -i /mnt/cdrom/Redhat/RPMS/modutils*.rpm
      bash# man lsmod
      bash# man insmod
      bash# man rmmod
      bash# man depmod
      bash# man modprobe
      

  4. Save and Exit "make xconfig". All the options which you selected is now saved into configuration file at /usr/src/linux/.config (dot config file). And now, do -
    bash# make dep
    bash# make clean
    

  5. Read the following file (to gain some knowledge about kernel building. Tip: Use the color editor gvim for better readability.
    bash# gvim -R   /usr/src/linux/arch/i386/config.in 
    bash# man less 
    bash# less   /usr/src/linux/arch/i386/config.in 
    Type 'h' for help and to navigate press i, j, k, l, h or arrow, page up/down keys. 
    

  6. Now, give the make command -
            bash# cd /usr/src/linux
            bash# man nohup
            bash# nohup make bzImage &  
            bash# tail -f nohup.out     (.... to monitor the progress) 
    This will put the kernel in /usr/src/linux/arch/i386/boot/bzImage 
            bash# man tail 
    

  7. After bzImage is successful, copy the kernel image to /boot directory. You must copy the new kernel image to /boot directory, otherwise the new kernel MAY NOT boot. And then read the manual page on lilo (see also http://www.linuxdoc.org/HOWTO/LILO-crash-rescue-HOWTO.html) and see the sample lilo.conf file. Always give a date extension to the filename, because it tells you when you built the kernel, as shown below:
    bash# cp /usr/src/linux/arch/i386/boot/bzImage     /boot/bzImage.myker.26mar2001
    bash# man lilo
    bash# man lilo.conf
    And edit /etc/lilo.conf file and put these lines - 
            image=/boot/bzImage.myker.26mar2001 
            label=myker
            root=/dev/hda1 
            read-only 
    You can check device name for 'root=' with the command - 
            bash# df   / 
    

  8. Now give
    bash# lilo 
    bash# lilo -q 
    

    You must re-run lilo even if entry 'myker' exists, everytime you create a new bzImage.

  9. Reboot the machine and at lilo press tab key and type 'myker' If it boots then you did a good job! Otherwise at lilo select your old kernel, boot and re-try all over again. Your old kernel is still INTACT and SAFE at say /boot/vmlinuz-2.0.34-0.6

  10. If your new kernel 'myker' boots and works properly, you can create the boot disk. Insert a blank floppy into floppy drive and -
    bash# cd /usr/src/linux
    bash# make bzdisk
    See also mkbootdisk -
    bash# rpm -i mkbootdisk*.rpm
    bash# man mkbootdisk
    

  11. LOADABLE MODULES: This step is required ONLY if you had enabled Loadable module support in step 3 above. Loadable module are located in /lib/modules. You MUST do this step if you enabled or disabled any modules, otherwise you will get 'unresolved symbols' errors during or after kernel boot. Check for insmod command which is extensively used for loading the modules.
    bash# cd /usr/src/linux
    bash# make modules
    bash# make modules_install
    bash# man insmod
    bash# insmod 
    

    This will copy the modules to /lib/modules directory.

2.1 Troublshoot Common Mistakes

No init found

The following mistake is commited very frequently by new users.

If your new kernel does not boot and you get -


Warning: unable to open an initial console
Kernel panic: no init found. Try passing init= option to kernel

The problem is that you did not set the "root=" parameter properly in the /etc/lilo.conf. In my case, I used root=/dev/hda1 which is having the root partition "/". You must properly point the root device in your lilo.conf, it can be like /dev/hdb2 or /dev/hda7.

The kernel looks for the init command which is located in /sbin/init. And /sbin directory lives on the root partition. For details see -


bash# man init

Kernel does not load module - Unresolved symbol error messages

When you boot kernel and system tries to load any modules and you get "Unresolved symbol : __some_function_name" then it means that you did not clean compile the modules and kernel. It is mandatory that you should do make clean and make the modules. Do this -


        bash# cd /usr/src/linux
        bash# make dep
        bash# make clean
        bash# nohup make bzImage &  
        bash# tail -f nohup.out     (.... to monitor the progress) 
        bash# make modules
        bash# make modules_install

Kernel fails to load a module

If the kernel fails to load a module (say loadable module for network card or other devices), then you may want to try to build the driver for device right into the kernel. Sometimes loadable module will NOT work and the driver needs to be built right inside the kernel. For example - some network cards do not support loadable module feature - you MUST build the driver of the network card right into linux kernel. Hence, in 'make xconfig' you MUST not select loadable module for this device.

Loadable modules

You can install default loadable modules with -

The step given below may not be required but is needed ONLY FOR EMERGENCIES where your /lib/modules files are damaged. If you already have the /lib/modules directory and in case you want replace them use the --force to replace the package and select appropriate cpu architecture.

For new versions of linux redhat linux 6.0 and later, the kernel modules are included with kernel-2.2*.rpm. Install the loadable modules and the kernel with


        This will list the already installed package.
bash# rpm -qa | grep -i kernel
        
bash# rpm -U --force  /mnt/cdrom/Redhat/RPMS/kernel-2.2.14-5.0.i686.rpm
(or)
bash# rpm -U --force  /mnt/cdrom/Redhat/RPMS/kernel-2.2.14-5.0.i586.rpm
(or)
bash# rpm -U --force  /mnt/cdrom/Redhat/RPMS/kernel-2.2.14-5.0.i386.rpm

This is only for old versions of redhat linux 5.2 and before. Boot new kernel and install the loadable modules from RedHat Linux "contrib" cdrom


bash# rpm -i /mnt/cdrom/contrib/kernel-modules*.rpm 
....(For old linux systems which do not have insmod pre-installed) 

2.2 Post Kernel Building

After successfully building and booting the Linux kernel, you may be required to do these additional steps to make some of the devices to work with Linux. (The steps below were tested on Redhat Linux but should work with other distributions as well.)

Video card/Monitor configuration:

  • Please see the video card manual which is usually shipped with the PC. You should look for a "Technical Specifications" page.
  • Please see the monitor's manual and look for a "Technical Specifications" page.
You can configure the Video card and monitor by using these commands:
bash$ su - root
bash# man Xconfigurator
bash# /usr/bin/X11/Xconfigurator --help
bash# /usr/bin/X11/Xconfigurator 
bash# /usr/bin/X11/Xconfigurator --expert

If your card is not detected automatically, then you can use the --expert option and select the "Unlisted card". If your monitor is not listed then select the generic monitor type SVGA 1024x768.

Sound card configuration:

  • Connect your external speakers to the sound card's audio port.
  • Connect your CDROM audio wire to sound card's audio 4-pin socket. (Otherwise your cdrom drive will not play the music from your music cd)
  • Refer to HOWTO docs on 'Sound' at http://www.linuxdoc.org

bash$ su - root
bash# man sndconfig
bash# /usr/sbin/sndconfig

Then start X-window 'KDE desktop' with 'startx' command. Click on 'K Start->ControlCenter->SoundServer->General->Test Sound'. This should play the test sound. Then click on 'K Start->MultiMedia->SoundMixer->SoundVolumeSlider' and adjust the sound volume.

Network card configuration:

Configure Firewall and IP Masquerading : For Linux kernel version 2.4 and above, the firewall and IP Masquerading is implemented by NetFilter package. Hence in kernel config you should enable Netfilter and run the Firewall/IPMasq script. Download the scripts from Firewall-IPMasq scripts , main page of Netfilter is at http://netfilter.samba.org. Related materials at firewalling-matures and Netfilter-FAQ.

For kernel version below 2.4 you should install the firewall rpms from rpmfind.net or firewall.src.rpm.

Configuration of other devices: Refer to HOWTO docs relating to your devices at http://www.linuxdoc.org

2.3 Sample lilo.conf

Given below is a sample /etc/lilo.conf file. You should follow the naming conventions like ker2217 (for kernel 2.2.17), ker2214 (for kernel 2.2.14). You can have many kernel images on the same /boot system. On my machine I have something like:


boot=/dev/hda
map=/boot/map
install=/boot/boot.b
prompt
timeout=50
default=firewall

image=/boot/vmlinuz-2.2.14-5.0
        label=ker2214
        read-only
        root=/dev/hda9

image=/boot/vmlinuz-2.2.17-14
        label=ker2217
        read-only
        root=/dev/hda9

#image=/usr/src/linux/arch/i386/boot/bzImage 
#       label=myker 
#       root=/dev/hda7
#       read-only 

image=/boot/bzImage.myker.11feb2001
        label=myker11feb 
        root=/dev/hda9
        read-only 

image=/boot/bzImage.myker.01jan2001
        label=myker01jan 
        root=/dev/hda9
        read-only 

image=/boot/bzImage.myker-firewall.16mar2001
        label=firewall 
        root=/dev/hda9
        read-only 


Next Previous Contents

Your Comments

Comment by RAYMUNDO LEON - 2001-09-15 12:29:31

i have an armada 1700 de compaq and the problem is: i have sound as follow #depmod -a #modprobe sound #modprobe sb io=0x220 irq=5 dma=5 dma16=5 with that i have sound but, when the computer restart, the configuration is lost.

how to get source code of command on redhat
Comment by gupta - 2001-09-07 19:26:01

I am looking if any body can tell the steps involving in getting the source code of command on redhat Thanks in advance

Saviour Has Descended!
Comment by hansk - 2001-08-13 21:56:30

And it is called bzdisk! For all you kernel newbies out there, use the "make bzdisk" instead the normal bzImage. It really can save your day :).

SB Live
Comment by Commy Killer - 2001-08-10 14:07:17

How can I make my soundcard make sound. I have a Soundblaster Live and running under corel linux First Edition.

startx
Comment by pungency - 2001-08-09 14:39:20

I cant get startx to start! at login i get a promp and i login. then i get another promp [pungency@localhost pungency]$ so i type startx then i thank my screen flashes but anyhow i get this msg. fatal server error: no screens found X connetion to :0.0 broken umm i wonder why? i try Xconfigurator but i dont get anyweres on that neather. keeps crashing. this is what i know. i have a Nvidia Riva TnT2 model 64 monator. video card i dont know and dont know how to find out. ok here is the confusig part also i have linux 6.5 mandeake on drive D: with lilo boot and windows 200 pro. on drive C:. Now, if i just install linux and NO windows it all works fine. i dont even see the login screen. im haveing a hard time with this. if anyone knows what is wrong or thank thay can help me. dont feel shy. let me know what you thank is wrong with this problum i am haveing. thank you the linux team user's who comes here. tell next time. this is pungency

to NEWBIES!! important!!!!
Comment by octahexxer - 2001-08-07 09:20:39

the ´linux´folder is not a real folder its just a symbolic link,and you must rename your source folder that you get after untaring your kernel,rename it from linux to linux-x.x.x replace x with the version of kernel. the delete the 'linux' folder in the /usr/src and copy your new linux-x.x.x folder to yoru /usr/src then use 'ln -sv linux-x.x.x linux' (note* this works under Redhat i cant say how other distros work) THIS INFO is left out in all the howtos ive read so far!!!!

PPP probs
Comment by David - 2001-08-05 23:35:08

I have ppp built into the kernel and at boot up it says ppp is part of the kernel but it still complains of ppp not supported. And yes I am booting the right kernel.

make modules
Comment by Anonymous - 2001-07-31 23:30:52

There should really be a more than a passing reference to 'make modules' and 'make modules_install' here.

Having trouble compiling Kernel 2.3.9 on Redhat 7.0

I have a really old Kernel and I use Redhat 7.0, I want to install the kernel 2.3.9 and so i did this:

cd /usr/src

tar -zxvf linux-2.3.9

cd linux; make menuconfig

make dep

Now here is where my instuction's say that Redhat 7.0 needs to use the make bimage like this:

make CC=kgcc bzImage

but it says no such command as kgcc so I compile like normal

make bzImage

make[2] ***checksum.o ERRROR 1 Leaving yadayada

ERRORS NOOOOO! and above those lines i says checksum.S:235 badly punctuated parameter list in #define and checksum.S:241 badly punctuated parameter list in #define HELP me plz fix this problem email me at haxor_servers_ceo@hotmail.com

PPP not working now
Comment by Anonymous - 2001-07-17 07:39:22

I moved from a 2.2.14 kernel to a 2.4.5 kernel. Everything works great except for the fact that Ksaferppp and Minicom tell me that my kernel doesnt support PPP connections. Any idea what could be wrong?

/scsi/ppa.o or /scsi/imm.o
Comment by Ming - 2001-06-29 12:58:52

Every time is /sbin/insmod /lib/modules/2.2.16/scsi/ppa.o or imm.o. I always get this message. I got a new kernel installed and compiled. This is the message it said, this error can be caused by incorrect module parameters, including invalid IO or IRQ parameters. I need to get this working so i can use my zip drive to do files copying. I did insmod parport.o , parport_pc.o, parport_probe.o. what should i do now? I tried to play around with IO or IRQ. but I wasn't sure what my IO or IRQ is? So i am kinda stuck please help

system hanging
Comment by really_mad - 2001-04-22 10:03:50

After compiling the new kernel, i get the 'uncompresing kernel...OK' text and then nothing happens, the system just hangs and i have to reboot it. any ideas!?

Patch files
Comment by Annon - 2001-04-22 09:50:10

when downloading the patch files, none of them could be read, are they currupt!? i tried downloading them in Windows becasue the whole reason im upgrading my kernel is to get the modem working!!!!!!!!!!!!

invalid compression format
Comment by Neil West - 2001-03-24 10:15:00

I recompiled the Kernel and used the make bzdisk and I get an error saying invalid compression format when I insert the disk and reboot. Any ideas. LEPP

bash
Comment by Anonymous - 2001-03-07 15:01:21

I wrote the following: r105152:/usr/src/linux # make xconfig Got: make: *** No rule to make target `xconfig'. Stop. What am I doing wrong?

newbie questions
Comment by newbie - 2001-02-15 20:47:44

I have a couple of questions that I think this HOWTO should address:

How does lilo deal with the bootsector? Does it generate it by looking at vmlinuz or does it get it from /boot? Do I have to manually copy bbootsect.b to /boot/boot.b before running lilo?

What about the map file? What is it, what does it do? I believe it has to be manually copied to /boot and referenced in lilo.conf before running lilo?

Does lilo backup the current kernel, or do I have to do it manually? Does lilo backup any files when it is run and what are they?

What are the other files in arch/i386/boot for? Such as, bbootsect, bsetup, Makefile, and install.sh? Can I use these to install the kernel?

What are all the files in /boot for? Such as boot.b, chain.b, mbr.b, etc.?

Debugging the Kernel and Modules ?

How about a chapter on setting up to debug the kernel and loadable modules ? What tools are available ?

Please share a comment:

You are posting anonymously. Create an account.

Name (optional):

Subject:

Comment:

Allowed tags in comment body: B BR I P U

convert newlines to <BR> tags

Please note that comments are moderated. This is done by a volunteer staff. In other words, not all comments will actually be posted here. All of your comments are appreciated though, so please contribute a comment and we will try to post as many as possible.

Please also note that your comment may be displayed alongside your name, email address and url, as supplied on your account details.