Checking the file system on the next reboot (fsck)
How do you force fsck on the next reboot? How do you configure a file system check every few reboots? How do you check file system integrity the next time the system starts? How do you check the file system during a reboot? How do you configure file system checks using tune2fs?
fsck is a Unix program for checking file systems. It is used to verify that the file system is in good condition and does not contain bad sectors. You can force a file system check the next time the system starts or after a specified number of reboots. Depending on the type of file system, its size, and the number of errors, the check may take a few moments or even several hours.
Check the file system on the next boot - /forcefsck file
To do this, simply create the /forcefsck file in the root directory. You will need administrator privileges.
First, go to the root directory
cd /Then create an empty /forcefsck file
sudo touch /forcefsckYou can now reboot the system.
sudo rebootCheck the file system on the next boot - shutdown command
An alternative method is to use the -F flag when running the shutdown command. Administrator privileges are also required here. This will check all relevant partitions. Note — this command may not work on newer distributions. In that case, using the /forcefsck file method is recommended.
sudo shutdown -rF nowPeriodic file system checks - tune2fs command
You can also check the file system periodically, for example every few boots or after a specified period of time. The tune2fs command is used for this. It also requires administrator privileges.
First, you need to find the disk names. You can easily do this with the df command, which does not require administrator privileges.
df -hTo force a file system check after a specified number of mounts, use the following syntax. Each mount happens when the system starts, so configuring this value effectively also configures a boot counter. The command is as follows:
sudo tune2fs -c <mount_count> <disc_name>To force a file system check of the primary disk /dev/sda1 every 10 mounts (reboots), use the following command:
sudo tune2fs -c 10 /dev/sda1You can also force a file system check after a specified period of time. The command is almost identical. For <mount_period>, specify a number together with the interval type. Available values are d - days, w - weeks, m - months.
sudo tune2fs -i <mount_period> <disc_name>To force a file system check of the primary disk /dev/sda1 every month, use the following command:
sudo tune2fs -i 1m /dev/sda1To check the configured settings, use the following command:
sudo tune2fs -l /dev/sda1 | grep -i 'last checked\|mount count'Comments (0)
No comments yet.
Add a comment
Comments are published after moderation. Your e-mail address stays private.