Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

How to Fix fsck Not Running on Startup in Linux Systems

How to Fix fsck Not Running on Startup in Linux Systems

Ensuring that fsck (file system check) runs automatically on startup is crucial for maintaining the integrity of your Linux file systems. When the system boots, fsck scans and repairs disk errors that might otherwise cause data corruption or system instability. Sometimes, however, fsck does not run as expected during boot, which can leave your file systems vulnerable. This guide will walk you through diagnosing and fixing the issue so your system runs fsck properly at startup.

What You’ll Need

  • Root or sudo access to your Linux system
  • Basic familiarity with the command line and system configuration files
  • Access to a terminal or console during boot (if recovery mode is needed)

Step-by-Step

  1. Verify the file systems and their settings: Run sudo blkid or lsblk -f to identify your partitions and their file system types. Confirm which devices need checking.
  2. Check the /etc/fstab file: Open /etc/fstab with sudo nano /etc/fstab or your preferred editor. Look for the sixth field in each line, which controls the fsck order and whether the file system is checked at boot. Typical values are 0 (no check), 1 (root file system), or 2 (other file systems). Make sure your important partitions have 1 or 2 as appropriate.
  3. Force a file system check on next reboot: You can create an empty file named /forcefsck by running sudo touch /forcefsck. This instructs the system to run a full fsck on all file systems at the next boot.
  4. Review systemd’s fsck behavior (if using systemd): Most modern Linux distributions use systemd, which manages fsck jobs. Check if systemd-fsck-root.service and systemd-fsck@.service units are enabled by running systemctl status systemd-fsck-root.service. If disabled, enable them with sudo systemctl enable systemd-fsck-root.service and sudo systemctl enable systemd-fsck@.service.
  5. Inspect kernel parameters: During boot, kernel parameters can influence fsck behavior. Check your bootloader configuration (e.g., GRUB) in /etc/default/grub for parameters like fsck.mode=skip or fastboot, which skip checks. Remove or adjust these to allow checks. After editing, update GRUB with sudo update-grub (Debian/Ubuntu) or the equivalent for your distro.
  6. Check the fsck pass count with tune2fs: For ext2/3/4 file systems, the tune2fs tool controls the maximum mount count and check intervals. Run sudo tune2fs -l /dev/sdXn (replace with your device) and look for Mount count and Maximum mount count. If the maximum mount count is set very high or disabled (-1), fsck may never run automatically. Set a reasonable max count with sudo tune2fs -c 30 /dev/sdXn to force checks every 30 mounts.
  7. Reboot and monitor fsck: Restart your system with sudo reboot. Watch the boot messages or use the recovery console to confirm that fsck runs on your partitions.
  8. Check system logs if fsck does not run: After boot, examine logs using journalctl -b or dmesg to look for messages related to fsck or file system checks.
  9. Manually run fsck if necessary: If automatic checks still fail, boot into recovery mode or a live CD/USB and run sudo fsck /dev/sdXn manually on your partitions to repair errors.
  10. Ensure proper shutdowns: Frequent unclean shutdowns can trigger fsck more often. Avoid forced power-offs and ensure your system shuts down cleanly to prevent unnecessary fsck skips or failures.

Common Mistakes

  • Setting the wrong fsck pass number in /etc/fstab: Using 0 disables checks; forgetting this leads to fsck not running.
  • Ignoring systemd services: On systemd-based systems, disabling or masking fsck services prevents them from running.
  • Misconfiguring bootloader parameters: Kernel options like fastboot or fsck.mode=skip are often overlooked but override fsck behavior.
  • Assuming manual fsck fixes auto check issues: Manually running fsck does not re-enable automatic checks if configuration is incorrect.
  • Not updating bootloader after changes: Failing to run update-grub or equivalent means changes won’t take effect.

Tips

  • Use systemctl status systemd-fsck@dev-sdXn.service to check fsck status on specific devices.
  • Keep backups before forcing fsck or making changes to file system parameters.
  • Set tune2fs parameters conservatively to avoid overly frequent checks that slow boot times.
  • Use the shutdown or reboot commands properly to prevent unclean shutdowns that complicate fsck behavior.
  • Consult your distribution’s documentation as some distros customize fsck behavior or use alternative tools.

Troubleshooting

If fsck still does not run on startup after following the above steps, consider the following troubleshooting strategies:

  • Boot into recovery or single-user mode: Interrupt the boot process and select recovery or single-user mode. From there, manually run fsck on your partitions to check for errors that prevent automatic checks.
  • Check for broken or corrupted file systems: Severe corruption may prevent fsck from running automatically. Manual intervention or rescue tools may be required.
  • Review system logs thoroughly: Use journalctl -b -1 to see logs from the previous boot. Look specifically for fsck-related errors or messages indicating why checks were skipped.
  • Verify initramfs or initrd configuration: Some systems run fsck from the initial RAM disk environment. Rebuild your initramfs with sudo update-initramfs -u (Debian/Ubuntu) or equivalent if corrupted.
  • Check for hardware problems: Disk errors or failing drives can cause fsck to fail silently. Use SMART tools like smartctl to assess disk health.
  • Disable conflicting services: Certain custom scripts or third-party tools may interfere with fsck. Temporarily disable them to isolate the problem.

Frequently Asked Questions

Why doesn’t fsck run automatically on some partitions?

If the /etc/fstab entry for a partition has a pass number of 0, fsck will skip checking it. Also, if the maximum mount count or check interval is set to disable checks, fsck won’t run automatically.

How can I force fsck to run on every boot?

Create an empty file named /forcefsck in the root directory using sudo touch /forcefsck. The system will run fsck on all filesystems during the next boot.

Does systemd handle fsck differently than traditional init systems?

Yes. systemd uses dedicated services like systemd-fsck-root.service to manage fsck. Ensuring these services are enabled is important for automatic checks.

Can fsck damage my data?

While fsck is designed to fix file system errors, in rare cases it can cause data loss when repairing severe corruption. Always back up important data before running fsck.

What does the sixth field in /etc/fstab control?

The sixth field determines the fsck order and if the file system is checked at boot. A value of 0 disables checking, 1 sets the root partition to check first, and 2 is for other partitions.

Why is fsck skipping checks despite having correct fstab settings?

Kernel boot parameters like fsck.mode=skip or fastboot can override fstab and skip fsck. Also, systemd service settings or masked fsck units can cause skipping.

By following this comprehensive guide, you can diagnose and resolve why fsck is not running on startup, improving your system’s reliability and file system health.

Related

How to Fix fsck Not Running on Startup in Linux Systems
Scroll to top