질문&답변
클라우드/리눅스에 관한 질문과 답변을 주고 받는 곳입니다.
리눅스 분류

실수로 /home 디랙토리를 날렸습니다... 도와주세요...

작성자 정보

  • 박태혁 작성
  • 작성일

컨텐츠 정보

본문

윤병훈 님의 글


안녕하세요.
제가 실수로 linux /home 디렉토리를 rm 으로 삭제시켜 버렸습니다.
df 명령어로 보니 /dev/hda2(/home) 가 안나오는 걸로 봐서 mount 까지 삭제된 것 같습니다.
/etc/fstab 파일안에도 /home 내용은 없습니다.

일단 debugfs /dev/hda2 로 복구를 시도했으나...
lsdel 명령어를 입력하면...
lsdel: Filesystem not open
라고 나옵니다... 

아마도 mount 까지 삭제되서 그런것 같은데... 
지금은 아무것도 안한 상태입니다... (다시 mount 했다거나 file 덮어쓰기 안함.)
다시 /home mount 해서 debugfs 돌리면 살릴 수 있을까요?
어떻게 해야 할지 모르겠습니다... 흑흑흑
도와주세요~

참고로 os는 wowlinux 7.1(ext2) 입니다...



별도움이 될지 안될지 모르겠네요.  ㅡㅡ^

웹에서 자료를 찾아보니 관련된 글이 있어 올려드립니다.

 

명령어로 지운 파일 복구하는 방법

리눅스에서의 파일 삭제는 신중을 기해야 한다.
왜냐면 삭제된 파일은 복구 할 수 없기 때문이다.
이것이 정석이였습니다.

물론 rm 의 소프트링크나 다른 삭제 프로그램으로 대체하는 프로그램들도
있습니다만 rm 자체의 복구는 없다고 알고 있으신 분들이 대부분 일 겁니다.

해답은

debugfs 라는 명령어 입니다. (man page 참조)

실제 사용예를 들어 설명하겠습니다.

가정1) /home/pds/portsentry.tar.gz 라는 파일이 있음.
가정2) /home 파티션은 hda8 입니다. (df -h 로 확인)
가정3) rm -f /home/pds/portsentry.tar.gz 명령으로 지웠음.
가정4) root 로 작업.

복구 절차.

1. #debugfs /dev/hda8

=> 설명 : hda8 파티션에 대해서 검사를 한다.

2. debugfs:

=> 대기상태를 뜻함. 이곳에서 lsdel 을 입력하고 엔터.
계속...

debugfs: lsdel
99 deleted inodes found.
Inode Owner Mode Size Blocks Time deleted
108123 0 100644 239 1/ 1 Thu Jan 3 01:25:33 2002
18417 0 100644 426625 420/ 420 Thu Jan 3 01:26:34 2002
45007 0 100644 343 1/ 1 Thu Jan 3 01:29:59 2002
28691 0 100400 879 1/ 1 Thu Jan 3 01:38:29 2002
18394 0 40755 0 1/ 1 Thu Jan 3 01:58:54 2002
..
.
14356 0 100644 2325 3/ 3 Fri Jan 25 16:13:24 2002
61239 0 100644 43034 44/ 44 Fri Jan 25 16:13:31 2002
debugfs:

위와 같은 상태로 나오고 다시 대기상태로 됩니다.
실제로는 너무 많이 나오더군요.. (내가 그렇게 많이 지웠었나? '.'a)

이제 이 목록중에서 하나를 선택해서 살려야 합니다.
다행히도 살리고자 하는 파일은 가장 최근에 지운 파일이므로 가장 아래쪽에 있는 것이겠죠.

debugfs: dump <61239> /home/debugfs/portsentry.tar.gz

=> Inode 값을 <> 안에 적어줍니다. 뒤에는 복구할 파일 이름을 적어주시면 됩니다.
=> 복구할 파일은 다른 디렉토리로 지정해 주시는게 좋습니다. 별 상관은 없지만...

#cd /home/debugfs
#tar -zxvf portsentry.tar.gz // 정상적으로 압축이 풀리더군요.

=> 아주 훌륭하게 복구가 되었더군요. ^^v

임의로 portsentry.tar.gz 를 지워서 테스트를 한 것입니다.

debugfs: 상태에서 사용할 수 있는 명령어는 help 를 쳐보면 알 수 있습니다.
끝내는 것은 q, quit 입니다.

아래는 debugfs: 에서 사용가능한 명령어들 입니다.
---------------------------------------------------------------------

Available debugfs requests:

show_debugfs_params, params
Show debugfs parameters
open_filesys, open Open a filesystem
close_filesys, close Close the filesystem
feature, features Set/print superblock features
dirty_filesys, dirty Mark the filesystem as dirty
init_filesys Initalize a filesystem (DESTROYS DATA)
show_super_stats, stats Show superblock statistics
ncheck Do inode->name translation
icheck Do block->inode translation
change_root_directory, chroot
Change root directory
change_working_directory, cd
Change working directory
list_directory, ls List directory
show_inode_info, stat Show inode information
link, ln Create directory link
unlink Delete a directory link
mkdir Create a directory
rmdir Remove a directory
rm Remove a file (unlink and kill_file, if appropriate)
kill_file Deallocate an inode and its blocks
clri Clear an inode's contents
freei Clear an inode's in-use flag
seti Set an inode's in-use flag
testi Test an inode's in-use flag
freeb Clear a block's in-use flag
setb Set a block's in-use flag
testb Test a block's in-use flag
modify_inode, mi Modify an inode by structure
find_free_block, ffb Find free block(s)
find_free_inode, ffi Find free inode(s)
print_working_directory, pwd
Print current working directory
expand_dir, expand Expand directory
mknod Create a special file
list_deleted_inodes, lsdel
List deleted inodes
write Copy a file from your native filesystem
dump_inode, dump Dump an inode out to a file
cat Dump an inode out to stdout
lcd Change the current directory on your native
filesystem
rdump Recursively dump a directory to the native filesystem
help Display info on command or topic.
list_requests, lr, ? List available commands.
quit, q Leave the subsystem

ext2 화일시스템 디버거로 ext3는 지원안한다네요. ("__)/

 

 

 

관련자료

댓글 1

윤병훈님의 댓글

  • 윤병훈
  • 작성일
답변해 주셔서 감사합니다...
이미 debugfs /dev/hda2 로 복구를 시도했으나...
lsdel 명령어를 입력하면...
lsdel: Filesystem not open
라고 나옵니다...
위의 내용은 파일만 삭제했을 경우 같습니다...
전 /home 디렉토리를 전체 삭제... 흑흑흑...
다시 /home 를 마운트 해서 debugfs 를 실행하면
살릴 수 있는 것까지 다 날아갈까봐 지금 아무것도 못하고 있습니다...


공지사항


뉴스광장


  • 현재 회원수 :  60,291 명
  • 현재 강좌수 :  36,951 개
  • 현재 접속자 :  342 명