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 磁碟修復指令大全:badblocks、cfdisk、dd、e2fsck、fsck、fdisk 完整參數詳解

編輯:Linux 教學

Linux 磁碟檢測、分區、備份、修復核心指令速查表

1. badblocks - 掃描壞軌

badblocks [-svw] [-b block_size] [-o output_file] device [blocks] [start_block]
  • -b:指定區塊大小 (bytes)。
  • -o:結果輸出至檔案。
  • -s:顯示進度。
  • -v:詳細資訊。
  • -w:寫入測試模式(會破壞資料,勿用於含資料分區)。

2. cfdisk - 互動式分區工具

cfdisk [-avz] [-c cylinders] [-h heads] [-s sectors] [-P format] device
  • 類似 DOS fdisk 但提供游標互動介面,操作直覺。
  • -z:忽略現有分區表,視為新磁碟。
  • -P r/s/t:顯示分區表詳細資訊(完整/依磁區/依磁頭-磁區-柱面)。

3. dd - 底層資料複製/轉換/備份

dd [bs=bytes] [cbs=bytes] [conv=conversion] [count=blocks] [ibs=bytes] [if=input] [obs=bytes] [of=output] [seek=blocks] [skip=blocks]
  • if=/dev/sda of=/dev/sdb:整顆磁碟複製。
  • if=/dev/zero of=/dev/sda bs=1M:清零磁碟。
  • conv=sync,noerror:跳過讀取錯誤並補零,適合損壞磁碟救援。

4. e2fsck (fsck.ext2/ext3/ext4) - ext2/3/4 檔案系統檢查修復

e2fsck [-acCdfFnprsStvVy] [-b superblock] [-B block_size] [-l/-L bad_blocks_file] device
  • -a / -p:自動修復不詢問。
  • -b:指定備用 superblock 位置(主 superblock 損壞時)。
  • -c:同時執行 badblocks 掃描壞軌。
  • -f:強制檢查即使標記乾淨。
  • -y:所有詢問回答 yes。
  • -n:唯讀模式,所有詢問回答 no。
  • 回傳碼:0=無錯誤、1/2=已修復、4=錯誤未修復、8=執行錯誤、16=語法錯誤、128=共享庫錯誤。

5. fsck - 檔案系統檢查統一入口

fsck [-aANPrRsTV] [-t fstype] [filesystems...]
  • 依 /etc/fstab 顺序檢查多個檔案系統。
  • -A:檢查 fstab 所有標記需檢查的檔案系統。
  • -R:搭配 -A 跳過根目錄 /。
  • -t ext4:僅檢查 ext4 類型。

6. fdisk - 傳統問答式分區工具

fdisk [-b sector_size] [-l] [-u] [-v] device
  • -l:列出分區表不進入互動模式。
  • -u:搭配 -l 以扇區為單位顯示起始/結束位置。
  • 不支援 GPT 分區表(需用 parted 或 gdisk)。

7. ext2ed - ext2 檔案系統十六進位編輯器 (僅 Red Hat 系列提供)

直接操作 inode、superblock、group descriptor 等結構,極高風險,僅供資深管理員資料救援使用。

使用建議

  1. 檢查修復前務必卸載檔案系統 (umount) 或以唯讀模式掛載。
  2. 重要資料先用 dd 或 ddrescue 完整鏡像備份再嘗試修復。
  3. 超過 2TB 磁碟必須使用 GPT 分區表,改用 parted / gdisk 操作。
  4. 定期執行 smartctl -a /dev/sdX 監控 S.M.A.R.T. 健康狀態,預防災難。
Copyright © Windows教程網 All Rights Reserved