Why does this loopback device creation malfunction?

Posted by user50118 on Server Fault See other posts from Server Fault or by user50118
Published on 2010-09-04T06:42:14Z Indexed on 2011/11/22 10:00 UTC
Read the original article Hit count: 312

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)

© Server Fault or respective owner

Related posts about linux

Related posts about filesystems