Product docs and API reference are now on Akamai TechDocs.
Search product docs.
Search for “” in product docs.
Search API reference.
Search for “” in API reference.
Search Results
 results matching 
 results
No Results
Filters
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 ext2
, ext3
, and 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 ext
filesystems.
On some systems, e2fsck runs automatically after an unclean shutdown or after a certain number of reboots.
e2fsck
tool 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
Option | Action |
---|---|
-a | Automatically repair (“preen”) the file system. This option is provided for backwards compatibility purposes only, and it is recommended that the -p option is used instead wherever possible. |
-b superblock | Uses an alternative superblock, replacing superblock as noted in the option. |
-B blocksize | Allows you to define a block size when performing e2fsck, instead of having e2fsck attempt multiple block sizes to find the correct one. Replace blocksize with the block size you would like to attempt a repair with. |
-c | 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. |
-C fd | Ensures that e2fsck writes completion information to a specified file descriptor to track the progress of the file system check. Replace fd with the file descriptor you would like to use. |
-d | Prints debugging output |
-D | 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. |
-E extended_options | Sets extended options for e2fsck. These are generally more advanced options. For more information, see the official man page for e2fsck. |
-f | Force filesystem checking even if the file system appears clean. |
-F | Flushes the file system device’s buffer caches before beginning. This is generally only useful for benchmarking purposes. |
-j external-journal | Sets the path name where the external-journal for the defined file system can be found. Replace external-journal with the path you will be using. |
-k | Used in combination with the -c option, uses the badblocks program, ensures that any existing bad blocks are preserved, and any new bad blocks found are added to the bad blocks list. |
-l filename | Adds block numbers listed in the file specified by filename to the list of bad blocks. |
-L filename | Same as the l option, however clears the bad blocks list before the blocks listed in the file are added. |
-n | Opens the filesystem as read-only and assumes an answer of no to any prompts. This option may not be specified at the same time as the -p or -y options. |
-p | Entered to automatically repair (“preen”) the file system. Automatically attempts to fix any filesystem issues without human intervention. |
-t | Prints statistics for e2fsck related to timing. |
-v | Enables verbose output. |
-V | Prints the version information for e2fsck without performing any scan. |
-y | Automatically selects the yes option to any prompts when performing e2fsck tasks. This option may not be specified at the same time as the -n or -p options. |
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
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
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. Apply the changes and reboot the Linode.
Manual Unmount
If you are working on a local machine, unmount the disk manually.
Use
umount
to unmount the disk location copied in the previous step:umount /dev/sdb
If the disk is declared in
/etc/fstab
, change themount point
tonone
there 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 (-fp
) on /dev/sda
:
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 |
---|---|
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 |
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.
This page was originally published on