Free Republic
Browse · Search
General/Chat
Topics · Post Article

Skip to comments.

How to Use ‘fsck’ to Repair File System Errors in Linux
tecMint ^ | 1 October 2018 | Marin Todorov

Posted on 03/04/2019 4:06:49 AM PST by ShadowAce

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 fsck (file system consistency check). This check can be done automatically during boot time or ran manually.

In this article, we are going to review the fsck utility and its usage to help you repair disk errors.

When to Use fsck in Linux

There are different scenarios when you will want to run fsck. Here are few examples:

fsck Available options

Fsck command needs to be run with superuser privileges or root. You can use it with different arguments. Their usage depend on your specific case. Below you will see some of the more important options:

How to Run fsck to Repair Linux File System Errors

In order to run fsck, 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 /dev/sdb mounted in /mnt.

Here is what happens if I try to run fsck when the partition is mounted.

# fsck /dev/sdb
Run fsck on Mounted Partition

Run fsck on Mounted Partition

To avoid this unmount the partition using.

# umount /dev/sdb

Then fsck can be safely ran with.

# fsck /dev/sdb
Run fsck on Linux Partition

Run fsck on Linux Partition

Understanding fsck exit codes

After running fsck, it will return an exit code. These cods can be seen in fsck’s manual by running:

# man fsck

0 No errors 1 Filesystem errors corrected 2 System should be rebooted 4 Filesystem errors left uncorrected 8 Operational error 16 Usage or syntax error 32 Checking canceled by user request 128 Shared-library error

Repair Linux Filesystem Errors

Sometimes more than one error can be found on a filesystem. In such cases you may want fsck to automatically attempt to correct the errors. This can be done with:

# fsck -y /dev/sdb

The -y flag, automatically “yes” to any prompts from fsck to correct an error.

Similarly, you can ran the same on all filesystems (without root):

$ fsck -AR -y 

How to Run fsck on Linux Root Partition

In some cases, you may need to run fsck on the root partition of your system. Since you cannot run fsck while the partition is mounted, you can try one of these options:

We will review both situations.

Force fsck Upon System Boot

This is relatively easy to complete, the only thing you need to do is create a file called forcefsck in the root partition of your system. Use the following command:

# touch /forcefsck

Then you can simply force or schedule a reboot of your system. During the next bootup, the fsck will be performed. If downtime is critical, it is recommended to plan this carefully, since if there are many used inodes on your system, fsck may take some extra time.

After your system boots, check if the file still exists:

# ls /forcefsck

If it does, you may want to remove it in order to avoid fsck on every system boot.

Run fsck in Rescue Mode

Running fsck in rescue mode requires few more steps. First prepare your system for reboot. Stop any critical services like MySQL/MariaDB etc and then type.

# reboot

During the boot, hold down the shift key so that the grub menu is shown. Select the “Advanced options”.

Grub Advance Options

Grub Advance Options

Then choose “Recovery mode”.

Select Linux Recovery Mode

Select Linux Recovery Mode

In the next menu select “fsck”.

Select fsck Utility

Select fsck Utility

You will be asked if you wish to have your / filesystem remounted. Select “yes”.

Confirm Root Filesystem

Confirm Root Filesystem

You should see something similar to this.

Running fsck Filesystem Check

Running fsck Filesystem Check

You can then resume to normal boot, by selecting “Resume”.

Select Normal Boot

Select Normal Boot



TOPICS: Computers/Internet
KEYWORDS: linux

1 posted on 03/04/2019 4:06:49 AM PST by ShadowAce
[ Post Reply | Private Reply | View Replies]

To: rdb3; Calvinist_Dark_Lord; JosephW; Only1choice____Freedom; Ernest_at_the_Beach; martin_fierro; ...

2 posted on 03/04/2019 4:07:10 AM PST by ShadowAce (Linux - The Ultimate Windows Service Pack)
[ Post Reply | Private Reply | To 1 | View Replies]

To: ShadowAce

Fsck? That’s a lot like what I say whenever I have computer problems.


3 posted on 03/04/2019 4:18:20 AM PST by HartleyMBaldwin
[ Post Reply | Private Reply | To 1 | View Replies]

To: HartleyMBaldwin

My problems usually begin with a typo


