Difference between revisions of "Kernel Compilation without ABS for New Users"

From ArchWiki
Jump to: navigation, search
(Deleting controversial script. If you want automation, use a PKGBUILD.)
(Undo revision 152200 by Falconindy (talk))
Line 3: Line 3:
  
 
Kernel versions 3.0-rc4-git5 & 2.6.39.1 were compiled and tested using this guide. During the kernel configuration process using 'make menuconfig', the Kernel Local Version (revision) which was appended to the kernel release is "ARCHMOD". You can obviously use a different description. The procedures documented here should be more than adequate for all other Linux distributions with minor, if any, differences.
 
Kernel versions 3.0-rc4-git5 & 2.6.39.1 were compiled and tested using this guide. During the kernel configuration process using 'make menuconfig', the Kernel Local Version (revision) which was appended to the kernel release is "ARCHMOD". You can obviously use a different description. The procedures documented here should be more than adequate for all other Linux distributions with minor, if any, differences.
 +
 +
==Versions 3.0 & 2.6 - Automated Script==
 +
'''NEW, and still more to come:''' A thoroughly tested BASH script is available which automates the entire manual compiling process listed below and encourages the "bleeding edge" philosophy when it comes to the latest Linux Kernel. This script allows a safe, easy, and alternative method to using makepkg. It includes an easy-to-use option for patching a MAINLINE(RC) Kernel release. Recent testing of kernel linux-3.0.tar.bz2 (July 22, 2011) resulted in successful compiling, and installing. (<code>uname -a:  Linux Galicja 3.0.0-ARCHMOD #1 PREEMPT Fri Jul 22 12:18:14 CEST 2011 x86_64 Genuine Intel(R) CPU 575 @ 2.00GHz GenuineIntel GNU/Linux</code>).
 +
 +
'''Procedures:'''
 +
 +
* Download the script (See link below procedures).
 +
 +
* Prior to initially opening or running the file {{filename|linux_kernel.sh}}, go into root (#) and use chmod to give it appropriate execution permissions (755):
 +
# chmod 755 linux_kernel.sh
 +
 +
* Download the kernel source for stable, mainline (rc), and snapshot (git/patch) from [http://www.kernel.org the Linux Kernel website] placing the files into the appropriate directory ({{filename|/usr/src}}).
 +
 +
* Open up {{filename|linux_kernel.sh}} and carefully enter values for '''only 7 variables''' which are required for the script to run, then save the file (See sample input area below procedures).
 +
 +
* Once values have been entered and source files downloaded, run the script in root (#):
 +
# ./linux_kernel.sh
 +
 +
* While running, one or two pauses which require user intervention are necessary, and this occurs at the very beginning (first minute or two). Your old .config file will automatically be copied into its new directory, and 'menuconfig' will be automatically invoked. Keep in mind, this script will '''never''' override or delete any original files (soft-link only) without a warning first, or automatic termination. There are numerous checks and controls built into it to ensure safe execution. The script works VERY well, so enjoy it!
 +
 +
Note: NVIDIA users, please make additional NECESSARY adjustments after script is completed, PRIOR to rebooting. Feel free to contact the author for any assistance and/or suggestions.
 +
 +
'''Script Download'''
 +
    '''[https://docs.google.com/leaf?id=0B8L9kuJ0hMgaY2MzYzk0ZjAtZjdkYi00ZjliLTk3YjQtMjM2MTc5NDZjYmZj&hl=en_US linux_kernel.sh]''' at Google Docs (Last Updated: Friday, July 22, 2011, 13:31 CET)
 +
 +
 +
'''Sample linux_kernel.sh BASH script Input Area for 7 required variables:'''
 +
 +
#==========================================================================
 +
# Enter 7 Kernel Variables Values Here (You MUST fill in ALL values after "="):
 +
 +
# Directory Name holding "mainline", "stable" and/or "snapshot"(patch) source files from kernel.org
 +
# Must end with "/"
 +
kern_src_dir=/usr/src/
 +
 +
# Directory Name holding current Kernel ".config" file (".config" will be copied automatically into new directory)
 +
# Must end with "/"
 +
config_dir=/usr/src/linux-2.6.39.1-KNL/
 +
 +
# Value of CONFIG_LOCALVERSION parameter in Kernel ".config" file (Ex.  CONFIG_LOCALVERSION="-ARCHMOD")
 +
local_ver=-ARCHMOD
 +
 +
# File Name of "mainline" or "stable" Linux Kernel (Must be downloaded and reside in the "kern_src_dir" (/usr/src/)
 +
kern_file_name=linux-3.0-rc4.tar.bz2
 +
 +
# Is a Patch file involved? YES or NO (Must be CAPITALIZED Letters)
 +
patch=YES
 +
 +
# If patch=YES, File Name of "snapshot" patch (Ex. patch-2.6.37-rc1-git12.bz2) residing in "kern_src_dir" (/usr/src/)
 +
# If patch=NO, then this value does NOT matter. If you wish, enter NONE (patch=NONE)
 +
patch_file_name=patch-3.0-rc4-git5.bz2
 +
 +
# To build the kernel in a multithreaded (faster) way, the -j option is used with the 'make' program
 +
# It is BEST to give a number to the -j option that corresponds to TWICE the number of processors in the system
 +
# ( Ex. Machine with 1 processor: jval=2, Machine with 2 processors: jval=4, etc.)
 +
# To disable this option, enter the value zero ("0"): ( Ex. jval=0 )
 +
jval=0
 +
 +
#==========================================================================
 +
 +
 +
'''Sample Output at End of Script:'''
 +
 +
                            *Summary of Changes - File(s) Created and/or Deleted*
 +
 +
                              8 File(s) Created:
 +
 +
                              /usr/src/linux-3.0-rc4-git5-KNL/
 +
                              /boot/vmlinuz-3.0-rc4-git5-ARCHMOD
 +
                              /boot/kernel30-3.0-rc4-git5-ARCHMOD.img
 +
                              /lib/modules/3.0.0-rc4-git5-ARCHMOD/
 +
                              /usr/src/linux
 +
                              /usr/src/linux-3.0
 +
                              /boot/System.map-3.0-rc4-git5
 +
                              /boot/System.map
 +
 +
                              4 File(s) Deleted:
 +
 +
                              /boot/System.map
 +
                              /usr/src/linux
 +
                              /usr/src/linux-2.6
 +
                              /usr/src/linux-3.0
 +
 +
 +
                                  *SUCCESS - Main Processes COMPLETE*
 +
 +
                      *NVIDIA users, please make additional NECESSARY adjustments*
 +
 +
          *Please Configure /boot/grub/menu.lst accordingly and you are done. Then REBOOT & TEST!*
 +
  
 
==Version 2.6.x - Step by Step==
 
==Version 2.6.x - Step by Step==

Revision as of 07:50, 17 August 2011

Note: Compiling using makepkg is generally considered to be safer than using root. (This opinion is open to strong debate.) See: Kernel Compilation with ABS

Kernel versions 3.0-rc4-git5 & 2.6.39.1 were compiled and tested using this guide. During the kernel configuration process using 'make menuconfig', the Kernel Local Version (revision) which was appended to the kernel release is "ARCHMOD". You can obviously use a different description. The procedures documented here should be more than adequate for all other Linux distributions with minor, if any, differences.

Versions 3.0 & 2.6 - Automated Script

NEW, and still more to come: A thoroughly tested BASH script is available which automates the entire manual compiling process listed below and encourages the "bleeding edge" philosophy when it comes to the latest Linux Kernel. This script allows a safe, easy, and alternative method to using makepkg. It includes an easy-to-use option for patching a MAINLINE(RC) Kernel release. Recent testing of kernel linux-3.0.tar.bz2 (July 22, 2011) resulted in successful compiling, and installing. (uname -a: Linux Galicja 3.0.0-ARCHMOD #1 PREEMPT Fri Jul 22 12:18:14 CEST 2011 x86_64 Genuine Intel(R) CPU 575 @ 2.00GHz GenuineIntel GNU/Linux).

Procedures:

  • Download the script (See link below procedures).
  • Prior to initially opening or running the file Template:Filename, go into root (#) and use chmod to give it appropriate execution permissions (755):
# chmod 755 linux_kernel.sh
  • Open up Template:Filename and carefully enter values for only 7 variables which are required for the script to run, then save the file (See sample input area below procedures).
  • Once values have been entered and source files downloaded, run the script in root (#):
# ./linux_kernel.sh
  • While running, one or two pauses which require user intervention are necessary, and this occurs at the very beginning (first minute or two). Your old .config file will automatically be copied into its new directory, and 'menuconfig' will be automatically invoked. Keep in mind, this script will never override or delete any original files (soft-link only) without a warning first, or automatic termination. There are numerous checks and controls built into it to ensure safe execution. The script works VERY well, so enjoy it!

Note: NVIDIA users, please make additional NECESSARY adjustments after script is completed, PRIOR to rebooting. Feel free to contact the author for any assistance and/or suggestions.

Script Download

   linux_kernel.sh at Google Docs (Last Updated: Friday, July 22, 2011, 13:31 CET)


Sample linux_kernel.sh BASH script Input Area for 7 required variables:

#==========================================================================
# Enter 7 Kernel Variables Values Here (You MUST fill in ALL values after "="):

# Directory Name holding "mainline", "stable" and/or "snapshot"(patch) source files from kernel.org
# Must end with "/"
kern_src_dir=/usr/src/

# Directory Name holding current Kernel ".config" file (".config" will be copied automatically into new directory)
# Must end with "/"
config_dir=/usr/src/linux-2.6.39.1-KNL/

# Value of CONFIG_LOCALVERSION parameter in Kernel ".config" file (Ex.  CONFIG_LOCALVERSION="-ARCHMOD")
local_ver=-ARCHMOD

# File Name of "mainline" or "stable" Linux Kernel (Must be downloaded and reside in the "kern_src_dir" (/usr/src/)
kern_file_name=linux-3.0-rc4.tar.bz2

# Is a Patch file involved? YES or NO (Must be CAPITALIZED Letters)
patch=YES

# If patch=YES, File Name of "snapshot" patch (Ex. patch-2.6.37-rc1-git12.bz2) residing in "kern_src_dir" (/usr/src/)
# If patch=NO, then this value does NOT matter. If you wish, enter NONE (patch=NONE)
patch_file_name=patch-3.0-rc4-git5.bz2

# To build the kernel in a multithreaded (faster) way, the -j option is used with the 'make' program
# It is BEST to give a number to the -j option that corresponds to TWICE the number of processors in the system
# ( Ex. Machine with 1 processor: jval=2, Machine with 2 processors: jval=4, etc.)
# To disable this option, enter the value zero ("0"): ( Ex. jval=0 )
jval=0

#==========================================================================


Sample Output at End of Script:

                           *Summary of Changes - File(s) Created and/or Deleted*

                              8 File(s) Created:

                              /usr/src/linux-3.0-rc4-git5-KNL/
                              /boot/vmlinuz-3.0-rc4-git5-ARCHMOD
                              /boot/kernel30-3.0-rc4-git5-ARCHMOD.img
                              /lib/modules/3.0.0-rc4-git5-ARCHMOD/
                              /usr/src/linux
                              /usr/src/linux-3.0
                              /boot/System.map-3.0-rc4-git5
                              /boot/System.map

                              4 File(s) Deleted:

                              /boot/System.map
                              /usr/src/linux
                              /usr/src/linux-2.6
                              /usr/src/linux-3.0


                                  *SUCCESS - Main Processes COMPLETE*

                     *NVIDIA users, please make additional NECESSARY adjustments*

         *Please Configure /boot/grub/menu.lst accordingly and you are done. Then REBOOT & TEST!*


Version 2.6.x - Step by Step

1) Switch from the User prompt ($) to Root (#)

       $ su
       Password: xxxxxx
       #

Note: The /usr/src directory is owned by Root. This is why Root is used.

2) Back up current kernel

Back up latest (current) kernel ".config" file and save to a /home/user directory

Example:

       # cp /usr/src/linux-`uname -r`/.config ~/config.save

Note: It is recommended to back up the .config file as to simplify the kernel configuration process later on using 'make menuconfig'. Many of the Linux kernel defaults already installed on your Linux distribution are properly configured, however, other specifications often require further adjustment for maximum optimization and performance.

AND

Delete any symlinks in /usr/src and /boot directories (assuming these exist):

       # cd /usr/src
       # rm linux
       # rm linux-2.6
       # cd /boot
       # rm System.map

3) Preparing /usr/src

Goto /usr directory and check if /usr/src exists

       # cd /usr
       # ls | grep src

If it does not exist, create /usr/src

       # mkdir src

and proceed to step 4;

If it does exist and is empty, proceed to step 4;

(Optional) If it does exist and contains previous kernel data, you may erase it all if you choose to do so. This is not recommended as you may want your previous kernel as an emergency backup for your system and your GRUB menu since it is functional. It is safer to leave the previous kernel and directory intact. However, if you prefer to erase it, you can do it by going into /usr/src

       # cd src

and removing it all

       # rm -rf *

(Warning: Be very careful with "rm -rf *" - extremely dangerous if not used properly) and proceed to step 4;

4) Save latest Linux kernel source

Goto the linux kernel website and save latest Linux kernel source "linux-2.6.38-rc5.tar.bz2" to the /home/user directory. Change to /home/user directory and copy kernel source to /usr/src;

       # cp linux-2.6.38-rc5.tar.bz2 /usr/src

5) Unpacking and entering the tarball

Go to /usr/src, unpack the kernel source, enter the source directory

       # cd /usr/src
       # tar -xvjf linux-2.6.38-rc5.tar.bz2
       # cd /usr/src/linux-2.6.38-rc5

6) Make (or edit) two symlinks to the kernel

       # ln -s /usr/src/linux-2.6.38-rc5 /usr/src/linux
       # ln -s /usr/src/linux-2.6.38-rc5 /usr/src/linux-2.6

Note: Why do we create these two symlinks? The Linux kernel sources may sometimes (more often not) be picked up from a “linux” or "linux-2.6" directory when they are packaged into a “tar” archive file; when you unpack them, therefore, they may sometimes (more often not) expect to go back into a “linux” or "linux-2.6" directory. If you only have a single “linux” directory, and you unpack them into /usr/src without doing the steps above, they will overwrite some of your existing source files, and leave you with a real mess. You’ll have old and new files all mixed together. In a situation like that, the only thing to do is remove the entire “linux” directory and start over. Using a symlink to point to the current version — and keeping each version in its own directory — makes it much easier to keep everything under control. These soft symlinks are created more as a safety measure, to be conservative - just in case.

7) Reset the source directory

Clean out all previous configurations and reset 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

8) Copy backup .config

