# [FAQF] KC: Kernel Compilation

## rac

This thread is to collect information for the Kernel Compilation section of the new FAQ forum.  Feel free to add answers to any of the questions here, or submit new questions that you think should be included in the Kernel Compilation section.  Here are some questions to get us started:

Q1. I made a mistake compiling my kernel and now my computer won't boot. What can I do now?

Q2. What is devfs?  Do I really need it in my kernel?  How do I enable it?

Q3. Networking worked during installation, but now that I compiled my own kernel, it doesn't work anymore. What's wrong?

Q4. I compiled a new kernel, but my changes aren't taking effect.  How do I install my new kernel?

Q5. I get errors about unresolved symbols when I'm compiling my kernel.  How do I get rid of them?

Q6. Which of the various kernel sources (gentoo-sources, vanilla-sources, etc.) are right for me?

Q7. How do I know when to compile something into the kernel, and when should I compile it as a module?

Q8. How do I install a new kernel while still keeping my current one around so that I can use it if necessary?

Q9. How do I install multiple kernel versions alongside one another without causing problems?

Q10. I'm upgrading my kernel sources.  Can I use my old configuration?  If so, how?

Q11. I've never compiled a kernel before and I'm totally lost.  Are there any good guides?  How do I get information about what all these options mean?

Q12.  I've changed some hardware in my computer.  What changes do I need to make to my kernel?

Q13. I just installed a new kernel and now I'm getting a panic at boot time trying to mount the root partition.  How do I fix this?

Q14. Why isn't the kernel being compiled with the CFLAGS that I set in /etc/make.conf?

Q15. I just compiled a new kernel and now my computer reboots instantly at startup.  Why and how do I fix it?

NOTE: Questions that are links have candidate answers already in their own threads.

----------

## yokem55

Q7. How do I know when to compile something into the kernel, and when should I compile it as a module?

First of all, if the option is required to boot the system, then it needs be compiled into the kernel.  This includes drivers for your ide or scsi controller and the filesystem driver for your root filesystem.  If these options are not built into the kernel, then the kernel can't access your hard drives to continue booting the system.  Other options that *should* be compiled into the kernel include acpi or apm support (you cannot have both in the kernel at the same time).  Pretty much everything else that can be compiled as a module can be used as a module without much problem.

----------

## rbacon2

Q8. How do I install a new kernel while still keeping my current one around so that I can use it if necessary? 

Once your new kernel is compiled, rename your current one to something snappy like bzImage_old then copy your new one from the source tree to the boot partition.

open /boot/grub/grub.conf or /boot/grub/menu.lst for editing and add a section for your old kernel.

That's it at the next power up you'll be able to choose the kernel you need.

----------

## rbacon2

Q10. I'm upgrading my kernel sources. Can I use my old configuration? If so, how? 

In /usr/src/linux you'll find the configuration file stored as .config, copy this to the new source tree before running your chosen kernel config.

Run through all the kernel sections anyway as there may be more suitable selections in your new sources, but most of the work will already be done.

----------

## rac

Thanks a lot to everybody who has participated so far.  This was much more much sooner than expected.  A couple of general comments: please address only one question per post.  Eventually, once these posts are formatted and finished, they will be split into their own threads in the FAQ forum, and having multiple questions in a single post makes that more complicated.

