System Administration Guide: Devices and File Systems

Interactively Checking and Repairing a UFS File System

You might need to interactively check file systems in the following instances:

When an in-use file system develops inconsistencies, error messages might be displayed in the console window, the system messages file, or the system might crash. For example, the system messages file, /var/adm/messages, might include messages similar to the following:


Sep  5 13:42:40 hostname ufs: [ID 879645 kern.notice] NOTICE: /: unexpected
free inode 630916, run fsck(1M)

hostname is the system reporting the error.

Before using the fsck command, you might want to refer to Syntax and Options for the fsck Command and Chapter 32, Resolving UFS File System Inconsistencies (Tasks), in System Administration Guide: Advanced Administration for information on resolving fsck error messages.

Keep the following points in mind when running the fsck command to check UFS file systems:

ProcedureHow to Check the root (/) or /usr File Systems From an Alternate Boot Device

This procedure assumes that a local CD or network boot server is available so that you can boot the system from an alternate device.

For information on restoring a bad superblock, see How to Restore a Bad Superblock.

Steps
  1. Become superuser or assume an equivalent role.

  2. For systems with mirrored root (/) file systems only: Detach the root (/) mirror before booting from the alternate device or you risk corrupting the file system.

    For information on detaching the root (/) mirror, see Working With Submirrors in Solaris Volume Manager Administration Guide.

  3. Identify the device, such as /dev/dsk/c0t0d0s0, of the root (/) or /usr file system that needs to be checked.

    You'll need to supply this device name when booted from an alternate device. It will more difficult to identify this device when you are already booted from the alternate device.

  4. Boot the system with the root (/) or /usr file system that needs to be checked from an alternate device, such as a local CD or the network, in single-user mode to ensure that there is no activity on these file systems.

    For example:


    # init 0
    ok boot net -s
    .
    .
    .
    #
  5. Check the device that contains the root (/) or /usr file system as identified in step #3.

    If the hardware for the file system to be checked or repaired has changed, the device names might have changed. Be sure to check that the fsck -n message Last Mounted on ... indicates the expected device for the file system.

    For example, the root file system to be checked is /dev/dsk/c0t0d0s0.


    # fsck -n /dev/rdsk/c0t0d0s0
    ** /dev/rdsk/c0t0d0s0 (NO WRITE)
    ** Last Mounted on /
    .
    .
    .
    fsck /dev/rdsk/c0t0d0s0
    ** /dev/rdsk/c0t0d0s0
    ** Last Mounted on /
    ** Phase 1 - Check Blocks and Sizes
    ** Phase 2 - Check Pathnames
    .
    .
    .
  6. Correct any reported fsck errors.

    For information about how to respond to the error message prompts while interactively checking one or more UFS file systems, see Chapter 32, Resolving UFS File System Inconsistencies (Tasks), in System Administration Guide: Advanced Administration.

  7. If necessary, run the fsck command again if you see messages similar to the following, FILE SYSTEM STATE NOT SET TO OKAY or FILE SYSTEM MODIFIED.

    The fsck command might be unable to fix all errors in one execution.

    If fsck cannot repair all of the problems after running it several times, see Fixing a UFS File System That the fsck Command Cannot Repair.

  8. Mount the repaired file system to see if there are any files in the lost+found directory.

    Individual files put in the lost+found directory by the fsck command are renamed with their inode numbers. If possible, rename the files and move them where they belong. You might be able to use the grep command to match phrases within individual files and the file command to identify file types.

    Eventually, remove unidentifiable files or directories left in the lost+found directory so it doesn't fill it up unnecessarily.

  9. Bring the system back to multi-user mode.


    # init 6
    

    If you press Control-D when booted in single-user mode from an alternate device, the system will start the Solaris installation process.

  10. For systems with mirrored root (/) file systems only: Reattach the root (/) mirror.

ProcedureHow to Check Non-root (/) or Non-/usr File Systems

This procedure assumes that the file system to be checked is unmounted.

