Run fsck -y everytime at startup on my main partition Linux

7,029

Solution 1

Are you using a particular distribution? On Debian based distributions it would be as simple as adjusting /etc/default/rcS and set FSCKFIX to yes.

If you want to force a full fsck after every boot, then you could simply write create an empty file named /forcefsck. Though I do not suggest you actually do this.

Solution 2

If there had been a power loss fsck will run anyway since the filesystem will not be marked as "clean". You can use tune2fs -c 1 /dev/sda to set the check-interval for ext2/3 to one. IMHO that should force an fsck on every boot.

Share:
7,029

Related videos on Youtube

Jonathan Henson
Author by

Jonathan Henson

Updated on September 18, 2022

Comments

  • Jonathan Henson
    Jonathan Henson over 1 year

    I have an embedded linux system. I use grub2 for the boot loader. I would like to run an fsck -y /dev/sda on /dev/sda every time it boots--even when the system had a power loss and the reboot command was not used. How can I do this?

    • ott--
      ott-- over 12 years
      Have you considered using a different boot medium like a flash device with jffs2 or ubi (if you could mod the hardware)?
    • Jonathan Henson
      Jonathan Henson over 12 years
      It is a transcend industrial 44pin flash module. I have the journaling setup and have the write caching turned off. I still get orphaned nodes sometimes though.
  • Jonathan Henson
    Jonathan Henson over 12 years
    It is debian based. This will cause it to happen before mounting each time?
  • Jonathan Henson
    Jonathan Henson over 12 years
    Also, will this pass -y to fsck?
  • Zoredache
    Zoredache over 12 years
    fsck is ran at every boot already, if the filesystem was unmounted correctly it runs very quickly. This change simply makes it so that the system will auto-repair anything that can be auto-repaired. Look at /etc/init.d/(checkfs.sh|checkroot.sh) to see the full details.
  • Jonathan Henson
    Jonathan Henson over 12 years
    thanks, I'll give this a try and let you know how it goes.
  • Jonathan Henson
    Jonathan Henson over 12 years
    will this clear orphaned nodes and fix datetime errors? fsck -y always does.
  • Avery Payne
    Avery Payne over 12 years
    +1, this is the correct way to do it. The system will be forced into a fsck on every restart, but that's pretty much what you're asking for.
  • 84104
    84104 over 12 years
    But does this work for non ext2/3/4 filesystems?
  • Jonathan Henson
    Jonathan Henson over 12 years
    @Nils I will try this, because Zoredache's solution still didn't work.
  • Jonathan Henson
    Jonathan Henson over 12 years
    Will this perform the check and fix all errors without user interaction?
  • Nils
    Nils over 12 years
    Normally not. in most distributions there are possibilities to pass extra options to fsck. For this you have to find the place where to put these. In CentOS/RH5 the script responsible for running fsck at boot is located at /etc/rc.sysinit - there are a number of hooks one could use there - but this is proably dependent on the distribution. My best bet is to do grep -Iw fsck /etc to find the script responsible for running fsck. If you found that, please post the script in your question.
  • Jonathan Henson
    Jonathan Henson over 12 years
    I don't believe fsck is being called each time because the boot screen is still hanging on a corrupted disk that could easily be fixed with fsck /dev/sda1 -y
  • Jonathan Henson
    Jonathan Henson over 12 years
    Nevermind, this is because I had everything on the same partition.