Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The stackoverflow people thought this was more appropriate here, I put it there as it is part of a program but I can see their POV, so here it is:

At the bottom of the code you can see it failing. In fact, I'll put it here at the start too because it is the problem I need to solve:

[350591.924819] EXT4-fs (loop0): bad geometry: block count 9750806 exceeds size of device (9750168 blocks)

I don't understand why the device is supposedly too small. I made this partition two days ago with normal fdisk, it was created and formatted with ext4 supplying no options other than the partition (/dev/sdb2) to format.

The only explaination I can think of is that ext4 has the size of the partition wrong somehow but that seems very unlikely. What is wrong with my math? The offset is correct, you can see that with the file command, and the size should be correct too because End - Start comes to the same number of sectors minus 1, just like it should (A disk starting on sector 1 and ending on sector 2 would be 2 - 1 = 1 and have two sectors).

# sfdisk -luS /dev/sdb

Disk /dev/sdb: 9729 cylinders, 255 heads, 63 sectors/track
Units = sectors of 512 bytes, counting from 0

   Device Boot    Start       End   #sectors  Id  System
/dev/sdb2      78295040 156296384   78001345  83  Linux

# losetup -r -f --show -o $((78295040 * 512)) --sizelimit $((78001345 * 512)) /dev/sdb
# file -s /dev/loop0
/dev/loop0: Linux rev 1.0 ext4 filesystem data (needs journal recovery) (extents) (large files) (huge files)
# mount -o ro -t ext4 /dev/loop0 /mnt
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 | tail -n 1
[350591.924819] EXT4-fs (loop0): bad geometry: block count 9750806 exceeds size of device (9750168 blocks)
share|improve this question
I assume that is a typo "/mnt".. surely /mnt/something. Which kernel is it? (I assume ext4 has either been compiled in or loaded) . Shouldn't that losetup line have an actual filesystem location rather than a disk specification? [/home/user/lo.img rather than /dev/sdb] c.f:… – Grizly Sep 4 '10 at 7:41
@Grizly: /mnt is reasonable, and preferred on Linux as per the FHS. The kernel log from EXT4-fs shows that ext4 support is available. I'm also puzzled with losetup /dev/sdb. – Gilles Sep 4 '10 at 13:30
@rob: do you remember exactly how the partition was created? The start of the partition is not aligned on a cylinder boundary (78295040 % (63*255) = 10295), and fdisk would have at least shown a warning message. – Gilles Sep 4 '10 at 13:43

From the first sight sizelimit variable is calculated incorrectly, thus target read-only loop device exceeds the size of /dev/sdb2 device. The result of (End - Start)* size of sector = sizelimit is 78001344 and it should be used during loop device creation to resolve the issue.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.