1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Best way to check and fix corrupt disk?

Discussion in 'General' started by bsdme2, Jan 29, 2009.

  1. bsdme2

    bsdme2 New Member

    Messages:
    23
    Likes Received:
    0
    Hi folksss,

    What is the best way to check for corrupt sector and fix it on
    FreeBSD? I check FSCK 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.

    Thanks folks.
     
  2. cajunman4life

    cajunman4life New Member

    Messages:
    119
    Likes Received:
    0
    FSCK should fix those errors. Boot into single user and run just bare "fsck" and wait. Depending on the size of your drive and how you partitioned it, it may take a long time.
     
  3. bsdme2

    bsdme2 New Member

    Messages:
    23
    Likes Received:
    0
    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.
     
  4. SirDice

    SirDice Moderator Staff Member Moderator

    Messages:
    17,392
    Likes Received:
    7
    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.
     
  5. Maxim

    Maxim New Member

    Messages:
    9
    Likes Received:
    0
    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!
     
  6. User23

    User23 Member

    Messages:
    348
    Likes Received:
    1
    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.
     
  7. Maxim

    Maxim New Member

    Messages:
    9
    Likes Received:
    0
    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..
     
  8. Maxim

    Maxim New Member

    Messages:
    9
    Likes Received:
    0
  9. User23

    User23 Member

    Messages:
    348
    Likes Received:
    1
    But the output says "(NO WRITE)" on every filesystem you check. This means fsck will check but wont repair anything.
     
  10. Maxim

    Maxim New Member

    Messages:
    9
    Likes Received:
    0
    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.
     
  11. danbi

    danbi New Member

    Messages:
    227
    Likes Received:
    0
    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"
     
  12. Maxim

    Maxim New Member

    Messages:
    9
    Likes Received:
    0
    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..
     
  13. danbi

    danbi New Member

    Messages:
    227
    Likes Received:
    0
    There is no point to run fsck on a live file system (that is, while multi-user).
    Your file system is ok.