Bookmark this page

Guided Exercise: Recovering from File System Corruption

Verify a file system and repair file system corruption.

Outcomes

You should be able to check and repair an XFS file system.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

[student@workstation ~]$ lab start storage-filesystem

This command creates the necessary file systems and files for this exercise.

Instructions

The /dev/vdb1 partition on servera contains an XFS file system, which holds the contents of the /etc directory from another system. Check the integrity of the XFS file system on /dev/vdb1. Repair any file system inconsistencies and then mount the file system at /mnt/etc_restore. If the file system repair relocates orphaned files to the file system's lost+found directory, then use the backup file, /root/etc.tgz, to determine the original file location and name. Restore the orphaned file to its proper location.

  1. Log in to servera and switch to the root user.

    [student@workstation ~]$ ssh student@servera
    ...output omitted...
    [student@servera ~]$ sudo -i
    [sudo] password for student: student
    [root@servera ~]#
  2. Check for any issues with the /mnt/etc_restore file system.

    1. Attempt to create the /mnt/etc_restore/etc/test file.

      [root@servera ~]# echo hello > /mnt/etc_restore/etc/test

      You can create the file without any issue.

    2. View the contents of the /mnt/etc_restore/etc/test file.

      [root@servera ~]# cat /mnt/etc_restore/etc/test
      hello

      You can view the content of the file without any issue.

    3. List the files in the /mnt/etc_restore/etc/security/console.apps directory.

      [root@servera ~]# ls /mnt/etc_restore/etc/security/console.apps
      ls: reading directory '/mnt/etc_restore/etc/security/console.apps/': Structure needs cleaning

      You get an error message that the structure needs cleaning. Troubleshoot and resolve this issue.

  3. Check the XFS file system on the /dev/vdb1 partition.

    1. Unmount the /dev/vdb1 file system, because a file system check cannot run on a mounted file system.

      [root@servera ~]# umount /mnt/etc_restore
    2. Use the xfs_repair command with the -n option to check the file system with no corrective actions taken.

      [root@servera ~]# xfs_repair -n /dev/vdb1
      Phase 1 - find and verify superblock...
      Phase 2 - using internal log
              - zero log...
              - scan filesystem freespace and inode maps...
              - found root inode chunk
      Phase 3 - for each AG...
              - scan (but don't clear) agi unlinked lists...
              - process known inodes and perform inode discovery...
              - agno = 0
              - agno = 1
      Invalid inode number 0x499602d2
      xfs_dir_ino_validate: XFS_ERROR_REPORT
      Metadata corruption detected at 0x564c8914a8e8, xfs_dir3_block block 0xa7e0/0x1000
      entry "subscription-manager" at block 0 offset 456 in directory inode 144973 references invalid inode 1234567890
      	would clear inode number in entry at offset 456...
              - process newly discovered inodes...
      Phase 4 - check for duplicate blocks...
              - setting up duplicate extent list...
              - check for inodes claiming duplicate blocks...
              - agno = 0
              - agno = 1
      entry "subscription-manager" at block 0 offset 456 in directory inode 144973 references invalid inode 1234567890
      	would clear inode number in entry at offset 456...
      No modify flag set, skipping phase 5
      Phase 6 - check inode connectivity...
              - traversing filesystem ...
      Invalid inode number 0x499602d2
      xfs_dir_ino_validate: XFS_ERROR_REPORT
      Metadata corruption detected at 0x564c8914a8e8, xfs_dir3_block block 0xa7e0/0x1000
      entry "subscription-manager" in directory inode 144973 points to non-existent inode 1234567890, would junk entry
      bad hash table for directory inode 144973 (no data entry): would rebuild
              - traversal finished ...
              - moving disconnected inodes to lost+found ...
      disconnected inode 145282, would move to lost+found
      Phase 7 - verify link counts...
      No modify flag set, skipping filesystem flush and exiting.

      Note the reported errors with information that might be helpful for file system recovery.

  4. Use the xfs_repair utility to repair the file system inconsistencies.

    [root@servera ~]# xfs_repair /dev/vdb1
    Phase 1 - find and verify superblock...
    Phase 2 - using internal log
            - zero log...
            - scan filesystem freespace and inode maps...
            - found root inode chunk
    Phase 3 - for each AG...
            - scan and clear agi unlinked lists...
            - process known inodes and perform inode discovery...
            - agno = 0
            - agno = 1
    Invalid inode number 0x499602d2
    xfs_dir_ino_validate: XFS_ERROR_REPORT
    Metadata corruption detected at 0x56258b0938e8, xfs_dir3_block block 0xa7e0/0x1000
    entry "subscription-manager" at block 0 offset 456 in directory inode 144973 references invalid inode 1234567890
    	clearing inode number in entry at offset 456...
    entry at block 0 offset 456 in directory inode 144973 has illegal name "/ubscription-manager":         - process newly discovered inodes...
    Phase 4 - check for duplicate blocks...
            - setting up duplicate extent list...
            - check for inodes claiming duplicate blocks...
            - agno = 0
            - agno = 1
    Phase 5 - rebuild AG headers and trees...
            - reset superblock...
    Phase 6 - check inode connectivity...
            - resetting contents of realtime bitmap and summary inodes
            - traversing filesystem ...
    bad hash table for directory inode 144973 (no data entry): rebuilding
    rebuilding directory inode 144973
            - traversal finished ...
            - moving disconnected inodes to lost+found ...
    disconnected inode 145282, moving to lost+found
    Phase 7 - verify and correct link counts...
    done
  5. Mount the repaired file system at /mnt/etc_restore to analyze the file system repair results.

    [root@servera ~]# mount /dev/vdb1 /mnt/etc_restore
  6. Determine whether the file system's lost+found directory has orphaned files.

    [root@servera ~]# ls -la /mnt/etc_restore/lost+found
    total 4
    drwxr-xr-x. 2 root root 19 Jan 19 23:07 .
    drwxr-xr-x. 4 root root 33 Jan 19 22:59 ..
    -rw-r--r--. 1 root root 62 Oct 13 11:00 145282
  7. Determine the correct name and location of the orphaned file in lost+found with the output that was generated during the file system repair.

    1. Based on the generated output, subscription-manager should be the name of the orphaned file.

      ...output omitted...
      Invalid inode number 0x499602d2
      xfs_dir_ino_validate: XFS_ERROR_REPORT
      Metadata corruption detected at block 0x258e0/0x1000
      entry "subscription-manager" at block 0 offset 456 in directory inode 144973 references invalid inode 1234567890
              clearing inode number in entry at offset 456...
      entry at block 0 offset 456 in directory inode 144973 has illegal name "/ubscription-manager":         - process newly discovered i
      nodes...
      ...output omitted...
    2. Based on the generated output, determine the directory name for the subscription-manager file. Use the find command to locate the directory with inode number 144973.

      ...output omitted...
      Invalid inode number 0x499602d2
      xfs_dir_ino_validate: XFS_ERROR_REPORT
      Metadata corruption detected at block 0x258e0/0x1000
      entry "subscription-manager" at block 0 offset 456 in directory inode 144973 references invalid inode 1234567890
              clearing inode number in entry at offset 456...
      entry at block 0 offset 456 in directory inode 144973 has illegal name "/ubscription-manager":         - process newly discovered i
      nodes...
      ...output omitted...
      [root@servera ~]# find /mnt/etc_restore -inum 144973
      /mnt/etc_restore/etc/security/console.apps
  8. Use the file system's content backup at /root/etc.tgz to verify the orphaned file's name and location.

    1. Extract the backup file to view its contents for comparison.

      [root@servera ~]# tar -C /tmp -xzf /root/etc.tgz
    2. Verify the contents of the orphaned file against the backup copy of the identified file.

      [root@servera ~]# cd /tmp/etc/security/console.apps
      [root@servera console.apps]# diff -s subscription-manager /mnt/etc_restore/lost+found/145282
      Files subscription-manager and /mnt/etc_restore/lost+found/145282 are identical
  9. When verified, move the orphaned file to its proper location on the /dev/vdb1 partition. Ensure that you move the file to the file system that is mounted on the /mnt/etc_restore directory.

    [root@servera console.apps]# cd /mnt/etc_restore/etc/security/console.apps
    [root@servera console.apps]# mv /mnt/etc_restore/lost+found/145282 subscription-manager
    mv: overwrite 'subscription-manager'? y
  10. Verify that you are able to view the contents of the /mnt/etc_restore/etc/security/console.apps directory.

    [root@servera console.apps]# ls /mnt/etc_restore/etc/security/console.apps
    config-util  ovirt-hibernate  ovirt-locksession  ovirt-shutdown  rhn_register  setup  subscription-manager
  11. Return to workstation as the student user.

    [root@servera console.apps]# exit
    [student@servera ~]$ exit
    [student@workstation ~]$

Finish

On the workstation machine, use the lab command to complete this exercise. This is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish storage-filesystem

Revision: rh342-8.4-6dd89bd