Superblock / partition table mismatch - misleading error message formulation
So, the other day I enlarged my Hyper-V Ubuntu guest's virtual disk using Windows' native tools. Then, in Ubuntu, I used the 'disks' tool to resize my filesystem. It's supposed to take care of the manipulation of the filesystem AND the partition table, but because of a non-reproducible quirk, it did only the former. After rebooting I got the following error message by fsck:
The filesystem size (according to the superblock) is %b blocks The physical size of the device is %c blocks\n Either the superblock or the partition table is likely to be corrupt!
(e2fsck/super.c:714, e2fsck/problem.c:140)
This was very misleading because neither is technically corrupt, there is simply a mismatch. The term "physical size" made me think that the virtual disk somehow reported wrong data. Additionally, it's not clear how e2fsck (and other disk/partition/filesystem tools) calculates or gets the size info.
I think it would be much clearer if the message tells you where the information is coming from, something along the line of
The filesystem size (according to the superblock) is %b blocks The size of /dev/sda1 (according to the partition table) is %c blocks\n The reported size of at least one of them is likely to be wrong!
(Setting the partition size manually with fdisk finally solved my problem, for anyone's reference who's looking for a solution to this message)
E2fsck gets the information from the OS; and it doesn't know whether it's a partition or a just a device --- and technically speaking, from the user space's /dev/sda1 is a block device (which happens to be a partition). And if it tries to write beyond what the OS thinks is the end of the block device partition, the OS will fail the write --- leading to potential data loss. So if Ubuntu is failing to modify the parition table, this is a SERIOUS bug, and not something to be taken lightly. (And if the file system size is larger than the physical container, arguably the file system IS corrupted, since it can lead to aforementioned data loss.)
I can modify the message to make it a bit clearer, but it's tricky, because trying to figure out whether the passed-in file system is a partition, or a full block device, or just a file, is possible, but it's a huge amount of complexity to add for a program which is intended to be used by system administrators who are hopefully well informed enough to figure whether /dev/sda1 or /dev/sda is a partition or a block device. If not, we would need a heck of a lot more hand holding than just a message clarification.....