How to repair a file system corruption?
Solution 1
You can instruct the filesystem to perform an immediate fsck
upon being mounted like so:
Method #1: Using /forcefsck
You can usually schedule a check at the next reboot like so:
$ sudo touch /forcefsck
$ sudo reboot
Method #2: Using shutdown
You can also tell the shutdown
command to do so as well, via the -F
switch:
$ sudo shutdown -rF now
NOTE: The first method is the most universal way to achieve this!
Method #3: Using tune2fs
You can also make use of tune2fs
, which can set the parameters on the filesystem itself to force a check the next time a mount is attempted.
$ sudo tune2fs -l /dev/sda1
Mount count: 3
Maximum mount count: 25
So you have to place the "Mount count" higher than 25 with the following command:
$ sudo tune2fs -C 26 /dev/sda1
Check the value changed with tune2fs -l
and then reboot!
NOTE: Of the 3 options I'd use tune2fs
given it can deal with force checking any filesystem whether it's the primary's (/
) or some other.
Additional notes
You'll typically see the "Maximum mount count:" and "check interval:" parameters associated with a partition that's been formatted as ext2/3/4. Often times they're configured like so:
$ tune2fs -l /dev/sda5 | grep -E "Mount count|Maximum mount|interval"
Mount count: 178
Maximum mount count: -1
Check interval: 0 (<none>)
When the parameters are set this way, the device will never perform an fsck
during mounting. This is fairly typical with most distros.
There are 2 forces that drive a check. Either number of mounts or an elapse time. The "Check interval" is the time based one. You can say every 2 weeks to that argument, 2w. See the tune2fs
man page for more info.
NOTE: Also make sure to understand that tune2fs
is a filesystem command, not a device command. So it doesn't work with just any old device, /dev/sda
, unless there's an ext2/3/4 filesystem there, the command tune2fs
is meaningless, it has to be used against a partition that's been formatted with one of those types of filessystems.
References
Solution 2
It is recommended to perform a fsck
unmount this partition /dev/sdb2
if you have nothing important riding on that device, if that does not work try doing a fsck with a live CD.
$ sudo fsck /dev/sdb2
Related videos on Youtube
Lexx Luxx
Updated on September 18, 2022Comments
-
Lexx Luxx over 1 year
Debian on external USB SSD drive. There was some error in
dmesg
log file:...[ 3.320718] EXT4-fs (sdb2): INFO: recovery required on readonly filesystem [ 3.320721] EXT4-fs (sdb2): write access will be enabled during recovery [ 5.366367] EXT4-fs (sdb2): orphan cleanup on readonly fs [ 5.366375] EXT4-fs (sdb2): ext4_orphan_cleanup: deleting unreferenced inode 6072 [ 5.366426] EXT4-fs (sdb2): ext4_orphan_cleanup: deleting unreferenced inode 6071 [ 5.366442] EXT4-fs (sdb2): 2 orphan inodes deleted [ 5.366444] EXT4-fs (sdb2): recovery complete ...
The system boots and works normally. Is it possible to repair this fully, and what is the proper way?
-
Olivier Dulac over 9 yearsIf this happens after a brutal shutdown, no worries, it s probably tmp files. If it happened during use, then you should first backup everything important (on 2 separate supports, in case one fails)
-
-
Lexx Luxx over 9 yearsI already ran
fsck -n -f
check, it show no errors. -
user3132678 over 9 yearsproblems and brings you this?
-
Lexx Luxx over 9 yearsthe first two methods are one-time operations, and #3 allows set this operation permanently?
-
slm over 9 yearsYeah it's set permanently, you generally need to go back and reset them after you're done with the
fsck
. At least that's what I do anyways. -
Lexx Luxx over 9 yearsno problem while installation is still fresh, but I want to avoid an unexpected problems in the future. Was the file system completely fixed during recovery?
-
user3132678 over 9 yearsThat will depend on the status of the disk physically, checking typically linux hdd automates every any given time, so it can also be a chore, however you must be careful . I recommend you to run a fsck to dismount the partition at the time this is not writing or reading any device access as long as this is not the file system of your
-
Lexx Luxx over 9 yearsI have
Mount count: 21
Maximum mount count: -1
Check interval:0 (<none>)
It's not clear, what setting to specify? -
slm over 9 yearsThe "Max mnt cnt: -1" and "check interval: 0" are blocking any checks from ever occurring. make "Max mnt cnt" set to 20 and "check interval" can stay 0. There are 2 forces that drive a check. Either number of mounts or an elapse time. The 2nd argument is the time based one. You can say every 2 weeks to that argument,
2w
. See thetune2fs
man page for more info. -
Lexx Luxx over 9 yearsthese setting are used for partitions only, or can be for disk
/dev/sdb
? -
slm over 9 years@triwo - see updates to A, hopefully they help.