位置于:首页>>操作系统>>Linux>>正文
 Linux创建文件及挂载文件系统流程详解

为什么我的系统有两个交换分区?因为我用移动U盘做的实验,主要是为写教程之用;sda6是我在U盘上建的swap分区;

如果让swap开机就加载,应该改 /etc/fstab文件,加类似如下一行;

/dev/sda6 swap swap defaults 0 0 注:把此行中的/dev/hda7 改为您的交换分区就行;

或者把命令行直接写入 /etc/rc.d/rc.local中也行;

swapon /dev/sda6

如果您的硬盘不能再分区,您可以创建一个swap文件

[root@localhost beinan]# dd if=/dev/zero of=/tmp/swap bs=1024 count=524288 注:创建一个大小为512M 的swap 文件,在/tmp目录中;您可以根据自己的需要的大小来创建swap 文件;

读入了 524288+0 个块

输出了 524288+0 个块

[root@localhost beinan]# mkswap /tmp/swap 注:把/tmp/swap 文件,创建成swap 交换区

Setting up swapspace version 1, size = 536866 kB

no label, UUID=d9d8645d-92cb-4d33-b36e-075bb0a2e278

[root@localhost beinan]# swapon /tmp/swap 注:挂载swap

[root@localhost beinan]# swapon -s

Filename Type Size Used Priority

/dev/hda7 partition 787144 888 -1

/tmp/swap file 524280 0 -2

注意:其实我们在安装系统的时候,就已经划分了交换分区;查看/etc/fstab,应该swap的行;如果您在安装系统时没有添加swap,可以通过这种办法来添加;

四、对文件系统进行扫描fsck;

大家对Windows中的scandisk不寞生吧,在Linux中就有类似这样的工具fsck,不过fsck 可不仅仅是扫描,还能修正文件系统的一些问题。值得注意的是fsck 扫描文件系统时一定要在单用户模式、修复模式或把设备umount后进行。

警告:如果扫描正在运行中的系统,会造成系统文件损坏;如果您的系统是正常,请不要用扫描工具,她可能会把您的系统搞坏掉,fsck运行是有危险的;

以Fedora 为例,文件系统扫描工具有 fsck fsck.ext2 fsck.jfs fsck.msdos fsck.vfat fsck.ext3 fsck.reiserfs(reiserfsck)

其中fsck 默认支持文件系统ext2,如果想支持ext3文件系统的扫描,应该加-j 参数,最好是我们应该根据不同的文件系统来调用不同的扫描工具,比如 fsck.ext2,fsck.jfs,fsck.msdos,fsck.ext3,fsck.reiserfs(reiserfsck)等。我们也可以根据自己的文件系统选择不同的扫描工具;

举例:扫描/dev/hda10分区(基于reiserfs文件系统 );

[root@localhost beinan]# fsck.reiserfs /dev/hda10

reiserfsck 3.6.19 (2003 www.namesys.com)

*************************************************************

** If you are using the latest reiserfsprogs and it fails **

** please email bug reports to reiserfs-list@namesys.com, **

** providing as much information as possible -- your **

** hardware, kernel, patches, settings, all reiserfsck **

** messages (including version), the reiserfsck logfile, **

** check the syslog file for any related information. **

** If you would like advice on using this program, support **

** is available for $25 at www.namesys.com/support.html. **

*************************************************************

Will read-only check consistency of the filesystem on /dev/hda10

Will put log info to 'stdout'

Do you want to run this program?[N/Yes] (note need to type Yes if you do):Yes

###########

reiserfsck --check started at Wed Sep 14 08:54:17 2005

###########

Replaying journal..

Reiserfs journal '/dev/hda10' in blocks [18..8211]: 0 transactions replayed

Checking internal tree..finished

Comparing bitmaps..finished

Checking Semantic tree:

finished

No corruptions found 注:没有发现错误;

There are on the filesystem:

Leaves 2046

Internal nodes 15

Directories 130

Other files 2305

Data block pointers 1863657 (70565 of them are zero)

Safe links 0

###########

reiserfsck finished at Wed Sep 14 08:54:33 2005

###########

对于fsck.ext2和fsck.ext3常用的几个选项:

-p Automatic repair (no questions) 注:自动修复文件系统存在的问题;

-y Assume "yes" to all questions 注:如果文件系统有问题,会跳出提示是否修复,如果修复请按y;

-c Check for bad blocks and add them to the badblock list 注:对文件系统进行坏块检查;这是一个极为漫长的过程;

-n Make no changes to the filesystem 注:不对文件系统做任何改变,只要扫描,以检测是否有问题;

举例:比如 /dev/hda6 (文件系统是ext3的),我想扫描并自动修复;

[root@localhost beinan]# fsck.ext3 -p /dev/hda6

注意: 针对不同文件系统,最好用相应的工具;虽然有时fsck 在不加参数的情况下能识别不同的文件系统;

对于不同工具的最为详细的参数,请参看--help或者man ,谢谢。。

后记:

创建文件系统和加载文件系统就算写的差不多了;再高深的可能也不是我所能写的。为了写文件系统系统的挂载,我已经写过几篇文档。可能还得需补充几篇短小文档,以及还有一个总结性的文档;

比如Fedora Core 4.0 默认安装不支持创建reiserfs 文件系统,解决办法是安装reiserfs-utils ,这也是需要补充的;

本新闻共4页,当前在第4页  1  2  3  4  

本新闻共4页,当前在第4页  1  2  3  4  

内部:http://xp163.com/
 Linux创建文件及挂载文件系统流程详解站内说明
 最新站点内更新

 

 书籍教程站内推荐信息
 书籍教程网站地图