什么是Linux
Linux是Unix操作系统的克隆,由Linus Torvalds及通过网络组织在一起的团队开发,目标是遵循POSIX和单一Unix规范。它有Unix的所有特性,包括多任务、虚拟内存、共享库、请求加载、共享写时复制执行、合理的内存管理及IPv4-IPv6的多层网络。使用开源协议GPL v2。
支持的硬件
现在的Linux至少可以运行在Compaq Alpha AXP, Sun Sparc/UltraSparc, Motorola 68000, PowerPC, PowerPC64, ARM, Hitachi SuperH, Cell, IBM S/390, MIPS, HP PA-RISC, Intel IA-64, DEC VAX, AMD x86-64 Xtensa, ARC。
Linux可以移植到大部分通用的32或64位的架构上(支持PMMU(页式内存管理单元)和gcc)。Linux也可以移植到没有PMMU的架构上,当然功能会裁剪。另外Linux可以用移植到Linux本系统上,作为一个用户空间应用运行,称为UML(UserMode Linux).
安装内核源码
- 如果你安装全部的sources,把内核tarball放在你有权限的目录下,解压缩,不要使用/usr/src/linux这个目录,因为这是linux系统使用的目录
xz -cd linux-4.X.tar.xz | tar xvf -
- 你也可以在4.x系列中通过补丁升级。补丁是xz格式,下载所有的补丁文件,如果要移除backup文件(some-file-name~或者some-file-name.orig),确保没有失败的补丁(some-file-name#或some-file-name.rej)。和为4.x内核打补丁不同,为4.x.y内核打补丁不是递增的,而是直接基于4.x内核进行。如果你当前内核是4.0,想应用4.0.3补丁,你一定要先应用4.0.1和4.0.2补丁,如果当前内核是4.0.2,想应用4.0.3补丁,你一定要先回退到4.0.2补丁(patch -R),然后再应用4.0.3补丁。可以使用内核补丁脚本来自动化这个过程。
xz -cd ../patch-4.x.xz | patch -p1
linux/scripts/patch-kernel linux
- 确保你没有stale.o文件和相关依赖
cd linux
make mrproper
现在你应该已经正确安装了源码。
软件要求
编译和运行4.x内核,对软件包有最低版本有求。
Program | Minimal version | Command to check the version |
---|---|---|
GNU C | 3.2 | gcc –version |
GNU make | 3.81 | make –version |
binutils | 2.20 | ld -v |
flex | 2.5.35 | flex –version |
bison | 2.0 | bison –version |
util-linux | 2.10o | fdformat –version |
module-init-tools | 0.9.10 | depmod -V |
e2fsprogs | 1.41.4 | e2fsck -V |
jfsutils | 1.1.3 | fsck.jfs -V |
reiserfsprogs | 3.6.3 | reiserfsck -V |
xfsprogs | 2.6.0 | xfs_db -V |
squashfs-tools | 4.0 | mksquashfs -version |
btrfs-progs | 0.18 | btrfsck |
pcmciautils | 004 | pccardctl -V |
quota-tools | 3.09 | quota -V |
PPP | 2.4.0 | pppd –version |
isdn4k-utils | 3.1pre1 | isdnctrl 2>&1|grep version |
nfs-utils | 1.0.5 | showmount –version |
procps | 3.2.0 | ps –version |
oprofile | 0.9 | oprofiled –version |
udev | 081 | udevd –version |
grub | 0.93 | grub –version || grub-install –version |
mcelog | 0.6 | mcelog –version |
iptables | 1.4.2 | iptables -V |
openssl & libcrypto | 1.0.0 | openssl version |
bc | 1.06.95 | bc –version |
Sphinx[1] | 1.3 | sphinx-build –version |
内核编译
- GCC,版本依赖于你使用的CPU
- Make
- Binutils,使用thin archives(ar T)替换incremental linking(ld -r)
- Flex,词法分析器
- Bison,语法分析器
- Perl
- BC
- OpenSSL
系统工具
- Util-linux
- Ksymoops,如果内核崩溃,可以使用ksymoops工具,但是大部分情部分是在编译内核进使用CONFIG_KALLSYMS选项。
模块初始化工具
- Mkinitrd
- E2fsprogs
- JFSutils,文件系统工具
- Reiserfsprogs
- Xfsprogs,
- PCMCIAutils
- Quota-tools,
- Intel IA32 microcode
- udev
- FUSE
网络
- Packet Filter/NAT,
- PPP
- isdn4k-utils
- NFS-utils
- mcelog
内核文档
- Sphinx
内核的编译目录
当编译内核时,生成文件默认与源文件保存的一起,使用make O=output/dir选项可以指定生成文件的存放目录。
例如:
kernel source code: /usr/src/linux-4.X
build directory: /home/name/build/kernel
那么可以这样配置:
cd /usr/src/linux-4.X
make O=/home/name/build/kernel menuconfig
make O=/home/name/build/kernel
sudo make O=/home/name/build/kernel modules_install install
如果使用的了O=output/dir选项,那么所有的make必须都要使用。
配置内核
- make config, plain text interface
- make menuconfig , text based color menus, radiolists & dialogs
- make nconfig , enhanced text based color menus
- make xconfig, qt based configuration tool
- make gconfig, gtk+ based configuration tool
- make oldconfig, default all questions based on the contents of your existing ./.config file and asking about new config symbols
- make olddefconfig, lkie above , but sets new symbols to their default values without prompting.
- make defconfig, create a ./.config file by using the default symbol values from either arch/$ARCH/defconfig or arc/$ARCH/configs/${PLATFORM}_defconfig, depending on the architecture.
- make ${PLATFORM}_defconfig, create a ./.config file by using default symbol values from arch/$ARCH/configs/${PLATFORM}_defconfig
- make allyesconfig, create a ./.config file by setting symbol values to 'y' as much as possible
- make allmodconfig, create a ./.config file by setting symbol values to 'm' as much as possible
- make allnoconfig , create a ./.config file by setting symbol values to 'n' as much as possible
- make randconfig, create a ./.config file by setting symbol values to random values
- make localmodconfig, create a config based on current config and loaded modules (lsmod), Disables any module option that is not needed for the loaded modules.
To create a localmodconfig for another machine,
store the lsmod of that machine into a file
and pass it in as a LSMOD parameter.
target$ lsmod > /tmp/mylsmod
target$ scp /tmp/mylsmod host:/tmp
host$ make LSMOD=/tmp/mylsmod localmodconfig
The above also works when cross compiling.
- make localyesconfig, similar to localmodconfig, except it will convert all module options to built in (=y) options
- make kvmconfig, Enable additional options for kvm guest kernel support
- make xenconfig, enable additional options for xen dom0 guest kernel support
- make tinyconfig, configure the tinest possible kernel.
编译内核
- 执行一个make来创建一个压缩的内核镜像,如果你安装了适配kernel makefiles的lilo,也可惟执行make install。编译时不需要root用户,但是安装时需要使用root用户。
- 如果你把内核的部分配置为modules,那么需要执行make modules_install
- 冗长的compile/build 输出。正常情况下,内核编译时处于quiet mode,如果你想看到具体的过程信息,可以使用verbose编译模式,通过给make命令传统V=1,默认V=0,V=2是rebuild of each target。
make V=1 all
- 保留内核的一个backup,以防止出问题。确保也为内核对应的modules也做了backup。可以在内核编译时配置LOCALVERSION选项来为内核版本添加前缀。
- 为了启动新内核,需要把内核镜像拷贝到正常内核加载的地方。
- 内核的加载不再支持从floppy中加载,如果从硬盘中启动Linux,使用LILO,通过/etc/lilo.conf文件来指内核镜像,内核镜像文件通常为/vmlinz, /boot/vmlinuz, /bzImage或/boot/bzImage,为了使用新内核,需要用新内核镜像替换老镜像,然后一定要重新运行LILO。重新安装LILO通常是运行/sbin/lilo,也可以修改/etc/lilo.conf文件。如果需要修改默认的root device ,video mode, ramdisk size等,可以使用rdev程序(或LILO启动参数),而不需要重新编译内核。
最后欢迎大家访问我的个人网站:1024s