Although focusing on GRUB is understandable and reasonable, I think it would be good if we could incorporate a few comments for people who are using other bootloaders, such as LILO and yaboot (those are the only others I've seen mention of on the forums - the Sparc and Alpha people might be using something else).

@rbacon2, it might be nice to make some mention of the "oldconfig" target and its function in the answer to Q10.

EDIT: yokem55's first answer to Q1 has been split.  See first post.

----------

## rac

phypor, for KC8 and KC9, can you add some stuff about how /lib/modules directories work, and potential pitfalls of having things conflicting in there?

----------

## _SkeLeToN_

 *Quote:*   

> Q9. How do I install multiple kernel versions alongside one another without causing problems? 

 

Also what about the /usr/src/linux link ??? when you have multiple kernel you need to change the link if you want for exemple include sound support with alsa for this specific kernel.  A way to change that automaticaly ???

----------

## ebrostig

 *_SkeLeToN_ wrote:*   

>  *Quote:*   Q9. How do I install multiple kernel versions alongside one another without causing problems?  
> 
> Also what about the /usr/src/linux link ??? when you have multiple kernel you need to change the link if you want for exemple include sound support with alsa for this specific kernel.  A way to change that automaticaly ???

 

I can't get this to make sense.

I guess you refer to the symlink between /usr/src/linux/include/linux (or asm-i386) and /usr/include/linux (or asm). This is only needed when compiling programs that needs version specific header files. This can be taken care of through an rc script (etc/conf.d/local.start).

For some reason (I can't remember why any longer, been using Linux too long) I have always named my kernels:

vmlinuz-2.4.19, vmlinuz-2.5.50 and so forth. This makes it easy to have multiple kernels and I now instantly which kernel version it is  :Smile: 

Erik

----------

## rac

I think Skeleton is talking about the fact that some kernel module ebuilds (alsa, nvidia-kernel, lm-sensors) rely on /usr/src/linux pointing to the sources for the kernel to build with, and if that points to different sources than you're running, bad things happen.

----------

## pilla

 Q13. I just installed a new kernel and now I'm getting a panic at boot time trying to mount the root partition. How do I fix this? 

First, you'll need to boot again using a previous kernel backup (or the installation CD, if you haven't made a backup of your kernel).  Then, you must verify if your kernel configuration has the correct file system for your root partition. For example, if your / file system is ext3, you need to activate it in File Systems->Ext3 journalling file system support. Make sure it is not compiled as a module but inside the kernel. Compile your kernel again and install it following the regular instructions.

----------

## pilla

I think that this is the most usual situation, but I may be wrong. I didn't want to make it overly complex, so I kept it very basic. If you think it is not enough, I can try to be more comprehensive.

 *Bloody Bastard wrote:*   

>  Q13. I just installed a new kernel and now I'm getting a panic at boot time trying to mount the root partition. How do I fix this? 
> 
> First, you'll need to boot again using a previous kernel backup (or the installation CD, if you haven't made a backup of your kernel).  Then, you must verify if your kernel configuration has the correct file system for your root partition. For example, if your / file system is ext3, you need to activate it in File Systems->Ext3 journalling file system support. Make sure it is not compiled as a module but inside the kernel. Compile your kernel again and install it following the regular instructions.

 

----------

## pilla

Q12. I've changed some hardware in my computer. What changes do I need to make to my kernel?

You may disable support for hardware that you don't have anymore and enable support for the new hardware.  Keep a backup of your kernel configuration (.config), so you can compare to your new configuration if any problems arise.

----------

## phypor

 *rac wrote:*   

> phypor, for KC8 and KC9, can you add some stuff about how /lib/modules directories work, and potential pitfalls of having things conflicting in there?

 

Couldn't think of any obvious pitfalls...

but then I don't have many different kernel versions on the same system either so my experience is limited.  I did get this tho:

KC16. What is /lib/modules and how is it used?

This applies only if you use kernel modules.

/lib/modules contains subdirectories for each current kernel version you have installed.

/lib/modules/2.4.19-gentoo-r7

/lib/modules/2.4.19-gentoo-r9

/lib/modules/2.4.19-vanilla

On boot /etc/init.d/modules calls /usr/sbin/update-modules which gentoo's

packages use for most modules.  /etc/modules.autoload can be used by you to handle

any modules you need to load on boot.  For instance, I have NVdriver there for

nvidia's video card module.

----------

## rac

 *phypor wrote:*   

> Couldn't think of any obvious pitfalls...

 If you have two kernels from the same source, but with different configs, they will share a directory in /lib/modules, which can hose things, making the "backup" kernel unbootable.  Possible solutions include stashing /lib/modules stuff somewhere, changing the kernel version string in the source tree temporarily, etc.  None of this matters when having kernels with different versions, but sometimes people try new configuration settings, but want to have a fallback, but they're using the same kernel version, and the fallback fails.

----------

## pilla

But critical hardware support necessary to boot is usually inside the kernel (at least for Gentoo, has somebody found mkinitrd somewhere?).  I think that the sollution for this problem should be resolved by the ebuild that installed the sources.

 *rac wrote:*   

