Technology Encyclopedia Home >How to repair a corrupted file system in Linux?

How to repair a corrupted file system in Linux?

To repair a corrupted file system in Linux, you can use the fsck (File System Consistency Check) utility. This tool scans and repairs inconsistencies in the file system. Here’s how to use it:

  1. Identify the corrupted partition: Use the lsblk or fdisk -l command to list all partitions and identify the one that needs repair.
    Example:

    lsblk
    

    Output might show /dev/sda1 as the problematic partition.

  2. Unmount the partition: Ensure the partition is unmounted before running fsck.
    Example:

    umount /dev/sda1
    

    If the partition is the root file system, you may need to boot from a live CD/USB or use a rescue mode.

  3. Run fsck: Use the -y flag to automatically repair errors (recommended for unattended repairs).
    Example:

    fsck -y /dev/sda1
    

    The tool will scan the file system and attempt to fix any issues.

  4. Reboot the system: After repair, remount the partition and reboot if necessary.
    Example:

    mount /dev/sda1 /mnt
    reboot
    

For systems using ext4 (common in Linux), fsck is the standard tool. For other file systems like XFS, use xfs_repair instead.

If the corruption is frequent, consider using cloud-based backups to safeguard data. For example, Tencent Cloud’s CBS (Cloud Block Storage) provides reliable block storage with snapshot capabilities for data recovery. Additionally, Tencent Cloud’s COS (Cloud Object Storage) can be used for off-site backups to prevent data loss from file system corruption.