Copy previously saved backup .config file (config.save) to /usr/src/linux-2.6.38-rc5;

       # cp /home/USERNAME/config.save /usr/src/linux-2.6.38-rc5/.config

9) Configure current kernel source using backup .config file

Note: This is the most crucial step in customizing the kernel to reflect your computer's precise specifications. By setting the configurations in 'menuconfig' properly, your kernel and computer will function most efficiently. Please see "Appendix A" below this guide for common items that are adjusted for a typical kernel.

       # make menuconfig

When done with configuration, save .config file.

10) Clean up

Clean up miscellaneous object files. This step is required for all versions of the kernel;

       # make clean

Note: The usual preceding command (# make dep) step is only required for the 2.4.x kernel tree in case you are wondering why it is missing in this Linux kernel guide.

11) Kernel Build

We are now (finally) ready to start the actual kernel build;

       # make bzImage

Note: This may take a while, be patient;

12) Create modules

After you have created the kernel, now you need to create all the loadable modules;

       # make modules

Note: This will take much longer than step 11, be patient;

Once the modules are built they can be installed;

       # make modules_install

13) Copy the new kernel to your /boot directory

       # cp -v arch/x86/boot/bzImage /boot/vmlinuz-2.6.38-rc5-ARCHMOD

14) Build a ramdisk if necessary (Recommended)

       # mkinitcpio -k 2.6.38-rc5-ARCHMOD -g /boot/kernel26-2.6.38-rc5-ARCHMOD.img

