fsck
(File system check) Is a command-line utility that allows you to perform consistency checks and interactive fixes on one or more Linux file systems. Fsck uses its own program for each type of system file it checks.
You can use commands fsck
For repairing corrupted system files in cases where the system fails to boot, or the partition cannot be loaded or read.
In this article we will talk about commands fsck
With usage examples.
How to use the fsck
Command fsck
It takes the following general form
fsck [OPTIONS] [FILESYSTEM]
Only root or user with rights sudo
Which can clear the buffer.
When there is no FILESYSTEM
As an argument, fsck
It will check the devices registered in the file fstab
.
Never run fsck
On the attached section (Vehicle) Because it can corrupt system files. Before trying to scan or repair system files, always use the command unmount
Before using the fsck tool.
Command fsck
It is a versatile tool for many Linux system file scanners (fsck.*
) And accept different options depending on the type of file system.
Check out the guy pages for more information on the specific checkers game. For example, to see the options available for fsck.ext4
, Type:
man fsck.ext4
How to repair corrupted system files
The fsck command is the simplest use case for repairing system files ext3
or ext4
Damaged.
- If you do not know the name of the device, use it
fdisk
,df
Or, another tool to find it. - Unmount the device to be scanned:
sudo umount /dev/sdc1
- Run the command
fsck
To repair a file system:sudo fsck -p /dev/sdc1
Selection
-p
I tell youfsck
To automatically fix problems that can be fixed safely without user intervention. - After repairing the file system, install the partition with the following command:
sudo mount /dev/sdc1
How to fix a root file system
fsck
The root system files could not be checked on a running device because they cannot be dismounted.
If you want to scan or repair root system files, you have several options. You can manage fsck
To boot at boot up, boot the system into recovery mode or use a live CD.
How do you run fsck
In recovery mode:
- Enter the boot menu and select Advanced options
- Select recovery mode then
fsck
“. - When prompted to re-mount the root file system, select
Yes
“. - Once done, proceed with the normal boot.
escape from fsck
From direct CD:
- Play live CD.
- use
fdisk
orparted
Find the name of the root partition. - Open a terminal and run:
sudo fsck -p /dev/sda1
- Once done, restart your system and boot up.
How to check file systems during operation
On most Linux distributions, fsck
It will run at boot time if marked “dirty” on system files or after a specified number of boot processes or time.
To find out the current download number, check the frequency number, check the interval, the last scan time for a particular section, use the tooltune2fs
:
sudo tune2fs -l /dev/sdc1 | grep -i 'last checked|mount count'
Mount count: 292 Maximum mount count: -1 Last checked: Tue Jul 24 11:10:07 2018 Check interval: 0 (<none>)
- “Maximum mount count” is the number of downloads after which the file system will be scanned. Score
or
-1
Which means fsck will never work. - The “verification interval” is the maximum time between two file system scans.
If you want to run, for example fsck
After every 25 shoes, write:
sudo tune2fs -c 25 /dev/sdc1
You can also set the maximum time between two tests. For example, to set it to 1 month, run the following command:
sudo tune2fs -i 1m /dev/sdc1
Determination fsck
Boot Up On Boot into SystemD Distribution Use the following parameters in kernel boot:
fsck.mode=force fsck.repair=yes
In old Linux distributions, fsck
It will run at boot if /forcefsck
exist:
sudo touch /forcefsck
Internal option fstab
fstab
A configuration file that tells the system how and where to install partitions.
Files /etc/fstab
It contains the list of entries as follows:
sudo nano /etc/fstab
# [File System] [Mount Point] [File System Type] [Options] [Dump] [PASS] /dev/sda1 / ext4 defaults 0 1 /dev/sda2 /home ext4 defaults 0 2 server:/dir /media/nfs nfs defaults 0 0
Last sixth column ([PASS]
) Is an option that controls the order in which system files are scanned upon restart.
– Don’t check.
1
– The file system is checked first one by one.2
All other system files are scanned later and (maybe) in parallel.
All root filesystems must have a value 1
, And any other system files you want to check should have value 2
Conclusion
fsck
It is a command-line tool to optionally check and repair Linux file systems.
Learn more about orders fsck
, Visit the fsck man page or type man fsck
At your stop.
.
Originally posted 2020-11-18 11:14:26.