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:
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
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:
1 | lsblk --version |
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:
1 | umount --version |
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:
1 | fsck --version |
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:
1 | lsblk |
You’ll get an output similar to this one:
1 2 3 4 5 6 7 8 9 10 11 | kgiii@kgiii:~$ lsblk 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 sr0 11:0 1 1024M 0 rom |
You can also run:
1 | sudo fdisk -l |
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:
1 2 3 4 5 | Device Start End Sectors Size Type /dev/sdb1 2048 2078517247 2078515200 991.1G Linux filesystem /dev/sdb2 2078517248 4143280127 2064762880 984.6G Linux filesystem /dev/sdb3 4143280128 6191525887 2048245760 976.7G Linux filesystem /dev/sdb4 6191525888 7813967871 1622441984 773.6G Linux filesystem |
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:
1 | sudo umount /dev/<device_ID> |
Then, you can just run fsck against the filesystem’s device ID, like so:
1 | sudo fsck -p /dev/<device_ID> |
For example, I could run:
1 2 | sudo umount /dev/sdb1 sudo fsck -p /dev/sdb1 |
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:
1 2 3 | Device Start End Sectors Size Type /dev/sda1 2048 1050623 1048576 512M EFI System /dev/sda2 1050624 1000214527 999163904 476.4G Linux filesystem |
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.