# Best way to check and fix corrupt disk?



## bsdme2 (Jan 29, 2009)

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 (Jan 29, 2009)

fsck(8) should fix those errors. Boot into single user and run just bare fsck(8) and wait. Depending on the size of your drive and how you partitioned it, it may take a long time.


----------



## bsdme2 (Jan 29, 2009)

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.


----------



## SirDice (Jan 29, 2009)

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.


----------



## Maxim (Sep 15, 2010)

After a unsafe shutdown causes by bad electricity stuff, I get a lot of output similar to this in phase 4 of checking:

```
UNREF FILE  I=47379  OWNER=nagios MODE=100666
SIZE=1626 MTIME=Sep 15 17:24 2010
RECONNECT? no
```

And in phase 5:

```
** 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!


----------



## User23 (Sep 15, 2010)

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


```
fsck -y
```

should just work.

If not, and every time the errors are changing, then your harddisk might dying soon.


----------



## Maxim (Sep 16, 2010)

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..


----------



## Maxim (Sep 16, 2010)

Here is fsck before a ran into single-user mode: http://www.mediafire.com/?tyr1e5cy1darsh1
This one is after: http://www.mediafire.com/?clj7783jur07i1m


----------



## User23 (Sep 16, 2010)

But the output says "(NO WRITE)" on every filesystem you check. This means fsck will check but wont repair anything.


----------



## Maxim (Sep 16, 2010)

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.


----------



## danbi (Sep 16, 2010)

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.


```
background_fsck="NO"
```


----------



## Maxim (Sep 16, 2010)

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..


----------



## danbi (Sep 16, 2010)

There is no point to run fsck on a live file system (that is, while multi-user).
Your file system is ok.


----------



## FritvetBE (Nov 15, 2015)

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.


----------



## SirDice (Nov 17, 2015)

FritvetBE, this thread is 5 years old. I'm sure you mean well but please look at the dates before responding.


----------

