<?xml version="1.0" encoding="UTF-8"?>
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/kernel-upgrade.xml,v 1.1 2004/11/02 09:36:23 swift Exp $ -->

<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
<guide link="kernel-upgrade.xml">
<title>Gentoo Linux Kernel Upgrade Guide</title>
<author title="Author">
	<mail link="dsd@gentoo.org">Daniel Drake</mail>
</author>

<abstract>
This document describes the process of upgrading your kernel from one release
to another.
</abstract>

<!-- The content of this document is licensed under the CC-BY-SA license -->
<!-- See http://creativecommons.org/licenses/by-sa/2.0 -->
<license/>

<version>0.1.0</version>
<date>November 1st, 2004</date>

<chapter>
<title>Introduction</title>
<section>
<body>

<p>
The kernel is one of the few package classes in portage that requires some
manual intervention to complete the upgrade. Portage will download and
install the kernel source for you, but then it is up to you to step in and
compile the new kernel before any changes will take effect.
</p>

<p>
Although this guide is targetted at users upgrading from one kernel release
to another, it will also be useful for users migrating from one kernel
package to another.
</p>

<p>
<c>gentoo-dev-sources</c> is used as an example in this document, however, the
instructions here also apply to the other packages present in our tree.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Why upgrade kernel?</title>
<section>
<body>

<p>
Generally, upgrading from one minor kernel release to the next won't bring any
major differences. Reasons for upgrading kernel are generally either to take
advantage of a specific new feature or driver, to be protected against a
security vulnerability, or just to maintain an up-to-date and healthy system.
</p>

<p>
Even if you choose not to update to every new kernel revision, it is
recommended that you at least upgrade from time to time. It is strongly
recommended that you immediately upgrade to a new kernel if that new release
solves a security problem.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Obtaining the newer sources through Portage</title>
<section>
<body>

<p>
You upgrade the kernel sources like you would upgrade any other package -
using the <c>emerge</c> utility. It will probably be the case that you want to
upgrade your kernel when you see the upgrade appearing on your world updates
list. For example:
</p>

<pre caption="New kernel sources appearing on update list">
# <i>emerge -Dup world</i>
Calculating dependencies ...done!
[ebuild     U ] sys-kernel/gentoo-dev-sources-2.6.9-r2 [2.6.8-r5]
</pre>

<p>
You can then go ahead and install the update, e.g.:
</p>

<pre caption="Upgrading your kernel sources">
# <i>emerge -u gentoo-dev-sources</i>
</pre>

<p>
The kernel sources will then be installed into a subdirectory of 
<path>/usr/src</path>. In the above example, my new kernel sources will be 
installed at <path>/usr/src/linux-2.6.9-gentoo-r2</path>.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Updating the /usr/src/linux symbolic link</title>
<section>
<body>

<p>
Gentoo requires you to maintain a symbolic link, located at 
<path>/usr/src/linux</path>. This should point to the sources of the 
kernel you are running.
</p>

<p>
In this case, we need to update the symbolic link to point at the kernel
sources that we are about to upgrade to. Continuing our example:
</p>

<pre caption="Updating the /usr/src/linux softlink">
# <i>cd /usr/src</i>
# <i>ln -sf linux-2.6.9-gentoo-r2 linux</i>
</pre>

</body>
</section>
</chapter>

<chapter id="install">
<title>Configuring, compiling and installing the new kernel</title>
<section>
<body>

<p>
For either of these options, you should refer to the instructions given in the
<uri link="http://www.gentoo.org/doc/en/handbook/index.xml">Gentoo
Handbook</uri> relating to <e>Configuring the Kernel</e> and <e>Configuring
the Bootloader</e>. A quick summary is provided here.
</p>

</body>
</section>
<section>
<title>Option 1: Automatic kernel setup with Genkernel</title>
<body>

<p>
If you are a genkernel user, you just need to repeat the stages you went
through when installing your kernel for the first time.
</p>

<p>
Simply run genkernel in the normal way:
</p>

<pre caption="Invoking genkernel">
# <i>genkernel all</i>
</pre>

<p>
You can also use extra parameters for other genkernel functionality. For
example, if you wish to configure some extra kernel options using
<c>menuconfig</c> and you wish genkernel to automatically update your grub
bootloader config, then invoke genkernel as follows:
</p>

<pre caption="Invoking genkernel with some common arguments">
# <i>genkernel --menuconfig --bootloader=grub all</i>
</pre>

<p>
For more info, follow the
<uri link="http://www.gentoo.org/doc/en/genkernel.xml">Gentoo Linux Genkernel
Guide</uri>, or refer to the handbook.
</p>

