Preface The file system is responsible for organizing how data is stored and restored. Anyway, over time the file system may get corrupted and parts of it may become inaccessible. If your file system exhibits such inconsistencies, it is recommended to verify its integrity. This can be done with a system utility called fsck (file system consistency check). This check can be done automatically during boot or run manually. In this article, we will 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 want to run fsck. Here are some examples:
Available fsck options You need to use superuser privileges or root to run the Fsck command. You can use different parameters. Their usage depends on your specific situation. You'll see some of the more important options below:
How to Run fsck to Repair Linux File System Errors To run fsck, you need to make sure the partition you want to check is not mounted. For the purpose of this article, I will use the second drive /dev/sdb mounted at /mnt. What happens if I try to run fsck while the partition is mounted. # fsck /dev/sdb Run fsck on the mounted partition To avoid this, use unmount partition. # umount /dev/sdb Then fsck can be run safely. # fsck /dev/sdb Running fsck on Linux partitions Understanding fsck exit codes After running fsck it will return an exit code. These cods can be seen in fsck's man page by running the following command: # 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 Fix Linux File System Errors Sometimes multiple errors can be found on a file system. In this case, you might want fsck to automatically try to correct the errors. This can be done by: # fsck -y /dev/sdb The -y flag automatically "yes" to any prompts from fsck to correct errors. Likewise, you can run the same operation on all file systems (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 scenarios. Force fsck on system startup This is relatively easy to accomplish, 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 You can then simply force or schedule a reboot of your system. During the next boot, fsck will be executed. If downtime is important, careful planning is recommended, as fsck may take some extra time if you have many used inodes on your system. After the system boots, check if the file is still there: # ls /forcefsck If so, you may want to remove it to avoid fsck appearing every time the system boots. Run fsck in rescue mode Running fsck in rescue mode requires a few more steps. First prepare your system for a reboot. Stop any critical services like MySQL/MariaDB etc. and then type. # reboot During boot, hold down the shift key to bring up the grub menu. Select Advanced options. Grub Advance Options Then select Recovery Mode. Select Linux Recovery Mode In the next menu select 'fsck'. Select fsck Utility You will be asked if you wish to remount the / filesystem. Select yes. Confirm the root file system You should see something similar to this. Run fsck file system check You can then resume normal startup by selecting "Resume". Select Normal Startup in conclusion In this tutorial, you have learned how to use fsck and run consistency checks on different Linux file systems. If you have any questions about fsck, don’t hesitate to submit them in the comments section below. Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM. You may also be interested in:
|
<<: In-depth understanding of the implementation principle of require loader
>>: MySQL 8.0.3 RC is about to be released. Let’s take a look at the changes
Table of contents 1. Process 2. Core Architecture...
The operating environment of this tutorial: Windo...
Port Mapping Before the Docker container is start...
Table of contents Preface 1. Array traversal meth...
Personal implementation screenshots: Install: npm...
After three days of encountering various difficul...
Table of contents 1. Overview 2. Routing Navigati...
[Usage and function of mysql cursor] example: The...
Say it in advance We all know that Docker can ach...
Table of contents Function Introduction function ...
Click here to return to the 123WORDPRESS.COM HTML ...
<br /> When we browse certain websites and s...
This article example shares the specific code of ...
A cool JavaScript code to unfollow Weibo users in...
“Inputs should be divided into logical groups so ...