Repair Your Filesystem With FSCK

Over the years, we’ve covered the fsck command fairly extensively but I’ve never really written an article about how you repair your filesystem with fsck. This may very well be the last time we have an fsck article on this site. It seems like I’ve covered everything you need to know.

This article is about using fsck when you’re booted into your operating system. You can’t run fsck against a mounted drive. So, if you want to check and repair your root filesystem, the following article may be of assistance:

Repair Your Linux Filesystem With a Live USB or DVD

That’s a fairly popular article, as it ranks well in search engines. I’ve also recently authored this article:

Enable fsck On System Start

This article will be fairly simple and reasonably short. We’ll see if that turns out to be true, ’cause I wrote this before I finished the article! We shall see!

The Tools:

You’ll only need a couple of tools to repair your filesystem with fsck. First and foremost, you’ll need a terminal. I’ll assume you have a terminal. All the tools in this article will require an open terminal. You can usually press CTRL + ALT + T to open your default terminal.

You will also need…

lsblk:

The lsblk application is the first tool we’ll be using. Using lsblk is how we’ll identify your partitions. You almost certainly won’t need to install anything as this is one of those tools installed by default. You can verify that lsblk is installed by running:

If you check the man page, you’ll see that this is indeed the tool for the job.

lsblk – list block devices

See? We want to list block devices – that will show us the partitions and various filesystems.

umount:

The next tool we’ll use is the umount command. You can’t run fsck against a mounted filesystem, so we’ll need first to unmount the devices before we can repair them with fsck. You can verify that umount is installed with this command:

Again, we’ll check the man page to ensure that this is the correct tool for the job.

umount – unmount filesystems

See? I wouldn’t steer you wrong. This is the tool we need to unmount filesystems before we use fsck, the next tool, to repair filesystem errors.

fsck:

This is the tool we’ll be using. We’re going to repair your filesystem with fsck, assuming your filesystem needs to be repaired. This must be a Linux filesystem, meaning Ext2, Ext3, Ext4, etc… You’ll need other tools for filesystems otherwise formatted. Once again, you can verify that fsck is installed with the following command:

Again, if we check the man page, you’ll see that this is the right tool for the job.

fsck – check and repair a Linux filesystem

I’d say that these are the best tools we can use for today’s task.

Repair Your Filesystem With FSCK:

I gave instructions above that told you how you can usually open your terminal. That keyboard combination is not true with every distro and I don’t know why. It seems to me that it should be a standard. If you’re using such a distro, you can open your terminal from the application menu.

With your terminal open, we first need to identify your filesystems. You can do that with the following command:

You’ll get an output similar to this one:

You can also run:

That has the added benefit of showing limited information and which filesystems are identified as Linux filesystems. I use lsblk above because I use that often and want a consistent set of directions across the site. However, an example output from the above command would contain information like this:

You can run that command if you prefer. You may have to scroll up to see all of the information. In the output I shared above, you’ll notice that it didn’t include any information about /dev/sda* filesystems. As those are mounted and need to be mounted (in my case) it doesn’t matter.

At this point, you need to identify the filesystem you want to check. If you use the first command, you’ll need to remember to add /dev to the front. So, it’s not sdb2, it’s /dev/sdb2. If you use the second command, it gives you that information.

Now, we’re just going to automatically check for problems and repair them with fsck, but first you need to unmount the filesystem. To do that, you just run the following command:

Then, you can just run fsck against the filesystem’s device ID, like so:

For example, I could run:

With the -p flag enabled, it will automatically check the filesystem for errors and repair them – unless they’re really serious. If they’re serious errors, it will ask you what to do.

NOTES:

Unfortunately, I don’t have any filesystems that need to be repaired. Linux is rather robust and our filesystems are usually fairly healthy. If you suffer from random reboots without properly shutting down, you might have a different experience.

When you’re done with this, you can remount the filesystems you checked for errors. Frankly, that’s a whole other article. If you open your file manager, the GUI one, you can often mount filesystems right from there. You can also unmount them, but we did that right there in the terminal.

Again, you can’t unmount your root partition or any other important partitions. If you use separate partitions like /home or /dev, you’ll need to use a live USB to repair those mounted filesystems. This command will only work with Linux filesystems. It is not going to work with FAT, EXFAT, NTFS, etc., it will only work with Linux filesystems.

That might be a good reason to run the 2nd command ( sudo fsck -l) where you’ll get an output like this:

Look at /dev/sda1, where it properly identifies the type as an “EFI System”. That means that it’s not a supported filesystem and fsck will do you no good when you target it. I figure you’re smart enough to know the differences and what you have used, so lsblk is easier – and more consistent as we use that command frequently here on Linux-Tips.us.

