LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
楼主: weixiao

RH7.3最终汉化实例与RedHat软件设置

[复制链接]
发表于 2006-6-27 15:43:26 | 显示全部楼层

处理旧软盘

制作模拟软驱的软盘

  用 dd 创建空映像文件,1.44M软盘映像文件(块大小是512字节,块数是2880),2.88M软盘映像文件(块大小是512字节,块数是5760)
#  dd if=/dev/zero of=./vfat-flo.img bs=512 count=2880
2880+0 records in
2880+0 records out

  把映像文件联系上回送设备(格式化程序是以设备文件作为参数)
# losetup /dev/loop0 vfat-flo.img

  格式化软盘文件(vfat)
# mkfs.vfat /dev/loop0
mkfs.vfat 2.8 (28 Feb 2001)

  卸载回送设备
# losetup -d /dev/loop0

  试挂载软盘文件
# [ -d /mnt/image ] || mkdir /mnt/image
# mount -t vfat vfat-flo.img /mnt/image -o loop
# df -T
# umount /mnt/image

  现在,windows下的模拟软驱软件可以挂载模拟软盘(vfat-flo.img)。
------------------------

真实软驱挂载旧软盘,检查坏块并创建文件系统

  把软盘放进软驱
1) 创建ext2文件系统
# fdformat -n /dev/fd0H1440
# badblocks /dev/fd0H1440 1440 > badblock.file
# mkfs.ext2 -l badblock.file /dev/fd0H1440

可以选择以下操作:检查并标记坏块(方便数据写入)
# badblocks /dev/fd0H1440 1440 > b-block.file
# fsck.ext2 -l b-block.file /dev/fd0H1440

测试
# mount -t ext2 /dev/fd0 /mnt/floppy
# umount /mnt/floppy
[ 注: fdformat 是低级格式化软盘,-n 是不验证。]

2) Linux系统下创建msdos文件系统
# fdformat /dev/fd0H1440
# mkdosfs /dev/fd0
# mount -t msdos /dev/fd0 /mnt/floppy

3) 有一次在软驱有问题时创建vfat文件系统的经历:
# fdformat /dev/fd0H1440
# mformat /dev/fd0
# mkdosfs /dev/fd0
# mkfs.vfat /dev/fd0

[ 注:新使用的软盘不用低级格式化(fdformat) ]
===============================

    注:/dev/fd0H1440 是第一个软驱(fd0),必须是3.5'软驱,使用3.5'高密度软盘(H),容量是1440KB(1440),即普通的3.5'HD软盘。

/dev/fd0 命名去除‘H1440’,是指不需要单一对应1440KB的HD软盘,可以自动识别一大批‘软盘’。

制作镜像文件经验:除制作一定规格的软盘格式镜像文件之外,其它规格大小的镜像文件不能格式化成dos 、fat 、fat16等等。

=====
---
-
回复 支持 反对

使用道具 举报

发表于 2006-6-27 16:12:20 | 显示全部楼层

制作一张软盘linux系统实例与应用

==  制作一张软盘linux系统实例与应用 <一>  ==
( 注:整理前段日子的一篇习作,更正了一些网友提出的问题 )


  让初接触linux的朋友加深了解linux文件系统,我写这篇实例是避开编译内核,用RH7.2现成内核(大约 794K),busybox软件集成指令,在RH7.3系统下操作。

  软盘不能有坏块,通常处理验证方法:
# fdformat -n /dev/fd0H1440
# badblocks /dev/fd0H1440 1440 > badblock.file
[ 如果有坏块指示,要换软盘 ]


  软盘linux系统分为boot盘启动部份和root根文件系统部份
1) boot盘启动部份


放入验证过的软盘,Root权限操作,创建ext2文件系统
# mke2fs  /dev/fd0
--------------------------
mke2fs 1.27 (8-Mar-2002)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
184 inodes, 1440 blocks
72 blocks (5.00%) reserved for the super user
First data block=1
1 block group
8192 blocks per group, 8192 fragments per group
184 inodes per group

Writing inode tables: done                           
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

--------------------------
[ 注:“mke2fs /dev/fd0”中的“72 blocks (5.00%)”是检修文件系统时预留空间,“mke2fs -m0 /dev/fd0”可释放这些空间,如果制作完成后发觉容量紧张,可以选择这条命令。当操作文件系统档案‘37 mounts or 180 days’,会提示检测文件系统,“e2fsck /dev/fd0”检测文件系统并更新信息。tune2fs -c or -i 是调节 ‘37 or 180’ 这两个参数 ]


挂载磁盘文件系统
# mount -t ext2 /dev/fd0 /mnt/floppy

转移 "lost+found" 目录
# cp -a /mnt/floppy/"lost+found" /tmp/

# rmdir /mnt/floppy/"lost+found"
# mkdir /mnt/floppy/boot
# mkdir /mnt/floppy/boot/grub
# cp /boot/grub/e2fs_stage1_5 /mnt/floppy/boot/grub/
# cp /boot/grub/stage1 /mnt/floppy/boot/grub/
# cp /boot/grub/stage2 /mnt/floppy/boot/grub/

[ 注:stage1,stage2为装入器,e2fs_stage1_5为两者桥梁 (不需块信息,有些主机配置必需用到) ,能在引导时从ext2文件系统顺利装入stage2。]

# cd  /mnt/floppy/boot/grub

# vi grub.conf
-------------------------
default=0
timeout=10
title wei make Linux
[TAB键] root (fd0)
[TAB键] kernel /boot/vmlinuz root=/dev/ram0
[TAB键] initrd /initrd.gz
-------------------------


# ln -s grub.conf menu.lst

离开磁盘目录进行操作
# cd /tmp
# mv /mnt/floppy/boot/grub/e2fs_stage1_5 /mnt/floppy/boot/grub/e2fs_stage1_5.bak


安装grub到软盘
# grub --batch --device-map=/dev/null
-------------------------
grub> device (fd0) /dev/fd0
grub> root (fd0)
grub> setup (fd0)

Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... no
Running "install /boot/grub/stage1 d (fd0) /boot/grub/stage2 p /boot/grub/grub
.conf "... succeeded
Done.

grub> quit
-------------------------


# mv /mnt/floppy/boot/grub/e2fs_stage1_5.bak /mnt/floppy/boot/grub/e2fs_stage1_5

[ 注: embed命令有点模糊,可能grub版本低。以上操作好似有点多余,主要是把e2fs_stage1_5文件放在最前。(心理作用!)]

# ls -Ri /mnt/floppy
--------------------------------------------------
/mnt/floppy:
     11 boot
