File System Check in Linux

The file system check commands are fsck and xfs_repair.

File system checks are done by following the below steps :

  • Linux fsck utility is used to verify and repair Linux filesystems like ext2, ext3, ext4, and so on. Depending on when was the last time a file system was verified, the system executes the fsck command at the boot time to monitor if the filesystem is in steady condition.
  • The system administrator can also execute the fsck command manually if there are issues with the filesystems. We should ensure that fsck is not run on a unmounted file to avoid loss of data.
  • Linux xfs_repair utility is used to verify and repair Linux filesystems of xfs type.
  • We should force a filesystem check even though it is clean with the -f option.
  • We should try to fix the detected issue by default with the -y option.
  • The xfs_repair utility is very scalable and is created to fix even very big file systems with multiple inodes. This utility does not execute at boot time.
  • The available exit codes for fsck command are:
    linux-fsckexitcode
  • To check the file system, run the command:
    df -h​
  • To get the information of the file system type, run the command:
    df -T​

linux-filetypes

The /dev/sdb1 file system is mounted on /data.

  • To run the xfs_repair utility on the file system /dev/sdb1 of type xfs , run the command:
    xfs_repair /dev/sdb1​
The xfs_repair utility can only be run on an unmounted file system.
  • To unmount the /dev/sdb1 from /data, run the command as a root user:
    umount /data​
  • To verify that /data has been unmounted, run the command:
    df -T​

linux-filesumount

There is no /dev/sdb1 filesystem mounted on /data available anymore.

  • To mount back /dev/sdb1 to /data, run the command:
    mount /dev/sdb1 /data​
  • To validate that the file system has been mounted, run the command:
    df -h​
    linux-filemount

System Backups in Linux

The types of System Backups are:

  • System Backup - The complete image is backed up with tools like acroins, Veenam, Commvault, and so on.
  • Application Backup - The backup is done with a third-party application backup solution.
  • Database Backup - The backup is done with Oracle data guard, SQL backup, and so on.
  • Filesystem Backup - The backup is done with Oracle tar, gzip directories, and so on.
  • Disk Backup or disk cloning is done with the help of the command dd.
The system backup commands should be run from root.

The dd is a command-line utility for Unix and Unix-like operating systems whose aim is to convert and copy files. For this, it can be utilized for actions like backing up the boot sector of a hard drive and getting a fixed amount of random data.

The source and destination of the disk size should be equal.
  • To back up or clone the complete hard disk to another disk that is in the same system, run the command -

dd if=<source file name> of=<target file name> [Options]. For example,

dd if=/dev/sda of=/dev/sdb​
  • To back up or copy the disk partition, run the command:
    dd if =/dev/sda1 of=/root/sda1.img​
  • To restore the image file sda1.img to another machine after copying the image, run the command:
    dd if=/root/sda1.img of=/dev/sdb3​

Fixing Corrupted File System in Linux

The different types of files and directories that we create constitute a file system. The types of file systems are ext3, ext4, xfs, NTFS, and so on. The file system layout and partitions are /var, /etc, /root, /home.

To check the file system, we use the commands df, fdisk -l.

The troubleshooting steps are as follows :

  • Check the /var/log/messages or /var/log/syslog.
  • Execute the command fsck on the block device and not on the mount point.
  • Unmount file system and then execute fsck.
About Author :

Myself Debomita Bhattacharjee, an IT employee with 6+ years of experience in Software industry. My area of interest is Automation testing and Front End Development.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions