Mount

幾何錯誤:塊數 967424 超出設備大小(415232 個塊)

  • August 13, 2019

我試圖了解我對以下mount命令做錯了什麼。

從這裡獲取以下文件:

只需從這裡img下載文件。

然後我驗證md5sum了上游頁面的正確性:

$ md5sum nand_2016_06_02.img
3ad5e53c7ee89322ff8132f800dc5ad3  nand_2016_06_02.img

這裡file有話要說:

$ file nand_2016_06_02.img 
nand_2016_06_02.img: x86 boot sector; partition 1: ID=0x83, starthead 68, startsector 4096, 3321856 sectors, extended partition table (last)\011, code offset 0x0

因此,讓我們檢查此映像的第一個分區的開始:

$ /sbin/fdisk -l nand_2016_06_02.img

Disk nand_2016_06_02.img: 1.6 GiB, 1702887424 bytes, 3325952 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
Disklabel type: dos
Disk identifier: 0x0212268d

Device               Boot Start     End Sectors  Size Id Type
nand_2016_06_02.img1       4096 3325951 3321856  1.6G 83 Linux

在我的情況下Units大小是512Start4096,這意味著偏移量是字節2097152。在這種情況下,以下應該只是工作,但不是:

$ mkdir /tmp/img
$ sudo mount -o loop,offset=2097152 nand_2016_06_02.img /tmp/img/
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
      missing codepage or helper program, or other error

      In some cases useful info is found in syslog - try
      dmesg | tail or so.

而且,dmesg 揭示:

$ dmesg | tail
[ 1632.732163] loop: module loaded
[ 1854.815436] EXT4-fs (loop0): mounting ext2 file system using the ext4 subsystem
[ 1854.815452] EXT4-fs (loop0): bad geometry: block count 967424 exceeds size of device (415232 blocks)

此處列出的解決方案都不適合我:

  • resize2fs 或,
  • 磁碟

我錯過了什麼?


我嘗試的其他一些實驗:

$ dd bs=2097152 skip=1 if=nand_2016_06_02.img of=trunc.img

這導致:

$ file trunc.img 
trunc.img: Linux rev 1.0 ext2 filesystem data (mounted or unclean), UUID=960b67cf-ee8f-4f0d-b6b0-2ffac7b91c1a (large files)

同樣的故事:

$ sudo mount -o loop trunc.img /tmp/img/
mount: wrong fs type, bad option, bad superblock on /dev/loop2,
      missing codepage or helper program, or other error

      In some cases useful info is found in syslog - try
      dmesg | tail or so.

我不能使用resize2fs,因為我需要先執行e2fsck

$ /sbin/e2fsck -f trunc.img 
e2fsck 1.42.9 (28-Dec-2013)
The filesystem size (according to the superblock) is 967424 blocks
The physical size of the device is 415232 blocks
Either the superblock or the partition table is likely to be corrupt!
Abort<y>? yes

一旦您提取了您感興趣的文件系統(使用dd),只需調整文件大小(967424*4096=3962568704):

$ truncate -s 3962568704 trunc.img

然後簡單地說:

$ sudo mount -o loop trunc.img /tmp/img/
$ sudo find /tmp/img/
/tmp/img/
/tmp/img/u-boot-spl.bin
/tmp/img/u-boot.img
/tmp/img/root.ubifs.9
/tmp/img/root.ubifs.4
/tmp/img/root.ubifs.5
/tmp/img/root.ubifs.7
/tmp/img/root.ubifs.2
/tmp/img/root.ubifs.6
/tmp/img/lost+found
/tmp/img/root.ubifs.3
/tmp/img/boot.ubifs
/tmp/img/root.ubifs.0
/tmp/img/root.ubifs.1
/tmp/img/root.ubifs.8

另一個更簡單的解決方案是直接在原始 img 文件上截斷:

$ truncate -s 3964665856 nand_2016_06_02.img
$ sudo mount -o loop,offset=2097152 nand_2016_06_02.img /tmp/img/

其中 3962568704 + 2097152 = 3964665856

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