Best way to check and fix corrupt disk?

Hi folks,

What is the best way to check for corrupt sector and fix it on FreeBSD? I check fsck(8) to see if there is any option but I can not find one ... maybe I'm wrong. You know like Windows have scandisk with fix option. My little baby press the reset button on the computer a couple of time and now the system found an "incorrect block count I=32 ..."

I would like to know if there are any other way to check and fix this beside fsck(8).

Thanks folks.
 
cajunman4life ... you are everywhere huh :)

anyway I just google on how to fix corrupt sector in FreeBSD and I got this in more detail. I just want to share with all the newbie or anyone how need this info.

Boot into Single-user mode
Reboot your machine:
# reboot
When you see the initial boot menu, select "Boot FreeBSD in single user mode" (option 4). The kernel will boot up as
usual, but instead of starting all the system processes, only a single root shell will be provided. Hit Enter when you see
this message:
Enter full pathname of shell or RETURN for /bin/sh:
Now check what filesystems are mounted:
# mount
/dev/ad0s1a on / (ufs, local, read-only)
devfs on /dev (devfs, local)
You should see that only "/" (the root filesystem) and the devices under /dev are mounted, and furthermore the root
filesystem is mounted read-only. There are also no virtual consoles and no daemons running. This is the simplest and
safest possible state for the system to be in.
Filesystem repairs
Since the filesystems are not mounted, you can run the filesystem repair tool "fsck" on them (fsck = File System Check).
Its job is to make corrupted filesystems functional again. If individual files have been damaged then they may not be
recoverable, but at least the filesystem will be working again and the other files on it can be accessed.
Firstly, have a look at which partitions are normally mounted; this information is kept in the fie "/etc/fstab"
# cat /etc/fstab
Pick one of these partitions, and run fsck on it. For example, if you decide to check the partition /dev/ad0s1d, then you
would type
# fsck -y /dev/ad0s1d
(The -y flag gives fsck permission to carry out any repairs it suggests). If your filesystem is "clean", that is, it was
unmounted properly at system shutdown, fsck may not do anything. In that case almost certainly it’s not needed, but you
can force it to check the filesystem like this:
# fsck -f -y /dev/ad0s1d
There’s no need to run fsck in single-user mode like this unless during bootup FreeBSD tells you that there’s a filesystem
error which it can’t handle. Make a note of which partition is at fault, reboot into single user mode, and run fsck on that partition only.
 
Filesystem errors are fixed by using fsck. A real bad sector however isn't. If you have an IDE or S-ATA disk and it's showing bad sectors replace the disk as soon as possible.
 
After a unsafe shutdown causes by bad electricity stuff, I get a lot of output similar to this in phase 4 of checking:
Code:
UNREF FILE  I=47379  OWNER=nagios MODE=100666
SIZE=1626 MTIME=Sep 15 17:24 2010
RECONNECT? no

And in phase 5:
Code:
** Phase 5 - Check Cyl groups
FREE BLK COUNT(S) WRONG IN SUPERBLK
SALVAGE? no

SUMMARY INFORMATION BAD
SALVAGE? no

BLK(S) MISSING IN BIT MAPS
SALVAGE? no

I rebooted in single-user mode and have done everything suggested above, then reboot into multiuser mode and run fsck again without parameters and get this messages again. Is there any way to fix this?

Thanks in advance!
 
Seems like you didnt make a fsck -y on every filesystem.

If you are in single user mode and you want to check and fix every filesystem

Code:
fsck -y

should just work.

If not, and every time the errors are changing, then your harddisk might dying soon.
 
I definitely used the "-y" option and yes, the errors are changing; I also thought that hdd is dying, but when I checked it with MHDD it identified "no errors".. So I'm puzzled now..
 
But the output says "(NO WRITE)" on every filesystem you check. This means fsck will check but wont repair anything.
 
It's when I run just "fsck" in multi-user mode, after I supposedly fixed the errors in single-user mode with instructions provided by bsdme2 above.
 
Just reboot in single user mode and run

# fsck -y

Repeat it, until it does not find any errors.

Running fsck on mounted filesystems can result in many 'errors' that are reflection of the fact that the filesystem is not static at that time.

Usually, FreeBSD will run fsck in background on all but the root filesystems 60 seconds after going multiuser, unless you disable this with the following in /etc/rc.conf.

Code:
background_fsck="NO"
 
In single-user mode "fsck -y" doesn't find any errors, they appear when I run "fsck" in multi-user mode.. Something strange is going on..
 
I had a very similar problem after an unexpected power loss to my laptop. Booting into single user mode, running fsck -f -y /dev/ada1p1 quickly took care of the problem.
 
Last edited by a moderator:
FritvetBE, this thread is 5 years old. I'm sure you mean well but please look at the dates before responding.
 
Back
Top