Repairing FFS / UFS filesystem on OpenBSD
Repair a corrupted FFS filesystem which prevents OpenBSD from booting.
301 Words, 2 Minutes
06 Mar 2024
Repairing FFS2 filesystem on OpenBSD
OpenBSD uses the FFS2 filesystem, also named UFS2. When the filesystem is corrupted, it's possible to repair it.
Tested on OpenBSD 7.4.
Discovering the problem
In most cases, when the filesystem is corrupted, it's automatically fixed before booting. In some other cases, the system won't be able to boot properly and will start in single user mode. A message similar to the following will be displayed.
THE FOLLOWING FILE SYSTEM HAD AN UNEXPECTED INCONSISTENCY ffs: a19c626adc5e60ef .l (/home) Automatic file system check failed; help! Enter the pathname of the shell or press [Enter] for sh:
Note the value after ffs:, it will help to identify which disk is concerned. Then, press [Enter].
Configuring the keyboard layout
By default, the keyboard is set to en_US / qwerty, it can be changed with the kbd command.
# kbd fr
kbd: keyboard mapping set to fr
Identifying the partition
To identify the partition reported in the error message, it's possible to use disklabel. From the error above we know that the error comes from the partition l (lowercase L) on disk with uid a19c626adc5e60ef, mounted as /​home, we have to find which disk is concerned.
# disklabel sd2
/dev/rsd2c:
[...]
duid: a19c626adc5e60ef
[...]
# size offset fstype [fsize bsize cpg]
[...]
l: xxxxxxxx xxxxxx 4.2BSD 4096 1298 1062 # /home
The partition is sd2l.
Repairing the filesystem
The filesystem can be repaired using the fsck_ffs command.
# fsck_ffs /dev/sd2l
fsck will list the problems and ask if it should try to fix them, one by one. Type y to validate the current one, or F to autocorrect all of them. Be aware that automatic validation could create problems in some situations.