{"id":12127,"date":"2019-03-22T11:20:21","date_gmt":"2019-03-22T11:20:21","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12127"},"modified":"2019-03-22T11:20:21","modified_gmt":"2019-03-22T11:20:21","slug":"how-to-use-fsck-to-repair-file-system-errors-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/22\/how-to-use-fsck-to-repair-file-system-errors-in-linux\/","title":{"rendered":"How to Use \u2018fsck\u2019 to Repair File System Errors in Linux"},"content":{"rendered":"<p>Filesystems are responsible for organizing how data is stored and recovered. One way or another, with time, filesystem may become corrupted and certain parts of it may not be accessible. If your filesystem develops such inconsistency it is recommend to verify its integrity.<\/p>\n<p>This can be completed via system utility called\u00a0<strong>fsck<\/strong>\u00a0(<strong>file system consistency check<\/strong>). This check can be done automatically during boot time or ran manually.<\/p>\n<p>In this article, we are going to review the fsck utility and its usage to help you repair disk errors.<\/p>\n<h4>When to Use fsck in Linux<\/h4>\n<p>There are different scenarios when you will want to run fsck. Here are few examples:<\/p>\n<ul>\n<li>The system fails to boot.<\/li>\n<li>Files on the system become corrupt (often you may see input\/output error).<\/li>\n<li>Attached drive (including flash drives\/SD cards) is not working as expected.<\/li>\n<\/ul>\n<h4>fsck Available options<\/h4>\n<p>Fsck command needs to be run with superuser privileges or\u00a0<strong>root<\/strong>. You can use it with different arguments. Their usage depend on your specific case. Below you will see some of the more important options:<\/p>\n<ul>\n<li>\n<ul>\n<li><code>-A<\/code>\u00a0\u2013 Used for checking all filesystems. The list is taken from\u00a0<code>\/etc\/fstab<\/code>.<\/li>\n<li><code>-C<\/code>\u00a0\u2013 Show progress bar.<\/li>\n<li><code>-l<\/code>\u00a0\u2013 Locks the device to guarantee no other program will try to use the partition during the check.<\/li>\n<li><code>-M<\/code>\u00a0\u2013 Do not check mounted filesystems.<\/li>\n<li><code>-N<\/code>\u00a0\u2013 Only show what would be done \u2013 no actual changes are made.<\/li>\n<li><code>-P<\/code>\u00a0\u2013 If you want to check filesystems in parallel, including root.<\/li>\n<li><code>-R<\/code>\u00a0\u2013 Do not check root filesystem. This is useful only with \u2018<code>-A<\/code>\u2018.<\/li>\n<li><code>-r<\/code>\u00a0\u2013 Provide statistics for each device that is being checked.<\/li>\n<li><code>-T<\/code>\u00a0\u2013 Does not show the title.<\/li>\n<li><code>-t<\/code>\u00a0\u2013 Exclusively specify the filesystem types to be checked. Types can be comma separated list.<\/li>\n<li><code>-V<\/code>\u00a0\u2013 Provide description what is being done.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>How to Run fsck to Repair Linux File System Errors<\/h3>\n<p>In order to run\u00a0<strong>fsck<\/strong>, you will need to ensure that the partition you are going to check is not mounted. For the purpose of this article, I will use my second drive\u00a0<code>\/dev\/sdb<\/code>\u00a0mounted in\u00a0<code>\/mnt<\/code>.<\/p>\n<p>Here is what happens if I try to run\u00a0<strong>fsck<\/strong>\u00a0when the partition is mounted.<\/p>\n<pre># fsck \/dev\/sdb\r\n<\/pre>\n<div id=\"attachment_30684\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Run-fsck-on-Mounted-Partition.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30684\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Run-fsck-on-Mounted-Partition.png\" alt=\"Run fsck on Mounted Partition\" width=\"730\" height=\"172\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Run fsck on Mounted Partition<\/p>\n<\/div>\n<p>To avoid this unmount the partition using.<\/p>\n<pre># umount \/dev\/sdb\r\n<\/pre>\n<p>Then\u00a0<strong>fsck<\/strong>\u00a0can be safely ran with.<\/p>\n<pre># fsck \/dev\/sdb\r\n<\/pre>\n<div id=\"attachment_30685\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Run-fsck-on-Linux-Partition.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30685\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Run-fsck-on-Linux-Partition.png\" alt=\"Run fsck on Linux Partition\" width=\"728\" height=\"186\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Run fsck on Linux Partition<\/p>\n<\/div>\n<h4>Understanding fsck exit codes<\/h4>\n<p>After running\u00a0<strong>fsck<\/strong>, it will return an exit code. These cods can be seen in fsck\u2019s manual by running:<\/p>\n<pre><strong># man fsck<\/strong>\r\n\r\n0      No errors\r\n1      Filesystem errors corrected\r\n2      System should be rebooted\r\n4      Filesystem errors left uncorrected\r\n8      Operational error\r\n16     Usage or syntax error\r\n32     Checking canceled by user request\r\n128    Shared-library error            \r\n<\/pre>\n<h4>Repair Linux Filesystem Errors<\/h4>\n<p>Sometimes more than one error can be found on a filesystem. In such cases you may want\u00a0<strong>fsck<\/strong>\u00a0to automatically attempt to correct the errors. This can be done with:<\/p>\n<pre># fsck -y \/dev\/sdb\r\n<\/pre>\n<p>The\u00a0<code>-y<\/code>\u00a0flag, automatically\u00a0<code>\u201cyes\u201d<\/code>\u00a0to any prompts from fsck to correct an error.<\/p>\n<p>Similarly, you can ran the same on all filesystems (without\u00a0<strong>root<\/strong>):<\/p>\n<pre>$ fsck -AR -y \r\n<\/pre>\n<h3>How to Run fsck on Linux Root Partition<\/h3>\n<p>In some cases, you may need to run\u00a0<strong>fsck<\/strong>\u00a0on the\u00a0<strong>root<\/strong>\u00a0partition of your system. Since you cannot run\u00a0<strong>fsck<\/strong>\u00a0while the partition is mounted, you can try one of these options:<\/p>\n<ul>\n<li>Force fsck upon system boot<\/li>\n<li>Run fsck in rescue mode<\/li>\n<\/ul>\n<p>We will review both situations.<\/p>\n<h4>Force fsck Upon System Boot<\/h4>\n<p>This is relatively easy to complete, the only thing you need to do is create a file called\u00a0<strong>forcefsck<\/strong>\u00a0in the root partition of your system. Use the following command:<\/p>\n<pre># touch \/forcefsck\r\n<\/pre>\n<p>Then you can simply force or schedule a reboot of your system. During the next bootup, the\u00a0<strong>fsck<\/strong>\u00a0will be performed. If downtime is critical, it is recommended to plan this carefully, since if there are many used inodes on your system,\u00a0<strong>fsck<\/strong>\u00a0may take some extra time.<\/p>\n<p>After your system boots, check if the file still exists:<\/p>\n<pre># ls \/forcefsck\r\n<\/pre>\n<p>If it does, you may want to remove it in order to avoid\u00a0<strong>fsck<\/strong>\u00a0on every system boot.<\/p>\n<h4>Run fsck in Rescue Mode<\/h4>\n<p>Running\u00a0<strong>fsck<\/strong>\u00a0in\u00a0<strong>rescue mode<\/strong>\u00a0requires few more steps. First prepare your system for\u00a0<strong>reboot<\/strong>. Stop any critical services like\u00a0<strong>MySQL\/MariaDB<\/strong>\u00a0etc and then type.<\/p>\n<pre># reboot\r\n<\/pre>\n<p>During the boot, hold down the\u00a0<code>shift<\/code>\u00a0key so that the grub menu is shown. Select the \u201c<strong>Advanced options<\/strong>\u201d.<\/p>\n<div id=\"attachment_30686\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Grub-Advance-Options.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30686\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Grub-Advance-Options.png\" alt=\"Grub Advance Options\" width=\"618\" height=\"409\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Grub Advance Options<\/p>\n<\/div>\n<p>Then choose \u201c<strong>Recovery mode<\/strong>\u201d.<\/p>\n<div id=\"attachment_30687\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Select-Linux-Recovery-Mode.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30687\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Select-Linux-Recovery-Mode.png\" alt=\"Select Linux Recovery Mode\" width=\"622\" height=\"391\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Select Linux Recovery Mode<\/p>\n<\/div>\n<p>In the next menu select \u201c<strong>fsck<\/strong>\u201d.<\/p>\n<div id=\"attachment_30688\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Select-fsck-Utility.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30688\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Select-fsck-Utility.png\" alt=\"Select fsck Utility\" width=\"655\" height=\"323\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Select fsck Utility<\/p>\n<\/div>\n<p>You will be asked if you wish to have your\u00a0<code>\/<\/code>\u00a0filesystem remounted. Select\u00a0<code>\u201cyes\u201d<\/code>.<\/p>\n<div id=\"attachment_30689\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Confirm-Root-Filesystem.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30689\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Confirm-Root-Filesystem.png\" alt=\"Confirm Root Filesystem\" width=\"664\" height=\"198\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Confirm Root Filesystem<\/p>\n<\/div>\n<p>You should see something similar to this.<\/p>\n<div id=\"attachment_30690\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Running-fsck-Filesystem-Check.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30690\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Running-fsck-Filesystem-Check.png\" alt=\"Running fsck Filesystem Check\" width=\"717\" height=\"356\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Running fsck Filesystem Check<\/p>\n<\/div>\n<p>You can then resume to normal boot, by selecting\u00a0<strong>\u201cResume\u201d<\/strong>.<\/p>\n<div id=\"attachment_30691\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Select-Normal-Boot.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30691\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/09\/Select-Normal-Boot.png\" alt=\"Select Normal Boot\" width=\"667\" height=\"326\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Select Normal Boot<\/p>\n<\/div>\n<h5>Conclusion<\/h5>\n<p>In this tutorial you learned how to use fsck and run consistency checks on different Linux filesystem.<\/p>\n<p>&nbsp;<br \/>\n<a href=\"https:\/\/www.tecmint.com\/fsck-repair-file-system-errors-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Filesystems are responsible for organizing how data is stored and recovered. One way or another, with time, filesystem may become corrupted and certain parts of it may not be accessible. If your filesystem develops such inconsistency it is recommend to verify its integrity. This can be completed via system utility called\u00a0fsck\u00a0(file system consistency check). This &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/22\/how-to-use-fsck-to-repair-file-system-errors-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Use \u2018fsck\u2019 to Repair File System Errors in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12127","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12127"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12127\/revisions"}],"predecessor-version":[{"id":12128,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12127\/revisions\/12128"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}