Menu

Checking or Repairing a File System using fsck

The system utility fsck (for "file system consistency check") is a tool for checking the consistency of a file system in Unix and Unix-like operating systems, such as Linux and OS X.

Firstly, we can change the number to 50, which chooses how often you want the check performed.
# tune2fs -c 50 /dev/hda1
1 makes it scan at every boot, 
# tune2fs -c 1 /dev/hda1
0 stops scanning altogether
# tune2fs -c 0 /dev/hda1
What /etc/fstab lines mean?
We have the following mounts
/dev/nvme0n1 / ext4 defaults 1 1  
/dev/nvme1n1 /home ext4 defaults 1 2
Defined as:
  • 0 = Do not check.
  • 1 = First file system (partition) to check;
     / (root partition) should be set to 1.
  • 2 = ALL OTHER file systems to be checked.
Not recommended you could disable checks all together but using the below mounts, changing 1 to 0 like example.
/dev/nvme0n1 / ext4 defaults 0 1
/dev/nvme1n1 /home ext4 defaults 0 2
Changing to 0 would disable disk checks.
Another was to check a hard drive is by touching a file called forcefsck, then reboot to check a disk.
Creating a forcefsck file triggers the file system to check hard disks after a restart, type below: 
# touch /forcefsck
I noticed this doesn't always work depending on your distributions and checkroot scripts during initial bootup.
There is also the -i switch to set an interval before the check if you prefer.
# tune2fs -c 50 -i 1m /dev/nvme0n1
How do you get the information from the drive on how many restarts will the fsck run?
# dumpe2fs -h /dev/sdb1 | grep -i 'mount count'
Outpur : -
dumpe2fs 1.39 (29-May-2006)
Mount count:              26
Maximum mount count:      31
On Debian, Ubuntu or Linux Mint, edit /etc/default/rcS as follows.
# vim /etc/default/rcS
Automatically repair filesystems with inconsistencies during boot
FSCKFIX=yes
Note: FSCKFIX=yes doesn't trigger automatic filesystem check on boot, it just attempts to fix all the errors automatically if fsck is triggered. 

On CentOS, edit /etc/sysconfig/autofsck (or create it if it doesn't exist) with the following content.
# vim /etc/sysconfig/autofsck
Add following line:
AUTOFSCK_DEF_CHECK=yes
Checking file system state:
# tune2fs -l /dev/nvme0n1 | grep -i state
Output:-
Filesystem state:clean
Listing all other attributes
# tune2fs -l /dev/nvme0n1
Output:-
tune2fs 1.39 (29-May-2006)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          ca04ea89-dd64-4e57-a5a2-a9cfff610da0
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery sparse_super large_file
Default mount options:    acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              61063168
Block count:              122096646
Reserved block count:     6104832
Free blocks:              119393584
Free inodes:              61062869
First block:              0
Block size:               4096
Fragment size:            4096
Reserved GDT blocks:      994
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         16384
Inode blocks per group:   512
Filesystem created:       Fri Feb  5 04:42:53 2016
Last mount time:          Tue Mar 15 02:03:45 2016
Last write time:          Tue Mar 15 02:03:45 2016
Mount count:              26
Maximum mount count:      31
Last checked:             Fri Feb  5 04:42:53 2016
Check interval:           15552000 (6 months)
Next check after:         Wed Aug  3 05:42:53 2016
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               128
Journal inode:            8
Default directory hash:   tea
Directory Hash Seed:      d757b293-691f-4220-890e-70cda6889cc8
Journal backup:           inode blocks

Schedule  File System Checks Monthly
Force filesystem check for every 1 months, use the command below.
# tune2fs -i 1m /dev/nvme0n1
Output:-
tune2fs 1.39 (29-May-2006) 
Setting interval between checks to 15552000 seconds
Now verify the scheduled monthly disk check.
# tune2fs -l /dev/nvme0n1 | grep -i interval

About Author:


I am a Linux Administrator and Security Expert with this site i can help lot's of people about linux knowladge and as per security expert i also intersted about hacking related news.TwitterFacebook

Next
Newer Post
Previous
Older Post

0 comments:

Post a Comment

 
Top