/mnt/floppy/boot:
     12 grub
/mnt/floppy/boot/grub:
     13 e2fs_stage1_5       16 menu.lst       15 stage2
     17 grub.conf           14 stage1
---------------------------------------------------


把 RH7.2 (2.4.7-10)内核复制到软盘
# cp vmlinuz-2.4.7-10 /mnt/floppy/boot/vmlinuz


注:如果想测试这部份制作是否可行,先把软盘‘grub.conf’文件备份,把系统‘grub.conf’文件覆盖原软盘文件(/mnt/floppy/boot/grub/grub.conf),然后软盘启动系统进行测试,记住测试完后把备份的软盘‘grub.conf’文件还原。

-----
---
-


==  制作一张软盘linux系统实例与应用 <二>  ==
2) root根文件系统部份(initrd.gz)

# cd /tmp
# mkdir flolinux
# cd flolinux
# mkdir {bin,dev,etc,mnt,proc,sbin,tmp}
# mkdir etc/rc.d
# mkdir mnt/{linux,floppy}
# cp -a /dev/{hda,hda[1-9]} dev/
# cp -a /dev/{sda,sda[1-9]} dev/
# cp -a /dev/{console,fd0,null,ram0,tty,tty0} dev/


# cd etc/rc.d

# vi rc.sysinit
-----------------------------
#!/bin/sh
mount -a
-----------------------------


# chmod 755 rc.sysinit
# cd /tmp/flolinux/etc

# vi fstab
-------------------------------------------------
proc /proc proc defaults 0 0
-------------------------------------------------


# vi inittab
-------------------------------------------------
::sysinit:/etc/rc.d/rc.sysinit
:: askfirst:/bin/sh (注意:askfirst前面没有空格,复制小心!)
-------------------------------------------------

[ 注:以上是三个配置文件/tmp/flolinux/etc/inittab,/tmp/flolinux/etc/fstab,/tmp/flolinux/etc/rc.d/rc.sysinit文件名以及文件内容。注:inittab文件内容不留空格。]

检查busybox是否被安装(rpm -q busybox),busybox在 RH 配套软件包里面。
[ rh7.2 :busybox-0.51.062801-3.i386.rpm ]
[ rh7.3 :busybox-0.60.2-4.i386.rpm ]


# rpm -ivh [path]/busybox-0.60.2-4.i386.rpm --test
# rpm -ivh [path]busybox-0.60.2-4.i386.rpm


# cd /tmp/flolinux/bin
# which busybox
/sbin/busybox


把busybox复制到当前目录并改成init文件
# cp /sbin/busybox ./init
# ln -s init cp
# ln -s init cat
# ln -s init date
# ln -s init df
# ln -s init dmesg
# ln -s init echo
# ln -s init fsck
# ln -s init kill
# ln -s init ln
# ln -s init ls
# ln -s init mount
# ln -s init umount
# ln -s init mv
# ln -s init ps
# ln -s init pwd
# ln -s init sed
# ln -s init sh
# ln -s init sync
# ln -s init tty

[ 注:创建符号链接前,查看man busybox 的commands选项中同系统达到共识的工具名称 ]

# cd /tmp/flolinux/sbin
# ln -s ../bin/init lsmod
# ln -s ../bin/init reboot

[ 注:在sbin子目录下建立lsmod,reboot符号链接。注意使用相对路径 ]

# cd /tmp/flolinux/
# ln -s bin/init linuxrc


转移目录
# cd /tmp


查看做了什么
# ls -R /tmp/flolinux/


制作镜像文件:
# cd /tmp
# dd if=/dev/zero of=/tmp/image bs=1k count=2048
# losetup /dev/loop0 /tmp/image
# mke2fs -m0 /dev/loop0
# mkdir /mnt/imloop
# mount -t ext2 /dev/loop0 /mnt/imloop
# cp -a /tmp/flolinux/* /mnt/imloop/
# umount /mnt/imloop
# losetup -d /dev/loop0
# dd if=/tmp/image|gzip -9 > /tmp/initrd.gz
# chmod 755 /tmp/initrd.gz
# sync


initrd.gz 复制至软盘
# cp /tmp/initrd.gz /mnt/floppy/
# cp -a /tmp/"lost+found" /mnt/floppy/
# sync
# sync

# df -h /mnt/floppy
Filesystem Size  Used  Avail  Use%   Mounted on
/dev/fd0   1.4M  1.3M   40k    99%   /mnt/floppy


# umount /mnt/floppy
  
测试用软盘启动!


[  注:    软盘通过处理验证方法(fdformat,badblocks),制作成的linux系统软盘 Use% 是 99% 。当 Use% 是 100%时不一定不能添加数据,只是占用了5%预留空间,这时建议使用“mke2fs -m0 /dev/fd0”,或者考虑从内核大小入手。 ]

---------
------
---
回复 支持 反对

使用道具 举报

发表于 2006-6-27 16:31:19 | 显示全部楼层

制作一张软盘linux系统实例与应用 &lt;三&gt;

==  制作一张软盘linux系统实例与应用 <三>  ==

  应用 1 :修改 root 密码的例子:

首先用软盘启动,自动安装内核跟解压镜像文件后:
please press Enter to activate this console. 回车
#


试输入命令
# ls /mnt


挂载Linux分区(例如:hda7)
# mount /dev/hda7 /mnt/linux


查看已经挂载哪些设备以及挂载点
# mount
/dev/ram0 on / type ext2 (rw)
proc on /proc type proc (rw)
/dev/hda7 on /mnt/linux type ext2 (rw)


# cd /bin
# pwd
# ln -s init more
# more /mnt/linux/etc/passwd


工具库busybox找不到文档编辑器,只有温习一下sed
# sed -n '/^root/p' /mnt/linux/etc/passwd
root:x:0:0:root:/root:/bin/bash


只要把x删去,就能畅通无助
# sed -n '/^root/s/x//p' /mnt/linux/etc/passwd
root::0:0:root:/root:/bin/bash


# cat /mnt/linux/etc/passwd
你会发现改动处丝毫无损,上步骤只能在内存起作用


# sed '/^root/s/x//' /mnt/linux/etc/passwd > /mnt/linux/etc/new.txt
先把原passwd文件备份,再把new.txt改名为passwd文件,就可以登录系统 。


要记住卸载,否则重新登录时,RH系统会自动fsck,暴露这次修改。
# umount /mnt/linux
# reboot


[ 注:尽可能在使用软盘时不把rm软链接,别小看1.3M东西,它能把几十G数据删掉。]

----
--


  应用 2 :分析 initrd.gz 小型Linux系统内的配置文件

