When managing and using any operating system, it has many components internally, but one of the most vital for all optimal operation are file systems. Basically a file system refers to the methods and data structures that the operating system possesses which in turn it uses to follow the sequence of the files on a disk or partition, in other words, the file system allows you to organize the files On the disk..
Types File Systems
File systems can be classified in 3 ways that are:
- Special purpose file systems.
Common mistakes
Now, it is normal that at some point the file system, in this case we talk about Linux, present anomalies for causes such as:
- Presence of viruses or malware
- The system does not boot.
- System failures and more.
In case the file system of the Linux distribution used is unstable, it presents errors of performance and reliability, as administrators or users we must proceed to validate its integrity and for this we have a utility called fsck which TechnoWikis will explain in detail.
What is fsck
Fsck (file system consistency check) is a command line utility developed to analyze and repair errors in the system file system.
This fsck check can be done automatically during boot time or run manually if necessary. fsck is used to verify and optionally repair one or more Linux file systems, file system elements (filesys) can cover values ​​such as:
- device name (/ dev / hdc1, / dev / sdb2)
- a mount point (/, / usr, / home)
- a UUID specifier (UUID = 8868abf6-88c5-4a83-98b8-bfc24057f7bd or LABEL = root).
By default, fsck will attempt to manage file systems on different physical disk drives in parallel to reduce the total amount of time required in the verification process. If no file system is specified on the command line, and the -A option is not indicated, fsck will run the verification of the file systems in the / etc / fstab directory in series.
Available fsck command options
The fsck command must be executed with superuser or root privileges and some of the parameters to be used are:
- -A: Applies to check all file systems. The origin of the list is / etc / fstab.
- -C: Displays the progress bar.
- -l: Lock the device in order to ensure that no other program will attempt to use the partition during verification and thus cause errors
- -M: Does not verify mounted file systems.
- -N: deploys the action to be performed but does not really execute it.
- -P: Allows you to check file systems in parallel, including root.
- -R: Does not check the root file system. This is useful only with '-A'.
- -r: provides statistics for each device that is being checked.
- -T: Does not display the title.
- -t: It allows us to specify exclusively the types of file systems to verify. The types can be a comma separated list.
- -V: Provides a description of the action taken.
Exit Code Options
When fsck is running on Linux, an exit code associated with the result is displayed, the options of these codes are:
- 1: File system errors fixed
- 2: The system must be restarted
- 4: File system errors left uncorrected
- 16: Error of use or syntax
- 32: Check canceled by user request
- 128: Shared library error
1. Verify partition status with fsck on Linux
Step 1
To execute fsck correctly it is necessary that the partition to be verified is not mounted, if we try to run fsck on a mounted drive we will see the following:
sudo fsck / dev / sda1
Step 2
In this case we must disassemble this unit by executing:
umount / dev / sda1
Step 3
Once disassembled, we execute the command on the partition to be analyzed again, in this case we have created a new partition, like this: “sudo fsck / dev / sdb†and this will be the result:
2. Use fsck command to repair file system errors on Linux
Step 1
In the event that fsck detects errors in the file system we can execute the following line so that fsck tries to correct the errors automatically:
sudo fsck -y / dev / sdb
Step 2
The "-y" parameter automatically says "yes" to any fsck request to correct a Linux error. It is also possible to run the same on all file systems (without root) as follows:
fsck -AR -y
Step 3
We can have other important tasks in which to use the fsck command
How to run fsck on root partition
At specific times it may be necessary to run fsck on the root partition of the system, remember that it is not possible to run fsck while the partition is mounted, and root must always be mounted, it will be possible to use any of the following options:
- Force fsck to be executed at system boot
How to force fsck on system boot
This is a simple task, for this we will create a file called forcefsck in the root partition of the system with the following commands:
touch / forcefsck
After this we will force or schedule a system restart, so, during the next boot, the fsck command will be executed. After the system boots up, we can verify if the file still exists with the following command:
ls / forcefsck
3. How to run fsck in rescue mode on Linux
For this process the first step is to stop any critical service, after this, reboot the system with the "reboot" command.
Step 1
In the start window we select the line “Advanced options for Ubuntuâ€:
Step 2
In the next window we will select the line (recovery mode):
Step 3
In the next window we select the “fsck†line:
Step 4
The following message will be displayed indicating if you want to reassemble the file system /, select "yes":
Step 5
It will start the process of analyzing the Linux file system:
Step 6
Once completed, the following window will be displayed:
Step 7
There we select the resume line to continue with the normal system startup. Recall that fsck takes the source list in the / etc / fstab directory, we can list the contents of that directory to know which partition will be analyzed by running the following line:
cat / etc / fstab
Step 8
In this directory there are certain variables that affect the behavior of fsck, these are.
FSCK_FORCE_ALL_PARALLEL
If this environment variable is set, fsck will attempt to verify all specified file systems in parallel, regardless of whether the file systems are on the same device.
FSCK_MAX_INST
This environment variable is responsible for limiting the maximum number of file system verifiers that can be run at the same time on Linux.
PATH
The PATH environment variable is used to find file system verifiers, first, a set of system directories is searched: / sbin, /sbin/fs.d, / sbin / fs, / etc / fs, and / etc, later the set of directories found in the PATH environment is searched.
FSTAB_FILE
This environment variable allows the system administrator to override the standard location of the / etc / fstab file.
LIBBLKID_DEBUG = 0xffff
Enable debug output.
LIBMOUNT_DEBUG = 0xffff
Enable debug output.
More options
Some additional options for use are:
- Check only one type of file system:
fsck -AR -t ext2 -y
- Do not run fsck on mounted drives
mount | grep "/ dev / sd *"
- Skip the title displayed at the exit of the results
fsck -TAR
- Repair damage automatically
fsck -a -AR
The fsck command is a comprehensive solution to optimize the use of the Linux file system and periodically check its status..