System Administration Guide, Volume I

Interactively Checking and Repairing a UFS File System

You may need to interactively check file systems:

When an in-use file system develops inconsistencies, error messages may be displayed in the console window or the system may crash.

Before using fsck, you may want to refer to "Syntax and Options for the fsck Command" and "Troubleshooting File System Problems" in System Administration Guide, Volume II for more information.

How to See If a File System Needs Checking

  1. Become superuser.

  2. Check the file system.


    # fsck -m /dev/rdsk/device-name
    

    In this command, the state flag in the superblock of the file system you specify is checked to see whether the file system is clean or requires checking.

    If you omit the device argument, all the UFS file systems listed in /etc/vfstab with a fsck pass value greater than 0 are checked.

Example--Seeing If a File System Needs Checking

The following example shows that the file system needs checking.


# fsck -m /dev/rdsk/c0t0d0s6
** /dev/rdsk/c0t0d0s6
ufs fsck: sanity check: /dev/rdsk/c0t0d0s6 needs checking

How to Check File Systems Interactively

  1. Become superuser.

  2. Unmount the local file systems except root (/) and /usr.


    # umountall -l
    
  3. Check the file system.


    # fsck
    

    All file systems in the /etc/vfstab file with entries in the fsck pass field greater than zero are checked. You can also specify the mount point directory or /dev/rdsk/device-name as arguments to fsck. Any inconsistency messages are displayed. See "Troubleshooting File System Problems" in System Administration Guide, Volume II for information about how to respond to the error message prompts to interactively check one or more UFS file systems.

  4. If you corrected any errors, type fsck and press Return.

    fsck may not be able to fix all errors in one execution. If you see the message FILE SYSTEM STATE NOT SET TO OKAY, run the command again. If that does not work, see "How to Fix a UFS File System fsck Cannot Repair".

  5. Rename and move any files put in the lost+found directory.

    Individual files put in the lost+found directory by fsck are renamed with their inode numbers. If possible, rename the files and move them where they belong. You may be able to use the grep command to match phrases with individual files and the file command to identify file types. When whole directories are dumped into lost+found, it is easier to figure out where they belong and move them back.

Example--Checking File Systems Interactively

The following example checks /dev/rdsk/c0t0d0s6 and corrects the incorrect block count.


# fsck /dev/rdsk/c0t0d0s6
checkfilesys: /dev/rdsk/c0t0d0s6
** Phase 1 - Check Block and Sizes
INCORRECT BLOCK COUNT I=2529 (6 should be 2)
CORRECT? y
 
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
** Phase 5 - Cylinder Groups
929 files, 8928 used, 2851 free (75 frags, 347 blocks, 0.6%
fragmentation)
/dev/rdsk/c0t0d0s6 FILE SYSTEM STATE SET TO OKAY
 
***** FILE SYSTEM WAS MODIFIED *****

Preening UFS File Systems

The preen option to fsck (fsck -o p) checks UFS file systems and automatically fixes the simple problems that normally result from an unexpected system halt. It exits immediately if it encounters a problem that requires operator intervention. The preen option also permits parallel checking of file systems.

You can run fsck with the -o p option to preen the file systems after an unclean halt. In this mode, fsck does not look at the clean flag and does a full check. These actions are a subset of the actions that fsck takes when it runs interactively.

How to Preen a File System

  1. Become superuser.

  2. Unmount the file system.


    # umount mount-point
    
  3. Check a UFS file system with the preen option.


    # fsck -o p /dev/rdsk/device-name
    

    You can preen individual file systems by using mount-point or /dev/rdsk/device-name as arguments to fsck.

Example--Preening a File System

The following example preens the /usr file system.


# fsck -o p /usr