1 / 18

一 Linux 内核概述

一 Linux 内核概述. 1 内核源码简介 2 内核编译 3 系统信息查看 4 编程环境简介 5 引导及初始化. General. Linux is a clone of the operating system Unix, written from scratch by Linus Torvalds with assistance from a loosely-knit team of hackers across the Net. As free-distribution, Linux is under GPL (通用公共许可证) .

red
Download Presentation

一 Linux 内核概述

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 一 Linux内核概述 1 内核源码简介 2 内核编译 3 系统信息查看 4 编程环境简介 5 引导及初始化

  2. General Linux is a clone of the operating system Unix, written from scratch by Linus Torvalds with assistance from a loosely-knit team of hackers across the Net. As free-distribution, Linux is under GPL(通用公共许可证). It has all the features you would expect in a modern fully-fledged Unix, including true multitasking, virtual memory, shared libraries, demand loading, shared copy-on-write executables, proper memory management, and multistack networking including IPv4 and IPv6.

  3. 1. 内核源码简介 • 特点 • 采用单内核(monolithic kernel)体系结构,并使用模块机制。 • 不支持完全意义上的用户态进程,但用共享上下文的进程实现LWP(Light Weight Process)机制。 • 非抢占式(non-preemptive)内核,即在特权级执行时不会任意改变执行流程。 • 支持对称多处理SMP(Symmetric Multiprocessing) • 符合IEEE的POSIX(Portable Operating System Interface based on Unix)标准。

  4. 用户进程 System Call Interface Modules Linux Kernel Interface Device Drivers Interface 各种硬件设备 * 内核结构

  5. Kernel Version Numbering: “version . major number . release”. Any even major number kernel (i.e. 2.6.10) is a stable kernel and any odd major number kernel (i.e. 2.5.12) is a development kernel. Kernel source is usually placed in /usr/src/linux, in which there are a number of sub-directories.

  6. * 源码组织结构 Linux arch net drivers modules mm alpha i386 … lib block char kernel fs ipc kernel mm … init include ext2 fat proc

  7. 2. 内核编译 • * 重新编译内核步骤 • 源码下载地址:www.kernel.org/pub/linux/kernel/ • (1)解压源代码 • #tar zxvf linux-2.4.18.tar.gz • (2)配置内核 • #make config //基于文本的传统配置界面 • #make memenuconfig //基于文本的彩色菜单式配置界面 • #make xconfig //基于X window的配置界面 • #make oldconfig //在原配置上做修改 • The configuration file is /usr/src/linux/.config.

  8. (3)编译内核和模块 • #make dep //检验内核源代码文件的依赖性及完整性 • #make clean //清除旧版本的目标文件等 • #make zImage //产生压缩形式的内核文件;“make bzImage”的压缩率更高。 • 注1:假设源代码在/usr/src/linux目录下,则编译后的文件在/usr/src/linux/arch/i386/boot目录下。 • 注2:如果选择了加载模块,则应对模块进行编译。 • #make modules // 编译所有选择的模块 • #make modules_install //编译模块并安装到标准的模块目录中

  9. (4)配置启动文件 •   如果用新的内核启动,需将编译好的内核及内核符号表文件拷贝到/boot目录下。 • #cp /usr/src/linux/arch/i386/boot/zImage /boot/zImage-2.4.18 • #cp /usr/src/linux/System.map /boot/System.map-2.4.18 • #ln –sf /boot/System.map-2.4.18 /boot/system.map • //系统正常启动时不会读这个符号表;主要是为了内核引导出错时便于调试。

  10. 如果用lilo启动linux,则需编辑/etc/lilo.conf文件修改系统引导配置。例如:如果用lilo启动linux,则需编辑/etc/lilo.conf文件修改系统引导配置。例如: • prompt • timeout=50 • default=linux • boot=/dev/had • map=/boot/map • install=/boot/boot.b • message=/boot/message • lba32

  11. image=/boot/vmlinux-2.4.7-10 // the old kernel label=linux read-only root=/dev/hdal image=/boot/zImage-2.4.18 // the new kernel label=newkernel read-only root=/dev/hdal   注意:必须运行lilo命令将激活新配置。 如果是grub则不需要。

  12. 3. 系统信息 • * 可以通过存在于内存的/proc虚拟文件系统,了解系统信息并且修改某些系统配置信息。 • The /proc file system presents a user readable window into the kernel's inner workings. Several Linux subsystems, such as Linux kernel modules, create entries in the the /proc file system. • Linux中很多显示系统信息的工具都是通过读取/proc中的文件来实现的。

  13. #procinfo //显示/proc下的系统信息。 • * 根据/proc文件系统根目录下的具体目录和文件。 • /proc/sys是可以更改的内核数据的目录,支持直接使用文件系统的写操作,完成对内核中预定的一些变量的改变,从而改善系统特性,包括网络,文件系统性能的微调。 • 例如: • #cat /proc/sys/fs/file-max • 4096 • #echo 8192>/proc/sys/fs/file-max • //将系统允许同时打开的文件数由4096变为8192

  14. 4. 编程环境简介 • GCC(GNU Compiler Collection)编译器:支持C、C++、Java、Ada等语言的编译;支持编译代码优化;能够产生调试代码。 • gcc编译过程(以C++为例)分3个阶段: • 预处理:gcc运行预处理程序cpp展开源程序中的宏并插入 #include <filename>所包含的头文件内容; • 编译:gcc将预处理后的源代码编译成与机器相关的目标代码; • 链接:gcc运行链接程序ld链接目标代码并创建相应的可执行二进制文件。 • * 程序员通过使用其命令行选项灵活使用。

  15. 调试器gdb gdb提供丰富的调试功能:在调试中查看代码,设置断点, 单步执行跟踪,变量监视,运行中改变程序代码。 • * 使用: • 启动gdb #gdb progname[core] //默认当前路径 • 或 #gdb –d dirname //指定源代码路径 • (gdb)list [m,n] // 在调试中查看代码 • (gdb)break <[文件名:]行号或函数名> [if <条件表达式>] // 设置断点。使用run命令执行程序 • (gdb)step 或 next // 单步执行跟踪

  16. (gdb)print <变量名> // 输出变量值 • (gdb)whatis <变量名> // 检查变量类型 • (gdb)set <变量名> = 值 // 修改变量的值 • (gdb)call funcname(args) //调用程序中的函数 • // 改变程序代码。 • (gdb)delete <断点号> • (gdb)disable <断点号> • (gdb)finish //结束当前函数并打印返回值 • (gdb)return value //结束当前函数并返回value

  17. 5. 引导及初始化 • 1)引导:即将操作系统读入内存的工作。 • 2)过程: • -系统加电/reset • -CPU转0xffff0h处执行。( 0xffff0h驻留在ROM中的Bios入口处) • -Bios完成系统检测,读取CMOS中的配置信息在内存的Bios处,并转到0x7c00h处执行,跳转到相应地址执行引导程序,由引导程序加载内核,加载完毕后,开始执行arch/i386/boot/start.S。 • -start.S在实模式下设置系统参数进行初始化,进入保护模式,跳转到内核映像的头部运行内核。 • -内核进一步完成系统表(head.S)的的初始化,核心数据结构及外设等初始化(start_kernel()),并启动分页机制,进行用户态初始化(/sbin/init),并启动mingetty显示登陆界面及提示。

  18. 关于shell Linux下shell: -- Bourne Shell 对应 bash -- C Shell 对应 tcsh -- Korn Shell 对应 pdksh Shell的功能: --命令解释 --后台运行 --I/O重定向 --管道 Shell编程略)

More Related