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

Linux 檔案系統修復神器:fsck 參數詳解、互動修復實戰與 lost+found 遺失檔案找回

編輯:Linux 教學

fsck(File System Check)是檔案系統一致性檢查與修復工具,屬於高風險操作,**嚴禁在掛載狀態下對讀寫分區執行**。本文詳解參數、五階段修復流程、互動模式實戰、lost+found 機制與遺失檔案找回技巧。

一、 核心參數與安全原則

參數功能風險等級
-a自動修復,無提示高(可能誤刪資料)
-r互動修復,逐項確認低(推薦生產環境)
-A依 /etc/fstab 檢查所有分區中
-t TYPE指定檔案系統類型低
-V顯示詳細執行過程低
-N模擬執行,不實際修改無

鐵律:執行修復前,**必須卸載目標分區**(umount /dev/sda10)。根分區修復需進入單用戶模式或 LiveCD 環境。

二、 互動修復實戰:fsck -rV -t ext3 /dev/sda10

fsck 1.39 (29-May-2006)
[/sbin/fsck.ext3 (1) -- /dev/sda10] fsck.ext3 -r /dev/sda10
e2fsck 1.39 (29-May-2006)
/opt contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Inode 6121 ref count is 2, should be 1. Fix? yes
Unattached inode 6122
Connect to /lost+found? yes
Inode 6122 ref count is 2, should be 1. Fix? yes
Pass 5: Checking group summary information
Block bitmap differences: -(519-529) -9273
Fix? yes
...
/opt: ***** FILE SYSTEM WAS MODIFIED *****
/opt: 19/128520 files (15.8% non-contiguous), 46034/514048 blocks

五階段流程:
1. Inode/區塊/大小檢查
2. 目錄結構檢查
3. 目錄連通性檢查
4. 參考計數檢查
5. 群組摘要資訊檢查

每階段發現錯誤會提示 Fix?,輸入 y 確認修復,其他鍵跳過。

三、 lost+found:遺失檔案的最後庇護所

  • 當 fsck 發現「無目錄項指向的 inode」(孤兒 inode),詢問是否連接至 lost+found。
  • 檔案以 **inode 號命名**(如 #6122),原檔名、路徑、權限、時間戳**全部遺失**。
  • 找回策略:
    ① file #6122 判斷檔案類型
    ② strings #6122 | head 檢視文本內容
    ③ 結合備份/日誌/業務知識人工識別重命名

四、 常見檔案系統專用工具

fsck 實為前端分發器,實際調用:

  • ext2/3/4:e2fsck(/sbin/fsck.ext*)
  • XFS:xfs_repair(不可用 fsck,XFS 無 journal replay 機制不同)
  • Btrfs:btrfs check --repair
  • VFAT/NTFS:fsck.vfat / ntfsfix

五、 結語

fsck 是「急救手術刀」,非「保健按摩椅」。平時建立完備備份、監控磁碟 SMART、使用 Journaling 檔案系統、避免強制斷電,才是守護資料的正道。唯有災難發生時,冷靜卸載、備份元數據、互動修復、耐心辨識 lost+found,方能最大程度挽回損失。

Copyright © Windows教程網 All Rights Reserved