>  *phypor wrote:*   Couldn't think of any obvious pitfalls... If you have two kernels from the same source, but with different configs, they will share a directory in /lib/modules, which can hose things, making the "backup" kernel unbootable.  Possible solutions include stashing /lib/modules stuff somewhere, changing the kernel version string in the source tree temporarily, etc.  None of this matters when having kernels with different versions, but sometimes people try new configuration settings, but want to have a fallback, but they're using the same kernel version, and the fallback fails.

 

----------

## UnderDog138

If anybody cares, I had a problem with the /usr/src/symlink messing up my NVdriver module when I switched kernels and I notice other people have similar problems so I wrote this little diddy. Run it before rebooting when switching to another kernel.

```

#!/bin/sh

# Enter the directory name of the kernel source in /usr/src

# to switch the symlink to

#

# Remember to run this before rebooting when switching kernels

# Usage

# bash# kernel-linkswap linux-2.4.20

rm -f /usr/src/linux

echo "Removed old symlink /usr/src/linux"

ln -s "/usr/src/$1" /usr/src/linux

echo "Added new symlink /usr/src/linux -> /usr/src/$1"

```

It's an automated solution, so some of you may want this.

----------

## _SkeLeToN_

 *rac wrote:*   

> I think Skeleton is talking about the fact that some kernel module ebuilds (alsa, nvidia-kernel, lm-sensors) rely on /usr/src/linux pointing to the sources for the kernel to build with, and if that points to different sources than you're running, bad things happen.

 

Yes that's exactly what I was talking about.  Sorry if my post was confusing ... 

Is there a way when you select the the kernel you want at boot to change the symlink for /usr/src/linux with the one you choose on boot ??

----------

## UnderDog138

I considered doing that but I couldn't figure out how so I just wrote a shell script to do it before I reboot.

----------

## carambola5

To keep track of what your kernels do and when they were used, I suggest creating a text file in your /boot partition that keeps track.

```

FILENAME        USED UNTIL        REASON GOING TO

========--------==========--------===============

bzImage.01      12/02/2002        Initial kernel

bzImage.02      12/03/2002        USB Mass Storage

bzImage.03      12/10/2002        Last one didn't work

bzImage.04                        removed IDE-CDROM (for CDRW)

```

----------

## SeJo

Q15. I just compiled a new kernel and now my computer reboots instantly at startup. Why and how do I fix it? 

You might have forgoten to update your bootloader. Most of the time this happens after upgrading a kernel version.

boot using install-cd or bootupdisk

mount your /  and your /boot partition.

chroot to your / partition. 

configure your bootloader. 

lilo: as root: nano /etc/lilo.conf  and  make sure you set the link to the correct kernel

grup: as root: grub, make sure you set the link to the correct kernel

Also you might want to heck if the bzImage in the /boot section is the correct one. I always use a ls -all /boot/bzImage and check the time and the size..

----------

## Sargonas

I wrote this because of a not exsisting one in the faq but didnt see the previous post until searching for a place to put this.  Sorry.

[faq] KC10: I'm upgrading my kernel sources. Can I use my old configuration? If so, how? 

Once you have emerged the new kernel there are several new ways to use your old config for you your new kernel pending that you have saved you your .config file from your old kernel or havent deleted the source from your last install. 

First thing to do is copy ( /usr/src/linux-2.(old version)/.config  or   /boot/config-(version) )   to /usr/src/linux-2.(spify new version)/.config

This will give you access to your old config.

Now if you do any of the make *config you should have the ability to load that config:

make oldconfig: This will configure the kernel from an old configuration file .config if it exsist otherwise will use arch/<your arch>/depconfig    recommended that you run menu or x config after this to check for any changes.

make menuconfig: Will first attempt to load .config, that failing it will load arch/<your arch>/depconfig  This provides you with an easier option of configuring and has option for loading configs and saving.

make xconfig:  Will load .config, failing will load defaults, this is probably the easiest for beginners because it will show everything in a nice pretty format.

Note on xconfig: requires xfree86 to be started + tcl/tk and wish

after you have loaded that up then just continue compiling as normal:

i.e. make clean dep bzImage modules modules_install install

Note: clean and install are not required but are recommended:

clean: clears all previously compiled modules and kernels from this source