Closure:

Well, it turns out that I was mistaken. I thought this was going to be a quick and easy article. I think it’s easy enough, but it wasn’t very quick. It has been a mixed bag lately as I play around with the formatting of various articles. This often makes them longer, but I’m okay with that. Plus, I type quickly!

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.

Enable fsck On System Start

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:

Repair Your Linux Filesystem With a Live USB or DVD
How To: Check A Disk For Errors
A Couple More Ways To Find Your File System Type

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.

lsblk:

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 CTRL + ALT + T and let’s get started learning how to enable fsck when you start your system up.

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:

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:

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:

So, let’s say we want to run fsck on sdb1 the next time we reboot. The command would look like this:

If I want to run this command every tenth time the system reboots, I can do that easily. I’d run this modified command:

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:

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!

Closure:

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.

A Couple More Ways To Find Your File System Type

Today we’re going to revisit a previous subject and share a couple more ways to find your file system type. I’ve covered this subject before, but I only shared a couple of ways. This being Linux, there are multiple file system types and multiple ways to find the details. So, let’s cover it again but with different options.

If you did your installation manually, you probably already know this information. You probably know the file system types you chose to use during the installation process. On the other hand, if you did your installation by just letting the installer use the defaults, you might not know this information. This may also be something like an unknown computer you’re tasked with fixing. So, there are real-world reasons why you might want to know the file system types in use.

If you want to visit the previous article, you can find that here:

How To: Find The File System Type

You could easily have multiple file system types in use right now. This is quite likely if you’re dual-booting with Windows or you’re using EFI as your boot method. You could even have external disks formatted in all sorts of file types.

All of these various file types may need specific commands to repair them and maintain them. You don’t want to go using the wrong tool for the wrong file type. That’d likely make your problems even worse. So, this is good information to have and this article will show you how to find your file system type.

Find Your File System Type:

This requires an open terminal. Like many of these articles, we’ll be using a terminal. It’s painless and it’s a good idea to know some of these commands. The terminal is fairly universal, so you can open your terminal (usually) by pressing CTRL + ALT + T.

In the previous article, we used lsblk and we also used df. Those are both excellent tools and excellent ways to get this information. They’re simple and easily memorized. The two commands we’ll use today will be similar in those regards. This truly is not a complicated task, it’s just fun to cover the different methods that one could use.

Using The mount Command:

The first command we’re going to learn about is the mount command. Don’t worry, this is part of your standard installation and you won’t need to do anything extra to use it. You can check the man page with man mount if you’d like. If you did do so, you’d find that the mount application is described as:

mount – mount a filesystem

No, we won’t be mounting and unmounting anything. We’ll just be using the command to find your file system types. That command’s syntax would look like this:

That’s the command that will show you all of your drives and all of the drive’s file system types in one go. I plugged a couple of external drives in so that I could run the command and show you the expected output:

using the mount command to find the file system type
You can see that there are vfat and ext4 file systems in use. That’s normal. It’s all good!

There’s nothing too eccentric in that output. Those are fairly normal file systems as far as Linux systems go. There are more. There are many more. You can check a list of file system types on Wikipedia.

Using The fsck Command:

Yes, you can even use the fsck command to find the file system types. You’re telling the command to not actually run and just spit out some information, so there’s nothing laborious or complicated with this command. You will need to know the path to the disk in question. I’m sure you know how to do that. Heck, the first command in this article will do that for you.

When you do this with the fsck command, you’re doing so on a disk-by-disk method. If you’re unfamiliar with the fsck command, you can check the man page with man fsck. Once again, you won’t have to install anything. The fsck command is a part of the standard base, files you’ll find on pretty much every distro by default. Anyhow, the man page describes fsck as:

fsck – check and repair a Linux filesystem

We will not be repairing a Linux filesystem (I’ve intentionally stylized this as ‘file system’ as it appears both spellings are in common usage) but we will sort of be checking them. We won’t be checking them for errors because that’d take too long and isn’t a part of this article. If you do want to check your file systems for errors with fsck, you should read this article:

How To: Check A Disk For Errors

Or maybe this article:

Repair Your Linux Filesystem With a Live USB or DVD

Anyhow, if you want to find your file system type with fsck, the syntax is simile and is as follows:

This is usually going to start with a /dev and then the drives populate  (enumerate?) as is logical. You would have drive sda, then partitions on that drive might be sda1, sda2, etc… So, an example command might be:

An example output is as follows:

