You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已设置FSCKFIX=yes,Ubuntu仍未自动执行fsck,如何实现遇错自动强制fsck -fy?

Automatically Force fsck -fy on Ubuntu When Filesystem Errors Occur

Got it, let's work through getting Ubuntu to automatically run fsck -fy whenever it hits that "UNEXPECTED INCONSISTENCY" error—even when your existing FSCKFIX=yes setting didn't kick in.

First, let's clarify why your initial FSCKFIX=yes in /etc/default/rcS might not have handled the issue: that setting only triggers automatic repairs for minor filesystem inconsistencies. When damage is more severe, the system defaults to pausing for manual intervention. Since your server is physically hard to access and you've got full cloud backups, we can tweak the config to skip that pause and force automatic fixes.

Step 1: Adjust SysVinit Config (For Older Ubuntu Versions)

If your system uses the traditional SysVinit system (you're editing /etc/default/rcS, so this applies to you), update the file with these critical settings:

sudo nano /etc/default/rcS

Make sure these lines are set correctly:

FSCKFIX=yes
SULOGIN=no
  • SULOGIN=no is the key addition here: by default, even with FSCKFIX=yes, the system will drop into a single-user login prompt for severe errors. Disabling this tells it to skip that prompt and proceed with automatic repairs.

Save the file (Ctrl+O, press Enter, then Ctrl+X to exit nano).

Step 2: Tweak systemd Settings (For Ubuntu 16.04+ Using Systemd)

If your server runs a newer Ubuntu version with systemd (most modern installs), you'll need to override the default fsck service behavior:

  1. Create an override directory for the fsck service if it doesn't exist:

    sudo mkdir -p /etc/systemd/system/fsck@.service.d
    
  2. Create an override config file:

    sudo nano /etc/systemd/system/fsck@.service.d/override.conf
    
  3. Add these lines to force fsck -fy and disable timeouts:

    [Service]
    ExecStart=
    ExecStart=/sbin/fsck -fy %I
    TimeoutSec=0
    
    • The empty ExecStart= clears the default command, then we replace it with fsck -fy %I (where %I targets the specific filesystem being checked).
    • TimeoutSec=0 prevents systemd from killing the fsck process if it takes longer than the default timeout.
  4. Reload systemd to apply the changes:

    sudo systemctl daemon-reload
    

Step 3: Verify /etc/fstab Settings

Double-check your /etc/fstab to ensure the filesystem in question ( /dev/sda1 in your case) is configured to be checked on boot:

  • Look for the line for /dev/sda1; the 6th column (fs_passno) should be set to 1 (for root filesystems) or 2 (for non-root filesystems). This tells the system to include it in the boot-time fsck sequence.
  • Avoid ro (read-only) or noauto options unless you specifically need them, as they can block automatic checks and repairs.

Important Reminder

You already know this, but it bears repeating: using fsck -fy can lead to data loss if the filesystem is severely corrupted. Since you've got full cloud backups, this risk is mitigated, but it's still good practice to monitor your filesystem health periodically to catch issues before they require forced repairs.

内容的提问来源于stack exchange,提问作者Roman Gaufman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:32:31