How to Check Filesystem Health on a Linux/Unix Server

I will never forget the college professor who once told me: The question isn’t “Will your hard drive crash?” The question is, “When will it crash?” From my experience as a tech, system administrator, and also desktop computer user, I can attest to the accuracy of that professor’s statement. Hard drives crash. It is inevitable. It make take seven weeks or seven years, but it will eventually happen.

Fortunately, software has come a long way in helping people protect their data and ensure they are ready when disaster strikes. It goes without saying that backing up your data is important, but I will say it anyway. No matter what steps you take in detecting hard drive problems, you still need to have backups.

On a Linux or Unix server, you can run the fsck command to check your file system’s integrity and also make repairs when necessary. Under normal circumstances, you probably have no reason to run this command, and Linux will detect problems at boot and run fsck in the event of a power failure or other abnormal shutdown. If you do need to run it, you will have to unmount the file system you want to check. Follow these steps:

  1. As Root, go to single user mode:
    # init 1
  2. Unmount the partition you want to check:
    # umount /dev/sda1
  3. Run fsck:
    # fsck /dev/sda1
  4. Remount the filesystem:
    # mount -a
  5. Return to multiuser mode (Init 2 or 3)
    # init 2

As you might expect, running fsck will cause server downtime. Furthermore, going to single user mode, as the name implies, will log out other users. Because of all of this, it is a good idea to give users prior notice before you take your server down for maintenance.