</body>
</section>
<section>
<title>Option 2: Manual configuration</title>
<body>

<p>
To begin, open the <c>menuconfig</c> utility in the kernel source tree:
</p>

<pre caption="Invoking menuconfig">
# <i>cd /usr/src/linux</i>
# <i>make menuconfig</i>
</pre>

<p>
Select the options required for your hardware and operating environment. Refer
to the <e>Gentoo Handbook</e> for additional guidance on this.
</p>

<p>
Next, compile your kernel and copy it over to your boot partition. Again,
follow the handbook instructions here, but don't forget to mount your /boot
partition first! In the initial installation, you would have already mounted
this at a much earlier stage.
</p>

<pre caption="Compiling and installing the new kernel">
# <i>make &amp;&amp; make modules_install</i>
# <i>mount /boot</i>
# <i>cp arch/i386/boot/bzImage /boot/bzImage-2.6.9-gentoo-r2</i>
# <i>cp System.map /boot/System.map-2.6.9-gentoo-r2</i>
</pre>

<p>
Finally, you should update your bootloader config, adding an entry for the
new kernel (don't delete the old one just yet!) and unmount the
<path>/boot</path> partition. Again, refer to the handbook for instructions 
here.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Reinstalling external modules</title>
<section>
<body>

<p>
If you use any kernel modules that are not included in the kernel source tree
but are provided elsewhere in portage (e.g. Nvidia or ATI graphics drivers),
then you must reinstall these on every kernel upgrade. This is as simple as
re-merging the packages involved. Refer again to the
<uri link="http://www.gentoo.org/doc/en/handbook/index.xml">Gentoo
Handbook</uri> <e>Configuring the Kernel</e> chapter for more info here.
Re-merging these packages will ensure they build against the source tree at
<path>/usr/src/linux</path> - therefore they will actually being installed 
for the kernel we just compiled.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Rebooting into the new kernel</title>
<section>
<body>

<p>
Next, close all applications and reboot your system. If you followed the above
instructions correctly, you will see an entry for your new kernel on your
bootloader. Select the new kernel and let the system boot.
</p>

<p>
Hopefully, your system will boot without problem and you can log in and start
working as usual. If everything is working, then the upgrade is complete at
this stage.
</p>
 
<p>
If you have made a mistake and your system will not boot into the new kernel,
then you can simply reboot and boot into your previous working kernel. You can
then restart from the <uri link="#install">Configuring, compiling, and
installing the new kernel</uri> stage - making the appropriate changes to
correct your mistake. In some cases (e.g. you just missed a network driver)
then you might not even need to reboot to do this.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Running multiple kernels</title>
<section>
<body>

<p>
You may have noticed, that when installing the sources for your newer kernel,
the sources for your existing kernel were not removed. This is by-design and
allows you to easily switch between running different kernels.
</p>

<p>
Switching between multiple kernels is as simple as leaving the kernel sources
under <path>/usr/src/</path> and leaving the <path>bzImage</path> binaries on 
your <path>/boot</path> partition (referenced by entries in your bootloader 
config). Every time you boot up, you will be presented with a choice of which
kernel to boot into.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Removing older kernels</title>
<section>
<body>

<p>
Continuing on from the last section, you may be happy with your new kernel and
not have any need to keep older kernel versions around. To easily remove all
sources for a particular kernel except for the newest one, you can take
advantages of emerge's <e>prune</e> option. Continuing the example using
gentoo-dev-sources:
</p>

<pre caption="Pruning old versions">
# <i>emerge -P gentoo-dev-sources</i>
</pre>

<p>
In most cases, temporary files used during compilation will still remain under
the appropriate source directory under <path>/usr/src</path>. It is safe to 
remove these using <c>rm</c>.
</p>

<p>
You can also safely delete any modules that were used by this kernel. This can
be done by removing the appropriate directories under <path>/lib/modules/</path>
that relate to the kernel versions you are removing. Be careful not to delete
modules belonging to kernels that you still use!
</p>

<p>
Finally, you can mount your <path>/boot</path> partition and remove the 
<path>bzImage</path> and <path>System.map</path> files for the kernel(s) 
you are pruning. You should also edit your bootloader config so that it 
no longer references this kernel.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Problems after a kernel upgrade?</title>
<section>
<body>

<p>
With the rapid development of the Linux kernel, it is inevitable that some
changes made from one kernel release to another may cause some problems. If
you have any issues with the latest versions of
<uri link="http://www.gentoo.org/doc/en/gentoo-kernel.xml#doc_chap2">
Gentoo-supported kernels</uri> then please do report the issues to us.
</p>

</body>
</section>
</chapter>

</guide>