软盘启动,解压initrd.gz后,busybox的init按照内置文件inittab提供一个可交互操作的Shell。

inittab内容如下:
-----------------------------
::sysinit:/etc/rc.d/rc.sysinit
:: askfirst:/bin/sh (askfirst前面没有空格)
-----------------------------


rc.sysinit内容如下:
-----------------------------
#!/bin/sh
mount -a
-----------------------------


fstab内容如下:
-----------------------------
proc /proc proc defaults 0 0
-----------------------------


如果把 inittab 修改如下,rc.sysinit,fstab内容形同虚设。
-----------------------------
::sysinit:
:: askfirst:/bin/sh (askfirst前面没有空格,小心察看)
-----------------------------


按修改后inittab进行操作,实验如下:
软盘启动 --> please press Enter to activate this console. 回车
#
# df
提示错误


手动挂载proc文件系统
# mount -t proc proc /proc


测试:
# df
# mount /dev/hda7 /mnt/linux
# mount
# umount /mnt/linux


[ 注:RH 配套软件包 busybox,可以很方便配置成与 RH 一样架构的小型Linux系统。]

-------
----
--


  应用 3 :  软盘系统 busybox 软件操作 :
软盘启动 --> please press Enter to activate this console. 回车
#

  制作 initrd.gz 时把 busybox 以 init 形式存在,对“ln -s init more”软链接不适应时,操作如下:
# cp bin/init bin/busybox

  查看关联的指令函数
# busybox --help


  指令函数操作
# busybox free
# busybox ls


  指令函数帮助
# busybox ls --help


-----
---


  应用 4 :  initrd.gz 修改或加入数据

  主操作系统:
挂载软盘Linux
# mount /dev/fd0 /mnt/floppy
# cp -a /mnt/floppy/initrd.gz /tmp/
# cd /tmp

# gunzip initrd.gz
# [ -d /mnt/image ] || mkdir /mnt/image
# mount -t ext2 initrd /mnt/image -o loop


可能你会对 “man busybox”的指令示例感兴趣,创建readme.txt收集示例信息(注意文件大小)。
# cp readme.txt /mnt/image/
  
# umount /mnt/image
# gzip -9 initrd
# chmod 755 initrd.gz
# cp -a initrd.gz /mnt/floppy/
# umount /mnt/floppy


[ 注: 软盘Linux启动解压后,一切在内存操作,不会存储数据。若存储数据,要建立挂载点,如:软盘Linux中的挂载点/mnt/floppy ,插入存储软盘,mount命令挂载,这就解决存储问题。]

-----
---
-
回复 支持 反对

使用道具 举报

发表于 2006-6-27 16:44:51 | 显示全部楼层

收藏的一篇文档

“Linux宝库”网站的文档:自己定制软盘上的Linux系统
-------------------------------------------------------------
一.前言
  嵌入式Linux是由一个几百KB的Linux内核和一个根据需要制定的文件系统所构成了, 由于Linux是开放源代码的操作系统,所以在嵌入式领域有着非常广阔的前景,并已经广泛应用在许多手机、PDA、MP3播放器等许多电子产品中。本文将介绍一种两张软盘上的Linux系统,它可以当作系统应急修复盘、路由器或防火墙等许多地方,通过对它的研究,也可以加深对嵌入式系统的理解。

..............................................................
..............................................................
..............................................................

八.前景
  按照本文方法所构造的Linux系统虽然还不完善,但通过逐步的改进,将能做出一个有价值的系统来。真正的Linux嵌入式系统根据不同的应用方向通常还包括图形用户界面或者是网络浏览器等应用程序。值得庆幸的是很多OpenSource的项目提供了所需要的组件,结合这些优秀的开源项目,就可以形成一套真正的嵌入式Linux操作系统。
-------------------------------------------------------------

!! 精品中的补品 !!
rdev 命令文档:
--------------------
NAME
rdev - 查询/设置内核映像文件的根设备,RAM 磁盘大小或视频模式   

SYNOPSIS
rdev [ -rvh ] [ -o offset ] [ image [ value [ offset ] ] ]
rdev [ -o offset ] [ image [ root_device [ offset ] ] ]
ramsize [ -o offset ] [ image [ size [ offset ] ] ]
vidmode [ -o offset ] [ image [ mode [ offset ] ] ]
rootflags [ -o offset ] [ image [ flags [ offset ] ] ]

描述 DESCRIPTION
不带任何参数的 rdev 命令将输出当前根文件系统的 /etc/mtab 文件行。不带任何参数的 ramsize, vidmode, 和 rootflags 将显示帮助信息。

在一个 i386 上的 linux 可引导内核映像文件中,有几对字节用来指定根设备,视频模式和 RAM 磁盘的大小。这些字节对,在默认情况下起始在内核映像的偏移量504 (十进制) 处。
    498 Root flags (根标志) (500 和 502 保留) 504 RAM Disk Size RAM (磁盘大小) 506 VGA Mode (VGA 模式) 508 Root Device (根设备) (510 Boot Signature (启动标记))

rdev 可以改变这些值。
典型的 image 参数的值是一个可启动的 linux 内核映像,可能是/vmlinux /vmunix /boot/bzImage-2.4.0  /dev/fd0  /dev/fd1

当使用 rdev 命令时, root_device 参数是类似如下所示的值:
    /dev/hda1 /dev/hdf13 /dev/sda2 /dev/sdc4 /dev/ida/c0d0p1

也可以通过使用一个逗号 (comma) 分隔的十进制整数对 major,minor 来指定这个设备。

对于 ramsize 命令, size 参数指定了 RAM 磁盘的大小,以千字节为单位。

对于 rootflags 命令, flags 参数包含在挂载 root 文件系统时额外的信息。当前这些标志的唯一作用是当 flags 非零时,强制内核以只读模式来挂载 root 文件系统。

对于 vidmode 命令, mode 参数指定了视频模式。
    -3 = Prompt (提示) -2 = Extended VGA (扩展的VGA) -1 = Normal VGA (普通VGA) 0 = as if "0" was pressed at the prompt (假设在提示时按下了"0") 1 = as if "1" was pressed at the prompt 2 = as if "2" was pressed at the prompt n = as if "n" was pressed at the prompt
如果没有指定 value ,将检测 image 来得到当前的设置。  

选项 OPTIONS
-r    使得 rdev 作为 ramsize 运行。
-R    使得 rdev 作为 rootflags 运行。
-v    使得 rdev 作为 vidmode 运行。
-h    提供帮助。

