[ SOLVED ] Bash command to check system integrity ?

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
mIROUZ
Level 2
Level 2
Posts: 93
Joined: Sun Feb 19, 2023 6:37 pm

[ SOLVED ] Bash command to check system integrity ?

Post by mIROUZ »

Hi,
I sometimes use the "chkdsk" or "sfc /scannow" command line tools to check the integrity of my Windows system.
I would like to know if there are equivalent routine commands to verify/repair the complete integrity of a Linux system ?

Thanks for your tips.
Last edited by LockBot on Sat Sep 23, 2023 10:00 pm, edited 4 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
spamegg
Level 14
Level 14
Posts: 5038
Joined: Mon Oct 28, 2019 2:34 am
Contact:

Re: Bash command to check system integrity ?

Post by spamegg »

Yes, it's called fsck. You can read up on it in the manuals: man fsck

A short summary:

Code: Select all

 ➜ tldr fsck
fsck
Check the integrity of a filesystem or repair it. The filesystem should be unmounted at the time the command is run.More information: https://manned.org/fsck.

 - Check filesystem /dev/sdXN, reporting any damaged blocks:
   sudo fsck {{/dev/sdXN}}

 - Check filesystem /dev/sdXN, reporting any damaged blocks and interactively letting the user choose to repair each one:
   sudo fsck -r {{/dev/sdXN}}

 - Check filesystem /dev/sdXN, reporting any damaged blocks and automatically repairing them:
   sudo fsck -a {{/dev/sdXN}}
Here /dev/sdXN is something like: /dev/sda1 or /dev/nvme0n1p1. You can see them with lsblk.

Please note that in order to repair anything, the file system has to be UNMOUNTED.

You can automate this file system check to run at every boot: sudo tune2fs -c 1 /dev/sdXN but some might consider this overkill.
User avatar
mIROUZ
Level 2
Level 2
Posts: 93
Joined: Sun Feb 19, 2023 6:37 pm

Re: Bash command to check system integrity ?

Post by mIROUZ »

Thank you very much for your very comprehensive answer.
It will be very useful to me before each backup of the evolution of my system.
User avatar
mIROUZ
Level 2
Level 2
Posts: 93
Joined: Sun Feb 19, 2023 6:37 pm

Re: Bash command to check system integrity ?

Post by mIROUZ »

One more thing...

Do you know how I do to unmount my partition ?
Because hot it's impossible. And the recoverymode also does not want.
Maybe from a live boot ?
User avatar
spamegg
Level 14
Level 14
Posts: 5038
Joined: Mon Oct 28, 2019 2:34 am
Contact:

Re: Bash command to check system integrity ?

Post by spamegg »

Yes, live boot will work. tune2fs also works: it will do fsck right before mounting and booting. You can't unmount it when the system is already booted on that file system. All the other file systems (the ones that don't have the root /) can be unmounted. You can click on their triangle icons in the file manager:
Untitled.png
Untitled.png (11.69 KiB) Viewed 757 times
The Terminal command is umount:

Code: Select all

 ➜ tldr umount
umount
Unlink a filesystem from its mount point, making it no longer accessible.A filesystem cannot be unmounted when it is busy.More information: https://manned.org/umount.8.

 - Unmount a filesystem, by passing the path to the source it is mounted from:
   umount {{path/to/device_file}}

 - Unmount a filesystem, by passing the path to the target where it is mounted:
   umount {{path/to/mounted_directory}}

 - Unmount all mounted filesystems (except the proc filesystem):
   umount -a
User avatar
mIROUZ
Level 2
Level 2
Posts: 93
Joined: Sun Feb 19, 2023 6:37 pm

Re: Bash command to check system integrity ?

Post by mIROUZ »

How do I run Tune2fs ?
Hot or before boot ?
Because I didn't see any way to launch a pre-boot terminal...
Cosmo.
Level 24
Level 24
Posts: 22968
Joined: Sat Dec 06, 2014 7:34 am

Re: Bash command to check system integrity ?

Post by Cosmo. »

You misunderstood. Tune2fs itself does not do a file system check, but it enables you to set a frequency for automatic execution. As with the command I gave you the check gets done at boot time and anything different is impossible for partitions, which are needed for the system (at least the system partition). Several years ago regularly checks got done by default, but since some years this is assumed as senseless and only time consuming. If you really think, that regular checks are needed, I would no longer trust the hardware. Checks cannot prevent, that the hardware fails.
User avatar
mIROUZ
Level 2
Level 2
Posts: 93
Joined: Sun Feb 19, 2023 6:37 pm

Re: Bash command to check system integrity ?

Post by mIROUZ »

Aaah ok, ok thank you. I didn't understand, yes.
No, but it's just to check my system sometimes before making a backup.
I'm going to do this in live boot. It will be very good.
Thanks again.
Cosmo.
Level 24
Level 24
Posts: 22968
Joined: Sat Dec 06, 2014 7:34 am

Re: [ SOLVED ] Bash command to check system integrity ?

Post by Cosmo. »

Perhaps you are interested to read this: viewtopic.php?t=393884
User avatar
mIROUZ
Level 2
Level 2
Posts: 93
Joined: Sun Feb 19, 2023 6:37 pm

Re: [ SOLVED ] Bash command to check system integrity ?

Post by mIROUZ »

Thanks Cosmo, i will look.
At the same time I was looking for commands to specifically check the integrity of my software, not hardware.
The hardware can fail over time, I know, and the software also because of the hardware, precisely.
Just to make sure that my software is integrated to migrate it from hardware to hardware over the years.
So. Thanks again...
Locked

Return to “Software & Applications”