If you've ever run the e2fsck command on an ext2 or ext3 filesystem, you might have encountered a message like this:
Pass 5: Checking group summary information
Block bitmap differences: -(123456) -(123457) -(123458) -(123459) ...
This message is telling you that there is a discrepancy between the number of free blocks reported by the filesystem and the number of free blocks calculated by e2fsck. But what does this mean, and how can you fix it? In this guide, we'll explain what's going on and show you how to troubleshoot and resolve the issue.
Understanding the problem
Before we can fix the problem, it's important to understand what's causing it. The ext2 and ext3 filesystems use a block group structure to organize data. Each block group contains a block bitmap, which tracks which blocks are in use and which are free. When you run e2fsck, it checks the block bitmap to see which blocks are free and which are in use. If the number of free blocks reported by the filesystem doesn't match the number of free blocks calculated by e2fsck, you'll see the message we mentioned earlier.
There are a few reasons why this might happen:
The filesystem was not unmounted cleanly. If the system crashed or the filesystem was forcibly unmounted, the block bitmap might not have been updated properly. This can cause
e2fsckto report a different number of free blocks than the filesystem.The filesystem has been modified by a third-party tool. If you've used a tool that modifies the filesystem directly, it might have updated the block bitmap incorrectly. This can also cause
e2fsckto report a different number of free blocks than the filesystem.There is a hardware error. If there is a problem with the disk or the disk controller, it might cause the block bitmap to become corrupted. This can cause
e2fsckto report a different number of free blocks than the filesystem.
Troubleshooting the problem
Now that we understand what's causing the problem, let's look at how to troubleshoot it. Here are the steps you should follow:
Unmount the filesystem. Before you do anything else, you should unmount the filesystem to prevent any further damage. You can do this with the
umountcommand:sudo umount /dev/sda1Replace
/dev/sda1with the path to your own filesystem.Run
e2fsckwith the-coption. This will check the filesystem for bad blocks. If there are any bad blocks,e2fsckwill mark them as unusable and add them to the block bitmap. Here's an example:sudo e2fsck -c /dev/sda1Again, replace
/dev/sda1with the path to your own filesystem.Run
e2fsckagain without the-coption. This will check the filesystem for any other errors. If there are any discrepancies between the number of free blocks reported by the filesystem and the number of free blocks calculated bye2fsck, you'll see the message we mentioned earlier. Here's an example:sudo e2fsck /dev/sda1If
e2fsckreports any errors, you can try running it again with the-yoption. This will automatically fix any errors thate2fsckfinds. Here's an example:sudo e2fsck -y /dev/sda1Be careful with the
-yoption, as it can potentially cause data loss if used on the wrong filesystem. Only use it if you're sure you know what you're doing.Remount the filesystem. Once you've run
e2fsckand fixed any errors, you can remount the filesystem with themountcommand. Here's an example:sudo mount /dev/sda1 /mntReplace
/dev/sda1and/mntwith the path to your own filesystem and mount point, respectively.
Preventing the problem
Now that you know how to troubleshoot and fix the problem, let's look at how to prevent it from happening in the first place. Here are some tips:
Always unmount the filesystem cleanly. If you're going to modify the filesystem directly, make sure to unmount it first. This will prevent any damage to the block bitmap.
Avoid using third-party tools that modify the filesystem directly. These tools can potentially cause damage to the block bitmap. If you need to modify the filesystem, use a tool that works at a higher level, such as a file manager or a package manager.
Monitor the filesystem for errors. If you see any errors, run
e2fsckas soon as possible to prevent any further damage.Use a filesystem that supports journaling, such as ext4. Journaling filesystems keep track of changes to the filesystem in a journal, which makes it easier to recover from errors. If you're using a journaling filesystem, you don't need to run
e2fsckas often.
In this guide, we've explained what the "Free blocks count wrong in e2fsck" message means, and how to troubleshoot and fix the problem. We've also provided some tips for preventing the problem from happening in the first place. If you follow these steps, you should be able to keep your filesystem healthy and avoid any data loss.
References
| Title | Author | Date | URL |
|---|---|---|---|
| e2fsck(8) | The e2fsprogs Project | 2022-02-14 | https://linux.die.net/man/8/e2fsck |
| Ext2 Filesystem | Wikipedia | 2022-02-14 | https://en.wikipedia.org/wiki/Ext2 |
| Ext3 Filesystem | Wikipedia | 2022-02-14 | https://en.wikipedia.org/wiki/Ext3 |