linux 创建文件系统及挂载文件系统流程详解 linuxsir_org.htm

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

HTM
599 行
字号
      0<BR>/dev/proc /proc proc defaults 0 0<BR>/dev/sys /sys sysfs defaults 0 
      0<BR>LABEL=SWAP-hda7 swap swap defaults 0 0<BR>/dev/hdc /media/cdrecorder 
      auto users,exec,noauto,managed 0 0</CODE></DIV>
      <P></P>
      <P><B>第一字段:</B>设备名,在这里表示是文件系统; 有时我们把挂载文件系统也说成挂载分区; 
      在这个字段中也可以用分区标签;在例子中/LABEL=/1就是Fedora 系统安装分区的标签,至于是在哪个分区,可以用 df -lh 
来查看;<BR>
      <DIV class=codeblock><CODE>[root@localhost beinan]# df -lh<BR>Filesystem 
      容量 已用 可用 已用% 挂载点<BR>/dev/hda8 11G 8.5G 1.9G 83% /<BR>/dev/shm 236M 0 236M 
      0% /dev/shm<BR>/dev/hda10 16G 6.9G 8.3G 46% /mnt/hda10</CODE></DIV>
      <P></P>
      <P>我们可以知道 LABEL=/1是/dev/hda8的标签;那我们用什么命令来创建硬盘分区的标签呢?</P>
      <P>对于ext3和ext2文件系统,我们可以用 e2label 来设置</P>
      <P>
      <DIV class=codeblock><CODE>e2label device [newlabel]</CODE></DIV>
      <P></P>
      <P>比如我们想把文件系统为ext3 的分区/dev/hda5的标签设备为 /5 ,我们应该执行如下的命令:<BR>
      <DIV class=codeblock><CODE>[root@localhost beinan]# e2label /dev/hda5 
      /5<BR>[root@localhost beinan]# mkdir /mnt/hda5 
      注:创建挂载/dev/hda5分区的目录;<BR>[root@localhost beinan]# chmod 777 /mnt/hda5 
      注:打开权限,所有用户可读可写可执行;</CODE></DIV>
      <P></P>
      <P>然后我们要改/etc/fstab 中加一行<BR>
      <DIV class=codeblock><CODE>/5 /mnt/hda5 ext3 defaults 0 0</CODE></DIV>
      <P></P>
      <P><FONT color=red><B>警告:</B></FONT> 请不要在您的Linux的安装分区(也就是Linux系统/ 
      所在的分区)实践,会导致您的Linux系统崩溃;如果想实践,请在其它分区测试;</P>
      <P>如果是reiserfs文件系统,我们应该用 </P>
      <P>[root@localhost beinan]# reiserfstune -l 标签 设备 </P>
      <P>举例:比如我为reiserfs 文件系统 /dev/hda10设置标签为 /10 ;<BR>
      <DIV class=codeblock><CODE>[root@localhost beinan]# reiserfstune -l /10 
      /dev/hda10</CODE></DIV>
      <P></P>
      <P>我们在/etc/fstab中加入一行;</P>
      <P>
      <DIV class=codeblock><CODE>/10 /mnt/hda10 reiserfs defaults 0 
      0</CODE></DIV><BR><FONT color=red><B>警告:</B></FONT> 
      请不要在您的Linux的安装分区(也就是Linux系统/ 所在的分区)实践,会导致您的Linux系统崩溃;如果想实践,请在其它分区测试;
      <P></P>
      <P><B>第二字段:</B>文件系统的挂载点;<BR><B>第三字段:</B>文件系统类型;<BR><B>第四字段:</B>mount 
      命令的选项,和mount 中的-o 同理;defaults包括这些选项 rw, suid, dev, exec, auto, nouser, 
      async;通过实践,这个默认的还能满足我们的需要;至于这些选项的意思,请参看man mount ;</P>
      <P><B>第五字段:</B>表示文件系统是否需要dump 备份,是真假关系;1是需要,0 是不需要;<BR><B>第六字段:</B> 
      是否在系统启动时,通过fsck磁盘检测工具来检查文件系统,1是需要,0是不需要,2是跳过;</P>
      <P>基于这些认识;比如我们要开机自动挂载/dev/hda5 ;我们可以如下做;</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost beinan]# mkdir /mnt/hda5/ 
      注:先创建一个挂载目录;<BR>[root@localhost beinan]# chmod 777 /mnt/hda5/ 
      注:设置/mnt/hda5的权限为任何用户可写可读可执行;这样所有的用户都能在写入;</CODE></DIV>
      <P></P>
      <P>然后我们在/etc/fstab 中加如下的一行;<BR>
      <DIV class=codeblock><CODE>/dev/hda5 /mnt/hda5 reiserfs defaults 0 
      0</CODE></DIV>
      <P></P>
      <P>这样重启机器就能看到效果了;</P>
      <P><FONT size=4><B><BR>四、对文件系统进行扫描fsck;<BR></B></FONT></P>
      <P>大家对Windows中的scandisk不寞生吧,在Linux中就有类似这样的工具fsck,不过fsck 
      可不仅仅是扫描,还能修正文件系统的一些问题。值得注意的是fsck 扫描文件系统时一定要在单用户模式、修复模式或把设备umount后进行。</P>
      <P><FONT 
      color=red><B>警告:</B></FONT>如果扫描正在运行中的系统,会造成系统文件损坏;如果您的系统是正常,请不要用扫描工具,她可能会把您的系统搞坏掉,fsck运行是有危险的;</P>
      <P>以Fedora 为例,文件系统扫描工具有 fsck fsck.ext2 fsck.jfs fsck.msdos fsck.vfat 
      fsck.ext3 fsck.reiserfs(reiserfsck)</P>
      <P>其中fsck 默认支持文件系统ext2,如果想支持ext3文件系统的扫描,应该加-j 
      参数,最好是我们应该根据不同的文件系统来调用不同的扫描工具,比如 
      fsck.ext2,fsck.jfs,fsck.msdos,fsck.ext3,fsck.reiserfs(reiserfsck)等。我们也可以根据自己的文件系统选择不同的扫描工具;</P>
      <P>举例:扫描/dev/hda10分区(基于reiserfs文件系统 );<BR>
      <DIV class=codeblock><CODE>[root@localhost beinan]# fsck.reiserfs 
      /dev/hda10<BR>reiserfsck 3.6.19 (2003 
      www.namesys.com)<BR>*************************************************************<BR>** 
      If you are using the latest reiserfsprogs and it fails **<BR>** please 
      email bug reports to reiserfs-list@namesys.com, **<BR>** providing as much 
      information as possible -- your **<BR>** hardware, kernel, patches, 
      settings, all reiserfsck **<BR>** messages (including version), the 
      reiserfsck logfile, **<BR>** check the syslog file for any related 
      information. **<BR>** If you would like advice on using this program, 
      support **<BR>** is available for $25 at www.namesys.com/support.html. 
      **<BR>*************************************************************<BR>Will 
      read-only check consistency of the filesystem on /dev/hda10<BR>Will put 
      log info to 'stdout'<BR>Do you want to run this program?[N/Yes] (note need 
      to type Yes if you do):Yes<BR>###########<BR>reiserfsck --check started at 
      Wed Sep 14 08:54:17 2005<BR>###########<BR>Replaying journal..<BR>Reiserfs 
      journal '/dev/hda10' in blocks [18..8211]: 0 transactions 
      replayed<BR>Checking internal tree..finished<BR>Comparing 
      bitmaps..finished<BR>Checking Semantic tree:<BR>finished<BR>No corruptions 
      found 注:没有发现错误;<BR>There are on the 
      filesystem:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Leaves 
      2046<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Internal nodes 
      15<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Directories 
      130<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Other files 
      2305<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Data block 
      pointers 1863657 (70565 of them are 
      zero)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Safe links 
      0<BR>###########<BR>reiserfsck finished at Wed Sep 14 08:54:33 
      2005<BR>###########</CODE></DIV>
      <P></P>
      <P>对于fsck.ext2和fsck.ext3常用的几个选项:<BR>
      <DIV class=codeblock><CODE>-p Automatic repair (no questions) 
      注:自动修复文件系统存在的问题;<BR>-y Assume "yes" to all questions 
      注:如果文件系统有问题,会跳出提示是否修复,如果修复请按y;<BR>-c Check for bad blocks and add them to 
      the badblock list 注:对文件系统进行坏块检查;这是一个极为漫长的过程;<BR>-n Make no changes to the 
      filesystem 注:不对文件系统做任何改变,只要扫描,以检测是否有问题;</CODE></DIV>
      <P></P>
      <P>举例:比如 /dev/hda6 (文件系统是ext3的),我想扫描并自动修复;</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost beinan]# fsck.ext3 -p 
      /dev/hda6</CODE></DIV>
      <P></P>
      <P><FONT color=red><B>注意:</B> </FONT>针对不同文件系统,最好用相应的工具;虽然有时fsck 
      在不加参数的情况下能识别不同的文件系统;</P>
      <P>对于不同工具的最为详细的参数,请参看--help或者man ,谢谢。。</P>
      <P><FONT size=4><B><BR>后记:</B></FONT></P>
      <P>创建文件系统和加载文件系统就算写的差不多了;再高深的可能也不是我所能写的。为了写文件系统系统的挂载,我已经写过几篇文档。可能还得需补充几篇短小文档,以及还有一个总结性的文档;</P>
      <P>比如Fedora Core 4.0 默认安装不支持创建reiserfs 文件系统,解决办法是安装reiserfs-utils 
      ,这也是需要补充的;</P>
      <P><FONT size=4><B><BR>附录:</B></FONT></P>
      <P><A href="http://www.linuxsir.org/main/?q=node/41">《Linux 
      查看磁盘分区、文件系统、使用情况的命令和相关工具介绍》</A><BR><A 
      href="http://www.linuxsir.org/main/?q=node/81">《实例解说 fdisk 使用方法》</A><BR><A 
      href="http://www.linuxsir.org/main/?q=node/23">《在Fedora core 4.0 
      加载NTFS和FAT32分区详述》</A><BR><A 
      href="http://www.linuxsir.org/main/?q=node/80">《合理规划您的硬盘分区》</A><BR><A 
      href="http://www.linuxsir.org/main/?q=node/82">《系统引导过程及硬盘分区结构论述》</A><BR><A 
      href="http://www.linuxsir.org/main/?q=node/40">《Fedora Core 4.0 
      HAL配置即插即用移动存储(USB及1394)的实践》</A></P></DIV>
      <DIV class=links></DIV></DIV></TD>
    <TD id=sidebar-right>
      <DIV class="block block-block" id=block-block-2>
      <H2 class=title>基础知识</H2>
      <DIV class=content>
      <UL>
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/23">安装配置</A> 
        <LI><A 
        href="http://www.linuxsir.org/main/?q=taxonomy/term/1/25/">基础入门</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/22/">硬件解决</A> 

        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/21">软件管理</A> 
        <LI><A 
        href="http://www.linuxsir.org/main/?q=taxonomy/term/35/48/">重要资源</A> 
        </LI></UL></DIV></DIV>
      <DIV class="block block-block" id=block-block-4>
      <H2 class=title>软件应用</H2>
      <DIV class=content>
      <UL>
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/30">网络工具</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/32">图形图像</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/31">音乐视频</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/49">字体中文</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/33">软件其它</A> 
        </LI></UL></DIV></DIV>
      <DIV class="block block-block" id=block-block-5>
      <H2 class=title>网络服务器</H2>
      <DIV class=content>
      <UL>
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/27">文件服务器<A> 
        <LI><A 
        href="http://www.linuxsir.org/main/?q=taxonomy/term/28">Web服务器</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/29">邮件服务器</A> 

        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/37">数据库应用</A> 

        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/50">服务器其它</A> 
        </LI></UL></DIV></DIV>
      <DIV class="block block-comment" id=block-comment-0>
      <H2 class=title>最新评论</H2>
      <DIV class=content>
      <DIV class=item-list>
      <UL>
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/222#comment-624">错了</A><BR>12 
        min 45 sec 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/222#comment-623">q</A><BR>32 
        min 22 sec 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/222#comment-622">有些道理</A><BR>53 
        min 51 sec 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/219#comment-621">"内置的摄像头也能用这个吗?"</A><BR>13 
        hours 59 min 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/80#comment-620">终于知道了...</A><BR>23 
        hours 13 min 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/106#comment-619">okok</A><BR>2 
        days 14 hours 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/93#comment-618">那要除去阴影呢?</A><BR>3 
        days 19 hours 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/227#comment-617">不错的机会</A><BR>4 
        days 6 hours 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/221#comment-616">配置可执行程序的路径</A><BR>4 
        days 12 hours 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/222#comment-615">修改hostname出现的问题</A><BR>5 
        days 2 hours 
前</LI></UL></DIV></DIV></DIV></TD></TR></TBODY></TABLE></BODY></HTML>

⌨️ 快捷键说明

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