In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Preface
The file system is responsible for organizing the storage and recovery of data. In any case, over time, the file system may be corrupted and some parts of it may not be accessible. If there is such an inconsistency in your file system, it is recommended that you verify its integrity.
This can be done through a system utility called fsck (file system consistency check). This check can be done automatically or manually during boot.
In this article, we will review the fsck utility and its usage to help you fix disk errors.
When to use fsck in Linux
When you want to run fsck, there are different scenarios. Here are some examples:
The system cannot be started. The file on the system is corrupted (usually you may see input / output errors). Additional drives, including flash drives / SD cards, do not work.
Fsck available options
You need to run the Fsck command with superuser privileges or root. You can use different parameters. Their usage depends on your specific situation. You will see some of the more important options below:
-A-used to check all file systems. The list is taken from / etc/fstab. -C-displays the progress bar. -l-Lock the device to ensure that no other programs are trying to use the partition during the check. -M-does not check mounted file systems. -N-displays only the actions to be performed-no actual changes are made. -P-if you want to check the file system in parallel, including root. -R-does not check the root file system. This applies only to'- A'. -r-provides statistics for each device being checked. -T-does not display the title. -t-specifically specifies the type of file system to check. The type can be a comma-separated list. -V-provides a description of what is in progress.
How to run fsck to fix Linux file system errors
To run fsck, you need to ensure that the partition you want to check is not installed. For the purposes of this article, I will use the second drive / dev/sdb installed on / mnt.
What happens if I try to run fsck when I install the partition.
# fsck / dev/sdb
Run fsck on an installed partition
To avoid this, use unmount partitions.
# umount / dev/sdb
Then fsck can run safely.
# fsck / dev/sdb
Run fsck on the Linux partition
Understand the fsck exit code
After running fsck, it returns the exit code. These cod can be seen in the fsck manual 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 error
Sometimes multiple errors can be found on the file system. In this case, you may want fsck to automatically try to correct the error. This can be done in the following ways:
# fsck-y / dev/sdb
-y flag, "yes" any prompt from fsck automatically "yes" to correct the error.
Similarly, you can run the same operation on all file systems (without root):
$fsck-AR-y
How to run fsck on the Linux root partition
In some cases, you may need to run fsck on the root partition of the system. Since fsck cannot be run when the partition is installed, you can try one of the following options:
Force fsck to run fsck in rescue mode when the system starts up
We will examine both situations.
Force fsck when the system starts
This is relatively easy to do, and the only thing you need to do is create a file called forcefsck in the root partition of the system. Use the following command:
# touch / forcefsck
You can then simply force or schedule a system restart. During the next startup, fsck will be executed. If downtime is important, it is recommended that you plan carefully, because if you have a lot of inode in use on your system, fsck may need some extra time.
After the system boots, check to see if the file still exists:
# ls / forcefsck
If so, you may want to delete it to avoid fsck every time the system boots.
Run fsck in rescue mode
Running fsck in rescue mode requires more steps. First prepare the system for reboot. Stop any critical services, such as MySQL / MariaDB, etc., and type.
# reboot
During startup, hold down the shift key to display the grub menu. Select Advanced options.
Grub Advance Options
Then select recovery Model.
Select the Linux recovery model
Select "fsck" from the next menu.
Select fsck Utility
You will be asked if you want to reinstall / filesystem. Select "yes".
Confirm the root file system
You should see something like that.
Run the fsck file system check
You can then resume normal startup by selecting restore.
Select normal startup
Conclusion
In this tutorial, you learned how to use fsck and run consistency checks on different Linux file systems. If you have any questions about fsck, please do not hesitate to submit them in the comments section below.
Summary
The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.