Note: In Linux distributions other than Arch Linux, the above command might be:

       # mkinitrd -k vmlinux-REVISION -i initrd-REVISION

OR

       # mkinitrd /boot/initrd-2.6.0.img 2.6.0

Note: What's an initial RAM disk and why is it necessary? The initial RAM disk (initrd option in the GRUB menu, or, the file "kernel26-2.6.38-rc5-ARCHMOD.img") is an initial root file system that is mounted prior to when the real root file system is available. The initrd is bound to the kernel and loaded as part of the kernel boot procedure. The kernel then mounts this initrd as part of the two-stage boot process to load the modules to make the real file systems available and get at the real root file system. The initrd contains a minimal set of directories and executables to achieve this, such as the insmod tool to install kernel modules into the kernel. In the case of desktop or server Linux systems, the initrd is a transient file system. Its lifetime is short, only serving as a bridge to the real root file system. In embedded systems with no mutable storage, the initrd is the permanent root file system.

15) System.map

Copy System.map to /boot and create symlink

       # cp System.map /boot/System.map-2.6.38-rc5
       # ln -s /boot/System.map-2.6.38-rc5 /boot/System.map

Note: What is "System.map"? The System.map file is not required for booting Linux. It is a type of "phone directory" list of functions in a particular build of a kernel. The System.map contains a list of kernel symbols (i.e function names, variable names etc) and their corresponding addresses. This "symbol-name to address mapping" is used by...

  • Some processes like klogd, ksymoops etc
  • By OOPS handler when information has to be dumped to the screen during a kernel crash (i.e info like in which function it has crashed).

Hence, it can be said that the kernel itself doesn't need this file and thus the absence of System.map in the /boot directory doesn't affect kernel booting.

After completing all steps above, you should have the following 3 files and 1 soft symlink in your /boot directory along with any other previously existing files:

       vmlinuz-2.6.38-rc5-ARCHMOD          (File - Kernel)
       kernel26-2.6.38-rc5-ARCHMOD.img     (File - Ramdisk)
       System.map-2.6.38-rc5               (File - System Map)
       System.map                          (Soft Symlink)

16) Configure Bootloader

Edit /boot/grub/menu.lst accordingly so that the partitions and kernel match and you are done!

Note: The GRUB configuration must be done in order to boot into your new Ramdisk and Kernel.

17) Testing

Reboot your system and test that the kernel loaded correctly.