General: Tools:

Basic Kernel Compilation http://www.cpqlinux.com/kernel.html Full Kernel Compilation http://www.digitalhermit.com/linux/Kernel-Build-HOWTO.html Copy Current Running Kernel for Compile: zcat /proc/config.gz >/usr/src/linux/.config zImage or bzImage http://www.ibiblio.org/oswg/oswg-nightly/oswg/en_US.ISO_8859-1/articles/alessandro-rubini/boot/boot/zimage.html -------------------------------------------------------------------------------- Patch a Linux SRC Tree via STDIN Redirects cd /usr/src wget http://path/to/linux-2.6.0-p2.tar.bz|.gz tar xfvj /path/to/linux-2.6.0-p2.tar.bz2 tar xfvz /path/to/linux-2.6.0-p2.tar.gz wget http://path/to/patch-2.6.0-p3.tar.gz wget http://path/to/patch-2.6.0-p4.tar.gz tar xvfz patch-2.6.0-p3.tar.gz tar xvfz patch-2.6.0-p4.tar.gz cd linux-2.6.0-p2 patch -p1 <../patch-2.6.0-p3 patch -p1 <../patch-2.6.0-p4 cd .. mv linux-2.6.0-p2 linux-2.6.0-p4 tar cfvj linux-2.6.0-p4.tar.bz2 linux-2.6.0-p4 # backup optional! -------------------------------------------------------------------------------- Kernel Configuration One of the first choices you will make is whether or not to build device support directly into the kernel or as a module. In the early days of Linux, when module support was in its infancy, it was possible that static (i.e., compiled in) drivers were faster. With any modern CPU, the time to load and unload the modules and the memory required for the module loader subsystem is negligible even to benchmarking utilities. Some devices, notably the disk controller, can be built directly into the kernel in order to simplify the boot process. You may also choose to disable some options entirely. Though you will not have any performance increases, there are advantages to disabling features that are not required. For one, the compile times will be drastically reduced depending on which subsystem is disabled. For another, the final kernel and installed modules will require less space. On modern hard drives of 40G, 60G, and even 250G, an extra 20M or so is negligible but is significant on embedded or older systems. The disadvantage is that you will not have support for those features until you recompile the kernel. One other thing to keep in mind, as noted in KERNELTRAP.ORG (http://www.kerneltrap.org/node/view/799): Having unnecessary drivers will make the kernel bigger, and can under some circumstances lead to problems: probing for a nonexistent controller card may confuse your other controllers. If you are using the sources from a vendor, then the default configuration files are usually included in the configs or in the ./arch/i386/defconfig (for i386 machines) file. You can use these configurations as a starting point for your customizations. The .config will be overwritten in the next step, so do make a backup before proceeding! To backup an existing configuration: cp .config config.save We begin the configuration by wiping out all previous configurations and resetting the source directory to a pristine state. The main reason for doing this is that some files do not automatically get rebuilt, which can lead to failed builds, or at worst, a buggy kernel. make mrproper In the 2.4.x series, a few dozen lines of rm -f commands will appear as all generated files get removed. The 2.6.x process is less noisy and returns only a few CLEAN messages. Please note that it is generally safe to omit the make mrproper step during subsequent rebuilds. It is a good idea to build support for your root filesystem directly into the kernel. Though the initrd utilities can get around the chicken-and-egg boot problem, it is generally safer and easier to just build the fs modules directly. Many options can also be safely disabled if you have no use for the feature. On the 2.6.x kernels there are four main frontend programs: config, menuconfig, and xconfig. config is the least user-friendly option as it merely presents a series of questions that must be answered sequentially. Alas, if an error is made you must begin the process from the top. Pressing Enter will accept the default entry which is in upper case. oldconfig will read the defaults from an existing .config and rewrite necessary links and files. Use this option if you've made minor changes to source files or need to script the rebuild process. menuconfig is an ncurses based frontend. Your system must have the ncurses-devel libraries installed in order to use this utility. As the help text at the top of the screen indicates, use the arrow keys to navigate the menu. Press Enter to select sub-menus. Press the highlighted letter on each option to jump directly to that option. To build an option directly into the kernel, press Y. To disable an option entirely, press N. To build an option as a loadable module, press M. You can also access content-specific help screens by pressing ? on each page or selecting HELP from the lower menu. xconfig is a graphical frontend using qconf by Roman Zippel. It requires the qt and X libraries to build and use. The interface is intuitive and customizable. Online help is automatically shown for each kernel configuration option. It also can show dependency information for each module which can help diagnose build errors. To configure the kernel compilation options, choose make and one of the menu systems above: make menuconfig -------------------------------------------------------------------------------- http://www.cromwell-intl.com/unix/linux-kernel.html ftp://ftp.COUNTRY.kernel.org/ (COUNTRY: us) cd /usr/src rm linux wget http://path/to/kernel-VERSION.tar.bz2 tar xvfj kernel-VERSION.tar.bz2 ln -s linux-VERSION linux chown -R root:root linux-VERSION ls -laF cd /usr/src/linux edit Makefile (EXTRAVERSION=) cp /path/to/config .config make xconfig make clean make dep # compile make bzImage | make boot (build kernel) make modules # install cp arch/i386/boot/bzImage /boot/vmlinuz-RELEASE cp System.map /boot/System.map-RELEASE cp vmlinux /boot/vmlinux-RELEASE make modules_install Quite likely the tar file has created files owned by some random UID other than 0, meaning root. This is not good! Fix it: chown -R root:root /usr/src/linux-VERSION If you want your kernel to announce its release when you run the uname -r command as, say, 2.4.20-spiffy instead of plain old 2.4.20, then edit /usr/src/linux/MAKFILE and change the fourth line: EXTRAVERSION = -spiffy There is a small chance that your tar file also dumped some inappropriate stale *.o object files into your otherwise pristine kernel source. Get rid of them. This is only necessary the first time you build anything in this kernel source, and if you re-run this in the future, you don't really cause any huge problems, but you will be forcing your system to re-build the object files. You probably only want to do this once! make clean Set up the dependencies. This is only necessary the first time, although if you re-run this you will only waste a little time. make dep Build the monolithic kernel. If you're on a PC, meaning an x86 processor: make bzImage If you're on an Alpha: make boot Build the loadable kernel modules: make modules Install the monolithic kernel: If you're on a PC, meaning an x86 processor: cp arch/i386/boot/bzImage /boot/vmlinuz-RELEASE Install the kernel system map (symbol table): cp System.map /boot/System.map-RELEASE On the off chance that you ever want to analyze kernel error messages (called "oops text" or "oops messages"), save the kernel image itself: Install the kernel system map (symbol table): cp vmlinux /boot/vmlinux-RELEASE Install the loadable kernel modules: make modules_install -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --------------------------------------------------------------------------------