fsck(File System Check)是檔案系統一致性檢查與修復工具,屬於高風險操作,**嚴禁在掛載狀態下對讀寫分區執行**。本文詳解參數、五階段修復流程、互動模式實戰、lost+found 機制與遺失檔案找回技巧。
| 參數 | 功能 | 風險等級 |
|---|---|---|
-a | 自動修復,無提示 | 高(可能誤刪資料) |
-r | 互動修復,逐項確認 | 低(推薦生產環境) |
-A | 依 /etc/fstab 檢查所有分區 | 中 |
-t TYPE | 指定檔案系統類型 | 低 |
-V | 顯示詳細執行過程 | 低 |
-N | 模擬執行,不實際修改 | 無 |
鐵律:執行修復前,**必須卸載目標分區**(umount /dev/sda10)。根分區修復需進入單用戶模式或 LiveCD 環境。
fsck -rV -t ext3 /dev/sda10fsck 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。#6122),原檔名、路徑、權限、時間戳**全部遺失**。file #6122 判斷檔案類型strings #6122 | head 檢視文本內容fsck 實為前端分發器,實際調用:
e2fsck(/sbin/fsck.ext*)xfs_repair(不可用 fsck,XFS 無 journal replay 機制不同)btrfs check --repairfsck.vfat / ntfsfixfsck 是「急救手術刀」,非「保健按摩椅」。平時建立完備備份、監控磁碟 SMART、使用 Journaling 檔案系統、避免強制斷電,才是守護資料的正道。唯有災難發生時,冷靜卸載、備份元數據、互動修復、耐心辨識 lost+found,方能最大程度挽回損失。