Compile kernel under Ubuntu

Source: Internet
Author: User

1. Install the Compile Kernel environment tool

<pre name= "code" class= "HTML" >sudo apt-get install build-essential kernel-package Libncurses5-dev Libqt3-headersbuild-essential (Basic Programming library (GCC, make, etc.) Kernel-package (some of the configuration files and tools generated Kernel-image in the Debian system) Libncurses5-dev (Meke menuconfig to invoke) Libqt3-headers (make Xconfig to invoke)


2. Download specific Linux kernel source code

I downloaded the Linux-3.17.4.tar.


3. Unzip the Linux-3.17.4.tar into your own directory, my mywork directory

TAR-XVF Linux-3.17.4.tar

4. Kernel Configuration and compilation

The Linux kernel has customizable benefits, and the steps

4.1 Make Distclean//clear temporary files, configuration files and intermediate files

Several other cleanup commands:

Make Clean:remove most generated files and keep the Configmake Mrproper:remove all generated files + config Filesmake dis Tclean:mrproper + Remove editor backup and patch files

4.2 Configuring Kernel Options

Determine the hardware and software configuration of the target system, such as the type of CPU, the model of the network card, the network protocol needed to support, etc.

There are several main commands

Make config: Interactive configuration based on text mode. Make Menuconfig: Menu-based configuration in text mode. (Recommended use)
Make Oldconfig: Use an existing configuration file (. config), but ask for new configuration options
Make Xconfig: Graphical configuration (requires installation of a graphical system)
where makeMenuconfig is the most commonly used kernel configuration method

Here's how to use it:

1. Use the arrow keys to move between the options;
2. Use "Enter" key to enter the next level menu; the highlighted letter on each option is a keyboard shortcut that allows you to quickly reach the selected item you want to set

3, in parentheses, press "Y" to compile the project into the kernel, press "M" to compile as a module, press "N" as not selected (press the SPACEBAR can also be compiled into the kernel, compiled into a module and do not compile the three switch between), press "H" will display This option, press "ESC" to return to the upper menu

Note: The configuration kernel is typically configured on the configuration basis of the existing kernel, The Linux kernel provides a series of references to the internal The kernel configuration file, located in a rch/$cpu The/configs directory below

Here we are to ensure that the compiled kernel is available, using the current Ubuntu system itself configuration items to compile, its own configuration items under /usr/src/linux-headers-2.6.32-21-generic/.config,

We'll copy it to the current directory.

Cp/usr/src/linux-headers-2.6.32-21-generic/.config  ./
Execute make menuconfig start configuration kernel, here we do not need to modify any configuration, we directly select "load, then select "Save"





5., compile the kernel

Make Zimage
Make Bzimage
Difference: On the X86 platform, Zimage can only be used for cores less than 512K

For detailed compilation information, you can use:
Make Zimage V=1
Make Bzimage V=1
The compiled kernel is located under the arch/<cpu>/boot/directory.

Here we can directly perform MAKE-J4 compilation, plus-j4, dual-core parallel compilation, much faster

The compiled kernel is below arch/x86/bzimage.

6. Compile kernel module,

Make modules
7. Installing kernel modules

Make Modules_install
Installed kernel module under the/lib/modules directory, I will appear here 3.17.4 such a new directory


8. Make init RAMDisk

It is usually used MKINITRD, and under the Ubuntu/debian is used Mkintramfs.

Their usage is slightly different, as follows:

sudo mkinitrd initrd.img_3.17.4 3.17.4//After this 3.17.4 is corresponding to the kernel module you compiled earlier, located under the/lib/modules directory

sudo mkinitramfs-o/boot/initrd.img_3.17.4

Where 2.6.26 is the directory name under/lib/modules.

9. Execute sudo make install system Automatic Update start (Ubuntu platform)

Note: Other platforms perform the following commands

1. CP./arch/x86/boot/bzimage/boot/vmlinuz-$version 2, CP <span style= "COLOR:RGB (102, 102, 102); Font-family: Song body, Arial; font-size:15.555556297302246px; line-height:25.98958396911621px; BACKGROUND-COLOR:RGB (240, 240, 240); " >initrd.img_3.17.4</span>/BOOT/3, modify/etc/grub.conf  or/etc/lilo.conf

10. Reboot Restart System






Compile kernel under Ubuntu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.