說明 : 檢查與修複 Linux 檔案系統,可以同時檢查一個或多個 Linux 檔案系統。
注意:fsck 掃描檔案系統時一定要在單使用者模式、修複模式或把裝置umount後進行。如果掃描運作中的系統,會造成系統檔案損壞。RHEL6中fsck預設支援檔案系統ext4,如果想支援ext3檔案系統的掃描,應該加-j 參數。最好是根據不同的檔案系統來調用不同的掃描工具,比如ext3的檔案系統使用fsck.ext3,ext2檔案系統使用fsck -t etx2等。
參數 :-a : 如果檢查有錯則自動修複
-r : 如果檢查有錯則由使用者回答是否修複
-t : 給定檔案系統的型式,若在 /etc/fstab 中已有定義或 kernel 本身已支援的則不需加上此參數
-s : 依序一個一個地執行 fsck 的指令來檢查
-A : 對/etc/fstab 中所有列出來的 partition 做檢查
-C : 顯示完整的檢查進度
-d : 列印 e2fsck 的 debug 結果
-p : 同時有 -A 條件時,同時有多個 fsck 的檢查一起執行
-R : 同時有 -A 條件時,省略 / 不檢查
-V : 詳細顯示模式
執行後的傳回值及代表意義
0 沒有任何錯誤發生。
1 檔案系統發生錯誤,并且已經修正。
2 檔案系統發生錯誤,并且已經修正。
4 檔案系統發生錯誤,但沒有修正。
8 運作時發生錯誤。
16 使用的文法發生錯誤。
128 共享的函數庫發生錯誤。
檢查 ext3 檔案系統的 /dev/sdb3 是否正常,如果有異常便自動修複
1
<code>[root@justin ~]</code><code># fsck -t ext3 -a /dev/sdb3</code>
一般出現以下提示時可以使用fsck指令來修複:
1、無法mount分區;
2、大量檔案、目錄丢失,根目錄下生成/LOST+FOUND檔案夾,裡面有大量#XXXXXX類的檔案和目錄;
3、fsck很快報錯完成;
4、fsck執行時,有大量提示,如修改節點、清0節點等操作
當Linux系統被強行關閉或重新啟動,電腦的檔案系統便有可能受損,系統會自動檢查并修複檔案系統;但當檔案系統未能自動修複,需要手動使用fsck進行掃描和修複。出現如下情況:
2
3
4
5
6
7
8
9
10
11
12
13
14
<code>…...</code>
<code>Checking file systems ...fsck </code><code>1.41</code><code>.</code><code>3</code><code>(</code><code>12</code><code>-OCT-</code><code>2008</code><code>)</code>
<code>/dev/sdb5 contains a file system </code><code>with</code> <code>errors check forced</code>
<code>/dev/sdb5: |========== ---進度條</code>
<code>……</code>
<code>/dev/sdb5: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY (i.e., without -a or -p options)</code>
<code>fsck died </code><code>with</code> <code>exit status4</code>
<code>……/</code><code>var</code><code>/log/fsck/ ---fsck報錯日志的存放位置</code>
<code>Warning</code>
<code>Press enter </code><code>for</code> <code>maintenance</code>
<code>(or type Control-D to </code><code>continue</code><code>): --- Ctrl+d繼續啟動伺服器。</code>
1、檢視報錯日志
<code>[root@justin ~]</code><code># ls -l /var/log/fsck/</code>
<code>total 8</code>
<code>-rw-r----- 1 root adm 190 2011-06-09 10:03 checkfs</code>
<code>-rw-r----- 1 root adm 192 2011-06-09 10:03 checkroot</code>
<code>[root@justin ~]</code><code># more /var/log/fsck/checkfs</code>
<code>[root@justin ~]</code><code># more /var/log/fsck/checkroot</code>
2、檢視運作級别
掃描檔案系統時一定要在單使用者模式、修複模式或把裝置umount後進行。如果掃描運作中的系統,會造成系統檔案損壞。
<code>[root@justin ~]</code><code># runlevel</code>
<code>N 3</code>
<code>[root@justin ~]</code><code># init 1</code>
<code>[root@justin ~]</code><code>#</code>
3、使用fsck對檔案系統進行掃描、修複
<code>[root@justin ~]</code><code># fsck</code>
<code>fsck</code> <code>fsck</code><code>.ext2 </code><code>fsck</code><code>.ext4 </code><code>fsck</code><code>.msdos </code>
<code>fsck</code><code>.cramfs </code><code>fsck</code><code>.ext3 </code><code>fsck</code><code>.ext4dev </code><code>fsck</code><code>.vfat </code>
<code>[root@justin ~]</code><code># fsck.ext4 -y /dev/sdb5</code>
<code>e2fsck 1.41.12 (17-May-2010)</code>
<code>/dev/sdb5</code> <code>已挂載.</code>
<code>WARNING!!! The filesystem is mounted. If you </code><code>continue</code> <code>you ***WILL***</code>
<code>cause ***SEVERE*** filesystem damage.</code>
<code>你真的想要要繼續 (y</code><code>/n</code><code>)? y</code>
fsck.ext4開始進入掃描、修正檔案系統,這個過程時間比較長,中間有數次停頓的過程,隻需等待即可,千萬不要以為當機而重新開機伺服器。fsck.ext4掃描、修正完檔案系統後,根據提示可能需要重新開機系統。如果沒有提示重新開機系統,也需要reboot來重新開機系統。在重新開機系統的過程中,fsck會對檔案系統進行掃描。fsck掃描完以後,會啟動到系統的登入界面,不需要進行任何幹涉。再次重新啟動系統,系統可以正常啟動。
e2fsck和fsck.ext2、fsck.ext3、fsck.ext4功能一樣都是檢查和修複檔案系統,在檢查之前一定要解除安裝待檢查的檔案系統分區。
主要參數包括:
-a: 檢查 partition,如發現問題會自動修複。
-B size: 指定 size 作為區塊大小。
-c: 檢查 partition 是否有壞軌。
-C file: 将檢查結果儲存到 file。
-d: 輸出 e2fsck debug 結果。
-f: e2fsck 預設隻會對錯誤的檔案系統檢查,加上 -f 是強制檢查。
<code>[root@justin ~]</code><code># umount /dev/sdb5</code>
<code>[root@justin ~]</code><code># e2fsck -f /dev/sdb5</code>
<code>第一步: 檢查inode,塊,和大小</code>
<code>第二步: 檢查目錄結構</code>
<code>第3步: 檢查目錄連接配接性</code>
<code>Pass 4: Checking reference counts</code>
<code>第5步: 檢查簇概要資訊</code>
<code>/dev/sdb5</code><code>: 11</code><code>/131648</code> <code>files (0.0% non-contiguous), 25432</code><code>/526113</code> <code>blocks</code>
案例:
機器斷電或者直接關電源強制重新開機後出現以下界面:
<a href="http://s1.51cto.com/wyfs02/M02/7D/74/wKioL1bo686ykiMwAACFn1xBJH0474.png" target="_blank"></a>
<a href="http://s3.51cto.com/wyfs02/M00/7D/76/wKiom1bo60PzootWAAGy5_BeVOo449.png" target="_blank"></a>
提示:Giveroot password for maintenance
(or type Control-D for normal startup):
輸入fsck -y 修複,時間可能比較長,等待修複完成exit退出重新開機
本文轉自 justin_peng 51CTO部落格,原文連結:http://blog.51cto.com/ityunwei2017/1343249,如需轉載請自行聯系原作者