How to fix corrupted filesystems in FreeBSD

Default featured post

I have an installation of FreeBSD on VirtualBox and once in awhile I work with it. Working with FreeBSD indeed is very amazing and it is a world itself. Anyhow, few days ago when I was working with the FreeBSD on VirtualBox on my Ubuntu machine, Unity got crazy and crashed. Therefore, I had to switch to terminal and reboot the system meaning VirtualBox killed unexpectedly.

After reboot, I wanted to continue my work which I’ve found that unfortunately FreeBSD filesystem corrupted due to unexpected shutdown. When the system booted, it was displaying an error message regarding some problems on disk and getting restarted again.

After some googling managed to find solution for the problem, which is described in following:

First of all need to boot into single user mode (option 4) from boot screen.

After that, the terminal shows the below message.

Enter full pathname of shell or RETURN for /bin/sh:

Pressed enter and then try to check the mounted filesystems using mount command.

Usually when you output of the command demonstrates that the root filesystem / is mounted as read-only. Write down the device path (example, /dev/ad0s1a).

Now the next step is to repair the filesystem using fsck. Remember some corrupted files might be removed using fsck which is not a big issue from my point of view, because they are corrupted anyway and cannot be used.

Lastly, run fsck like following:

# fsck -y /dev/ad0s1d

-y parameter allows fsck to do repairing automatically.

Occasionally, it happens that fsck refuse to scan the disk, in that case you can add -f to force scan the disk.