Hack 70 Copy a Working Kernel 
Use Knoppix to restore a working kernel to a
system that has had its kernel either deleted or overwritten.
By default, most Linux
distributions include only a single kernel. These kernels are
generally very modular, which is fine, because it makes boot loader
configuration simple—you have to configure only a single
kernel. Unfortunately, if that kernel somehow gets deleted or
corrupted, you have no way of booting, because it is the only kernel
on the system. However, you can use a rescue disk like Knoppix to
restore a working kernel to the system. This hack covers a number of
methods that restore a working kernel to a system, including how to
use Knoppix's own kernel on a system.
Before you can restore a kernel, you must determine which kernel
needs to be restored and find another copy of it. If you have been
using the default kernel for your distribution, this step is simple;
just grab the installation CD and find the kernel package, or
download the package from the distribution's package
repository. To restore the kernel, simply use the appropriate package
manager under Knoppix. If you have a Deb-based system, refer to [Hack #68] for instructions on how to
use dpkg within a chrooted
environment. If you have an RPM-based system, refer to [Hack #69] for
instructions on how to use rpm within a
chrooted environment.
If you have built your own kernel, you might still have a copy of the
kernel on your system you can use. Unless you ran a
make clean since you have built
your kernel, a copy of the kernel might still be sitting in
/usr/src/linux/arch/i386/boot/. If you built a
bzipped kernel image with make bzImage, then the
file should be named bzImage. After mounting the
drive read/write (type mount -rw
/dev/hda1
/mnt/hda1 in a terminal),
simply copy the bzImage file to
boot, and name it after the corrupted or deleted
kernel.
If you wish, you can also use Knoppix's own kernel
on your system. The Knoppix kernels are in the
/boot directory on the Knoppix root filesystem.
Copy the kernel image you want to use to the
boot directory on your read/write mounted root
partition. Finally, copy your chosen kernel's
modules directory located in /lib/modules on the
Knoppix root filesystem to lib/modules on your
root partition. For a root partition mounted at
/mnt/hda1, type:
knoppix@tty0[knoppix] sudo cp /boot/vmlinuz-`uname -r` /mnt/hda1
/boot/
knoppix@tty0[knoppix] sudo cp -a /lib/modules/`uname -r` /mnt/hda1
/lib/modules/
 |
These commands use the shell command uname -r to
return the currently booted Knoppix kernel. This method should work
identically for you. If you want to copy a kernel other than the one
you are currently using, simply replace `uname -r`
with the kernel version you are using.
|
|
Whichever method you use to copy a working kernel to your system,
once it is copied, make sure that your boot loader's
configuration file references the new kernel. If you simply installed
the default kernel package for your distribution, you should not need
to perform any additional configuration. If you use
lilo as a boot loader, you also must update
lilo in your boot sector (covered in [Hack #52] ) before you
can reboot your system to the restored kernel.
Keep in mind that you aren't required to use a
kernel included with your system. If there is another kernel image
you wish to boot from that you know will work with your hardware,
simply perform the same steps used to copy Knoppix's
kernel to the system to use your kernel. If you do this, be sure to
update your boot loader and, preferably, keep a backup distribution
kernel just in case. Otherwise, if the new kernel
doesn't boot, just try this hack again.
|