内核管理概述 linuxsir_org.htm

来自「linuxSir 网站的精华文章」· HTM 代码 · 共 451 行 · 第 1/2 页

HTM
451
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0039)http://www.linuxsir.org/main/?q=node/88 -->
<HTML lang=zh-hans xml:lang="zh-hans" 
xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>内核管理概述 | LinuxSir.Org</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<STYLE type=text/css media=all>@import url( misc/drupal.css );
</STYLE>

<STYLE type=text/css>@import url( http://www.linuxsir.org/main/modules/codefilter/codefilter.css );
</STYLE>

<STYLE type=text/css media=all>@import url( modules/taxonomy_context/taxonomy_context.css );
</STYLE>
<LINK media=screen href="内核管理概述  LinuxSir_Org.files/menuExpandable3.css" 
type=text/css rel=stylesheet>
<SCRIPT src="内核管理概述  LinuxSir_Org.files/menuExpandable3.js" 
type=text/javascript></SCRIPT>
<LINK href="内核管理概述  LinuxSir_Org.files/common.css" type=text/css rel=stylesheet>
<STYLE type=text/css media=all>@import url( themes/chameleon/marvin/style.css );
</STYLE>

<META content="MSHTML 6.00.2900.2769" name=GENERATOR></HEAD>
<BODY>
<DIV id=header><A title=Home href="http://www.linuxsir.org/main/"><IMG alt=Home 
src="内核管理概述  LinuxSir_Org.files/logo.jpg"></A></DIV>
<DIV class=navlinks>
<DIV class=primary><A href="http://www.linuxsir.org/main/?q"><FONT 
color=white>首页</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=taxonomy/term/34"><FONT 
color=white>事件</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=taxonomy/term/1/25/"><FONT 
color=white>文档</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=taxonomy/term/35/48/"><FONT 
color=white>资源</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=search"><FONT color=white>搜索</FONT></A> | 
<A href="http://www.linuxsir.org/bbs"><FONT color=white>论坛</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=taxonomy/term/38"><FONT 
color=white>贡献者</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=node/3"><FONT color=white>关于</FONT></A> | 
<A href="http://www.linuxsir.org/main/?q=user"><FONT 
color=white>注册/登录</FONT></A></DIV></DIV>
<TABLE id=content>
  <TBODY>
  <TR>
    <TD id=sidebar-left>
      <DIV class="block block-block" id=block-block-1>
      <H2 class=title>子站索引</H2>
      <DIV class=content>
      <UL>
        <LI><A href="http://fedora.linuxsir.org/" target?_blank?>Fedora中文</A> 
        <LI><A href="http://debian.linuxsir.org/" target?_blank?>Debian中文</A> 
        <LI><A href="http://lfs.linuxsir.org/" target?_blank?>LFS 中文</A> 
        <LI><A href="http://slack.linuxsir.org/">Slackware</A> 
        <LI><A href="http://gentoo.linuxsir.org/">Gentoo中文</A> 
        <LI><A href="http://arch.linuxsir.org/">Arch 中文</A> </LI></UL></DIV></DIV>
      <DIV class="block block-block" id=block-block-3>
      <H2 class=title>重要资讯</H2>
      <DIV class=content>
      <UL>
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/36">本站公告</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/34">新闻事件</A> 
        <LI><A href="http://www.linuxsir.org/bbs" target=_blank>本站论坛</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/38">贡 献 者</A> 
        </LI></UL></DIV></DIV>
      <DIV class="block block-block" id=block-block-7>
      <H2 class=title>项目索引</H2>
      <DIV class=content>
      <UL>
        <LI><A href="http://www.fcitx.org/" target=_blank>小企鹅输入法</A> 
        <LI><A href="http://lumaqq.linuxsir.org/" target=_blank>LumaQQ</A> 
        <LI><A href="http://openq.linuxsir.org/" target=_blank>OpenQ</A> 
        <LI><A href="http://www.relaxbsd.org/" target=_blank>RelaxBSD</A> 
      </LI></UL></DIV></DIV>
      <DIV class="block block-user" id=block-user-1>
      <H2 class=title>站点导航</H2>
      <DIV class=content>
      <DIV class=menu>
      <UL>
        <LI class=leaf><A title=注册/登录 
        href="http://www.linuxsir.org/main/?q=user">注册/登录</A> 
        <LI class=collapsed><A 
        href="http://www.linuxsir.org/main/?q=aggregator">新闻聚合</A> 
      </LI></UL></DIV></DIV></DIV>
      <DIV class="block block-aggregator" id=block-aggregator-feed-2>
      <H2 class=title>LinuxSir.Org 论坛</H2>
      <DIV class=content>
      <DIV class=item-list>
      <UL>
        <LI><A 
        href="http://www.linuxsir.org/bbs/showthread.php?t=287633&amp;goto=newpost">等2。6。20内核出来就编译内核并改装arch-64</A> 

        <LI><A 
        href="http://www.linuxsir.org/bbs/showthread.php?t=287632&amp;goto=newpost">介绍一个挺不错的多地址多线程下载工具aria2</A> 

        <LI><A 
        href="http://www.linuxsir.org/bbs/showthread.php?t=287631&amp;goto=newpost">关于yum源的问题,要让哪些Enable呀?</A> 

        <LI><A 
        href="http://www.linuxsir.org/bbs/showthread.php?t=287630&amp;goto=newpost">sk 
        11 图形界面 问题~</A> 
        <LI><A 
        href="http://www.linuxsir.org/bbs/showthread.php?t=287629&amp;goto=newpost">esmtprc 
        发信的问题</A> </LI></UL></DIV>
      <DIV class=more-link><A title=查看此feed的最新消息 
      href="http://www.linuxsir.org/main/?q=aggregator/sources/2">更多</A></DIV></DIV></DIV>
      <DIV class="block block-user" id=block-user-2>
      <H2 class=title>最新注册</H2>
      <DIV class=content>
      <DIV class=item-list>
      <UL>
        <LI>supperbond
        <LI>service66069547
        <LI>yrf1981
        <LI>dyljf
        <LI>haolcn</LI></UL></DIV></DIV></DIV>
      <DIV class="block block-user" id=block-user-3>
      <H2 class=title>当前在线</H2>
      <DIV class=content>2 users 和 85 游客 在线
      <DIV class=item-list>
      <H3>在线用户</H3>
      <UL>
        <LI>skid
        <LI>supperbond</LI></UL></DIV></DIV></DIV></TD>
    <TD id=main>
      <DIV class=breadcrumb><A href="http://www.linuxsir.org/main/?q=">首页</A> » 
      <A href="http://www.linuxsir.org/main/?q=taxonomy/term/1">Linux</A></DIV>
      <H2>内核管理概述</H2><!-- begin content -->
      <DIV class=node>
      <DIV class=content>
      <P><B>作者:</B>北南南北<BR><B>来自:</B>LinuxSir.Org<BR><B>摘要:</B>本文讲述与内核操作有关的基础知识;比如编译内核,装载、移除内核模块,查看模块信息等;本文涉及相关的命令有modprobe、insmod、depmod、rmmod、modinfo等;</P>
      <P><B><BR>++++++++++++++++++++++++++++++++++++++++++++++++++++++<BR>正文<BR>++++++++++++++++++++++++++++++++++++++++++++++++++++++<BR></B></P>
      <P><FONT size=4><B><BR>一、什么是内核;<BR></B></FONT></P>
      <P>内核官方:http://www.kernel.org<BR>内核洋文用 kernel,我刚才翻了一下词典,kernel 
      中文意思是内核、核心、中心、精髓的意思;也是果仁、果核的意思。从字面理解,kernel 是一事物的中心,植物的果实最重要的也是果仁和果核;:) 
      由此我们可以推断内核是操作系统的中心。</P>
      <P>我们知道Linus Torvalds 开发了Linux ,其实他开发的就是内核,按内核官方主页的理解,这个内核就是Linux 
      ;其它的扩展和应用都是围绕内核而展开的。所有Linux应用程序都会和内核发生直接或者间接的接触;比如硬件需要内核支持,网络的通信也需要内核支持;文件系统更需要内核支持... 
      ... </P>
      <P>直言我的能力的不行,如果您想了解和学习解操作系统,我写的教程只是初级应用,理论性的东西不是一言两语能说的清楚的,更不是应用者能说的清楚的。</P>
      <P><FONT size=4><B><BR>二、为什么需要编译内核和管理内核<BR></B></FONT></P>
      <P>硬件是需要内核支持才行,有些硬件的支持没有被编入内核,这也需要我们重编内核;内核的包含的不仅仅是设备的驱动,还有其它的内容,比如网络协议的支持,防火墙的支持... 
      ... 比如iptables的实现,有些功能是需要内核支持的,如果内核与iptables相关的内容没有被编入,iptables 
      相关的功能就无法实现;</P>
      <P><FONT size=4><B><BR>三、内核编译方法<BR></B></FONT></P>
      <P><B>请参考:</B><A href="http://www.linuxsir.org/main/?q=node/66">《编译内核操作流程 
      ──为新手指南》</A></P>
      <P><FONT size=4><B><BR>四、管理内核模块的相关命令<BR></B></FONT></P>
      <P><FONT size=3><B><BR>1、lsmod 列加以挂载的内核模块;<BR></B></FONT></P>
      <P>lsmod 是列出目前系统中已加载的模块的名称及大小等;另外我们还可以查看 /proc/modules 
      ,我们一样可以知道系统已经加载的模块;<BR>
      <DIV class=codeblock><CODE>[root@localhost beinan]# 
      lsmod</CODE></DIV><BR><FONT size=3><B><BR>2、modinfo 查看模块信息;<BR></B></FONT>
      <P></P>
      <P>modinfo 可以查看模块的信息,通过查看模块信息来判定这个模块的用途;</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost beinan]# moinfo 
