If you ever want to check your filesystem’s health in Linux, you might have wanted to enable fsck on system start. This is some maintenance work that we should probably consider performing regularly. Verifying the health of our data is not a bad thing and it doesn’t even take that long.
When you run fsck, you’re not checking the hardware’s integrity. That’s something done with S.M.A.R.T. and is something else you might want to check regularly. This is checking the integrity of our data, the health of your partitions, and that sort of thing.
I’m inept and didn’t remember to write this ahead of time, so this was written after eating way too much and a few glasses of wine. You have been warned.
Anyhow, I’ve written about fsck before:
If you get a minute, those articles might interest you.
What Is fsck:
You won’t need to install anything in this article. If you hunt around the ‘net, you’ll find that fsck somehow stands for ‘file system consistency check’. Please don’t blame me, I didn’t name anything. You’ll find that fsck is installed by default on most anything UNIX-like, including the BSD family and MacOS.
You can run fsck manually against unmounted partitions. In this case, we’ll make that easier by running fsck during the boot process. We’ll be telling fsck to run during the startup process. This means it’ll run automatically when you reboot.
If you check the man page for fsck, you’ll see it’s described like so:
fsck – check and repair a Linux filesystem
So, this is the correct tool for the job. If you look further, you’ll also come across this bit of information:
fsck is used to check and optionally repair one or more Linux filesystems.
You can verify that fsck is installed with this command:
The output from that command will tell you the version and the bit about ‘util-linux’ will let you know why I can assume that fsck is installed by default.
We’ll also be using the following tool…
What is tune2fs:
The tune2fs application is the tool we’ll be using to schedule the fsck command. The syntax is quite simple and you’ll be a professional in no time. If you were to check the man page, you’d see it described like this:
tune2fs – adjust tunable file system parameters on ext2/ext3/ext4 filesystems
NOTE: It’s important to realize that this is only going to work if you’re using one of those three formats. If you’re not using an ext* formatted partition, this isn’t going to work for you. There are other tools. This one is not for you.
The tune2fs application is almost certainly installed by default. If you check the man page it says it’s an invalid option – but it does tell you the version. Which means you can ensure that it is installed. However, you can just as easily verify that tune2fs is installed with this command:
While that won’t give you a version number, you don’t need to know the version. This is one of those applications that are robustly finished, for lack of a better term. It’ll work with your system.
We will also be using lsblk. We’ve used this command many times. Several other commands will get you the same information, but lsblk is a nice and easy example. If you check the man page, you’ll see that lsblk is described as:
lsblk – list block devices
Which, as you can see, is exactly the right tool for the job. Block devices are, in this case, drives and partitions. We’re interested in the partitions for this exercise. It’s a basic Linux utility and will be installed by default. You can verify that lsblk is installed by default with this command:
If any of these tools aren’t installed by default, please leave a comment. I don’t think I can recall a server or desktop distro that doesn’t have these basic tools installed by default. You shouldn’t need any additional tools for this exercise.
Enable fsck On System Start:
If it’s not obvious, fsck is a tool usually called from the terminal. I’m sure a GUI frontend exists somewhere, but that’s not covered in this article. So, press
First, let me cover another method. If you want to run fsck on the next boot and against your root partition, you can skip all of this and just run this command:
sudo touch /forcefsck
I think I’d be doing you a disservice if I didn’t mention that. The next time you reboot the device, it will run fsck on the root partition. It will clean itself up afterward and only run it that once, assuming all goes to plan.
What we’ll be doing is using tune2fs to schedule running fsck. We’ll specify the disk name and the frequency at which fsck is run. You’ll have options with the tune2fs method. I’ll explain them as well as I can.
Enable fsck With tune2fs:
With that open terminal, we need first to find the name of the partition you want to check. For that, we’ll use the lsblk command. The syntax is easy.
An example output from that command would be:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 476.9G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
└─sda2 8:2 0 476.4G 0 part /
sdb 8:16 0 3.6T 0 disk
├─sdb1 8:17 0 991.1G 0 part /media/kgiii/elements1
├─sdb2 8:18 0 984.6G 0 part /media/kgiii/elements2
├─sdb3 8:19 0 976.7G 0 part /media/kgiii/elements3
└─sdb4 8:20 0 773.6G 0 part /media/kgiii/elements4
We are interested in the name section, which is sda* and we’ll be adding /dev to that name.
In this instance, we can see that there’s an efi partition and that efi isn’t an ext* formatted partition. So, that leaves us with sda2. As you learned earlier in this article, we could just run fsck against the root (the / partition) easily enough. So, in this article, we’re going to refer to sdb1 and you’ll apply it to your personal needs.
The syntax to enable fsck on system start is quite simple. I’ll give you an example:
sudo tune2fs -c <frequency> /dev/<drive_name>
So, let’s say we want to run fsck on sdb1 the next time we reboot. The command would look like this:
sudo tune2fs -c 1 /dev/sdb1
If I want to run this command every tenth time the system reboots, I can do that easily. I’d run this modified command:
sudo tune2fs -c 10 /dev/sdb1
You can schedule fsck easily this way, and apply it to different partitions without much additional effort. If you want to set it to check every 25 times, you can do that. You can just set it and forget it and then you’d have a slower boot time every 25 system starts because the system would be checking the drive(s) for errors.
When you’re done, you can disable this command easily enough. Just change the frequency to zero. If I were to disable fsck from running at system startup, I’d run this command:
sudo tune2fs -c 0 /dev/sdb1
That’s all there is to it. I’m sure you can manage. Hopefully, those directions are clear enough. If not, you can always ask questions!
Well, I didn’t expect I’d write a long article tonight. I expected it to be a short and easy article. You can see how that turned out. Though, if you ever need to enable fsck on system start, you now know how you can go about doing so.
Best of all, assuming I’ve done my job well enough, you’ll be able to do so easily and without mistakes. However, mistakes with just this won’t be too worrisome. I suppose the worst case is that you check your filesystem’s health more often than you want to. Even then, that’s easily corrected.
You might want to write down how to cancel it or remember this page so that you can return to remind you how to disable it. It’s not complicated and might even be stored in your bash history file so that you can reference it easily.
Either way, I hope you all had a happy Thanksgiving – if you celebrate. If you do not celebrate, I hope you had a happy Thursday! As for me and mine, it was a pretty good day. I have no complaints, other than there wasn’t a giant snowstorm to make things interesting.
Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.