Linux源码研究-用户和管理员手册-release 4.x

什么是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内核,对软件包有最低版本有求。

 

ProgramMinimal versionCommand to check the version
GNU C3.2gcc –version
GNU make3.81make –version
binutils2.20ld -v
flex2.5.35flex –version
bison2.0bison –version
util-linux2.10ofdformat –version
module-init-tools0.9.10depmod -V
e2fsprogs1.41.4e2fsck -V
jfsutils1.1.3fsck.jfs -V
reiserfsprogs3.6.3reiserfsck -V
xfsprogs2.6.0xfs_db -V
squashfs-tools4.0mksquashfs -version
btrfs-progs0.18btrfsck
pcmciautils004pccardctl -V
quota-tools3.09quota -V
PPP2.4.0pppd –version
isdn4k-utils3.1pre1isdnctrl 2>&1|grep version
nfs-utils1.0.5showmount –version
procps3.2.0ps –version
oprofile0.9oprofiled –version
udev081udevd –version
grub0.93grub –version || grub-install –version
mcelog0.6mcelog –version
iptables1.4.2iptables -V
openssl & libcrypto1.0.0openssl version
bc1.06.95bc –version
Sphinx[1]1.3sphinx-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​​​​​​​

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值