How to check root partition with fsck?

137,691

Solution 1

sudo touch /forcefsck

Then reboot.

Solution 2

You can use shutdown command for this too.

shutdown -rF now

From man:

The -F flag means 'force fsck'.
This only creates an advisory file /forcefsck which can be tested by the system when it comes up again. The boot rc file can test if this file is present, and decide to run fsck(1) with a special `force' flag so that even properly unmounted file systems get checked. After that, the boot process should remove /forcefsck.

Solution 3

Here is another way to do this:

tune2fs -C 2 -c 1 /dev/THEDEVTHATROOTIS

reboot

then the filesystem will be checked, and once all is good you should do

tune2fs -c 60 /dev/THEDEVTHATROOTIS

I have assumed that the max-mount-count was set to 60, you should find out before issuing the first command with

dumpe2fs /dev/THEDEVTHATROOTIS |grep "Maximum mount count"

Solution 4

On my systems (several x86 notebooks and a Banana Pi Pro), saying sudo shutdown now brings me to runlevel 1 (aka maintenance mode) where I can safely check my root FS:

mount -o remount,ro /dev/rootpartition
fsck /dev/rootpartition
reboot

There's no need to alter /etc/fstab to do this, and I have the opportunity to run fsck with whatever options that may be needed to fix a tricky case.

Note: /forcefsck and tune2fs tricks work on x86, but not on Banana Pi.

Share:
137,691
Sproket
Author by

Sproket

Updated on September 18, 2022

Comments

  • Sproket
    Sproket over 1 year

    I installed Linux Mint 12 KDE, and I would like to check the root partition for any errors.

    How do I check the root partition with fsck at boot time?

  • Colin D Bennett
    Colin D Bennett over 10 years
    I tried this with Linux Mint 15 MATE and it didn't cause a check when rebooting. But sudo touch /forcefsck worked when I did that before sudo reboot.
  • THESorcerer
    THESorcerer over 9 years
    your answer is good and ... should work most of the time (I mean on most of standard installed Linux) BUT, you ASSUME that root partition is ext2,3,4 formatted, what if is something else like xfs or reiserfs ? :)
  • pabouk - Ukraine stay strong
    pabouk - Ukraine stay strong over 9 years
    shutdown supplied with Upstart does not support the -F option any more. You should use sudo touch /forcefsck instead. See for example Why was -F removed from /sbin/shutdown? and Bug #74139: shutdown missing -F (force fsck) option.
  • g24l
    g24l over 9 years
    True this is a 9/10 solution.
  • Daniel B
    Daniel B over 8 years
    It would be possible to make tune2fs etc work on any platform, given that a (possibly embedded) initramfs is supported. So it really just depends on the Linux distribution.
  • Francisco  Tapia
    Francisco Tapia over 8 years
    is linux mint 12, should work
  • Daniel B
    Daniel B over 8 years
    Could you please elaborate on these “modern Linux systems”, that are, in keeping with the question, Linux Mint?
  • Sopalajo de Arrierez
    Sopalajo de Arrierez about 8 years
    Answer not working for remote checkings.
  • Dmitry Grigoryev
    Dmitry Grigoryev about 8 years
    @SopalajodeArrierez Yeah, you need access to a local terminal in single user mode, hence the name.
  • FiftiN
    FiftiN almost 4 years
    Only working to me! Thank you!
  • Seppo Enarvi
    Seppo Enarvi over 3 years
    This works, but for whatever reason, systemd recommends to pass fsck.mode=force on the kernel command line instead. (A warning appears in journalctl -xb.)
  • kkm
    kkm almost 3 years
    Did it for me (Debian 10).
  • kkm
    kkm almost 3 years
    @SeppoEnarvi: the forcefsck is (was?) natively supported only by system V init, but neither upstart nor systemd. The support for it may be added by the distro (Debian and, therefore, Ubuntu, do). The solution you mention is distro-independent. Too bad it's not a simple business to pass anything on the kernel command line on a headless server or a cloud VM...
  • Pavel Niedoba
    Pavel Niedoba almost 3 years
    mount point is busy, ubuntu20