首先是umount掉误删文件的分区,这一点已经做到了,我机器上两套系统(debian和arch,系统a的fstab里并没有写入对系统b所在的挂载,系统b里的fstab同样没有写入对系统a所在分区的挂载)。
然后检查了一下debian系统所在分区的剩余空间还有多少
CODE:
df -h结果发现剩余空间并不够作误删分区/dev/hdc9的镜像(debian里用的是2.6.18的内核,如果是2.6.2*的内核就应该是/dev/sda9),找朋友借来了一块20g的空硬盘挂上(在系统中,那块硬盘识别为hdb,只分有一个区,在系统中表示为/dev/hdb1)
CODE:
mkfs.reiserfs /dev/hdb1将那块硬盘格式化为reiserfs文件系统(其实我也不知道是不是非得格式话为reiserfs,因为我误删的文件分区是reiserfs格式的,所以我把这块硬盘也格式化成了相同的格式。接下来就是按照文档里面的步骤来了。
CODE:
mkdri /mnt/back
mount -t reiserfs /dev/hdc1 /mnt/back
dd if=/dev/hdc9 conv=noerror > /mnt/back/hdc9.img等个几分钟镜像就作好了。
CODE:
losetup -f #检查哪个loop设备是空的(感觉好像每次都是/dev/loop0,貌似还没见过loop1,loop2空过
losetup /dev/loop0 /mnt/back/hdc9.img #把hdc9.img 镜象关联到/dev/loop0的设备中这样/dev/loop0就拥有了hdc9.img的所有属性,我们在loop0上进行修复操作,据说用loop0进行操作比直接对分区进行修复操作要来的安全:)开始修复啦:
CODE:
reiserfsck --rebuild-tree -S -l undelete.log /dev/loop0 #恢复的日志存在undelete.log里这里有个选项让你选
CODE:
reiserfsck 3.6.19 (2003 www.namesys.com)
*************************************************************
** Do not run the program with --rebuild-tree unless **
** something is broken and MAKE A BACKUP before using it. **
** If you have bad sectors on a drive it is usually a bad **
** idea to continue using it. Then you probably should get **
** a working hard drive, copy the file system from the bad **
** drive to the good one -- dd_rescue is a good tool for **
** that -- and only then run this program. **
** 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 rebuild the filesystem (/dev/loop0) tree
Will put log info to 'undelete.log'
Do you want to run this program?[N/Yes] (note need to type Yes if you do):要继续修复 当然得选Yes,注意Y要大写。然后就是一个稍微有点漫长的等待过程了(时间应该是视误删文件所暂磁盘空间的大小来决定吧,不过和误删那个分区的总空间使用量也有一定的关系:
CODE:
Replaying journal..
Reiserfs journal '/dev/loop0' in blocks [18..8211]: 0 transactions replayed
###########
reiserfsck --rebuild-tree started at Thu Dec 1 21:01:53 2005
###########
Pass 0:
The whole partition (251984 blocks) is to be scanned
Skipping 8218 blocks (super block, journal, bitmaps) 243766 blocks will be read
0%....20%....40%....60%....80%....100% left 0, 6588 /sec
"r5" hash is selected
Flushing..finished
Read blocks (but not data blocks) 243766
Leaves among those 56
Objectids found 77
Pass 1 (will try to insert 56 leaves):
Looking for allocable blocks .. finished
0%....20%....40%....60%....80%....100% left 0, 56 /sec
Flushing..finished
56 leaves read
45 inserted
11 not inserted
non-unique pointers in indirect items (zeroed) 633
Pass 2:
0%....20%....40%....60%....80%....100% left 0, 0 /sec
Flushing..finished
Leaves inserted item by item 11
Pass 3 (semantic):
Flushing..finished
Files found: 42
Directories found: 12
Pass 3a (looking for lost dir/files):
Looking for lost directories:
Looking for lost files:0 /sec
Flushing..finished 48, 0 /sec
Objects without names 16
Dirs linked to /lost+found: 1
Files linked to /lost+found 15
Pass 4 - finished done 44, 0 /sec
Flushing..finished
Syncing..finished
###########
reiserfsck finished at Thu Dec 1 21:02:31 2005
###########这样子,修复就差不多完成了,把loop0挂上看看恢复程度如何
CODE:
mkdir /mnt/back/loopback
mount /dev/loop0 /mnt/back/loopback简单看了一下,恢复的程度应该还不算太失望,~/目录恢复了80%左右的样子,undelete.log也好长,用more看翻了几十页才翻完,没什么特重要的文件,我就没仔细去看他了。这时候把原来误删的那个分区给挂上
CODE:
mount /dev/hdc9 /mnt/arch #-t reiserfs好像加不加都一样,不加也可以挂上去,貌似现在mount比较智能了
cp -drpP /mnt/back/loopback/home/qwinding /mnt/arch/home到了这里,基本上算是恢复了不少了,但是还有好多文件是恢复在lost+found里看一下lost+found大概有多少文件
CODE:
du -sh /mnt/back/loopback/lost+found/居然有2g之多。那还真的得进去看下,应该还可以找出点什么来。
CODE:
cd /mnt/back/loopback/lost+found
find . -user qwinding|less这时候慢慢看把 有的文件只是目录名变了你还可以认得出它来,需要的就cp回原来误删的那个分区里去吧。但是有些就直接是一行一行的数字了,看不出个所以然来,也没多大的办法了。到这里基本就结束了。
把loop0 umount掉 /dev/hdc7 umount掉,重启系统进arch里面看看是否还正常。
不过这次还算运气比较好的,恢复过来的文档基本都没受到什么损害,不过很多音乐就有点倒霉了,好多都缩水了。放一半直接跳到下一首了。。不过有得恢复的总比没得恢复的好。:)
ps:在系统中执行命令的时候要小心谨慎,犯我这样错误可不好玩。建议在.barchrc里面加入
CODE:
alias rm = `rm -i`