Linux command + shell script collection: file system inspection and repair

Recommended free tutorials: Python, C++, Java, JS, Rust, Go Language Introduction Complete Manual (6 in 1).zip-Python Documentation Resources-CSDN Download


Even modern file systems can go wrong if there is a sudden power outage or if some rogue program locks up the system while accessing files . Fortunately, there are some command line tools that can help you restore the file system to normal.
Each filesystem has its own recovery commands that can interact with the filesystem. This may make the situation uncomfortable. As
more file systems are available in the Linux environment, you also have to master a large number of corresponding commands. Fortunately, there is a common front-end
program that can determine the file system on the storage device and call the appropriate file system recovery command according to the file system to be restored. The fsck command can check and repair most types of Linux filesystems, including ext, ext2, ext3, ext4, ReiserFS, JFS, and XFS
discussed earlier in this chapter .
The format of the command is:
fsck options filesystem
You can list multiple file systems to check on the command line.
A file system can be referenced by the device name, the mount point in the virtual directory , and the unique UUID value assigned to the file system.



Tip: Although users of journaling filesystems need to use the fsck command, it is debatable whether users of COW filesystems should also use this command. In fact, the ZFS filesystem doesn't even provide an interface to the fsck utility.


The fsck command uses the /etc/fstab file to automatically determine the filesystems of storage devices normally mounted on the system. If the storage
device is not mounted yet (for example, you just created a file system on a new storage device), you need to specify the file system
type with the -t command line option. Table 8-4 lists other available command-line options.

You may have noticed that some command line options are duplicated. This is part of the problem with implementing a common front end for multiple commands
. Some filesystem repair commands have additional options available. If you want more advanced error checking, you need to check the
man page of the file system repair tool to determine whether there are extended options specific to the file system.

Tip: The fsck command can only be run on unmounted file systems. For most filesystems, you can simply unmount the filesystem
to check it, and then remount it when the check is complete. But because the root filesystem contains all core Linux
commands and log files, you cannot unmount it on a running system.


Now is a good time to experience a Linux LiveCD for yourself! Just boot the system with the LiveCD and
run the fsck command on the root file system.
So far, this chapter has explained how to deal with the file system in the physical storage device. Linux has other ways to
create logical storage devices for file systems. The next section will tell you how to use logical storage devices. 

Recommended free tutorials: Python, C++, Java, JS, Rust, Go Language Introduction Complete Manual (6 in 1).zip-Python Documentation Resources-CSDN Download

Guess you like

Origin blog.csdn.net/tysonchiu/article/details/125873111