you can use the fsck command to find the file system type for a specific drive
This only really works on one drive/partition at a time. That’s plenty useful.

See? Pretty useful if you need to know a file system type before working on it.

Closure:

So, we’ve covered a couple of new ways for you to find your file system type. This time around, we’ve used fsck and mount and both of them are perfectly useful for this application. If you work on multiple computers, if you work on someone else’s computers, if you work on remote computers, etc. then these commands may come in useful. 

Plus, this seemed like a fun article to write. There are all sorts of older articles that could have more information added to them. Some of the older articles contain errors that should be fixed. Some could use being written again but with a more suitable format.

A couple of the articles are just plain garbage and should have been deleted. They weren’t… They should have been, but they weren’t. I should probably go back and write those over again in their entirety. I’ve completely blown it a few times. I do like to point out that I probably learn more than you do by writing these articles and (importantly) getting feedback on them. I do love some feedback, though it’d be cool if it was left here when it adds something to the article.

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.

Repair Your Linux Filesystem With a Live USB or DVD

It’s possible for your filesystem to become so corrupted that you can’t repair it easily. In that case, you can repair your Linux filesystem with a live USB or DVD.

Your filesystem may become corrupted for any number of reasons. One of the most common reasons is an improper shutdown, where your filesystem doesn’t have time to properly write everything to disk because it wasn’t shut down properly. You might see that sort of thing when you suffer from a power outage. 

There are any number of reasons why your filesystem will have become corrupted and, in most instances, your system will automatically repair your Linux filesystem when you boot your computer.

It’s also possible that a simple boot won’t repair your Linux filesystem. In that case, your OS probably has some sort of recovery mode and you can use that mode to repair your filesystem. 

Once in a while, your filesystem may have become so corrupted that you can’t fix it in recovery mode because you can’t get to recovery mode to fix it. Not to worry. This is something you can easily do with a live USB or DVD.

This article assumes you already have a USB or DVD with an OS that runs live. I’ll use Ubuntu as the example OS, as it’s really common. Adjust for your distro and you’ll be okay.

Here’s a link if you need to know how to access your temporary boot menu

NOTE: If you’re using Btrfs, you shouldn’t need to run fsck, it should heal itself. If not, here are Btrfs-specific commands that you should learn.

Repair Your Linux Filesystem:

The first thing you’re going to do is boot to the USB or DVD. You’ll need to be patient as the live instance loads into RAM. Once the OS has loaded to a GUI, you’ll want to select “Try Ubuntu”. (Remember to adjust that for your own distro, should you not be using Ubuntu.)

Again, this will take a minute – especially on older hardware. Eventually, the GUI will load and you’ll have a functional live instance running. If you needed to use nomodeset, acpi=off, or anything similar, you’ll probably also need to use those things to get the live instance of Linux running.

The tool we’re going to use is known as ‘fsck‘, which is a tool in and of itself and a front end for other tools. fsck interacts with more specific tools for your specific filesystem, but that’s not important right now. 

If you’re curious, fsck stands for ‘file system consistency check‘ and the man page helpfully describes it as:

fsck – check and repair a Linux filesystem

Now that you have a functional live desktop, it’s time to repair your Linux filesystem. The first step is, as is often the case, opening up your terminal. You can use your keyboard to do this, just press CTRL + ALT + T and a terminal should pop right up.

At this point, you’ll want to identify the correct disk. To do that, you run:

You’ll want to identify the disk where you installed Linux. That’s the disk that has the corrupted filesystem that is preventing you from booting. It’s often something like ‘/dev/sda1’ or maybe even ‘/dev/nvme0n1p1’.

Once you have the disk identified, it’s time to repair your Linux filesystem. Enter this:

NOTE: Change the /dev/sda* to match the data from the fdisk command you ran earlier.

That ‘fsck’ command should find and fix any errors automatically. If you really know what you’re doing, you can run ‘fsck’ manually and maybe do a better job than the automatic method. Then again, if you know that much then I’d suspect you don’t actually need this article.

This shouldn’t take very long to run, unless there were a whole lot of errors. Next, all you need to do is reboot and you should find that you were able to successfully repair your Linux filesystem. To do that from the terminal, you can just type:

When prompted, remove the disk from the drive and press the ENTER button.

Closure:

There you have it, another way to run fsck and to repair your Linux filesystem when it is broken. This method works even when the recovery mode will have worked.

Thanks for reading! If you want to help, you can buy some cheap hosting, unblock ads, donate, sign up for the newsletter (below), write an article, leave a comment, register to help, or just vote for the article below and leave a comment!

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.