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.

Unzip .gz Files With gunzip

You can just as easily do this in a GUI, but we’ll be using the Linux terminal to unzip .gz files with gunzip. Why? Because we can! You never know when you’ll be limited to a terminal and need to extract the files found in a .gz file.

If you do some searching around the web, you’ll see that .gz files are made with gzip. If you do some more digging, you’ll learn that gzip is both a file type and the name of the application. The .gz files are referred to as gzip files.

While you may encounter just plain .gz files, you’ll often find them as ‘tar.gz’ files, meaning they’ve been prepared for tape archives. You can read about that here:

Let’s Decompress A File (tar.gz) In The Terminal

You won’t need to install anything for this article. The tools will be installed on any major distro – and even on most minor distros. Gzip has been around for more than 30 years, at the time of this writing, and is widely used – even though there are many other compression tools out there. The .gz format is not patent encumbered, nor is it proprietary.

We’ll be using gunzip to unzip .gz files. If you check the man page, you’ll see:

gzip, gunzip, zcat – compress or expand files

As you can see, that means it is the right tool for the job. You can just as easily use ‘file-roller’ in your GUI to unzip .gz files. You have choices!

It’s currently a Sunday evening and my last few articles have been quite long. I think we’ll keep this one short. I might as well…

Unzip .gz Files With gunzip:

As I mentioned earlier, you can do this with a GUI application. We’ll be unzipping .gz files in the terminal. Just press CTRL + ALT + T to get your terminal open and we can begin.

The first thing you need is a .gz file.

Download example.gz here: Link

With that freshly downloaded, you can use cd to get to your ~/Downloads directory (or whichever directory you used):

Now, you can simply extract the contents, like so:

If you want to extract multiple .gz files at one time, try this:

If you want to extract all the .gz files in a folder, try this command:

There you have it. That’s all you need to know if you want to unzip .gz files with gunzip. It’s not even a little complicated. Anyone can figure this one out.

Closure:

I wasn’t kidding when I said I’d keep this one short. There’s no reason to make it all that long and it’s a weekend. It’s also a holiday weekend and you got a lovely article on Saturday. This one is just a simple task, for those who might want to unzip ..gz files with gunzip – in the Linux terminal. It’s pretty easy!

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.

Block A Specific Port In Linux Mint

If you’re using Linux Mint, you’ll find you have ufw already installed which means it’s easy to block a specific port in Linux Mint! I’ll explain how to do that in this article and do what I can to make it easy enough for a new Linux user to follow. If this interests you, read on!

You might want to block a port for all sorts of reasons. If you’re open to the public web via your router, you might find bots hammering at the default ports (such as 22 for SSH) trying to find the login credentials, even if none exist. This is unnecessary traffic and can cause the system to slow down if it’s overwhelmed with connection requests.

Also, Linux uses a lot of ports. There are a bunch that are reserved, for example. You can also designate your ports for many things. I’ve written articles about ports before, so here’s some light reading material:

How To: Check If A Specific Port Is Open
How To: Scan A Remote Host For Open Ports
Find Out What Process Is Listening On A Specific Port
Prevent Brute-Force SSH Attacks With fail2ban

About Ports:

Now, I think I’ll let an AI tell you what a port is in Linux.

A Linux port is a virtual concept that helps access different services within a network. A port is a 16-bit integer ranging from 0 to 65535 with no physical existence.

A port acts as a communication endpoint for identifying a given process or application on the Linux operating system. A port is a 16-bit (o to 65535) number that differentiates a single application from others on various end systems.

As the blurb says, these are virtual ports. They’re not like the physical ports on your router, or anything like that. They’re used for communication and sending traffic to a specific port is asking for traffic on that port. 

If you have nmap installed, you could run nmap localhost to find out which ports are open on your computer. You probably should run that command (you’ll need to install nmap with sudo apt install nmap before you can run this command in Linux Mint). If the port isn’t open, then you don’t need to block that specific port.

UFW:

Linux Mint comes with ‘ufw’ already installed. It is not enabled by default, however. It’s good that it comes installed, which means it’s almost ready for use and you only need to enable ufw for it to be of use. If you don’t know what ufw is, you can check the man page with man ufw to learn more. For simplicity’s sake, you’ll find that ufw is described as:

ufw – program for managing a netfilter firewall

We will be using ufw to block a specific port in Linux Mint. You’ll learn that ufw stands for “Uncomplicated Firewall” and is a frontend for iptables. You can do anything with iptables that you can with ufw, but ufw is much easier for a new Linux Mint user. It doesn’t need to be complicated, as you’ll see in this article.

Use UFW To Block A Specific Port In Linux Mint:

While there is a GUI front-end for ufw, we won’t be using that. Instead, we’ll just use the installed terminal and ufw. As you’re using Linux Mint, you can open your default terminal by pressing CTRL + ALT + T.

With your terminal now open, we first need to enable ufw because ufw is not enabled by default. To enable ufw, run the following command:

That will enable ufw on system startup. That command should output something that looks like this:

You can later disable ufw if you find you no longer wish to use it. That command would look like this:

Now, to block a specific port in Linux Mint with ufw, the syntax would be easy enough to figure out. It just looks like this:

If you want to block the default SSH port (port 22) then you can do that like so:

If you change your mind at a later date, the command to undo this would be:

All you need to do is remember ‘deny’ and ‘allow’ and that ufw commands require elevated permissions which means you need to use sudo. If you can remember that, you can block and unblock specific ports in Linux Mint!

Closure:

Yes, this article is about blocking a specific port in Linux Mint with the ufw command, but it applies to many other distros. I just happened to be using Linux Mint when I wrote the article and didn’t want to test on other systems before smashing the schedule button. So, I wrote it specifically for Linux Mint. This will likely be an accurate tutorial for Ubuntu, the official Ubuntu flavors, other Ubuntu derivatives, and maybe Debian. I’m not sure about Debian.

And now you know…

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.

How To: Enable NTP In Linux

Time is very important to the Linux operating system so keeping accurate time is important, which is why we want to enable NTP in Linux. This won’t be a major article and it should be simple enough to follow along. It’s pretty easy to enable NTP in Linux.

If you don’t know, NTP stands for Network Time Protocol. This allows your computer to connect to a networked device that tells your computer the accurate time and then syncs your computer’s clock with that accurate time.

This networked time server is usually just on the public web, but you could do things like run your own NTP server with a GPS device. (GPS uses really, really, really accurate time. In fact, that really accurate time is how GPS works.) Your company may even run its own NTP servers, but there are plenty of public servers available.

While we’re on the subject, your Linux computer keeps time in a very funny fashion. It counts the seconds since the epoch. The “UNIX Epoch” is an arbitrary date and time. Specifically, it counts the seconds since January 1st, 1970 at 00:00:00 UTC. I’ll write an article on the subject at some point. It is also sometimes referred to as “POSIX Time”. In the meantime, you can always look it up at your favorite search engine. 

Time is very important to Linux. After all, the kernel is a task scheduler. It’s also important for accurate record keeping, among other things. It’s also not difficult to enable NTP in Linux.

NOTE: This article assumes you’re using systemd, as most mainstream distros do. If this isn’t true, this article isn’t for you.

Enable NTP In Linux:

Yes, this is another article that requires an open terminal. You can usually just press CTRL + ALT + T to open your default terminal. If that’s not true, fix the keybindings!

If you’re a desktop user, you can probably skip this article. If you’re a desktop Linux user, odds are good that your distro came preconfigured to sync the time already. Let’s go ahead and verify that with this command:

What you’re looking for is these lines:

You’re especially interested in the last line. If that line says that the NTP service is active, you can ignore this article and read one of the prior articles on the timedatectl command:

How To: Find Your Timezone In The Terminal
How To: Change The Timezone

If the NTP service is not active, you can start the service with this command:

That’s all you need to do to enable NTP in Linux.

If you want to disable NTP, that’s just as easy. That command looks like this:

Next, you can run this command to confirm that you’ve enabled NTP:

That should output information that says the NTP service is active. It may not say that the clock has synchronized as that may take some time before the scheduled task runs and syncs your time with a dedicated time-keeping server.

If you want to muck about with the settings, they’re viewed here:

You’d edit that file with Nano, or some other terminal text editor. Before doing so, you should first read the man page, with this command:

There you go! You can enable NTP in Linux!

Closure:

It seems that I’ve developed a few different styles for my article writing. Longer articles get treated differently, as in they’re formatted differently. The shorter articles have been formatted like this for quite a while. I think that’s a comfortable mix, though it is (as always) subject to change. As I learn and grow, so too may the formatting.

Anyhow, this seemed like a fun article to write. I doubt it’ll be all that popular. It’s unlikely to rank all that well in the search engines. Still, it’ll be information that’s on the site, and the more information I have the better I think I’ll be doing.

It’s not always about the traffic. Indeed, it was never really about the traffic. The traffic is secondary. My primary objective is to share information. Today’s article covered how to enable NTP in Linux. Further, it is limited to just those who use systemd.

Most of my readers will have no use for this information. But, there will be someone – and maybe only that one someone – who will find this information and need it to enable NTP on their Linux device. Good. To that reader and my regulars, I say thanks for visiting.

Now my usual blurb at the bottom of every 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.

Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.