I mean I'm already here right. If not, why?
1 Answers
No.
Do not run fsck on a live or mounted file system. fsck
is used to check and optionally repair a Linux file systems. Running fsck
on a mounted filesystem can usually result in disk and/or data corruption.
Outdated method (SysVinit/upstart based, Ubuntu before version 15.04):
This will force a check on next boot:
sudo touch /forcefsck
So will this but it will also reboot the machine at the moment you hit enter:
shutdown -rF now
There are more ways (like telling the machine to go to init 1
and then umount the partition/disc your want to check) but these 2 are the easiest.
Nowadays (systemd based systems, Ubuntu 15.04 and later) we can use
sudo tune2fs -c 1 /dev/sdX
replace sdX
by your partitions device name. 1 is the amount of boots for it to do a new filesystemcheck (so 1 is every time. 10 would check every 10 boots. 0 or -1 disables it).
So after the boot do
sudo tune2fs -c 0 /dev/sdX
to disable it.
Example:
rinzwind@discworld:~$ sudo tune2fs -c 1 /dev/nvme0n1p3
tune2fs 1.47.0 (5-Feb-2023)
Setting maximal mount count to 1
rinzwind@discworld:~$
Using it on a device with the wrong filesystem errors out:
inzwind@discworld:~$ sudo tune2fs -c 1 /dev/nvme0n1p1
tune2fs 1.47.0 (5-Feb-2023)
tune2fs: Bad magic number in super-block while trying to open /dev/nvme0n1p1
/dev/nvme0n1p1 contains a vfat file system
(that is the /boot/EFI one ;) )

- 107,489

- 299,756
sudo touch /forcefsck
only works with the old SysVinit and early versions of Upstart, it won’t work with systemd – dejanualex Aug 25 '21 at 13:21