Linux

Linux 核心無法辨識分區表

  • October 24, 2020

我經常遇到 U 盤或 SD 卡的分區表突然不再被核心辨識,而 (g)parted 和 fdisk 仍然可以看到它,其他系統也是如此。我什至可以指示 gparted 在其中一個分區上執行 fsck,但它當然會失敗,因為設備文件假設 /dev/sdbX 不存在。

我將附上 dmesg 輸出:

[ 8771.136129] usb 1-5: new high-speed USB device number 4 using ehci_hcd
[ 8771.330322] Initializing USB Mass Storage driver...
[ 8771.330766] scsi4 : usb-storage 1-5:1.0
[ 8771.331108] usbcore: registered new interface driver usb-storage
[ 8771.331118] USB Mass Storage support registered.
[ 8772.329734] scsi 4:0:0:0: Direct-Access     Generic  STORAGE DEVICE   0207 PQ: 0 ANSI: 0
[ 8772.334359] sd 4:0:0:0: Attached scsi generic sg1 type 0
[ 8772.619619] sd 4:0:0:0: [sdb] 31586304 512-byte logical blocks: (16.1 GB/15.0 GiB)
[ 8772.620955] sd 4:0:0:0: [sdb] Write Protect is off
[ 8772.620971] sd 4:0:0:0: [sdb] Mode Sense: 0b 00 00 08
[ 8772.622303] sd 4:0:0:0: [sdb] No Caching mode page present
[ 8772.622317] sd 4:0:0:0: [sdb] Assuming drive cache: write through
[ 8772.629970] sd 4:0:0:0: [sdb] No Caching mode page present
[ 8772.629992] sd 4:0:0:0: [sdb] Assuming drive cache: write through
[ 8775.030231] sd 4:0:0:0: [sdb] Unhandled sense code
[ 8775.030240] sd 4:0:0:0: [sdb]  Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
[ 8775.030249] sd 4:0:0:0: [sdb]  Sense Key : Medium Error [current] 
[ 8775.030259] sd 4:0:0:0: [sdb]  Add. Sense: Data phase CRC error detected
[ 8775.030271] sd 4:0:0:0: [sdb] CDB: Read(10): 28 00 00 00 00 00 00 00 08 00
[ 8775.030291] end_request: I/O error, dev sdb, sector 0
[ 8775.030300] quiet_error: 30 callbacks suppressed
[ 8775.030306] Buffer I/O error on device sdb, logical block 0
[ 8775.033781] ldm_validate_partition_table(): Disk read failed.
[ 8775.033813] Dev sdb: unable to read RDB block 0
[ 8775.037147]  sdb: unable to read partition table
[ 8775.047170] sd 4:0:0:0: [sdb] No Caching mode page present
[ 8775.047185] sd 4:0:0:0: [sdb] Assuming drive cache: write through
[ 8775.047196] sd 4:0:0:0: [sdb] Attached SCSI removable disk

另一方面,parted 必須同時對同一個磁碟說:

(parted) print                                                            
Model: Generic STORAGE DEVICE (scsi)
Disk /dev/sdb: 16.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
1      4194kB  62.9MB  58.7MB  primary  fat16        lba
2      62.9MB  16.2GB  16.1GB  primary  ext4

它不僅是分開的,即使是較舊的 fdisk 對該分區表也沒有問題:

Command (m for help): p

Disk /dev/sdb: 16.2 GB, 16172187648 bytes
64 heads, 32 sectors/track, 15423 cylinders, total 31586304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000dbfc6

  Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/sdb2          122880    31586303    15731712   83  Linux

我真是一頭霧水。很容易說分區表已損壞,但是為什麼 gparted 仍然可以毫無怨言地讀取它(並且沒有抱怨),或者我如何從 (g)parted 奇蹟般地發現的內容重建分區表?

由於某種原因,您的核心無法讀取分區表:

[ 8775.030291] end_request: I/O error, dev sdb, sector 0
[ 8775.030300] quiet_error: 30 callbacks suppressed
[ 8775.030306] Buffer I/O error on device sdb, logical block 0
[ 8775.033781] ldm_validate_partition_table(): Disk read failed.

因此,它無法為分區創建設備,因為它沒有讀取分區表。稍後當您嘗試使用 parted 或 fdisk 查看分區表時,IO 已成功執行。

partprobe /dev/sdX當您的核心在啟動時無法辨識分區時,請嘗試使用。

人部分探針:

PARTPROBE(8)                                                         GNU Parted Manual                                                        PARTPROBE(8)

NAME
      partprobe - inform the OS of partition table changes

SYNOPSIS
      partprobe [-d] [-s] [devices...]

DESCRIPTION
      This manual page documents briefly the partprobe command.

      partprobe  is  a  program  that informs the operating system kernel of partition table changes, by requesting that the operating system re-read the
      partition table.

引用自:https://unix.stackexchange.com/questions/52206