模块名</CODE></DIV>
      <P></P>
      <P>举例:</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost beinan]# modinfo 
      ne2k-pci<BR>filename: 
      /lib/modules/2.6.11-1.1369_FC4/kernel/drivers/net/ne2k-pci.ko<BR>author: 
      Donald Becker / Paul Gortmaker<BR>description: PCI NE2000 clone 
      driver<BR>license: GPL<BR>parmtype: debug:int<BR>parmtype: options:array 
      of int<BR>parmtype: full_duplex:array of int<BR>parm: debug:debug level 
      (1-2)<BR>parm: options:Bit 5: full duplex<BR>parm: full_duplex:full duplex 
      setting(s) (1)<BR>vermagic: 2.6.11-1.1369_FC4 686 REGPARM 4KSTACKS 
      gcc-4.0<BR>depends: 8390<BR>alias: 
      pci:v000010ECd00008029sv*sd*bc*sc*i*<BR>alias: 
      pci:v00001050d00000940sv*sd*bc*sc*i*<BR>alias: 
      pci:v000011F6d00001401sv*sd*bc*sc*i*<BR>alias: 
      pci:v00008E2Ed00003000sv*sd*bc*sc*i*<BR>alias: 
      pci:v00004A14d00005000sv*sd*bc*sc*i*<BR>alias: 
      pci:v00001106d00000926sv*sd*bc*sc*i*<BR>alias: 
      pci:v000010BDd00000E34sv*sd*bc*sc*i*<BR>alias: 
      pci:v00001050d00005A5Asv*sd*bc*sc*i*<BR>alias: 
      pci:v000012C3d00000058sv*sd*bc*sc*i*<BR>alias: 
      pci:v000012C3d00005598sv*sd*bc*sc*i*<BR>alias: 
      pci:v00008C4Ad00001980sv*sd*bc*sc*i*<BR>srcversion: 
      6ACE95F441CD26DF9DC31C2</CODE></DIV><BR>上面的例子是我们查看 ne2k-pci 
      这个模块的信息,通过查看,我们知道ne2k-pci 模块是8029网卡(PCI NE2000 clone driver)的驱动;模块是位于 
      /lib/modules/2.6.11-1.1369_FC4/kernel/drivers/net/ 中ne2k-pci.ko
      <P></P>
      <P>我们现在常用的网卡也有8139的,8139网卡所用的驱动是 8139too ;查查看?</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost beinan]# modinfo 
      8139too</CODE></DIV>
      <P></P>
      <P>我们再查查vfat 和ntfs 的模块信息;</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost beinan]# modinfo 
      vfat<BR>[root@localhost beinan]# modinfo ntfs</CODE></DIV>
      <P></P>
      <P>自己尝试一下;</P>
      <P><FONT color=red><B>注意:</B></FONT> 模块名是不能带有后缀的,我们通过modprobe -l 
      所看到的模块,都是带有.ko 或.o后缀;</P>
      <P><FONT size=3><B><BR>3、modprobe 挂载新模块以及新模块相依赖的模块<BR></B></FONT></P>
      <P>modprobe 我们常用的功能就是挂载模块,在挂载某个内核模块的同时,这个模块所依赖的模块也被同时挂载;当然modprobe 
      也有列出内核所有模块,还有移除模块的功能;下在我们举个例子说一说咱们常用的功能和参数;</P>
      <P>
      <DIV class=codeblock><CODE>modprobe [-v] [-V] [-C config-file] [-n] [-i] 
      [-q] [-o &lt;modname&gt;] &lt;modname&gt; [parameters...]<BR>modprobe -r 
      [-n] [-i] [-v] &lt;modulename&gt; ...<BR>modprobe -l -t &lt;dirname&gt; [ 
      -a &lt;modulename&gt; ...]</CODE></DIV>
      <P></P>
      <P>上面是modprobe 的用法,具体更为详细的帮助,我们可以查看 man modprobe ;</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost beinan]# modprobe 
      -c</CODE></DIV>
      <P></P>
      <P>modprobe -c 可以查看modules 的配置文件,比如模块的别名是什么等;</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost beinan]# modprobe 
      -l</CODE></DIV>
      <P></P>
      <P>modprobe -l 是列出内核中所有的模块,包括已挂载和未挂载的;通过modprobe -l 
      ,我们能查看到我们所需要的模块,然后根据我们的需要来挂载;其实modprobe -l 读取的模块列表就位于 /lib/modules/'uname 
      -r' 目录中;其中uname -r 是内核的版本;<BR>
      <DIV class=codeblock><CODE>[root@localhost beinan]# uname 
      -r<BR>2.6.11-1.1369_FC4<BR>[root@localhost beinan]# ls 
      /lib/modules/2.6.11-1.1369_FC4/</CODE></DIV>
      <P></P>
      <P>通过上面的命令,自己试试看?</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost beinan]# modprobe 模块名 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?