How to Compile Linux Kernel from Source to Build Custom Kernel
来源:互联网 发布:sql注入布尔型攻击 编辑:程序博客网 时间:2024/06/03 01:31
原文: http://www.thegeekstuff.com/2013/06/compile-linux-kernel/
Linux kernel is the life force of all Linux family of operating systems including Ubuntu, CentOS, and Fedora.
For most part, you don’t need to compile the kernel, as it is installed by default when you install the OS. Also, when there is a critical update done to the kernel, you can use yum, or apt-get to update the kernel on your Linux system.
However you might encounter certain situation, where you may have to compile kernel from source. The following are few situation where you may have to compile Kernel on your Linux system.
- To enable experimental features that are not part of the default kernel.
- To enable support for a new hardware that is not currently supported by the default kernel.
- To debug the kernel
- Or, just to learn how kernel works, you might want to explore the kernel source code, and compile it on your own.
In this tutorial, we’ll explain how to compile Linux kernel from source.
Also, please note that if you just want to compile a driver, you don’t need to compile the kernel. You need only the linux-headers package of the kernel.
1. Download the Latest Stable Kernel
The first step is to download the latest stable kernel from kernel.org.
# cd /usr/src/# wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.9.3.tar.xz
2. Untar the Kernel Source
The second step is to untar the kernel source file for compilation.
# tar -xvJf linux-3.9.3.tar.xz
3. Configure the Kernel
The kernel contains nearly 3000 configuration options. To make the kernel used by most people on most hardware, the Linux distro like Ubuntu, Fedora, Debian, RedHat, CentOS, etc, will generally include support for most common hardware. You can take any one of configuration from the distro, and on top of that you can add your own configuration, or you can configure the kernel from scratch, or you can use the default config provided by the kernel
# cd linux-3.9.3# make menuconfig
The make menuconfig, will launch a text-based user interface with default configuration options as shown in the figure. You should have installed “libncurses and libncurses-devel” packages for this command to work.
We will use the default config provided by the kernel. So select “Save” and save the config in the file name “.config”.
The following is a sample of the “.config” file:
CONFIG_MMU=yCONFIG_NEED_DMA_MAP_STATE=yCONFIG_NEED_SG_DMA_LENGTH=yCONFIG_GENERIC_ISA_DMA=yCONFIG_GENERIC_BUG=yCONFIG_GENERIC_HWEIGHT=y
4. Compile the Linux Kernel
Compile the main kernel:
# make
Compile the kernel modules:
# make modules
Install the kernel modules:
# make modules_install
At this point, you should see a directory named /lib/modules/3.9.3/ in your system.
5. Install the New Kernel
Install the new kernel on the system:
# make install
The make install command will create the following files in the /boot directory.
- vmlinuz-3.9.3 – The actual kernel
- System.map-3.9.3 – The symbols exported by the kernel
- initrd.img-3.9.3 – initrd image is temporary root file system used during boot process
- config-3.9.3 – The kernel configuration file
The command “make install” will also update the grub.cfg by default. So we don’t need to manually edit the grub.cfg file.
6. Boot Linux to the new Kernel
To use the new kernel that you just compiled, reboot the system.
# reboot
Since, in grub.cfg, the new kernel is added as default boot, the system will boot from the new kernel. Just in case if you have problems with the new kernel, you can select the old kernel from the grub menu during boot and you can use your system as usual.
Once the system is up, use uname command to verify that the new version of Linux kernel is installed.
$ uname -r3.9.3
- How to Compile Linux Kernel from Source to Build Custom Kernel
- how to compile kernel
- how to compile kernel
- How to Compile the Linux Kernel
- How to: Compile Linux kernel 2.6
- How to: Compile Linux kernel 2.6
- How to: Compile Linux kernel modules
- How to: Compile Linux kernel 2.6
- How to: Compile Linux kernel 2.6
- how to compile the linux kernel
- how to compile uClinux kernel
- How to compile your kernel
- How to build kernel for Beaglebone for custom cape support
- How to build CE6 kernel
- linux compile source to ko(kernel object) successfully!
- How to Create, Compile, Load Linux LKM Loadable Kernel Modules
- how to compile kernel in android ?
- Compile linux kernel source
- Would You Like a Shave or a Haircut?
- struts2标签库无法运行
- “Borland license information was found,but it is not valid for delphi.”
- STL源码剖析之map set multimap multiset【2013.12.10】
- ArcGIS WebAPI接入google瓦片服务
- How to Compile Linux Kernel from Source to Build Custom Kernel
- javaee加密,tomcat使用自己的classloader解密
- 同样的sql传入的条件不同执行效率相差百倍的原因
- [IE兼容性]
- hibernate使用hql 查询
- Java 解析 XML 文件之 DOM 解析
- Robotium_易测云生成的自动化测试脚本(5)
- Mongodb architecture
- Hql语句注意事项总结 批量删除 批量查询