1,929 瀏覽數

Linux command – sfck

系統有一顆硬碟壞了,抽出來到別台 RedHat RHEL 6.5 檢查得到一個無情的結果

  
[root@localhost Desktop]# fsck -y /dev/sdb1
fsck from util-linux 2.20.1
e2fsck 1.42.9 (4-Feb-2014)
ext2fs_open2: Bad magic number in super-block
fsck.ext2: Superblock invalid, trying backup blocks...
fsck.ext2: Bad magic number in super-block while trying to open /dev/sdb1

The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem.  If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193 <device>
 or
    e2fsck -b 32768 <device>

無效的 Superblock 是代表?

先來看看 Linux 下的檔案儲存是採用什麼方式,他採用了 superblock / inode /data block 的方式來儲存資料.

data block

資料在儲存時不太可能每一次都有連續的空間可供資料的儲存,所以資料會切割成固定大小分開存放,這大小的空間就是 data block 但在談 data block 大小前,先來說說硬碟的儲存最小單位 block size ,通常硬碟在出廠前都先經過低階格式化,而預設的大小就是 512bytes , 但512bytes 真的太小所以在 Linux 下我們用的是另外一種單位就是 data block ,而他的大小必須為 512bytes 的倍數. 512,1024,2048,4096 bytes 通常在 Linux 下為 4096bytes.Data, Data block 與 block 的相關如下所是.

Data –> Data block(s) –> block(s)

inode

剛剛說到 data block 的資料是一塊塊分散的儲存(索引式檔案系統),所以此時必須要一塊資料要紀錄哪些 data block 是屬於哪一個 data 的, 而記錄了這些資料的就叫做 inode ,每一個檔案都會對應到一個 inode 他的大小為 128bytes 除了紀錄 data block 的位置外還儲放了檔案的權限與相關屬性.

superblock

那剛剛 inode/block 的使用情況(使用量,剩餘…)是由誰來紀錄,就是透過 superblock 基本上他記錄該檔案系統所有的資訊. 所以我們可以很清楚了解 superblock / inode / data block 的關係.

superblock –>inode –> data block

更多有關於 Linux 的檔案系統可以參考 http://benjr.tw/93162

那 無效的 Superblock 應該就 GG 了.

不過我們還是來看一下正常情況要怎麼救.

被掛載的磁區是不能做 fsck ,如果是系統碟那就要用其他方式開機再來下 fsck 指令.

[root@localhost Desktop]# fsck /dev/sdb7
fsck from util-linux 2.20.1
e2fsck 1.42.9 (4-Feb-2014)
/dev/sdb7 is mounted.
e2fsck: Cannot continue, aborting.

常用的兩個參數 -y , -a 都是可以做自動修復,不需要一一輪詢.

  • -y
    For some filesystem-specific checkers, the -y option will cause the fs-specific fsck to always attempt to fix any detected filesystem corruption automatically.
  • -a
    Automatically repair the filesystem without any questions.

沒有下參數 -y 或是 -a 系統會一直詢問你是否修復.

 
[root@localhost Desktop]# fsck /dev/sdb6
fsck from util-linux 2.20.1
e2fsck 1.42.9 (4-Feb-2014)
Superblock has an invalid journal (inode 8).
Clear<y>? yes
*** ext3 journal has been deleted - filesystem is now ext2 only ***

/dev/sdb6 was not cleanly unmounted, check forced.
Pass 1: Checking inodes, blocks, and sizes
Journal inode is not in use, but contains data.  Clear<y>? yes
yInode 10000, i_blocks is 249376, should be 224800.  Fix<y>? yes
Inode 49537, i_blocks is 10280, should be 112.  Fix<y>? yes
Inode 49541, i_blocks is 2080, should be 104.  Fix<y>? yes
Inode 49549, i_blocks is 160, should be 104.  Fix<y>? yes
[root@localhost Desktop]# fsck -a /dev/sdb6
fsck from util-linux 2.20.1
/dev/sdb6 was not cleanly unmounted, check forced.
/dev/sdb6: Inode 270816, i_blocks is 24296, should be 16512.  FIXED.
/dev/sdb6: Inode 270611, i_blocks is 15560, should be 8304.  FIXED.
/dev/sdb6: Inode 270818, i_blocks is 1512, should be 104.  FIXED.
[root@localhost Desktop]# fsck -y /dev/sdb6
...
/dev/sdb6: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sdb6: 340410/655776 files (0.6% non-contiguous), 2374655/2622603 blocks

fsck 與 e2fsck 的差別是!!

  • fsck is used to check and optionally repair one or more Linux filesys‐tems.
  • e2fsck is used to check the ext2/ext3/ext4 family of file systems.

e2fsck 是針對 ext2/ext3/ext4 而 fsck 支援多種檔案格式.

[root@localhost Desktop]# ll fsck*
-rwxr-xr-x 1 root root 30540 Sep  2  2015 fsck*
-rwxr-xr-x 1 root root 13820 Sep  2  2015 fsck.cramfs*
lrwxrwxrwx 1 root root     6 Sep  9  2015 fsck.ext2 -> e2fsck*
lrwxrwxrwx 1 root root     6 Sep  9  2015 fsck.ext3 -> e2fsck*
lrwxrwxrwx 1 root root     6 Sep  9  2015 fsck.ext4 -> e2fsck*
lrwxrwxrwx 1 root root     6 Sep  9  2015 fsck.ext4dev -> e2fsck*
-rwxr-xr-x 1 root root 54900 May 26 05:22 fsck.fat*
-rwxr-xr-x 1 root root 30292 Sep  2  2015 fsck.minix*
lrwxrwxrwx 1 root root     8 May 26 05:22 fsck.msdos -> fsck.fat*
-rwxr-xr-x 1 root root   333 Feb 16  2016 fsck.nfs*
lrwxrwxrwx 1 root root     8 May 26 05:22 fsck.vfat -> fsck.fat*   

那如果是 VLM 的檔案格式要怎麼處理? 什麼是 LVM http://benjr.tw/174

我們要先找出來當初訂的 LV (LVM 的組成為 PV – VG – LV)

[root@localhost Desktop]# pvscan
[root@localhost Desktop]# vgscan
[root@localhost Desktop]# lvscan

Volume Group active

[root@localhost Desktop]# vgchange -ay

使用 fsck 修復 LVM 檔案系統.

[root@localhost Desktop]# e2fsck -f /dev/VolGroup00/LogVol01

發表迴響