Outils pour utilisateurs

Outils du site


issue208:mon_opinion

Ceci est une ancienne révision du document !


One of our readers sent us a letter (FCM#207) stating that you can no longer force fsck on Ubuntu, and honestly, it has been so long since I have used it personally, I thought it may be a good idea to refresh people’s memory regarding fsck. (I did do this recently for my cousin over the phone, but he still uses 18.04). If you are a n00b, you will find this interesting, so stick around. We have been spoiled with journaling file systems, because they rarely need the fsck touch.

I suggest opening the fsck man page and looking at the exit codes. Mostly you need to know about 0,1,2,4.

Now fsck is like a blanket term, behind the scenes it invokes, say, fsck.ext4. Think of them as a family of commands, where you can specify what you need. For instance, I use ext4, so I can say:

fsck.ext4 /dev/sda1

or just:

fsck /dev/sda1

Tip: You can see them all by typing: ls -l /usr/sbin/fsck*

If you come from a Windows background, and most of you do, then think chkdsk. You used to run it with -f now -p (I think; I also have not done it in years). Just keep it in the back of your mind, we will touch on that again.

For n00bs: open your gnome-disks utility and look below the drive. You should see what file system you are using, under “Contents” eg:

Reminder: do not try to run fsck on mounted drives!

For n00bs: to see if your drives are mounted, run lsblk (you can also use df, but lsblk is cleaner).

My disk has a mount point, so if I were to try fsck, it will warn me (see below)

As with Windows chkdsk, you can use -p to basically tell fsck to go ahead and automatically fix errors, without you having to click yes to each repair. (I’ll have to check if this is still the case, as it is not listed in the man page.) Prior Windows used chkdsk -f (windows before NT, iirc) to check and fix the drive automatically, but in Linux, the -f is FORCE, so be very careful when tacking on an option. This forces a check, even if the file system is marked clean.

Other notable tacks are -y, -n -c: -y being “yes to everything”, -n being “no to everything” and -c being “show completion bar”.

Example: (I have an NVME in my laptop, but the process is the same for mechanical drives): • list with lsblk • unmount partition with umount • confirm with lsblk • check drive with fsck (you need to be root)

As you can see from my “exit code” that we talked about, right at the beginning, my drive is fine.

I know my drive is fine, so I expected 0 as an outcome. If you suspect errors on your drive, your desired outcome is 1. If you see 4, you need to worry.

Now, the mount root “/” is different.

In older versions of Ubuntu, you could type: sudo touch /forcefsck and reboot. You could also boot into recovery mode and select the fsck option.

Another way is to use tune2fs, or I should say the modern way, as forcefsck no longer works in Ubuntu from 20.04 onwards. (I’ll add a link at the end of the article).

The man page for tune2fs is a spaghetti jumble, that no new user should try and traverse, I just had a look and found the skeleton of a user from 2014 still stuck in there. Tune2fs is a great tool, but it is like a Swiss army knife when all we need is a flat head screwdriver.

If you did look at the man page, the only flag we are interested in is the first one, -c (count how many times a drive is mounted before checking). We are not going to dive in here, as I still have to sleep sometime. Armed with what you now know, you can run a check.

sudo tune2fs -c 1 /dev/nvme1np (in my laptop)

sudo tune2fs -c 1 /dev/sda1 (in my old box)

The recipe for you is:

sudo tune2fs -c 1 /dev/<YOUR DRIVE>

Reboot.

Ok all fine and dandy, but how can you check to see when the last drive was checked?

sudo tune2fs -l /dev/nvme1n1p1 | egrep -i 'check|mount'

(replace nvme1n1p1 with your drive – if I have to keep posting images, Ronnie will swear at me and you guys are a bright lot…).

Bonus:

How to set up regular checks, with the -i flag: (interval)

“sudo tune2fs -i 1w /dev/nvme1n1p1” – this would set it to check every week (on my drive). You can replace that, say with 1m, for every one month, 2w, every two weeks and so on and remember to change the drive name to yours if you are copying from the magazine.

I hope we simplified it for you, (I think it is short ‘n to the point) if not, look here: https://askubuntu.com/questions/1352774/how-to-force-fsck-on-reboot-for-ubuntu-20-04

Again, thanks to our wonderful readers for pointing out our mistakes, without you we would be Windows (L)users! :)

Let us know: misc@fullcirclemagazine.org

issue208/mon_opinion.1725107600.txt.gz · Dernière modification : 2024/08/31 14:33 de auntiee