On Linux, how does one implement automatic file system check and repair?

Source: Internet
Author: User
One of the most important tasks in Linux management is to check the integrity of the file system. Linux file systems may be damaged in various situations, such as system crashes, sudden power outages, disk disconnections, or accidental overwriting of file nodes. Therefore,

One of the most important tasks in Linux management is to check the integrity of the file system. Linux file systems may be damaged in various situations, such as system crashes, sudden power outages, disk disconnections, or accidental overwriting of file nodes. Therefore, it is a good idea to regularly check the integrity of the file system to minimize the risk of damage to the file system. Speaking of checking and repairing Linux file systems, fsck is a practical tool.

In this tutorial, I will introduce how to use the fsck tool to automatically check the file system.

When the system is started, the automatic file system check mechanism is triggered.

If you want the system to automatically trigger fsck as soon as it is started, there are some ways to implement unattended fschk during the startup process, depending on the specific Linux release.

On Debian, Ubuntu, or Linux Mint, edit/etc/default/rcS as follows.

 
  1. ___FCKpd___0nbsp;sudo vi /etc/default/rcS 

# Automatic repair of inconsistent file systems during startup

 
  1. FSCKFIX=yes 

On CentOS, use the following content to edit/etc/sysconfig/autofsck (if it does not exist, create it ).

 
  1. ___FCKpd___2nbsp;sudo vi /etc/sysconfig/autofsck 
  2. AUTOFSCK_DEF_CHECK=yes 

Force regular file system check

If the file system is large, you can forcibly check the file system on a regular basis, instead of checking the file system every time the system starts. To achieve this, you must first use the tune2fs command to find the file system configuration. The following command line shows the current value of parameters related to the file system. Note:/dev/sda1 is the partition where the file system super block is located. BitsCN.com

 
  1. ___FCKpd___3nbsp;sudo tune2fs -l /dev/sda1 

From the output result of tune2fs, we can not only view the file system status (clean or not), but also see some parameters related to file system check. "Maximum mount count" (Maximum number of mounting times) indicates the number of mounting times after the file system check is triggered. "Check interval" (Check interval) indicates the maximum time between two file system checks. In most Linux distributions, these parameters are not set by default, which means no regular file system check is performed.

To forcibly check the file system every 30 times, run the following command.

 
  1. ___FCKpd___4nbsp;sudo tune2fs -c 30 /dev/sda1 

To forcibly check the file system every three months, use the following command.

 
  1. ___FCKpd___5nbsp;sudo tune2fs -i 3m /dev/sda1 

Now confirm that the file system check conditions you just added have been correctly set.

 
  1. ___FCKpd___6nbsp;sudo tune2fs -l /dev/sda1 
  2. . . . 
  3. Last mount time:          n/a 
  4. Last write time:           Fri Mar 14 22:29:24 2014 
  5. Mount count:             20 
  6. Maximum mount count:   30 
  7. Last checked:             Mon Mar  3 20:55:08 2014 
  8. Check interval:           7776000 (3 months) 
  9. Next check after:          Sun Jun  1 21:55:08 2014 

Force one-time file system check during the next system restart

If you want to trigger a one-time file system check during the next system restart, you can use this command.

 
  1. ___FCKpd___7nbsp;sudo touch /forcefsck 

Once you create an empty file named forcefsck in a directory similar to the top-level Directory (/) above, it will force the file system check during your next restart. After the system is started successfully,/forcefsck is automatically cleared.

Link: http://xmodulo.com/2014/03/automatic-filesystem-checks-repair-linux.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.