Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Ext3 檔案系統誤刪檔案恢復實戰:debugfs + dd 從 Journal 還原資料

編輯:Linux 教學

Ext3 日誌式檔案系統刪除檔案後,inode 與資料區塊不會立即清零,透過 debugfs 讀取 Journal 可恢復誤刪檔案。前提:刪除後未重啟系統,Journal 尚未覆寫。

場景準備

# 建立測試檔
echo "this is test file" > test.txt
ls -il test.txt
# 15 -rw-rw-r-- 2 root root 20 Apr 17 12:08 test.txt  (inode 15)

# 刪除檔案
rm test.txt

方法一:已知 inode 號恢復

1. 查詢 Journal 記錄

debugfs /dev/sda5
debugfs: logdump -i <15>

關鍵輸出:

Blocks: (0+1): 10234   # 資料區塊位址

2. dd 提取資料區塊

dd if=/dev/sda5 of=/tmp/test.txt bs=4096 count=1 skip=10234
  • bs=4096:區塊大小 (Ext3 預設 4KB)
  • skip=10234:跳過 10234 區塊,讀取第 10235 區塊
  • count=1:讀取 1 區塊

3. 驗證恢復內容

cat /tmp/test.txt
# this is test file

方法二:未知 inode,透過檔名查詢

1. 列出目錄含刪除項目

debugfs /dev/sda5
debugfs: ls -d
# 輸出含:<2121567> (20) mytest.txt   # 尖括號表示已刪除 inode

2. 查詢該 inode Journal

debugfs: logdump -i <2121567>

尋找 Type: regular 且含 Blocks: 的記錄:

Blocks: (0+1): 2142216

3. 恢復檔案

dd if=/dev/sda5 of=/home/user/mytest_recovered.txt bs=4096 skip=2142216 count=1
cat /home/user/mytest_recovered.txt
# this is my test file

恢復流程總結

  1. debugfs: ls -d 找刪除檔 inode (尖括號標記)
  2. debugfs: logdump -i <inode> 找資料區塊位址 (Blocks: 行)
  3. dd if=裝置 of=恢復檔 bs=4096 skip=區塊號 count=1 提取資料

關鍵限制與注意事項

  • 僅限 Ext3/Ext2,Ext4 延遲配置機制導致區塊對應更複雜
  • 不可重啟:重啟會清空/覆寫 Journal
  • 單區塊檔案:大檔案跨多區塊需依序提取所有區塊
  • lsdel 指令亦可列出刪除 inode,但輸出較難解析

預防勝於恢復

  • 重要資料建立快照 (LVM/ZFS/Btrfs)
  • alias rm='rm -i' 強制確認
  • 使用 trash-cli 移至回收桶而非直接刪除

掌握 debugfs 與 dd 配合 Journal 的恢復技巧,可在關鍵時刻挽回誤刪損失,但建立完備備份策略才是根本之道。

Copyright © Windows教程網 All Rights Reserved