Difference between revisions of "Genkernel Quick Start Tutorial"
(→Third step: Building and installing the kernel) |
|||
| Line 158: | Line 158: | ||
# genkernel --no-mrproper all | # genkernel --no-mrproper all | ||
</pre> | </pre> | ||
| + | |||
| + | The same remarks written in the third paragraph of the first use case are still valid here. | ||
Revision as of 02:46, 24 May 2011
Genkernel is a tool which help you to build a Linux kernel and deploy it along with a ramdisk image which contains all of the necessary modules to make the kernel being able to mount the different partitions of your harddrives in the VFS at the system startup.
Contents |
Concepts
TBC
Business case #1: Genkernel applied to the Debian sources
A good candidate to quickly start with Genkernel is the Debian kernel (sys-kernel/debian-sources) mainly because:
- Configuration files are available for the various platforms supported by the Debian project
- The configuration makes an intensive use of putting features in modules
First step: emerging the required packages
The first step is to emerge:
- The Debian sources
- Genkernel itself
This is achieved with:
# emerge sys-kernel/debian-sources sys-kernel/genkernel
Once the Debian kernel sources are deployed, you should find a directory named linux-debian-version (e.g. linux-debian-2.6.32.30) under /usr/src. Update your the linux symlink to point on this directory:
# cd /usr/src # rm linux # ln -s linux-debian-2.6.32.30 linux
Alternatively, emerge the debian-sources with USE="symlink"
Second step: Grabbing a configuration file
If is now time to download the kernel configuration file. For this tutorial we will use a configuration file for AMD64 (several others architectures like MIPS or SPARC64 are available) as published by the Debian project, if you plan to use the Debian kernel you are advised to review it adjust it to your needs although it is tailored for a vast range of machines.
# cd linux # wget http://merkel.debian.org/~jurij/2.6.32-30/amd64/config-2.6.32-5-amd64.gz # gunzip config-2.6.32-5-amd64.gz
Alternatively, you can use Funtoo's config-extract tool to generate an official Debian kernel configuration. Use it as follows:
# cd linux # ./config-extract amd64 Wrote amd64_none_amd64 kernel configuration to /usr/src/linux-debian-2.6.32.30/.config.
config-extract also allows you to extract special Debian featuresets, such as settings for Xen and OpenVZ kernels:
# ./config-extract amd64 openvz Wrote amd64_openvz_amd64 kernel configuration to /usr/src/linux-debian-2.6.32.30/.config.
To see a full list of available Debian kernel configurations, type ./config-extract --list from within the root kernel source tree.
After using config-extract, run make oldconfig and accept all default options by hitting Enter at all prompts.
Third step: Building and installing the kernel
This is simply achieved by:
# genkernel --kernel-config=config-2.6.32-5-amd64 all
- --kernel-config: use the given name located in the kernel source tree (/usr/src/linux by default is taken unless overridden by --kerndir)
- all: rebuild the kernel image and the initramfs ramdisk image (aside of kernel modules, the ramdisk image contains tools such as BusyBox and some generic startup scripts, depending on options you use on the command line several additional tools like lvm or raid volume management can be incorporated as well).
Unless explicitly stated via --no-clean or no-mrproper, Genkernel will do a make mroprer in the kernel source tree, thus cleaning a previous build and removing the previous kernel configuration file in it.
If you use Genkernel to rebuild a Linux kernel on SPARC64, remember to either:
- Set sparc64-unknown-linux-gnu- in General setup --> Cross-compiler tool prefix
- Put --kernel-cross-compile=sparc64-unknown-linux-gnu- on the Genkernel command line
One the kernel has been compiled and the ram disk has been generated, the kernel image plus its companion files (initramfs image and System.map) are placed in the /boot directory, You can use your favourite tool to update your bootloader configuration files.
Business case #2: Recompiling the Gentoo kernel sources from a SystemRescue CD chroot
A second case that many Funtoo users will face to is to compile their own kernel when installing a brand new Funtoo instance from a stage 3 archive (the most common scenario is to boot the machine with SystemRescue CD).
First step emerging the required packages
The first step is to emerge:
- The Gentoo kernel sources
- Genkernel itself
This is achieved with:
# emerge sys-kernel/gentoo-sources sys-kernel/genkernel
Once the Gentoo kernel sources are deployed, you should find a directory named linux-version-gentoo (e.g. linux-2.6.39-gentoo) under /usr/src. Update the linux symlink to point on this directory:
# cd /usr/src # rm linux # ln -s linux-2.6.39-gentoo linux
Second step: Grabbing and tweaking a configuration file
How to start your kernel configuration? Simply by using the same configuration template the running System Rescue CD kernel had been built with! Before chrooting in your Funtoo instance, you did something like:
# mount -o bind /proc /mnt/gentoo/proc
Or:
# mount -t proc none /mnt/gentoo/proc
In your chroot environment (or from a System Rescue CD virtual terminal) if you look what /proc contains you will notice a file named config.gz:
# ls /proc ... dr-xr-xr-x 7 root root 0 May 23 03:13 952 dr-xr-xr-x 7 root root 0 May 23 03:13 953 dr-xr-xr-x 7 root root 0 May 23 18:42 9834 ... -r--r--r-- 1 root root 16024 May 23 22:27 config.gz -r--r--r-- 1 root root 0 May 23 22:27 consoles -r--r--r-- 1 root root 0 May 23 22:27 cpuinfo ...
config.gz holds the running kernel (System Rescue CD) configuration, just copy the gunziped content in the Gentoo sources directory:
# cd /usr/src/linux # zcat /proc/config.gz > .config
Next, run make oldconfig to set all newly added options:
# make oldconfig
Next, tweak the kernel configuration in the way you prefer (manually edition of the .config file, make nconfig, make menuconfig....) if you wish. You are not ready yet! A final step is required: you must either set CONFIG_INITRAMFS_SOURCE to a black value (CONFIG_INITRAMFS_SOURCE="") either delete the statement in the .config file. Forgotting to do that will make Genkernel abort the compilation process with a message like:
/usr/src/linux-2.6.39-gentoo/scripts/gen_initramfs_list.sh: Cannot open '/var/tmp/genkernel/initramfs-2.6.32.14-std155-i386.cpio.gz' make[1]: *** [usr/initramfs_data.cpio.lzma] Error 1
Third step: Building and installing the kernel
This is simply achieved by:
# genkernel --no-mrproper all
The same remarks written in the third paragraph of the first use case are still valid here.