Merge pull request #708 from geekpi/master

[Translating] 28 The Linux Kernel--Compiling and Installing
This commit is contained in:
geekpi 2014-01-19 20:40:52 -08:00
commit 2fb72f6082
2 changed files with 57 additions and 57 deletions

View File

@ -1,57 +0,0 @@
28 The The Linux Kernel--Compiling and Installing
================================================================================
![](http://www.linux.org/attachments/slide-jpg.762/)
Aloha! After you have spent a lot of time configuring your kernel to make the kernel you need, you can now compile it. The source code is C code in the form of plain text. This is readable to humans but not computers. Compiling the code converts the code to a form computers understand called binary (ones [on] and zeros [off]). Compilation will also make all of those kernel files one file called the kernel.
To compile the kernel, type "make" in a terminal that is in the same directory as the kernel's source code folders. This will take some time. Once done, the modules must be compiled by typing "make modules". To make the compiling process easier from the beginning, type "make; make modules". This will make the kernel and then the modules instead of the user coming back later to type "make modules".
![](http://www.linux.org/attachments/compiling_01-png.763/)
WARNING: Before you install a kernel, backup all of the important data. Be sure to make a copy of /boot/ onto a FAT32 memory card. This helps to repair the system if the installation fails. FAT32 does not store permissions, so it will be easier to use a live disk to copy the files back. Remember to set the original file permissions and executable bits.
Once the compilation has finished successfully, we can then install the kernel to the local system (I will explain how to install the kernel on other systems in a moment [cross-compiling]). In the same terminal, after compilation, type "make install". This will place some files in the /boot/ directory. The "vmlinuz" (or some similar name) is the kernel itself. "initrd" is the temporary RAM-based filesystem that is placed in memory and used during boot-up. The "System-map" contains a list of kernel symbols. These are global variables and functions used in the kernel's code. "config" is the configuration file for the kernel. grub.cfg will automatically be updated. However, some other bootloaders may need to be manually configured. The kernel installer can configure the Grub, LILO, and SysLinux bootloader automatically. Bootloaders like BURG may need to be manually configured. The modules must also be installed by typing "make modules_install".
![](http://www.linux.org/attachments/compiling_04-png.764/)
NOTE: Both the kernel and modules can be installed using one line - “make install && make modules_install”
![](http://www.linux.org/attachments/compiling_05-png.765/)
Once that process is complete, the user can ensure the kernel was installed by restarting the system and typing "uname -r" in a terminal when the system is back on. If the system fails to boot or uname reports a different version number than expected, the issue may be due to one of many issues. Either the bootloader was improperly setup, feature/configuration conflict, compilation error, improperly installed, or some other reason. The best way to start finding the source of the issue is to look at the systems logs (if the system boots up enough to produce logs). "dmesg" is a command that prints the kernels logs to the screen. Look for any errors, warnings, or unexpected results. If the system does not boot or does not boot-up enough to produce logs, use a live Linux disc to perform diagnostics and repairs. If all else fails, compile the kernel again and make sure you installed the kernel as Root or used "sudo".
NOTE: The best way to repair such a system is to use a live Linux distro to remove the new/broken kernel and then manually fix (or paste a backup) Grub's files.
Some Linux users like to have the documentation installed as well, but this is not required. For those that like to have the documentation installed, type this line where version is the kernel version - "install -d /usr/share/doc/linux-VERSION && cp -r Documentation/* /usr/share/doc/linux-VERSION" (VERSION is the kernel's version number). Obviously, Root privileges are required.
To compile a newer kernel with the same features as your current kernel, then type this command "zcat /proc/config.gz > .config". This file may not exist, if so, you may be able to ask the developers of your distro/kernel for the file. The "zcat" command uncompresses the data and places it in the file ".config". Remember to type where you want ".config". This file is to be placed in the Linux kernel directory and allow it to replace the current file. Then, compile and install the kernel as you normally would.
Cross-compiling is slightly different. Configure the kernel for the intended system. Make sure that when the kernel was configured, that it was configured with cross-piling in mind. When cross-compiling, their are two terms to be familiar with. "Host" is the system performing the compilation. The "Target" is the system that will receive the new kernel. Make sure that the host system has the proper compilers. For example, to cross-compile for ARM systems, users will need gcc-arm-linux-gnueabi on the host system. Generally, the developer can do a search in their package manager or Google for the proper/best cross-compiler for their needs. The specific command used to cross-compile for ARM systems is "make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-". The "ARCH=arm" refers to the target's processor type and "CROSS_COMPILE" declares the cross-compiler. Notice that the cross-compiler is missing the "gcc-" at the beginning and ends in a dash. That is the format users must use when using the cross-compiler as a parameter. The modules can be cross-compiled by typing "make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules". To install the kernel on the target system, copy the Linux kernel folder to the target system. Once the files are on the target system and a terminal is open in that directory, type "make install && make modules_install". Of course, you must be Root or use "sudo".
INFO: Kernel.org hosts a list of supported cross-compilers ([https://www.kernel.org/pub/tools/crosstool/][1]).
### Compilation and Installation Summary: ###
#### Standard: ####
make && make modules && make install && make modules_install
#### Make a newer version or remix of your kernel: ####
zcat /proc/config.gz > .config && make && make modules && make install && make modules_install
#### Cross-compile: ####
make ARCH={TARGET-ARCHITERCTURE} CROSS_COMPILE={COMPILER}; make ARCH={TARGET-ARCHITERCTURE} CROSS_COMPILE={COMPILER} modules && make install && make modules_install
In the next article, we will discuss adding and activating modules. Mahalo!
--------------------------------------------------------------------------------
via: http://www.linux.org/threads/the-linux-kernel-compiling-and-installing.5208/
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:https://www.kernel.org/pub/tools/crosstool/

View File

@ -0,0 +1,57 @@
戴文的Linux内核专题28 编译与安装
================================================================================
![](http://www.linux.org/attachments/slide-jpg.762/)
你好在花费了大量的时间在配置你需要的内核后你现在可以编译它了。源代码是纯文本形式的C代码。这对人来可读但是对机器不这样。编译会将代码转换成计算机可理解的一种称之为二进制码的形式(1是 [开],0 是 [关])。编译同样会将所有内核代码文件变成一个内核的文件。
为了编译内核,在内核源代码相同目录下,在终端内输入"make"。这会花费一些时间。一旦完成,模块必须通过"make modules"来编译。为了从一开始就简化编译过程,输入"make; make modules"。这会先编译接着是模块,而不用用户再回来输入"make modules"。
![](http://www.linux.org/attachments/compiling_01-png.763/)
警告:在你安装一个内核时,备份所有的重要数据,确保有一份/boot目录备份在FAT32的存储卡上。这可以在如果安装失败后帮助修复系统。FAT32不会存储权限因此它更容易被用作live盘来还原数据。记住设置原始文件权限和可执行位。
一旦编译已经成功完成,我们可以安装内核到本地系统中(我会马上解释如何在其他系统上安装内核[交叉编译])。在相同的终端下,在编译完成后,输入"make install"。这会在/boot目录下存放一些文件。"vmlinuz"(或者其他相似的名字)是内核自身。"initrd"是基于内存的文件系统,它被置于内存中且在启动中使用。"System-map"包含了一张内核符号列表。这些全局变量和函数用于内核代码。"config" 是内核的配置文件。grub.cfg会自动更新。然而有些bootloder需要手动配置。内核安装器会自动配置GrubLILO和SysLinux bootloder。像BURG这类bootloder需要手动配置。模块的安装同样需要输入"make modules install"。
![](http://www.linux.org/attachments/compiling_04-png.764/)
注:内核和模块的安装可以写在一行-“make install && make modules_install”。
![](http://www.linux.org/attachments/compiling_05-png.765/)
一旦上面的过程完成了,用户可以通过重启系统并在开机后在终端内输入"uname -r"来确保内核已经安装。如果系统无法启动或者uname报告你预期外的版本号这个问题可能众多问题之一引起。或者是bootloader没有正确设置特性/配置冲突,编译失败,不正确的安装,或者其他原因。找出问题源头最好的方法是查看系统日志(如果系统已经启动到足以产生日志)。"dmsg"是一个在屏幕上打印内核日志的命令。查看错误、警告或者未预料的结果。如果系统没有启动或者没有足够启动完全来生成日志使用live linux盘来执行诊断和修复。如果所有的都失败了再次编译内核并确保你已经用root或者"sudo"安装了内核。
最好的修复系统的方式是使用live Linux发行版来移除新的/损坏的内核接着手动修复Grub文件(或者复制一个备份)。
一些Linux用户也喜欢安装文档但这并不是必要。对于那些想要安装文档的用户输入这行这里的version是你的内核版本号 "install -d /usr/share/doc/linux-VERSION && cp -r Documentation/* /usr/share/doc/linux-VERSION"(VERSION 是内核版本号)。很明显这需要root特权。
为了编译一个如你目前内核一样特性的内核,输入这条命令"zcat /proc/config.gz > .config"。这个文件可能不存在,如果是这样,你可能需要询问你发行版/内核的开发者这个文件。"zcat"命令解压并写入数据到一个".config"文件中。记住在你希望的地方输入".config"。这个文件放置在Linux内核目录下并允许它替换当前的文件。接着像往常一样编译安装你的内核。
交叉编译稍微有点不同。为目标系统配置内核。确保内核配置完后,它在脑海中交叉配置过了。当交叉编译时,需要熟悉两条术语。"Host"是执行编译的系统,"Target"是接收新内核的系统。确保主机系统有合适的编译器。比如对于ARM系统的交叉编译用户需要在主机系统上有gcc-arm-linux-gnueabi。通常来说开发这可以在他们的包管理器上搜寻或者Googledao合适/最好的适合他们需要的交叉编译器。特定的用于ARM系统交叉编译的命令是"make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-"。"ARCH=arm"指的是目标处理器的类型,"CROSS_COMPILE"指明了交叉编译器。注意交叉编译器前面缺少了"gcc-"并以破折号结束。这是用户在使用交叉编译器作为参数使用时必须使用的格式。模块可以通过输入"make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules".交叉编译。为了在目标系统上安装内核,复制内核文件夹到目标系统上。一旦文件已在目标系统上并在该目录下打开了终端,输入"make install && make modules_install"。当然你必须是root或者使用"sudo"。
信息Kernel.org放了一个支持的交叉编译器列表([https://www.kernel.org/pub/tools/crosstool/][1])。
### 安装编译总结: ###
#### 标准: ####
make && make modules && make install && make modules_install
#### 做一个更新的版本或者重混你的内核: ####
zcat /proc/config.gz > .config && make && make modules && make install && make modules_install
#### 交叉编译: ####
make ARCH={TARGET-ARCHITERCTURE} CROSS_COMPILE={COMPILER}; make ARCH={TARGET-ARCHITERCTURE} CROSS_COMPILE={COMPILER} modules && make install && make modules_install
下篇文章中,我们会讨论加入和激活模块。谢谢!
--------------------------------------------------------------------------------
via: http://www.linux.org/threads/the-linux-kernel-compiling-and-installing.5208/
译者:[geekpi](https://github.com/geekpi) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:https://www.kernel.org/pub/tools/crosstool/