1

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
/dev/loop0
# 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)
4
  • 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: walkernews.net/2007/07/01/…
    – Grizly
    Sep 4, 2010 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. Sep 4, 2010 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. Sep 4, 2010 at 13:43
  • 1
    Why is a 9-years old question still open and even bumped to homepage? Whatever the original problem was, I highly doubt it's relavant anymore...
    – Massimo
    Jun 28, 2020 at 3:38

1 Answer 1

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .