To check the consistency of the hard disk in Linux one must use the fsck command. Fsck stands for exactly what I just mentioned in the previous sentence, file system consistency check. The Linux file system banks its data on a set of internal tables, These tables help the operating system input/output (I/O) routines maintain consistency by keeping track of used inodes and available blocks. When these tables are corrupted for some reason or another, then one will see the dreaded bad block message.
Corruption comes about from improperly un-synchronized data on a disk. This is when you come to know that such inconsistencies require a file system repair. To manage, view, create, and delete partitions one uses fdisk and to check the file system one uses fsck. Both of these software tools come in handy when having issues with your hard disk or ssd’s.
As mentioned in the previous paragraph files system corruptions comes about from power failures during read/write operations, my favorite accidentally unplugging the power cord. Done that so many times! Improperly shutting down a system. Rare but possible, bad code in the kernel or bad I/O software code in a program. There could be many reasons, unfortunately they all lead to corrupted data in a disk that could cause a system not to boot.
The process to fix these issues are fairly simple but does require some command line (CLI) dexterity. To summarize the process boot into rescue mode, if not boot directly into CLI, use the fdisk command to view your hard disk(s) identify and Verify the disk(s), then if applicable proceed to use fsck.
one thing about fdisk, keep in mind that fdisk is an extremely powerful text-based utility for managing and viewing hard disk partitions on Linux. If you don’t know what you are doing with fdisk you could wipeout partitions etc., I recommend some reading prior to using both fdisk and fsck. I personally like to use both to check and manages my drives. As a last resort use fdisk to wipeout the hard disk and re-install from scratch if you feel that fsck did not do the job. If nothing works then you may need new drives.
How to use fsck and fdisk is beyond the point of this article. Like I always say, there’s no need to reinvent the wheel. There are numerous on-line articles that help address hard disk issues. Below I listed a few articles that are excellent sources of information:
- Bad Sectors Explained: Why Hard Drives Get Bad Sectors and What You Can Do About It by Chris Hoffman, How-to Geek
- File System Consistency, Oracle Corp.
- How to Run Chkdsk in Ubuntu by Kristen Waters, Chron
- How to Use ‘fsck’ to Repair File System Errors in Linux by Marin Todorov, TecMint
- How to use fsck to Find and Repair Disk Errors and Bad Sectors, by Edward Angert, linode
- How to Use fdisk in Linux, by Shahriar Shovon, LinuxHint
- 10 fdisk Commands to Manage Linux Disk Partitions by Ravi Saive, TecMint