我应该怎么做才能在启动时强制检查根文件系统(以及可选的修复程序)?


10

昨天,我们的一台计算机掉到了grub外壳上,或者说实话,我不确定打开计算机时它是什么外壳。

结果表明,由于不一致,它无法挂载根文件系统或某种意义上的东西。

我跑了,我相信:

fsck -fy /dev/sda2

重新启动,问题消失了。

这里是问题部分:

我已经在她的根目录下了crontab:

@reboot /home/ruzena/Development/bash/fs-check.sh

而脚本包含:

#!/bin/bash
touch /forcefsck

考虑一下,我不知道为什么我要为这么短的命令创建脚本文件,但是无论如何...

此外,在文件中:

/etc/default/rcS

我定义了:

FSCKFIX=yes

所以我不明白。情况怎么会出现?


我应该怎么做才能在启动时强制检查根文件系统(以及可选的修复程序)?

还是这两项我能做到的最大?

操作系统: Linux Mint 18.x Cinnamon 64-bit。

fstab:

cat /etc/fstab | grep ext4

显示:

UUID=a121371e-eb12-43a0-a5ae-11af58ad09f4    /    ext4    errors=remount-ro    0    1

grub:

fsck.mode=force

已添加到grub配置中。

Answers:


12

ext4 引导期间检查文件系统

在OS上测试:虚拟机中的Linux Mint 18.x

基本信息

/etc/fstab具有fsck顺序作为最后一列(第6列),例如:

<file system>    <mount point>    <type>    <options>    <dump>    <fsck>
UUID=2fbcf5e7-1234-abcd-88e8-a72d15580c99 / ext4 errors=remount-ro 0 1

FSCKFIX=yes 可变的 /etc/default/rcS

这会将fsck更改为自动修复,但不强制执行fsck检查。

来自man rcS:

FSCKFIX
    When  the  root  and all other file systems are checked, fsck is
    invoked with the -a option which means "autorepair".   If  there
    are  major  inconsistencies then the fsck process will bail out.
    The system will print a  message  asking  the  administrator  to
    repair  the  file  system manually and will present a root shell
    prompt (actually a sulogin prompt) on the console.  Setting this
    option  to  yes  causes  the fsck commands to be run with the -y
    option instead of the -a option.  This will tell fsck always  to
    repair the file systems without asking for permission.

从 man tune2fs

If you are using journaling on your filesystem, your filesystem
will never be marked dirty, so it will not normally be checked.

从...开始

设置以下

FSCKFIX=yes

在文件中

/etc/default/rcS

检查并记下上一次检查fs的时间:

sudo tune2fs -l /dev/sda1 | grep "Last checked"

这两个选项不起作用

  1. 将-F(强制fsck重启)参数传递给shutdown:

    shutdown -rF now
    

    不; 请参阅:man shutdown。

  2. 使用以下命令添加/forcefsck空文件:

    touch /forcefsck
    

    这些脚本似乎使用此:

    /etc/init.d/checkfs.sh
    /etc/init.d/checkroot.sh
    

    根本不是在重新启动工作,但该文件已被删除。

    经核实:

    sudo tune2fs -l /dev/sda1 | grep "Last checked"
    sudo less /var/log/fsck/checkfs
    sudo less /var/log/fsck/checkroot
    

    这些似乎是init脚本的日志。

我重复一遍,这两个选项均无效!


这两种方法都可以DID起作用

  1. systemd-fsck内核启动开关

    编辑主grub配置文件:

    sudoedit /etc/default/grub
    
    GRUB_CMDLINE_LINUX="fsck.mode=force"
    
    sudo update-grub
    sudo reboot
    

    这确实进行了文件系统检查,并通过以下方式进行了验证:

    sudo tune2fs -l /dev/sda1 | grep "Last checked"
    

    注意:此DID是一项检查,但也要强制进行修复,您需要指定fsck.repair="preen"或fsck.repair="yes"。

  2. 使用tune2fs来设置文件系统的挂载数量,然后再执行fsck,man tune2fs

    tune2fs' info is kept in the file system superblock
    

    -c 开关设置检查fs之前安装fs的次数。

    sudo tune2fs -c 1 /dev/sda1
    

    验证:

    sudo tune2fs -l /dev/sda1
    

    此DID可以通过以下方式验证:

    sudo tune2fs -l /dev/sda1 | grep "Last checked"
    

摘要

要fsck在Linux Mint 18.x上的每次引导上强制执行a ,请使用tune2fs或fsck.mode=force,以及带有可选的fsck.repair=preen/ fsck.repair=yes的内核命令行开关。


在基于Grub的Debian系统上,考虑使用创建/etc/default/grub.d/local.cfg文件GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT fsck.mode=force"。这样可以避免/etc/default/grub在升级过程中合并配置文件。
— Vincas Dargis
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.