install: moves bzImage to /boot and names it according to the kernel name and will attempt to update lilo for you.( I dont use lilo so I anwser no to this ) this will also copy your config to /boot/config-kernelname   that way you will still have it no matter what you do to /usr/src/linux* and if this is a recompile of an old kernel that is already in boot it will move it to vmlinuz-(version).old

Be sure to update /etc/modules.autoload    adding any modules ( that you have changed ) you want loaded at boot.

update grub or lilo and reboot.  Enjoy your spify new kernel!

----------

## rac

Apologies to all participants in this thread, especially Sesshomaru.  I must have fallen asleep and not noticed the last several posts.  We've decided to go with IWBCMAN's KC10.

@SeJo: for KC15 I was basically looking for https://forums.gentoo.org/faq.php#15.

----------

## buckyball

Something that I haven't seen mentioned here is how you maintain multiple, serial copies of kernels (and their associated modules) built from the same source tree so that you can incrementally "tweak" the config of your kernel while maintaining one or more working "fallback" copies.

The way I do it is to modify the "EXTRAVERSION = " line in /usr/src/linux/Makefile to have something like:

```

VERSION = 2

PATCHLEVEL = 4

SUBLEVEL = 20

EXTRAVERSION = -0

```

This will result in a kernel with the internal revision 2.4.20-0 whose modules will be installed to /lib/modules/2.4.20-0.  I copy the kernel image to /boot/bzImage-2.4.20-0 and add a new section to /boot/grub/grub.conf (or 'menu.lst' for older systems).  

It's also a prudent idea (as mentioned elsewhere here) to make a backup copy of the /usr/src/linux/.config file to /boot/config-kernel-version so that you can revert to the configuration of a previously-built kernel if needed.

Finally, for machines with Nvidia support, ALSA, etc., I re-emerge those items to get the proper modules in /lib/modules/kernel-version.

The next time I want to adjust the kernel in some way, I simply bump the EXTRAVERSION value by 1 before the 

     'make dep && make clean bzImage modules modules_install'.

Hope this helps someone.  It's sure useful for me.

----------

## dimde

Please add https://forums.gentoo.org/viewtopic.php?t=8407&highlight=inital+console to KC15. 

I moved my working gentoo installation to another HD and forgot to copy /dev. 

So I messed around with new Kernels, etc... for more than a week until I found this thread about the empty /dev directory.

Here's what you have to do:

```

boot from the LiveCD

mkdir /mnt/gentoo

mount /dev/hdxy (your existing-installation's root dir)

cd /tmp 

tar -xvjpf /cdroot/nocompress/stage1-*.tbz2

cp -a /tmp/dev /mnt/gentoo/dev

umount /mnt/gentoo

reboot

```

----------

## discomfitor

Q5. I get errors about unresolved symbols when I'm compiling my kernel. How do I get rid of them?

From what I've seen, this is usually caused by a dependency problem.  You've probably enabled some option (like mousedev) without enabling another option that it depends on (like keybdev) and so it fails to compile.  Check over your configuration and see if you're missing something.

Also, if this (unresolved symbols) happens to your modules when you try to load them, you can fix it by doing:

```
cd /usr/src/linux

cp .config ~/

rm -rf /lib/modules/{kernel name here}

make mrproper

cp ~/.config ./

make menuconfig

exit menuconfig

make dep && make clean bzImage modules modules_install

cp arch/{arch}/boot/bzImage /{boot}/bzImage
```

Hope this helps!

----------

## yokem55

Q11. I've never compiled a kernel before and I'm totally lost. Are there any good guides? How do I get information about what all these options mean? 

First of all, don't be worried about feeling lost.  Building your own kernel is a challenging experience, but fortunately there are a lot of resources available to help you through the process.

Probably the definitive guide to getting started with building your own kernel is the Linux Documentation Project's Linux Kernel HOWTO located here.  Alternatively, Linux Planet has a good guide for building a kernel located here.

If you are looking for information on what all of the options mean, you can find a brief description of each option in the kernel menuconfig screen by selecting an option and then then pressing the "h" key.  Many times these brief descriptions will refer to documents outside of the kernel configuration screen which can be found in your /usr/src/linux/Documentation folder.

----------

## yokem55

Q13. I just installed a new kernel and now I'm getting a panic at boot time trying to mount the root partition. How do I fix this?