BUGS
rdev 工具,如果不是用做查找当前根设备的名称,那么就是一种古老的破解 (hack) ,依靠对内核的一个特定 (magic) 位移以特殊 (magic) 数字进行修改来工作。它在 i386 之外的体系中不能工作。不鼓励使用它。使用一个启动管理器,例如 SysLinux , LILO 或者 grub 来替代它。  

历史 HISTORY
偏移 502 从前是交换设备的设备号 (在 linux 0.12 中),运行 "rdev -s" 或者 "swapdev" 将设置它。但是,从 linux 0.95 起,这个常量不再使用,交换设备是以 swapon() 系统调用来指定的。  

作者 AUTHORS
------------------
--------------
---------
回复 支持 反对

使用道具 举报

发表于 2006-6-30 11:32:11 | 显示全部楼层

版本太旧了

版本太旧了,用的人太少了。你要说到FC糸列或者 RHEL4.X糸列可能还有人会一些。
回复 支持 反对

使用道具 举报

发表于 2006-7-4 10:01:36 | 显示全部楼层

实验: 恢复“删除文件”的数据

软驱放入软盘,并格式化成Ext2文件系统
# mke2fs /dev/fd0

# dumpe2fs /dev/fd0
------------------------------------------------------------
dumpe2fs 1.27 (8-Mar-2002)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          128469b0-01ce-4b77-b1b0-73cc245721e8
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      filetype sparse_super
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              184
Block count:              1440
Reserved block count:     72
Free blocks:              1396
Free inodes:              171
First block:              1
Block size:               1024
Fragment size:            1024
Blocks per group:         8192
Fragments per group:      8192
Inodes per group:         184
Inode blocks per group:   23
Last mount time:          Fri Jun 30 09:12:40 2006
Last write time:          Fri Jun 30 09:16:43 2006
Mount count:              2
Maximum mount count:      32
Last checked:             Fri Jun 30 08:41:01 2006
Check interval:           15552000 (6 months)
Next check after:         Wed Dec 27 08:41:01 2006
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:    128

Group 0: (Blocks 1-1439)
  Primary Superblock at 1,  Group Descriptors at 2-2
  Block bitmap at 3 (+2), Inode bitmap at 4 (+3)
  Inode table at 5-27 (+4)
  1396 free blocks, 171 free inodes, 2 directories
  Free blocks: 41-1439
  Free inodes: 12-184
--------------------------------------------------------

复制测试文件
# mount /dev/fd0 /mnt/floppy
# cp /etc/passwd /mnt/floppy/
# cp /etc/group /mnt/floppy/
# sync;sync
#  ls -hli /mnt/floppy
total 15k
  12 -rw-r--r--    1 root     root    525  6 30 08:42 group
  11 drwx------    2 root     root    12k  6 30 08:42 lost+found
  13 -rw-r--r--    1 root     root   1.3k  6 30 08:42 passwd
# umount /mnt/floppy

熟练 debugfs 操作(‘debugfs:’是提示符)
# debugfs /dev/fd0
debugfs 1.27 (8-Mar-2002)
debugfs:

超级块明细表或部分参数
debugfs:  params
Open mode: read-only
Filesystem in use: /dev/fd0
debugfs:  dirty
dirty: Filesystem opened read/only
debugfs:  features
Filesystem features: filetype sparse_super
debugfs:  stats
[ 显示信息跟dumpe2fs相似 ]

‘debugfs’命令帮助信息
debugfs:  help (lr 或 ?)

