磁碟問題和解決: fsck,gdisk,fdisk等

2023-07-28 15:01:31

錯誤: Resize inode not valid

對於gpt分割區的硬碟一般fsck只能檢查分割區, 不能用於檢查整個硬碟, 但是如果對硬碟裝置執行時遇到這樣的錯誤

$ sudo fsck -n /dev/sdc
fsck from util-linux 2.37.2
e2fsck 1.46.5 (30-Dec-2021)
GW1.5T was not cleanly unmounted, check forced.
Resize inode not valid.  Recreate? no

用 gdisk檢查一下分割區表, 可能會提示下面的資訊

$ sudo gdisk /dev/sdc
GPT fdisk (gdisk) version 1.0.8

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************


Warning! Secondary partition table overlaps the last partition by
33 blocks!
You will need to delete this partition or resize it in another utility.

對於這種情況, 需要清空GPT和MBR, 命令 x -> z -> y * 2

Command (? for help): x

Expert command (? for help): z
About to wipe out GPT on /dev/sdc. Proceed? (Y/N): y
GPT data structures destroyed! You may now partition the disk using fdisk or
other utilities.
Blank out MBR? (Y/N): y

之後再看就正常了

$ sudo gdisk /dev/sdc
GPT fdisk (gdisk) version 1.0.8

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

用gdisk分割區

Command (? for help): n
Partition number (1-128, default 1): 
First sector (34-2813066894, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-2813066894, default = 2813066894) or {+-}size{KMGTP}: 
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'
Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdc.
The operation has completed successfully.

分割區之後, 會顯示GPT資訊

$ sudo gdisk /dev/sdc
GPT fdisk (gdisk) version 1.0.8

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

錯誤: Bad magic number in super-block

如果用fsck直接檢查GPT分割區的硬碟時就會報這個錯誤

$ sudo fsck -n /dev/sdc
fsck from util-linux 2.37.2
e2fsck 1.46.5 (30-Dec-2021)
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/sdc

需要指定檔案系統對應的分割區進行檢查

$ sudo fsck -n /dev/sdc1
fsck from util-linux 2.37.2
e2fsck 1.46.5 (30-Dec-2021)
1T4B: clean, 11/87908352 files, 5800552/351633105 blocks

如果需要檢查硬碟, 用 gdisk /dev/sdc, 然後在裡面用 v 命令

錯誤 ata1: irq_stat 0x00400000, PHY RDY changed

在N2 NS-1 (CPU:hi3798mv200)上掛載一塊 SanDisk ECO 1.92T SSD 時, 在dmesg中每隔100秒出現如下錯誤

[  360.673489] ata1: exception Emask 0x10 SAct 0x0 SErr 0x10000 action 0xe frozen
[  360.679463] ata1: irq_stat 0x00400000, PHY RDY changed
[  360.683343] ata1: SError: { PHYRdyChg }
[  360.685977] ata1: hard resetting link
[  370.720684] ata1: softreset failed (device not ready)
[  370.724476] ata1: hard resetting link
[  375.681723] ata1: SATA link up 6.0 Gbps (SStatus 133 SControl 300)
[  375.684718] ata1.00: configured for UDMA/133
[  375.684745] ata1: EH complete

根據網上搜尋到的結果, 大部分原因為: 供電問題, 硬碟硬體問題, 以及檔案格式錯誤. 參考 https://forums.gentoo.org/viewtopic-t-815278.html
將整塊SSD重新格式化為ext4後, 未再報錯.