You are on page 1of 5

(https://linode.

com)

Guides & Tutorials (https://www.linode.com/docs/)


»  Quick Answers (https://www.linode.com/docs/quick-answers/)
»  Linux (https://www.linode.com/docs/quick-answers/linux/)
»  How to use fsck to Find and Repair Disk Errors and Bad Sectors

How to use fsck to Find and Repair Disk Errors and Bad Sectors
Updated Thursday, September 20, 2018 by Linode Written by Edward Angert

Try this guide (https://login.linode.com/signup?promo=DOCS20AA00X1) to receive $20 at signup on a new account.


Sign Up Here!

 Contribute on GitHub
Report an Issue (https://github.com/linode/docs/issues/new?
title=How%20to%20use%20fsck%20to%20Find%20and%20Repair%20Disk%20Errors%20and%20Bad%20Sectors%20Proposed%20Changes&body=Link%3A https%3A%2F%2Flinode.com%2fdocs%2fquick-
answers%2flinux%2fhow-to-use-fsck-to-fix-disk-problems%2f%0A%23%23%20Issue%0A%0A%23%23%20Suggested%20Fix%0A&labels=inaccurate guide) | View File
(https://github.com/linode/docs/blob/master/docs/quick-answers/linux/how-to-use-fsck-to-fix-disk-problems/index.md) | Edit File (https://github.com/linode/docs/edit/develop/docs/quick-
answers/linux/how-to-use-fsck-to-fix-disk-problems/index.md)

This guide is part of a series on Linux commands and features. Not all commands may be relevant to Linode-specific hardware, and are included
here to provide an easy to access reference for the Linux community. If you have a command or troubleshooting tip that would help others, please
submit a pull request or comment.

What is fsck?
fsck, short for file system consistency check, is a utility that examines the file system for errors and attempts to repair them if possible. It uses a
combination of built-in tools to check the disk and generates a report of its findings.

On some systems, fsck runs automatically after an unclean shutdown or after a certain number of reboots.
When to Use fsck
Use fsck to check your file system if your system fails to boot, if files on a specific disk become corrupt, or if an attached drive does not act as
expected. Unmount the disks you intend to work on before attempting to check or repair them.

Caution
Unmount the target disk first. You risk corrupting your file system and losing data if you run fsck on an active disk.

fsck Options and Arguments


Option Action

-a Attempt to fix errors automatically. Use with caution.

-f Force fsck to check a file system even if it thinks it’s clean.

-A Check all disks listed in /etc/fstab .

-C Show progress bar (ext2 and ext3 file systems only).

-M Skip mounted file systems.

-N Test run. Describes what would happen without executing the check itself.

-P Use with the -A option to run multiple checks in parallel.

-R If using the -A option, do not check the root filesystem.

-t Check only a specific type of filesystem.

-T Skip the title on startup.

-y Interactive repair mode.

Unmount the Disk


Boot into Rescue Mode
If you are using fsck on a Linode, the easiest and safest way to unmount your disk is to use Rescue Mode. Visit our Rescue and Rebuild
(/docs/troubleshooting/rescue-and-rebuild/#booting-into-rescue-mode) guide for instructions on how to boot your Linode into Rescue Mode. If
you’re working on a local machine, consider using the distribution’s recovery mode or a live distribution to avoid working on a mounted disk. fsck
should be run only as a user with root permissions.

View Mounted Disks and Verify Disk Location


1. Run df to view a list of currently mounted disks. If you are using Rescue Mode, the disk you want to check should not be listed:

df -h

2. Use fdisk to view disk locations:


fdisk -l

Copy the location of the target disk to use with the fsck command.

Configuration Profile
If you are working on a Linode but do not wish to use Rescue Mode, shut down the Linode from the Linode Manager. Unmount the disk from the
Configuration Profile (/docs/platform/disk-images/disk-images-and-configuration-profiles/#editing-a-configuration-profile). Apply the changes and
reboot the Linode.

Manual Unmount
If you are working on a local machine, unmount the disk manually.

1. Use umount to unmount the disk location copied in the previous step:

umount /dev/sdb

2. If the disk is declared in /etc/fstab , change the mount point to none there as well.

How to Check for Errors on a Disk


Run fsck on the target disk, using the desired options. This example checks all file systems ( -A ) on /dev/sdb :

fsck -A /dev/sdb

Understand fsck Error Codes


The error codes that fsck returns can be understood with the following table from man7.org (http://man7.org/linux/man-pages/man8/fsck.8.html):

Code Error Code Meaning

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

Use fsck to Repair File System Errors


Use the -r option to use the interactive repair option.

This example uses fsck to check all file systems except the root, and will attempt repair using the interactive feature:
fsck -AR -y

To check and attempt to repair any errors on /dev/sdb , use this format:

fsck -y /dev/sdb

What if fsck got interrupted?


If fsck gets interrupted, it will complete any checks in process, but will not attempt to repair any errors it finds.

More Information
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful,
please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

fsck on man7.org (http://man7.org/linux/man-pages/man8/fsck.8.html)

Join our Community


Find answers, ask questions, and help others. (https://www.linode.com/community/questions/)

Was This Guide Helpful?


Your feedback is important to us. Let us know if this guide helped you find the answer you were looking for by taking this survey.
(https://delighted.com/t/iVc7nAYL?referrer=%2Fdocs%2Fquick-answers%2Flinux%2Fhow-to-use-fsck-to-fix-disk-problems%2F)


Linode Comment Policy
Important Update
Comments must be respectful, constructive, and relevant to the topic of the guide. No external links or advertisements.

When you log in with Disqus, we process personal data to facilitate your authentication and posting of comments. We also
store the comments you post and those comments are immediately viewable and searchable by anyone around the world.
1 Comment Linode 🔒 Disqus' Privacy Policy  All Sujat Kamal
Please access our Privacy Policy to learn what personal data Disqus collects and your choices about how it is used.
users of our service are also subject to our Terms of Service.
 Recommend t Tweet f Share Sort by Best

Proceed
Linode requires you to verify your email address before posting. Send verification email to marketpredictions@gmail.com ×

Join the discussion…

Jefferson André Voigt


a year ago

This is an excellent tutorial, very explanatory. Thank you.
△ ▽ Reply

✉ Subscribe ⚠ Do Not Sell My Data

This guide is published under a CC BY-ND 4.0 (https://creativecommons.org/licenses/by-nd/4.0) license.


Write for Linode.
We're always expanding our docs. If you like to help people, can write, and have expertise in a Linux or cloud infrastructure topic,
learn how you can contribute (https://www.linode.com/lp/write-for-linode?utm_source=library&utm_medium=contribute-
link&utm_campaign=write-for-linode) to our library.

Get started in the Linode Cloud today.

Create an Account (https://login.linode.com/signup)

© 2019 All rights reserved.

r.com/linode/) (https://www.instagram.com/linode/) (https://www.youtube.com/linode/) (https://www.linkedin.com/company/linode/) (https://

You might also like