修改工作目录(cd)和显示当前路径(pwd)
debugfs:  cd "lost+found"
debugfs:  pwd
[pwd]   INODE:     11  PATH: /lost+found
[root]  INODE:      2  PATH: /
debugfs:  ls -l
debugfs:  cd ..
debugfs:  pwd
[pwd]   INODE:      2  PATH: /
[root]  INODE:      2  PATH: /
debugfs:  ls -l
debugfs:  stat "lost+found"
[注:"lost+found"目录十分特别,离开磁盘文件系统后(# cp -a /mnt/floppy/"lost+found" /tmp/ ),状态大小跟新建的目录一样 ]

关闭当前文件系统
debugfs:  close
debugfs:  ls
ls: Filesystem not open

打开文件系统(有写的模式)
debugfs:  open -w /dev/fd0
debugfs:  params
Open mode: read-write
Filesystem in use: /dev/fd0
debugfs:  dirty
debugfs:  

重新打开文件系统(默认‘只读’模式)
debugfs:  close
debugfs:  open /dev/fd0
debugfs:  params
Open mode: read-only
Filesystem in use: /dev/fd0
debugfs:  dirty
dirty: Filesystem opened read/only

查看文件节点与块信息:
显示当前目录信息
debugfs:  ls -l
      2   40755 (2)      0      0    1024 30-Jun-2006 08:42 .
      2   40755 (2)      0      0    1024 30-Jun-2006 08:42 ..
     11   40700 (2)      0      0   12288 30-Jun-2006 08:41 lost+found
     12  100644 (1)      0      0    1292 30-Jun-2006 08:42 passwd
     13  100644 (1)      0      0     525 30-Jun-2006 08:42 group

inode->name(索引节点对应文件名信息)
debugfs:  ncheck 12
Inode Pathname
12 /passwd

显示文件的索引节点信息
debugfs:  stat /passwd
Inode: 12   Type: regular    Mode:  0644   Flags: 0x0   Generation: 421988
User:     0   Group:     0   Size: 1292
File ACL: 0    Directory ACL: 0
Links: 1   Blockcount: 4
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x44a4737e -- Fri Jun 30 08:42:38 2006
atime: 0x44a4737e -- Fri Jun 30 08:42:38 2006
mtime: 0x44a4737e -- Fri Jun 30 08:42:38 2006
BLOCKS:
(0-1):41-42
TOTAL: 2

查看passwd文件内容
debugfs:  cat /passwd
或:cat <12>

索引节点作为参数显示信息
debugfs:  stat <12>
  [ 注:显示信息跟系统使用stat命令相似,多了个块信息: BLOCKS: ( 0-1 ) : 41-42 TOTAL :  2]

block->inode (块对应索引节点信息)
debugfs:  icheck 41
Block Inode number
41 12
debugfs:  icheck 42
Block Inode number
42 12

测试块号是43的是否被使用及占用状况
debugfs:  testb 43
Block 43 marked in use
debugfs:  icheck 43
Block Inode number
43 13
debugfs:  ncheck 13
Inode Pathname
13 /group
debugfs:  testi /group
Inode 13 is marked in use

debugfs:  stat /group
Inode: 13   Type: regular    Mode:  0644   Flags: 0x0   Generation: 422030
User:     0   Group:     0   Size: 525
File ACL: 0    Directory ACL: 0
Links: 1   Blockcount: 2
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x44a4738e -- Fri Jun 30 08:42:54 2006
atime: 0x44a4738e -- Fri Jun 30 08:42:54 2006
mtime: 0x44a4738e -- Fri Jun 30 08:42:54 2006
BLOCKS:
(0):43
TOTAL: 1

测试块号44
debugfs:  testb 44
Block 44 not in use

查找空闲的节点号和块号
debugfs:  ffi
Free inode found: 14
debugfs:  ffb
Free blocks found: 44

退出debufgs界面
debugfs:  quit
#

   软盘文件系统状况:块号(1-27)供给文件系统使用,块号28留给‘/’(stat /),lost+found(29-40)节点号是11,passwd(41-42)节点号是12,group(43)节点号是13。空闲的节点号(14)和块号(44)。

========
====
--
回复 支持 反对

使用道具 举报

发表于 2006-7-4 10:08:43 | 显示全部楼层

实验(续)

--- 同一分区,删除文件后,在写入数据的情况下,还原删除文件数据(1) ---

尝试用镜像文件作试验(效果跟软盘一样)
# dd if=/dev/fd0 of=/tmp/fd0-bak.img

做一个备份镜像文件
# cp /tmp/fd0-bak.img /tmp/fd1-bak.img

# dumpe2fs /tmp/fd0-bak.img | tail -n 2
dumpe2fs 1.27 (8-Mar-2002)
  Free blocks: 44-1439
  Free inodes: 14-184

挂载镜像文件(操作前要保证/mnt/image目录存在)
# mount -t ext2 /tmp/fd0-bak.img /mnt/image -o loop
# ls -lhi /mnt/image

测试文件备份并作记号
# cp -a /mnt/image/passwd /tmp/passwd
# echo "hello,hello,test" >> /tmp/passwd

删除文件
# rm /mnt/image/passwd
rm: remove `/mnt/image/passwd'? y
# ls -lhi /mnt/image

写入带标记的同名文件
# cp -a /tmp/passwd /mnt/image/
# ls -lhi /mnt/image
total 15k
     13 -rw-r--r--    1 root     root          525  6 30 08:42 group
     11 drwx------    2 root     root          12k  6 30 08:41 lost+found
     12 -rw-r--r--    1 root     root         1.3k  6 30 10:22 passwd
# tail -n 1 /mnt/image/passwd      
hello,hello,test
# umount /mnt/image

查看带标记同名文件的信息
# debugfs
debugfs 1.27 (8-Mar-2002)
debugfs:  open /tmp/fd0-bak.img
debugfs:  stat /passwd
Inode: 12   Type: regular    Mode:  0644   Flags: 0x0   Generation: 432374
User:     0   Group:     0   Size: 1309
File ACL: 0    Directory ACL: 0
Links: 1   Blockcount: 4
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x44a48be8 -- Fri Jun 30 10:26:48 2006
atime: 0x44a48c52 -- Fri Jun 30 10:28:34 2006
mtime: 0x44a48ad6 -- Fri Jun 30 10:22:14 2006
BLOCKS:
(0-1):44-45
TOTAL: 2
[ 注:原 passwd 文件块号(41-42)和节点号是12,现在节点号依然是12,块号改成(44-45)。]

下一个写入文件使用的节点号和块号
debugfs:  ffi
Free inode found: 14
debugfs:  ffb
Free blocks found: 41
debugfs:  quit

# dumpe2fs /tmp/fd0-bak.img | tail -n 2
dumpe2fs 1.27 (8-Mar-2002)
  Free blocks: 41-42, 46-1439
  Free inodes: 14-184

[ 注:rm 删除文件有机会产生‘空隙块’,不难想像安装Linux时携带这么多软件包,一次性把‘块带’挤满,若考虑到经常删除改动文件的分区划分为单独分区也是提高性能的一种方案。]

尝试把(41-42)数据还原
---------------------------
# debugfs -w /tmp/fd0-bak.img
debugfs:  lsdel
Inode  Owner  Mode    Size    Blocks   Time deleted
0 deleted inodes found.
[ 已经写入了数据(带标记passwd),虽然节点号都是12,节点信息已经改变,lsdel 未见效。]

退出
debugfs:  quit

dd -- 恢复数据文件
# dd if=/tmp/fd0-bak.img of=/tmp/rescue.file bs=1024 skip=41 count=2
2+0 records in
2+0 records out

# cat /tmp/rescue.file
  [ 应该没有“hello,hello,test”标记 ]

# ls -l /tmp/rescue.file
-rw-r--r--    1 root     root         2048  6 30 14:51 /tmp/rescue.file

还原文件
# cat /tmp/rescue.file | col -b > /tmp/r-passwd
[或者 ‘vi /tmp/rescue.file’把特殊字符行删除 ]

# diff /etc/passwd /tmp/r-passwd
# ls -l /tmp/r-passwd
-rw-r--r--    1 root     root         1292  6 30 15:28 /tmp/r-passwd
[  size : 1292,现在总算合规格。 ]

# mount /tmp/fd0-bak.img /mnt/image -o loop

删除带标记passwd文件
# rm /mnt/image/passwd

# cp /tmp/r-passwd /mnt/image/passwd
# umount /mnt/image

[ 现在把被删除文件内容恢复,“但未还原。节点号是12,但块号是44-45,41-42未被写入”这点在恢复被删除文件上不是重要,只是把问题研究深入些。]

构思试验方法 1:清除节点12的信息

  删除带标记passwd文件在debugfs进行
# debugfs
debugfs 1.27 (8-Mar-2002)
debugfs:  open -w /tmp/fd0-bak.img
删除带标记的passwd
debugfs:  rm /passwd
Kill file by inode 12
debugfs:  ls -l
      2   40755 (2)      0      0    1024 30-Jun-2006 16:12 .
      2   40755 (2)      0      0    1024 30-Jun-2006 16:12 ..
     11   40700 (2)      0      0   12288 30-Jun-2006 08:41 lost+found
      0       0 (1)      0      0       0                   passwd
     13  100644 (1)      0      0     525 30-Jun-2006 08:42 group

debugfs:  stat <12>
[ 文件已经删除,节点信息依然保留 ]

清除节点信息
debugfs:  clri <12>
debugfs:  stat <12>
Inode: 12   Type: bad type    Mode:  0000   Flags: 0x0   Generation: 0
User:     0   Group:     0   Size: 0
File ACL: 0    Directory ACL: 0
Links: 0   Blockcount: 0
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x00000000 -- Thu Jan  1 08:00:00 1970
atime: 0x00000000 -- Thu Jan  1 08:00:00 1970
mtime: 0x00000000 -- Thu Jan  1 08:00:00 1970
BLOCKS:

debugfs:  ffi
Free inode found: 12
debugfs:  ffb
Free blocks found: 41
debugfs:  quit

复制恢复文件
# mount /tmp/fd0-bak.img /mnt/image -o loop
# cp /tmp/r-passwd /mnt/image/passwd
# umount /mnt/image

[ ffi,ffb显示下一个写入文件会使用 节点号12,41块号。复制恢复文件后,ffi,ffb显示空闲节点号14,41块号。恢复文件数据仍写入44-45,41-42块仍没被使用。]

构思试验方法 2:在试验方法 1 基础上加入把块号44-45置为正在使用,不让恢复文件数据写入此区块

......................
debugfs: setb 44
debugfs: setb 45
debugfs:  testb 44
Block 44 marked in use
debugfs:  testb 45
Block 44 marked in use
......................

[ 注:复制恢复文件后,ffi,ffb显示空闲 节点号14,41块号。恢复文件数据没写入44-45,却写入了46-47,41-42块仍没被使用。“失败”!]

[freeb 44、freeb 45可解除块的使用状态。]

----
--
-
回复 支持 反对

使用道具 举报

发表于 2006-7-4 10:14:14 | 显示全部楼层

实验(续)

--- 同一分区,删除文件后,在写入数据的情况下,还原删除文件数据(2) ---

今天忘记那份试验到了那个环节,索性把备份镜像文件拷了,重新试验
# cp /tmp/fd1-bak.img /tmp/fd0-bak.img

# dumpe2fs /tmp/fd0-bak.img | tail -n 2
dumpe2fs 1.27 (8-Mar-2002)
  Free blocks: 44-1439
  Free inodes: 14-184

试验条件:镜像文件系统(或软盘文件系统)上把文件删除,然后把类似状态文件写入。
试验方案:恢复后的被删除文件(/tmp/r-passwd)重新写入文件系统,让文件节点号是12,占用块号是41-42。

创建试验条件:
# mount -t ext2 /tmp/fd0-bak.img /mnt/image -o loop
# ls -lhi /mnt/image
total 15k
     13 -rw-r--r--    1 root     root          525  6 30 08:42 group
     11 drwx------    2 root     root          12k  6 30 08:41 lost+found
     12 -rw-r--r--    1 root     root         1.3k  6 30 08:42 passwd
# cp /mnt/image/passwd /tmp/passwd
# echo "hello,hello,test" >> /tmp/passwd
# rm /mnt/image/passwd
# cp /tmp/passwd /mnt/image/
# ls -lhi /mnt/image
total 15k
     13 -rw-r--r--    1 root     root          525  6 30 08:42 group
     11 drwx------    2 root     root          12k  6 30 08:41 lost+found
     12 -rw-r--r--    1 root     root         1.3k  7  1 08:52 passwd
# tail -n 1 /mnt/image/passwd      
hello,hello,test
# umount /mnt/image

# dumpe2fs /tmp/fd0-bak.img | tail -n 2
dumpe2fs 1.27 (8-Mar-2002)
  Free blocks: 41-42, 46-1439
  Free inodes: 14-184

试验方案:
# debugfs -w /tmp/fd0-bak.img
debugfs 1.27 (8-Mar-2002)
debugfs:  ls
debugfs:  cat passwd
...........
...........
hello,hello,test

debugfs:  rm passwd
Kill file by inode 12

debugfs:  ffi
Free inode found: 12
debugfs:  ffb
Free blocks found: 41

显示命令使用格式
debugfs:  write
write: Usage: write <native file> <new file>

debugfs:  write /tmp/r-passwd passwd
Allocated inode: 12
[ 注:“new file”名字前不要带特殊字符,如“/passwd”]

debugfs:  ffi
Free inode found: 14
debugfs:  ffb
Free blocks found: 44

debugfs:  stat passwd
Inode: 12   Type: regular    Mode:  0644   Flags: 0x0   Generation: 0
User:     0   Group:     0   Size: 1292
File ACL: 0    Directory ACL: 0
Links: 1   Blockcount: 4
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x44a5d0a0 -- Sat Jul  1 09:32:16 2006
atime: 0x44a5d0a0 -- Sat Jul  1 09:32:16 2006
mtime: 0x44a5d0a0 -- Sat Jul  1 09:32:16 2006
BLOCKS:
(0-1):41-42
TOTAL: 2
debugfs: quit

  注:符合试验方案,成功 !。!

    总结试验方案:对上试验方法失败原因是没使用专业工具debugfs进行write。我尝试过没有进行write还原文件时,不断cp写入文件,节点号无隙延伸,块号数却如此:(41-42)空闲块,(43)group,(44-45)带标记passwd,(46-47)filename,(48)filename, (49)filename......。删除文件的节点号会被占用,遗留的空闲块(41-42)始终没被写入。[被rm删除文件的内容保存周期会很长]

==================
提供参考,选择操作以下步骤:
==================
原本passwd文件的索引节点信息
----------------------------
Inode: 12   Type: regular    Mode:  0644   Flags: 0x0   Generation: 421988
User:     0   Group:     0   Size: 1292
File ACL: 0    Directory ACL: 0
Links: 1   Blockcount: 4
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x44a4737e -- Fri Jun 30 08:42:38 2006
atime: 0x44a4737e -- Fri Jun 30 08:42:38 2006
mtime: 0x44a4737e -- Fri Jun 30 08:42:38 2006
BLOCKS:
(0-1):41-42
TOTAL: 2
---------------------------------------------

修改节点信息跟原本一样(‘回车’--> 下一个提示)
debugfs:  mi <12>
                          Mode    [0100644]
                       User ID    [0]
                      Group ID    [0]
                          Size    [1292]
                 Creation time    [1151719949] 1151628158
             Modification time    [1151719949] 1151628158
                   Access time    [1151719949] 1151628158
                 Deletion time    [0]
                    Link count    [1]
                   Block count    [4]
                    File flags    [0x0]
                    Generation    [0x0]0x67064
                      File acl    [0]
              High 32bits of size    [0]
              Fragment address    [0]
               Fragment number    [0]
                 Fragment size    [0]
               Direct Block #0    [41]
               Direct Block #1    [42]
               Direct Block #2    [0]
               Direct Block #3    [0]
               Direct Block #4    [0]
               Direct Block #5    [0]
               Direct Block #6    [0]
               Direct Block #7    [0]
               Direct Block #8    [0]
               Direct Block #9    [0]
              Direct Block #10    [0]
              Direct Block #11    [0]
                Indirect Block    [0]
         Double Indirect Block    [0]
         Triple Indirect Block    [0]

debugfs:  stat <12>
[ 显示同原来信息一样 ]

------------
--------
---
回复 支持 反对

使用道具 举报

发表于 2006-7-4 10:21:50 | 显示全部楼层

实验(续)

--- 同一分区,删除文件后,没有写入数据的情况下,还原删除文件数据 ---
  
1. 试验:准备

测试用的镜像文件(软盘文件)
# cp /tmp/fd1-bak.img /tmp/fd0-bak.img
# mount /tmp/fd0-bak.img /mnt/image -o loop
# ls /mnt/image
group  lost+found  passwd

删除 passwd 文件
# rm /mnt/image/passwd
rm: remove `/mnt/image/passwd'? y
# umount /mnt/image

测试删除信息
# echo "lsdel" | debugfs /tmp/fd0-bak.img
debugfs 1.27 (8-Mar-2002)
debugfs:   Inode  Owner  Mode    Size    Blocks   Time deleted
    12      0 100644   1292    2/   2 Mon Jul  3 08:31:36 2006
1 deleted inodes found.
[ 注:设备是软盘时 (echo "lsdel" | debugfs /dev/fd0)]

2. 试验:还原删除文件
查看删除文件信息
# debugfs /tmp/fd0-bak.img
debugfs 1.27 (8-Mar-2002)
debugfs:  ls -l
      2   40755 (2)      0      0    1024  3-Jul-2006 08:31 .
      2   40755 (2)      0      0    1024  3-Jul-2006 08:31 ..
     11   40700 (2)      0      0   12288 30-Jun-2006 08:41 lost+found
     13  100644 (1)      0      0     525 30-Jun-2006 08:42 group

debugfs:  lsdel
Inode  Owner  Mode    Size    Blocks   Time deleted
    12      0 100644   1292    2/   2 Mon Jul  3 08:31:36 2006
1 deleted inodes found.

debugfs:  stat <12>
Inode: 12   Type: regular    Mode:  0644   Flags: 0x0   Generation: 421988
User:     0   Group:     0   Size: 1292
File ACL: 0    Directory ACL: 0
Links: 0   Blockcount: 4
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x44a86568 -- Mon Jul  3 08:31:36 2006
atime: 0x44a4737e -- Fri Jun 30 08:42:38 2006
mtime: 0x44a4737e -- Fri Jun 30 08:42:38 2006
dtime: 0x44a86568 -- Mon Jul  3 08:31:36 2006
BLOCKS:
(0-1):41-42
TOTAL: 2

debugfs:  quit

还原文件数据(转移数据和恢复数据)
---------------------------------
1. -- dump 转移数据
# debugfs /tmp/fd0-bak.img
debugfs:  dirty
dirty: Filesystem opened read/only
debugfs:  lsdel
debugfs:  stat <12>

debugfs:  dump -p <12> /tmp/toto
[或:  ‘-p’选项:恢复原文件信息可以详细点 ]

debugfs:  quit

恢复数据
A >
# mount /tmp/fd0-bak.img /mnt/image -o loop
# cp -a /tmp/toto /mnt/image/passwd
# umount /mnt/image

B >
# debugfs -w /tmp/fd0-bak.img
debugfs:  write /tmp/toto passwd
debugfs:  stat passwd
debugfs:  quit

2. -- mi 转移数据

# debugfs -w /tmp/fd0-bak.img
debugfs:  lsdel
Inode  Owner  Mode    Size    Blocks   Time deleted
    12      0 100644   1292    2/   2 Mon Jul  3 08:31:36 2006
1 deleted inodes found.

debugfs:  mi <12>
                          Mode    [0100644]
                       User ID    [0]
                      Group ID    [0]
                          Size    [1292]
                 Creation time    [1151886696]
             Modification time    [1151628158]
                   Access time    [1151628158]
                 Deletion time    [1151886696] 0
                    Link count    [0] 1
                   Block count    [4]
                    File flags    [0x0]
                    Generation    [0x67064]
                      File acl    [0]
           High 32bits of size    [0]
              Fragment address    [0]
               Fragment number    [0]
                 Fragment size    [0]
               Direct Block #0    [41]
               Direct Block #1    [42]
               Direct Block #2    [0]
               Direct Block #3    [0]
               Direct Block #4    [0]
               Direct Block #5    [0]
               Direct Block #6    [0]
               Direct Block #7    [0]
               Direct Block #8    [0]
               Direct Block #9    [0]
              Direct Block #10    [0]
              Direct Block #11    [0]
                Indirect Block    [0]
         Double Indirect Block    [0]
         Triple Indirect Block    [0]
debugfs:  quit

fsck 工具帮助转移
# losetup /dev/loop0 /tmp/fd0-bak.img
[ 注:假如提示/dev/loop0 ‘busy’,把‘loop0’更改成‘loop1’]

# dumpe2fs /dev/loop0 | tail -n 2
dumpe2fs 1.27 (8-Mar-2002)
  Free blocks: 41-42, 44-1439
  Free inodes: 12, 14-184

# fsck -f /dev/loop0
--------------------------------------------
fsck 1.27 (8-Mar-2002)
e2fsck 1.27 (8-Mar-2002)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Unattached inode 12
Connect to /lost+found<y>? yes
Inode 12 ref count is 2, should be 1.  Fix<y>? yes
Pass 5: Checking group summary information
Block bitmap differences:  +(41--42)
Fix<y>? yes
Free blocks count wrong for group #0 (1398, counted=1396).
Fix<y>? yes
Free blocks count wrong (1398, counted=1396).
Fix<y>? yes
Inode bitmap differences:  +12
Fix<y>? yes
Free inodes count wrong for group #0 (172, counted=171).
Fix<y>? yes
Free inodes count wrong (172, counted=171).
Fix<y>? yes

/dev/loop0: ***** FILE SYSTEM WAS MODIFIED *****
/dev/loop0: 13/184 files (0.0% non-contiguous), 44/1440 blocks
--------------------------------------------

# losetup -d /dev/loop0

恢复数据
#  ls -l /"lost+found"
[ 提示:不是这个分区的"lost+found" ]

# mount /tmp/fd0-bak.img /mnt/image -o loop
# ls -li /mnt/image/"lost+found"
total 2
     12 -rw-r--r--    1 root     root         1292  6 30 08:42 #12

#  cp -a /mnt/image/"lost+found"/"#12" /mnt/image/passwd
# umount /mnt/image

[ 注:"#12"文件已经占用节点号 12,块号数41-42。删除文件后的‘空隙块’的保存周期‘长’和‘fsck’有关。]

3. -- 最简单转移恢复数据方法(undel)
# debugfs  -w /tmp/fd0-bak.img
debugfs 1.27 (8-Mar-2002)

debugfs:  lsdel
Inode  Owner  Mode    Size    Blocks   Time deleted
    12      0 100644   1292    2/   2 Mon Jul  3 08:31:36 2006
1 deleted inodes found.

查看命令用法
debugfs:  undel
undel: Usage: undelete <inode_num> <dest_name>
debugfs:  undel <12> passwd

debugfs: cat passwd
debugfs: stat passwd
debugfs: quit

----
--

[ 注:经过以上实验操作,EXT文件系统的节点信息与块关联有了大概认识。以后操作‘系统’删除文件时额外不舍得,‘/home’划分单独分区具有安全性和重要性。]

--
----
回复 支持 反对

使用道具 举报

发表于 2006-7-13 14:53:27 | 显示全部楼层
实验(续)

-- 还原“被删除目录”--


试验:目录(lost+found)、ext2文件系统(/tmp/fd0-bak.img)

复制“备份镜像文件”
# cp /tmp/fd1-bak.img /tmp/fd0-bak.img

# mount /tmp/fd0-bak.img /mnt/image -o loop

系统自带stat软件,“测试目录”作为参数查看文件系统信息
# stat -f /mnt/image/"lost+found"
  File: "/mnt/image/lost+found"
    ID: 0        0        Namelen: 255     Type: EXT2/EXT3
Blocks: Total: 1412       Free: 1396       Available: 1324       Size: 1024
Inodes: Total: 184        Free: 171      

查看“测试目录”信息
# stat /mnt/image/"lost+found"
或(stat -l /mnt/image/"lost+found")

  File: "/mnt/image/lost+found"
  Size: 12288             Blocks: 24         IO Block: -4611692546777673728 Directory
Device: 700h/1792d        Inode: 11          Links: 2   
Access: (0700/drwx------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: Fri Jun 30 08:41:01 2006
Modify: Fri Jun 30 08:41:01 2006
Change: Fri Jun 30 08:41:01 2006

查看“测试目录”简要信息
# stat -t /mnt/image/"lost+found"

/mnt/image/lost+found 12288 24 41c0 0 0 700 11 2 0 0 1151628061 1151628061 1151628061 13835051526931877888
  [ 注:‘151628061’对应时间信息,mi修改节点信息时有很大帮助 。举例如下:]

例子:对上“实验(续)”中‘提供参考,选择操作以下步骤:’标题项内容是怎样知道‘ctime: 0x44a4737e -- Fri Jun 30 08:42:38 2006’对应节点信息‘1151628158’?

==-------------------------==
# man touch
# touch -t 200606300842.38 /tmp/touch.note

# ls -l /tmp/touch.note
-rw-r--r--  1 root  root  0  6 30 08:42 /tmp/touch.note

# stat /tmp/touch.note | grep Modify
Modify: Fri Jun 30 08:42:38 2006

# stat -t /tmp/touch.note
/tmp/touch.note 0 0 81a4 0 0 801 199753 1 16 0 1151628158 1151628158 1152233084 13835051526931877888

==-------------------------==

继续实验:
# ls /mnt/image
group  lost+found  passwd

# echo "stat lost+found" | debugfs /tmp/fd0-bak.img
debugfs:  Inode: 11   Type: directory    Mode:  0700   Flags: 0x0   Generation: 0
User:     0   Group:     0   Size: 12288
File ACL: 0    Directory ACL: 0
Links: 2   Blockcount: 24
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x44a4731d -- Fri Jun 30 08:41:01 2006
atime: 0x44a4731d -- Fri Jun 30 08:41:01 2006
mtime: 0x44a4731d -- Fri Jun 30 08:41:01 2006
BLOCKS:
(0-11):29-40
TOTAL: 12

删除 lost+found 目录
# rmdir /mnt/image/"lost+found"
# ls /mnt/image
group  passwd
# umount /mnt/image

1) 恢复“lost+found”目录
# echo "lsdel" | debugfs /tmp/fd0-bak.img
debugfs 1.27 (8-Mar-2002)
debugfs:   Inode  Owner  Mode    Size    Blocks   Time deleted
    11      0  40700      0   12/  12 Fri Jul  7 09:09:37 2006
1 deleted inodes found.

# echo "undel <11> lost+found" | debugfs -w /tmp/fd0-bak.img

# echo "ls" | debugfs /tmp/fd0-bak.img
debugfs 1.27 (8-Mar-2002)
debugfs:   2  (12) .    2  (12) ..    11  (20) lost+found    12  (16) passwd    13  (964) group   

[ 注:跟恢复删除文件方法一样 ]

2)  恢复“lost+found”特殊目录
  以上是对 EXT2 文件系统做的目录恢复实验,在EXT3日志文件系统,‘lsdel’根本行不通。假如用根分区“lost+found”目录代替:(cp -a /"lost+found" /mnt/image/ ),替代后的/mnt/image/"lost+found"目录变成两回事。

  mklost+found命令恢复特殊目录
# mount /tmp/fd0-bak.img /mnt/image -o loop
# cd /mnt/image
# mklost+found
mklost+found 1.27 (8-Mar-2002)
# ls
group  lost+found  passwd

# cd
# umount /mnt/image

# echo "stat lost+found"|debugfs /tmp/fd0-bak.img
debugfs 1.27 (8-Mar-2002)
debugfs:  Inode: 11   Type: directory    Mode:  0755   Flags: 0x0   Generation: 431179
User:     0   Group:     0   Size: 46080
File ACL: 0    Directory ACL: 0
Links: 2   Blockcount: 92
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x44adbc7e -- Fri Jul  7 09:44:30 2006
atime: 0x44adbc7e -- Fri Jul  7 09:44:30 2006
mtime: 0x44adbc7e -- Fri Jul  7 09:44:30 2006
BLOCKS:
(0-11):29-40, (IND):44, (12-44):45-77
TOTAL: 46

  [ 注:/mnt/image/"lost+found"目录的 size 和 BLOCKS 都是变成两回事,但是,这是操作系统接受的“lost+found”目录 ]

-------

  操作电脑的,多数面对是操作系统。空隙块(碎片)过多的处理方法:
  “备份系统里的文件 > 格式化系统分区 >  还原备份文件”

-------
----
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表