EXT4 Filesystem – Fix EXT4-fs Bad Geometry Error

ext4filesystemsfsck

I have a micro SD card which has a FAT32 partition and an EXT4 partition. The EXT4 partition will no longer mount. dmesg shows the following error:

EXT4-fs (sdb2): bad geometry: block count 2199023779840 exceeds size of device (524288 blocks)

I've Googled, but still don't fully understand where the problem is (in the partition table? the filesystem?) nor how to fix it. I have attempted a number of solutions:

  • Using testdisk to write the partition table
  • Using fsck to restore the superblock from the backups (I've tried all of them). e.g. fsck.ext4 -b 163840 -B 4096 /dev/sdb2
  • Using fsck -cc to check for bad blocks
  • Using resize2fs to set the size of the partition. Output: The combination of flex_bg and !resize_inode features is not supported by resize2fs.

When I run fsck, it comes up with a bunch of errors (full output below), which it claims to fix. If I run it again, however, it shows the same errors all over again, every time.

How can I fix the bad geometry issue and make my filesystem mountable again? How did this happen?

fsck output:

e2fsck 1.42 (29-Nov-2011)
One or more block group descriptor checksums are invalid.  Fix<y>? yes

Group descriptor 0 checksum is invalid.  FIXED.
Group descriptor 1 checksum is invalid.  FIXED.
Group descriptor 2 checksum is invalid.  FIXED.
Group descriptor 3 checksum is invalid.  FIXED.
Group descriptor 4 checksum is invalid.  FIXED.
Group descriptor 5 checksum is invalid.  FIXED.
Group descriptor 6 checksum is invalid.  FIXED.
Group descriptor 7 checksum is invalid.  FIXED.
Group descriptor 8 checksum is invalid.  FIXED.
Group descriptor 9 checksum is invalid.  FIXED.
Group descriptor 10 checksum is invalid.  FIXED.
Group descriptor 11 checksum is invalid.  FIXED.
Group descriptor 12 checksum is invalid.  FIXED.
Group descriptor 13 checksum is invalid.  FIXED.
Group descriptor 14 checksum is invalid.  FIXED.
Group descriptor 15 checksum is invalid.  FIXED.
/dev/sdb2 contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Free blocks count wrong for group #0 (24465, counted=24466).
Fix<y>? yes

Free blocks count wrong for group #2 (4788, counted=5812).
Fix<y>? yes

Free blocks count wrong for group #3 (8710, counted=8881).
Fix<y>? yes

Free blocks count wrong for group #8 (5682, counted=22066).
Fix<y>? yes

Free blocks count wrong (299742, counted=317322).
Fix<y>? yes

Inode bitmap differences:  -(8193--8194) -8197 -8208 -(8225--8226) -8229 -(8240--8241) -(8257--8258) -8261 -8272 -8274 -(8289--8290) -8293 -(8304--8306) -(8321--8322) -8325 -8336 -8339 -16387 -16389 -16400 -16419 -16421 -(16432--16433) -16451 -16453 -16464 -16466 -16483 -16485 -(16496--16498) -16515 -16517 -16528 -16531 -24577 -24579 -24581 -24592 -24609 -24611 -24613 -(24624--24625) -24641 -24643 -24645 -24656 -24658 -24673 -24675 -24677 -(24688--24690) -24705 -24707 -24709 -24720 -24723 -(32770--32771) -32773 -32784 -(32802--32803) -32805 -(32816--32817) -(32834--32835) -32837 -32848 -32850 -(32866--32867) -32869 -(32880--32882) -(32898--32899) -32901 -32912 -32915 -(40961--40963) -40965 -40976 -(40993--40995) -40997 -(41008--41009) -(41025--41027) -41029 -41040 -41042 -(41057--41059) -41061 -(41072--41074) -(41089--41091) -41093 -41104 -41107 -(49156--49157) -49168 -(49188--49189) -(49200--49201) -(49220--49221) -49232 -49234 -(49252--49253) -(49264--49266) -(49284--49285) -49296 -49299 -57345 -(57348--57349) -57360 -57377 -(57380--57381) -(57392--57393) -57409 -(57412--57413) -57424 -57426 -57441 -(57444--57445) -(57456--57458) -57473 -(57476--57477) -57488 -57491 -65538 -(65540--65541) -65552 -65570 -(65572--65573) -(65584--65585) -65602 -(65604--65605) -65616 -65618 -65634 -(65636--65637) -(65648--65650) -65666 -(65668--65669) -65680 -65683 -(73729--73730) -(73732--73733) -73744 -(73761--73762) -(73764--73765) -(73776--73777) -(73793--73794) -(73796--73797) -73808 -73810 -(73825--73826) -(73828--73829) -(73840--73842) -(73857--73858) -(73860--73861) -73872 -73875 -(81923--81925) -81936 -(81955--81957) -(81968--81969) -(81987--81989) -82000 -82002 -(82019--82021) -(82032--82034) -(82051--82053) -82064 -82067 -90113 -(90115--90117) -90128 -90145 -(90147--90149) -(90160--90161) -90177 -(90179--90181) -90192 -90194 -90209 -(90211--90213) -(90224--90226) -90241 -(90243--90245) -90256 -90259 -(98306--98309) -98320 -(98338--98341) -(98352--98353) -(98370--98373) -98384 -98386 -(98402--98405) -(98416--98418) -(98434--98437) -98448 -98451 -(106497--106501) -106512 -(106529--106533) -(106544--106545) -(106561--106565) -106576 -106578 -(106593--106597) -(106608--106610) -(106625--106629) -106640 -106643 -114694 -114704 -114726 -(114736--114737) -114758 -114768 -114770 -114790 -(114800--114802) -114822 -114832 -114835 -122881 -122886 -122896 -122913 -122918 -(122928--122929) -122945 -122950 -122960 -122962 -122977 -122982 -(122992--122994) -123009 -123014 -123024 -123027
Fix<y>? yes

Free inodes count wrong for group #0 (7803, counted=7804).
Fix<y>? yes

Free inodes count wrong (130683, counted=130684).
Fix<y>? yes


/dev/sdb2: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sdb2: 388/131072 files (22.7% non-contiguous), 206966/524288 blocks

fdisk -l output:

Disk /dev/sdb: 16.0 GB, 16012804096 bytes
64 heads, 32 sectors/track, 15271 cylinders, total 31275008 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: 0x0005ce93

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048    27080703    13539328    c  W95 FAT32 (LBA)
/dev/sdb2        27080704    31275007     2097152   83  Linux

Best Answer

Same problem after truncating a SD card image where the SD had a few blocks less than the original. Repartitioned the drive with fdisk (see above), but message "Size in superblock is different from the physical size of the partition" remained. Found the solution here: http://www.linuxquestions.org/questions/linux-hardware-18/size-in-superblock-is-different-from-the-physical-size-of-the-partition-298175/

So, on the unmounted partition: e2fsck -f /dev/XXX resize2fs /dev/XXX

Related Question