{"id":2083,"date":"2015-04-04T15:59:42","date_gmt":"2015-04-04T15:59:42","guid":{"rendered":"https:\/\/qbytes.cloud\/?p=2083"},"modified":"2015-04-04T15:59:42","modified_gmt":"2015-04-04T15:59:42","slug":"how-to-set-up-automatic-filesystem-checks-and-repair-on-linux","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2015\/04\/04\/how-to-set-up-automatic-filesystem-checks-and-repair-on-linux\/","title":{"rendered":"filesystem checks and settings on CentOS"},"content":{"rendered":"<p>Normally on CentOS the file system check is in the fstab file.<\/p>\n<p>If all you want to do is avoid an fsck, adding the -f option to shutdown should help with that. <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n&#x5B;bash]\n\n# shutdown -f\n\n<\/pre>\n<p>[\/bash]<\/p>\n<p>The other option is you can manually make it skip fsck checks at boot by updating the 6th field in your \/etc\/fstab:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n# \/dev\/sda2  \/  ext3  defaults,errors=remount-ro 0       1\n\n<\/pre>\n<p>This is the similar to what most fstabs will have 1 means that it should be checked and is a root file system, 2 means it should be checked but will be done in parallel with other file systems and 0 means skip checking<\/p>\n<p>Other ways to configure and check the settings:<\/p>\n<p>On CentOS, edit \/etc\/sysconfig\/autofsck (or create it if it doesn&#8217;t exist) with the following content.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n# sudo vi \/etc\/sysconfig\/autofsck\nAUTOFSCK_DEF_CHECK=yes\n\n<\/pre>\n<p>If the filesystem is large, you can force filesystem checks on a regular basis, instead of every boot time. In order to do so, first find out the filesystem configuration with tune2fs command. The following command line shows the current values of filesystem related parameters. Note that \/dev\/sda1 is the partition where the filesystem superblock is located.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n# sudo tune2fs -l \/dev\/sda1 \n\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nDisk identifier: 0x00000000\n\n&#x5B;root@cloud1 log]# tune2fs -l \/dev\/sda1\ntune2fs 1.41.12 (17-May-2010)\nFilesystem volume name:   &lt;none&gt;\nLast mounted on:          \/boot\nFilesystem UUID:          3f3d720d-781c-402f-8599-94a97f7a824f\nFilesystem magic number:  0xEF53\nFilesystem revision #:    1 (dynamic)\nFilesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize\nFilesystem flags:         signed_directory_hash\nDefault mount options:    user_xattr acl\nFilesystem state:         clean\nErrors behavior:          Continue\nFilesystem OS type:       Linux\nInode count:              128016\nBlock count:              512000\nReserved block count:     25600\nFree blocks:              394486\nFree inodes:              127963\nFirst block:              1\nBlock size:               1024\nFragment size:            1024\nReserved GDT blocks:      256\nBlocks per group:         8192\nFragments per group:      8192\nInodes per group:         2032\nInode blocks per group:   254\nFlex block group size:    16\nFilesystem created:       Fri Jan 23 19:06:50 2015\nLast mount time:          Sun Mar 29 12:10:18 2015\nLast write time:          Sun Mar 29 12:10:18 2015\nMount count:              8\nMaximum mount count:      -1\nLast checked:             Fri Jan 23 19:06:50 2015\nCheck interval:           0 (&lt;none&gt;)\nLifetime writes:          108 MB\nReserved blocks uid:      0 (user root)\nReserved blocks gid:      0 (group root)\nFirst inode:              11\nInode size:               128\nJournal inode:            8\nDefault directory hash:   half_md4\nDirectory Hash Seed:      ea055f98-4239-40e2-a8a7-0dae21287819\nJournal backup:           inode blocks\n\n<\/pre>\n<p>From tune2fs output, you can see not only the filesystem state (clean or not), but also parameters that are related to filesystem checks. &#8220;Maximum mount count&#8221; parameter is the number of mounts after which the filesystem check gets triggered. &#8220;Check interval&#8221; parameter shows the maximum time between two filesystem checks. On most Linux distros, these parameters are not set by default, meaning no regular filesystem checks are occurring.<\/p>\n<p>To force filesystem check for every 30 mounts, run the following command.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n# sudo tune2fs -c 30 \/dev\/sda1\n\n<\/pre>\n<p>To force filesystem check for every 3 months, use the command below.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n# sudo tune2fs -i 3m \/dev\/sda1\n\n<\/pre>\n<p>Now verify that newly added filesystem check conditions are set properly.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n#sudo tune2fs -l \/dev\/sda1\n\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n. . .\nLast mount time:          n\/a\nLast write time:          Fri Mar 14 22:29:24 2014\nMount count:              20\nMaximum mount count:      30\nLast checked:             Mon Mar  3 20:55:08 2014\nCheck interval:           7776000 (3 months)\nNext check after:         Sun Jun  1 21:55:08 2014\n\nForce One-Time Filesystem Check on the Next Reboot\n\n<\/pre>\n<p>If you want to trigger one-time filesystem check on your next reboot, you can use this command.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n# sudo touch \/forcefsck\n\n<\/pre>\n<p>Once you create an empty file named forcefsck in the top directory (\/) like above, it will force filesystem check the next time you boot up. After successful booting, \/forcefsck will automatically be removed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Normally on CentOS the file system check is in the fstab file. If all you want to do is avoid an fsck, adding the -f option to shutdown should help with that. &#x5B;bash] # shutdown -f [\/bash] The other option is you can manually make it skip fsck checks at boot by updating the 6th &#8230; <a title=\"filesystem checks and settings on CentOS\" class=\"read-more\" href=\"https:\/\/www.qbytes.cloud\/index.php\/2015\/04\/04\/how-to-set-up-automatic-filesystem-checks-and-repair-on-linux\/\" aria-label=\"Read more about filesystem checks and settings on CentOS\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-2083","post","type-post","status-publish","format-standard","hentry","category-administration"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/2083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=2083"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/2083\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=2083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=2083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=2083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}