For information on restoring a bad superblock, see How to Restore a Bad Superblock.

Steps
  1. Become superuser or assume an equivalent role.

  2. Unmount the local file system first to ensure that there is no activity on the file system.

    Specify the mount point directory or /dev/dsk/device-name as arguments to the fsck command. Any inconsistency messages are displayed.

    For example:


    # umount /export/home
    # fsck /dev/rdsk/c0t0d0s7
    ** /dev/dsk/c0t0d0s7
    ** Last Mounted on /export/home
    .
    .
    .
  3. Correct any reported fsck errors.

    For information about how to respond to the error message prompts while interactively checking one or more UFS file systems, see Chapter 32, Resolving UFS File System Inconsistencies (Tasks), in System Administration Guide: Advanced Administration.

  4. If necessary, run the fsck command again if you see the following messages, FILE SYSTEM STATE NOT SET TO OKAY or FILE SYSTEM MODIFIED.

    The fsck command might be unable to fix all errors in one execution.

    If fsck cannot repair all of the problems after running it several times, see Fixing a UFS File System That the fsck Command Cannot Repair.

  5. Mount the repaired file system to see if there are any files in the lost+found directory.

    Individual files put in the lost+found directory by the fsck command are renamed with their inode numbers. If possible, rename the files and move them where they belong. You might be able to use the grep command to match phrases within individual files and the file command to identify file types.

    Eventually, remove unidentifiable files or directories left in the lost+found directory so it doesn't fill it up unnecessarily.

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


Example 20–1 Checking Non-root (/) or Non-/usr File Systems Interactively

The following example shows how to check the /dev/rdsk/c0t0d0s6 file system and corrects the incorrect block count. This example assumes that the file system is unmounted.


# fsck /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 fsck -o p command (p is for preen) checks UFS file systems and automatically fixes the problems that normally result from an unexpected system shutdown. This command exits immediately if it encounters a problem that requires operator intervention. This command also permits parallel checking of file systems.

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

ProcedureHow to Preen a UFS File System

This procedure assumes that the file system is unmounted or inactive.

Steps
  1. Become superuser or assume an equivalent role.

  2. Unmount the UFS file system.


    # umount /mount-point
    
  3. Check the 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 the fsck command.


Example 20–2 Preening a UFS File System

The following example shows how to preen the /export/home file system.


# fsck -o p /export/home

Fixing a UFS File System That the fsck Command Cannot Repair

The fsck command operates in several passes, and a problem corrected in a later pass can expose other problems that are only detected by earlier passes. Therefore, it is sometimes necessary to run fsck repeatedly until it no longer reports any problems, to ensure that all errors have been found and repaired. The fsck command does not keep running until it comes up clean, so you must rerun it manually.

Pay attention to the information displayed by the fsck command. This information might help you fix the problem. For example, the messages might point to a damaged directory. If you delete the directory, you might find that the fsck command runs cleanly.

If the fsck command still cannot repair the file system, you can try to use the ff, clri, and ncheck commands to figure out and fix what is wrong. For information about how to use these commands, see fsdb(1M), ff(1M), clri(1M), and ncheck(1M). You might, ultimately, need to re-create the file system and restore its contents from backup media.

For information about restoring complete file systems, see Chapter 25, Restoring Files and File Systems (Tasks).

If you cannot fully repair a file system but you can mount it read-only, try using the cp, tar, or cpio commands to retrieve all or part of the data from the file system.

If hardware disk errors are causing the problem, you might need to reformat and divide the disk into slices again before re-creating and restoring file systems. Check that the device cables and connectors are functional before replacing the disk device. Hardware errors usually display the same error again and again across different commands. The format command tries to work around bad blocks on the disk. If the disk is too severely damaged, however, the problems might persist, even after reformatting. For information about using the format command, see format(1M). For information about installing a new disk, see Chapter 12, SPARC: Adding a Disk (Tasks) or Chapter 13, x86: Adding a Disk (Tasks).