Using e2fsck to Find and Repair Disk Errors On ext File Systems
Traducciones al EspañolEstamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
What is e2fsck?
e2fsck is a utility that examines
ext4 filesystems for errors, and attempts to repair them if possible. It is the backend tool that the popular fsck frontend utility calls for a combination of tasks related to
On some systems, e2fsck runs automatically after an unclean shutdown or after a certain number of reboots.
e2fscktool will be installed as the default disk repair utility. For instructions specific to performing a filesystem check on the Linode platform, see our Troubleshooting Guide: Booting into Rescue Mode for guidance.
When to Use e2fsck
You can 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.
e2fsck Options and Arguments
|Automatically repair (“preen”) the file system. This option is provided for backwards compatibility purposes only, and it is recommended that the |
|Uses an alternative superblock, replacing |
|Allows you to define a block size when performing e2fsck, instead of having e2fsck attempt multiple block sizes to find the correct one. Replace |
|Uses the badblocks program to perform a read-only scan to find any bad blocks, and then add any back blocks to the inode to prevent them from being allocated.|
|Ensures that e2fsck writes completion information to a specified file descriptor to track the progress of the file system check. Replace |
|Prints debugging output|
|Ensures the e2fsck attempts to optimize all directories by re-indexing them or by sorting and compressing directories for smaller directories, or traditional linear directories.|
|Sets extended options for e2fsck. These are generally more advanced options. For more information, see the official man page for e2fsck.|
|Force filesystem checking even if the file system appears clean.|
|Flushes the file system device’s buffer caches before beginning. This is generally only useful for benchmarking purposes.|
|Sets the path name where the external-journal for the defined file system can be found. Replace |
|Used in combination with the |
|Adds block numbers listed in the file specified by |
|Same as the |
|Opens the filesystem as |
|Entered to automatically repair (“preen”) the file system. Automatically attempts to fix any filesystem issues without human intervention.|
|Prints statistics for |
|Enables verbose output.|
|Prints the version information for |
|Automatically selects the |
Unmount the Disk
Boot into Rescue Mode
If you are using e2fsck on a Linode, the easiest and safest way to unmount your disk is to use Rescue Mode. Visit our Rescue and Rebuild 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. e2fsck should be run only as a user with root permissions.
View Mounted Disks and Verify Disk Location
dfto view a list of currently mounted disks. If you are using Rescue Mode, the disk you want to check should not be listed:
fdiskto view disk locations:
Copy the location of the target disk to use with the fsck command.
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. Apply the changes and reboot the Linode.
If you are working on a local machine, unmount the disk manually.
umountto unmount the disk location copied in the previous step:
If the disk is declared in
/etc/fstab, change the
nonethere as well.
How to Check for Errors on a Disk
Run fsck on the target disk, using the desired options. This example forces a file system check and attempts to fix any issues without human intervention (
e2fsck -pf /dev/sda
Understand fsck Error Codes
The error codes that fsck returns can be understood with the following table from man7.org:
|Code||Error Code Meaning|
|1||Filesystem errors corrected|
|2||System should be rebooted|
|4||Filesystem errors left uncorrected|
|16||Usage or syntax error|
|32||Checking canceled by user request|
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.
This page was originally published on