This is a fairly common problem that is caused by the kernel not having the necessary drivers built into the kernel for using the disk controller, recognizing your hard drive itself, and accessing the filesystem on the root partion.  

To fix this, first follow the directions in Kernel Compilation FAQ 1 on booting your system when your default kernel doesn't work.  Once your system is up and running again, enter the base directory of your kernel tree at /usr/src/linux.

Type:

```
#make menuconfig
```

 as usual to bring up the kernel configuration menu.  

If your root partition is on an ide drive, you will need to make sure you have support for your ide controller built into the kernel.  To do this select the "ATA/IDE/MFM/RLL support  --->" menu and press enter.  Then select "<*> ATA/IDE/MFM/RLL support" and say yes.  Then, select yes to the following options:

<*> Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support

<*>   Include IDE/ATA-2 DISK support

[*]     Use multi-mode by default

[*]   Generic PCI IDE chipset support

[*]     Sharing PCI IDE interrupts support

[*]     Generic PCI bus-master DMA support

You will then also need to say yes to whichever ide disk controller support option applies to the disk controller that is running the hard drive with your root partition on it.  If you are in doubt about which controller support to choose, you can simply say yes to all of the disk controller support options.  If any of the bugfix/support options apply to your system, be sure to say yes to those options as well.  None of these options should be built as modules.  The options specific to cdrom support, can however be built as modules.

If your root partion is on a SCSI device, from the root menuconfig menu select "SCSI support  --->" and say yes "<*>" to "SCSI support".  Then say yes to "<*>   SCSI disk support (NEW)".  Then under the "SCSI low-level drivers  --->" menu select the scsi controller driver that applies to your scsi controller and say yes to that option.  

Now, we need to make sure you have support for your root filesystem built into the kernel.  From the menuconfig root menu, select the "File systems  --->" menu.  Then, select yes to the filesystem that you formated your root partition with.  Most recent kernels should have full support for ext2, ext3, reiserfs, and jfs.  If you need xfs filesystem support you will need to make sure that you have a kernel installed with xfs support.  Your best bet for an xfs supporting filesystem is the xfs-sources kernel.  

Now, make any other changes the kernel you might have been wanting to make, and select exit and save your new kernel configuration.  Then make and install your new kernel as usual.

----------

## ebichu

 *_SkeLeToN_ wrote:*   

> Is there a way when you select the the kernel you want at boot to change the symlink for /usr/src/linux with the one you choose on boot ??

 

I do it during system boot. I add the following to /etc/conf.d/local.start:

```
echo "Setting /usr/src/linux link"

/usr/local/bin/ln_linux
```

This is the /usr/local/bin/ln_linux script run by the above:

```
#! /bin/bash

rel="`uname -r`"

buildlink="/lib/modules/$rel/build"

link="/usr/src/linux"

linkdir="`dirname $link`"

linkname="`basename $link`"

if [ ! -L "$link" ]; then

   echo "$link: not a symlink, so cannot change it" 1>&2

   exit 1

fi

if [ ! -L "$buildlink" ]; then

   echo "$buildlink: not a symlink, so cannot use it" 1>&2

   exit 1

fi

if cd "$buildlink"; then

   builddir="`/bin/pwd`"

else

   err=$?

   echo "Cannot cd to \"$buildlink\", so giving up" 1>&2

   exit $err

fi

linkto=`echo "$builddir" | sed "s|^$linkdir/||"`

cd "$linkdir" || exit $?

rm -f "$linkname" || exit $?

ln -s "$linkto" "$linkname" || exit $?

echo "$link -> $linkto"

exit 0

```

The script relies on the /lib/modules/`uname -r`/build symlink pointing to the directory which was used to build the kernel. This symlink is set by make modules_install, at least for 2.4 series kernels and upwards.

----------

## BlueEar

Previous posts mention how to install multiple kernels and the need to update modules, such as nvidia, for the new sources. However when I run emerge nvidia-kernel nvidia-glx emu10k1 with new sources, it deletes them from old sources (In my case it installed them in 2.4.21-ac4 and removed them from 2.4.20). As I have xdm added to the default runlevel this makes booting back to 2.4.20 very painful ... after failing to load emu10k1 and struggling with X11  it finally falls back to a console. Is there a way of emerging nvidia, emu10k1, i2c, lm-sensors and all such extras so that they stay in both previous version of the kernel (say /lib/modules/2.4.20) and current version of the kernel (say, 2.4.21-ac4)?