4 posted on 03/04/2019 4:22:12 AM PST by a fool in paradise (Denounce DUAC - The Democrats Un-American Activists Committee)
[ Post Reply | Private Reply | To 3 | View Replies]

To: HartleyMBaldwin

Call it f-suck.


5 posted on 03/04/2019 4:23:28 AM PST by bobcat62
[ Post Reply | Private Reply | To 3 | View Replies]

To: ShadowAce

I came to work on Monday and discovered IT completely fsck’ed my computer over the weekend.


6 posted on 03/04/2019 4:27:55 AM PST by IndispensableDestiny
[ Post Reply | Private Reply | To 1 | View Replies]

To: bobcat62
f-suck is when fsck fails and your backups fail and your last chance is fsdb.

fsdb That's f-suck!

7 posted on 03/04/2019 4:38:47 AM PST by lurked_for_a_decade (Imagination is more important than knowledge! ( e_uid == 0 ) != ( e_uid = 0 ). I Read kernel code.)
[ Post Reply | Private Reply | To 5 | View Replies]

To: lurked_for_a_decade

Been there, done that. Would rather have a root canal.


8 posted on 03/04/2019 4:39:42 AM PST by lurked_for_a_decade (Imagination is more important than knowledge! ( e_uid == 0 ) != ( e_uid = 0 ). I Read kernel code.)
[ Post Reply | Private Reply | To 7 | View Replies]

To: ShadowAce

Just the thing I want to read about on a Monday morning.


9 posted on 03/04/2019 4:53:22 AM PST by LibFreeUSA
[ Post Reply | Private Reply | To 1 | View Replies]

To: ShadowAce

Don’t make a mistake or you’re fscked! Thanks for the articles!


10 posted on 03/04/2019 5:42:47 AM PST by Still Thinking (Freedom is NOT a loophole!)
[ Post Reply | Private Reply | To 1 | View Replies]

To: ShadowAce

Great post! Thank you! New users need this! I forgot what error code I got, but I had to do this one time because of a hard shutdown (pretty sure it was this?). My battery is no good and the power went off causing a hard shutdown. Linux doesn’t like that the first time it happens and it makes you go through the Q&A session to fix the boot process. But from what it looks like it only needs to be done the one time and then it doesn’t affect the boot if it happens anymore after.


11 posted on 03/04/2019 6:06:14 AM PST by Openurmind
[ Post Reply | Private Reply | To 1 | View Replies]

To: ShadowAce

“How to Use ‘fsck’ to Repair File System Errors in Linux”

I use that word all the time whether I’m trying to fix something or not. Especially useful when talking about democrats.


12 posted on 03/04/2019 6:55:38 AM PST by Bonemaker (invictus" maneo)
[ Post Reply | Private Reply | To 1 | View Replies]

To: a fool in paradise

Most of mine can be classified as ID-ten-T errors.


13 posted on 03/04/2019 7:55:53 AM PST by HartleyMBaldwin
[ Post Reply | Private Reply | To 4 | View Replies]

To: ShadowAce

Is there an article on image backups using Clonezilla? A Clonezilla article would be useful to newbies.


14 posted on 03/04/2019 1:37:28 PM PST by bobcat62
[ Post Reply | Private Reply | To 1 | View Replies]

To: bobcat62
Many, many years ago when *nix was new to me, I explained my issue to a colleague and he glibbly advised, "Just run fsck."
I did just that. However, I forgot to use the -y flag. It was a large filesystem and I sat there for quite a very long time having to press 'enter' again and again and again...

I decided to read all things fsck after that.

15 posted on 03/05/2019 6:55:33 AM PST by Bloody Sam Roberts (Atrophy of science is visible when the spokesman goes from Einstein to Sagan to Neil Degrasse Tyson.)
[ Post Reply | Private Reply | To 5 | View Replies]

Disclaimer: Opinions posted on Free Republic are those of the individual posters and do not necessarily represent the opinion of Free Republic or its management. All materials posted herein are protected by copyright law and the exemption for fair use of copyrighted works.

Free Republic
Browse · Search
General/Chat
Topics · Post Article

FreeRepublic, LLC, PO BOX 9771, FRESNO, CA 93794
FreeRepublic.com is powered by software copyright 2000-2008 John Robinson