Compiling a kernel has the advantage to make it as minimal and featureful as you want, you can test kernel patches and tweaks and optimize your system.
* You need the kernel source, build tools, the kernel configuration file (optional), and root or sudo privileges for the final stages of the process.
* Back up all of your files.
* Have a distro in a Live CD or USB at hand just in case.
* Give yourself a cup of tea or coffee while you wait to compile.
* OPTIONAL: Is standard to download Linux sources under /usr/src/, link the downloaded kernel tree to /usr/src/linux-<VERSION_NUMBER> and work there, but is not a requirement.
* Remove compiled files from the kernel tree AND the configuration file (backup your configuration file before this if you have one in the current directory).
This process makes a .config file in the kernel source directory determines which drivers are built and other support. And turn on only the minimal set of options you need.
* OPTION 3: Generate a config file disabling all options not loaded by the currently running kernel and will make questions on what kernel options to support when it finds new kernel options. Could have problems with peripherals not in use at that time unless you plug all devices like USBs. Available from kernel version 2.6.32 and up. Attach devices you use or insert modules manually with the insmod command before using this option.
* OPTION 4: Create a minimal kernel config file which necessarily needs to manually enable options afterwards to have a working system. Avaiable from kernel version 3.17-rc1 and up.
* OPTION 1: Start a menu and browse options. Requires curses library but likely is already on your computer. Press "H" or "?" to see help. You can use the space bar to cycle between the available choices or press the appropriate key mentioned above. Pressing "/" to search for keywords.
* OPTION 2: Will make questions on what kernel options to support when it finds new kernel options not marked on an existing config file (takes time and and if you are using a striped down config file it requires you knowledge).
_NOTE_: The "-j<X>" flag, where <X> is the number of cores +1, is OPTIONAL and only goes if you have a processor with multiple cores. If you install ccache (OPTIONAL) you can speed up subsequent compilations by including CC="ccache gcc" after the "-j<X>" flag.
* OPTION A: Compile and move everything to its place. The "all" flag makes modules AND the bzImage at the same time (replaces "bzImage" and "modules" flags).
* If your configuration does not contain answers for all of the options, especially if they are new and not currently included in your running kernel, you will need to answer the prompts for these options.
* OPTION B2: Automatically move kernel to /boot (and in certain distros, symlink the new kernel to /boot/vmlinuz and update the bootloader configuration).
* Compile individual files for each question you answered M during kernel config. The object code is linked against your freshly built kernel. (For questions answered Y, these are already part of vmlinuz, and for questions answered N they are skipped). Modules end with .ko.
_NOTE_: The vmlinuz can be any name but that exact name has to be added to the configuration file of your bootloader of choice. Usually a version number is appended to the new kernel image. This has the advantage to avoid replacing a current kernel and having a fallback as backup to boot. You can set to boot from any image in the bootloader once you configure them in the bootloader.
## INITRD
* The initrd is used only while booting, unless you compile the kernel with the filesystem it resides on (initfs)
* The -p flag specifies a number of leading directories to remove, location is at the top of the patch file filename and is relative to the current directory.
* OPTION 4: Create a minimal kernel config file which necessarily needs to manually enable options afterwards to have a working system. Available from kernel version 3.17-rc1 and up.
* OPTION 1: Start a menu and browse options. Requires curses library but likely is already on your computer. Press "H" or "?" to see help. You can use the space bar to cycle between the available choices or press the appropriate key mentioned above. Pressing "/" to search for keywords.
* OPTION 2: Will make questions on what kernel options to support when it finds new kernel options not marked on an existing config file (takes time and and if you are using a striped down config file it requires you knowledge).
_NOTE_: The "-j<X>" flag, where <X> is the number of cores +1, is OPTIONAL and only goes if you have a processor with multiple cores. If you install ccache (OPTIONAL) you can speed up subsequent compilations by including CC="ccache gcc" after the "-j<X>" flag.
* OPTION A: Compile and move everything to its place. The "all" flag makes modules AND the bzImage at the same time (replaces "bzImage" and "modules" flags).
* If your configuration does not contain answers for all of the options, especially if they are new and not currently included in your running kernel, you will need to answer the prompts for these options.
* OPTION B2: Automatically move kernel to /boot (and in certain distros, symlink the new kernel to /boot/vmlinuz and update the bootloader configuration).
* Compile individual files for each question you answered M during kernel config. The object code is linked against your freshly built kernel. (For questions answered Y, these are already part of vmlinuz, and for questions answered N they are skipped). Modules end with .ko.
_NOTE_: The vmlinuz can be any name but that exact name has to be added to the configuration file of your bootloader of choice. Usually a version number is appended to the new kernel image. This has the advantage to avoid replacing a current kernel and having a fallback as backup to boot. You can set to boot from any image in the bootloader once you configure them in the bootloader.
## INITRD
* The initrd is used only while booting, unless you compile the kernel with the filesystem it resides on (initfs)
* The -p flag specifies a number of leading directories to remove, location is at the top of the patch file filename and is relative to the current directory.