Manually run the file system checker and repair tool

Author: AndreasKuehl andreas dot kuehl at clicktivities dot net FreeBSD

Reviewer: name contact BSD flavour

Reviewer: name contact BSD flavour


Concept

Be aware of the utilities available to check the consistency of a file system and to use them under supervision.

Introduction

Under certain circumstances, the ffs/BSD file system can get corrupt or broken. It may be better to say: The metainformation is corrupt/damaged. As a result of this, places where data live could not be found or space is marked empty but old data is overwriten, when new data is writen to the filesystem.

To prevent this, a file system is marked as unclean by certain mechanism in the operating system and can not be mounted. During the booting process, unclean filesystems are checked to rebuild the metainformation. Newer FreeBSDs (What about the other BSDs?) can mount a file system and do a check in the background after the booting process.

Sometimes, the automatic check breaks and the system stops in the booting process. (Why?)(What is single user mode?) Sometimes it is necessary to check a filesystem as you attach a foreign disk by firewire or usb os scsi or something else.

The command for this operation is fsck. You can name the filesystem you want to check by the devicename i.e. /dev/ad0s3h or, if the filessystem is in the /etc/fstab by the mountpoint.

During the check, fsck will ask you questions about what to do with data, that was found in the filesystem without beeing accounted in the metainformation. It is save to answer with "y". (Really?) Recovered data will appear in a directory called lost+found at the base of the filesystem. This could be examined to find lost data. Most times, and with Soft updats switched on, almost always, you will find (parts of) already deleted files. (Really?)

Examples

fsck /dev/ad0s1a

will check first ide disk, partition 1, slice 1

fsck /usr

will check the filesystem, that is normally mounted at /usr

Practice Exercises

More information

fsck(8)