----------

## RedBeard0531

There is a much easier way. Add this to the end of your local.start:

```
 rm /usr/src/linux

ln -s /usr/src/linux-`uname -r` /usr/src/linux 

```

This set /usr/src/linux to whatever the current kernel is. I use it on all my boxen as i follow the mm-sources, so I change kernels frequently. I think that this should be added to the faq.

 *ebichu wrote:*   

> 
> 
> I do it during system boot. I add the following to /etc/conf.d/local.start:
> 
> ```
> ...

 

----------

## torque2k3

Is there anything others need to know about "genkernel"? I accidently found out about the --config option in a thread (giving genkernel a "make menuconfig" option) but there are literally NO docs (man, info or --help) I can find on this... 

Now that 1.4 Final docs are pushing this as an alternative for newbies (and even seasoned Gentoo-ists), can someone add a FAQ item here for it?

Specifically, I asked a similar set of questions in this thread:

https://forums.gentoo.org/viewtopic.php?t=94339&highlight= so I won't bother re-asking here. It seems as though genkernel is a great way to get up-and-running, but there needs to be more info, especially info on switching from genkernel back to the standard sequence of kernel building (ie: what to change in grub.conf, can we get rid of initrd-2.4.xxxxx).

Sorry if this isn't the place to ask...    :Embarassed: 

Thanks for the great FAQs, though! I love KC8!!!

----------

## dangerweasel

 *RedBeard0531 wrote:*   

> There is a much easier way. Add this to the end of your local.start:
> 
> ```
>  rm /usr/src/linux
> 
> ...

 

I used your solution, as it was the easiest, IMO, and the most straight forward.  I ran into a problem, however.  'uname -r' returns 2.6.0-gentoo when I am using the newest dev-sources (2.6.0-test9), but the directory of the sources is actually 2.6.0-test9-gentoo.  This leads to a problem finding the sources.  Any suggestions?

----------

## mhermanns

There are some questions about kernels that I have and that I have not found in the FAQ. I add them here since they may be interesting for the FAQ in case they are relevant. In other case, could somebody give me the answer to them?

1) After updating a given kernel source package (in my case mm-sources), compiling it, installing it and testing it, how do I delete the old version? Is it as simple as removing the directories /usr/src/linux-oldblabla and /lib/modules/oldblabla and the corresponding kernel image and System.map from the /boot directory?

2) When is System.map required and for what is it?

3) Why do some kernel source packages create the /usr/src/linux-beta link instead of the /usr/src/linux one, if the latter one is required while the former one is never used?

Thanks in advance

----------

## TheCoop

1. 

```
emerge -pC <old kernel emerge name>

rm -rf /usr/src/<old linux source>

rm -rf /lib/modules/<old linux modules>

rm /boot/[bzImage.old,System.map.old]

nano /boot/grub/grub.conf to remove the old entry
```

2. Dunno. Grub doesnt need or use it, and i dont know anything about lilo

3. Probably to tell you that it is a beta and not a stable source, but ask the ebuild authors. it serves no purpose and i always delete it afterwards

----------

## mhermanns

```
emerge -pC <old kernel emerge name>
```

Interesting...but you cannot just use the emerge name since then both kernels are deleted. Instead, for example mm-sources-2.6.0_beta9-r1 deletes my old one and ommits the newer one. That would be interesting to include in the kernel howto or faq, since it is not obvious.

Thanks for the answers.

----------

## ferret

Try

```
emerge -pC =mm-sources-2.6.0_beta9-r1
```

----------

## FastTurtle

You list Grub but there is no information for those of us who are bitten by the Grub Bug and restricted to using Lilo.

Please add Lilo Information.

----------

## EvilFurby

I have input the script into my system. It works fine apart from outputing the date to the file name. I get for example System.map-date +%y%m%d-2.6.8-gentoo-r1

Is there a typo in KC8 on the following line?

WHEN='date +%y%m%d'

----------

## Bob P

over a year has passed with no answer -- question removed.

----------

