Support for checking file systems from /etc/fstab

This patch adds support for running fsck on all file systems listed in
/etc/fstab with a passno > 0.  The fsck runs sequentially, starting with
the root fs (passno 1).

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2016-08-01 18:08:54 +02:00
1 parent 501deae4ed
commit d2a5e65862
5 files changed
+46 -8

No files matched your search

+1 -1
View File
@@ -58,7 +58,7 @@ networking, [/etc/finit.d/](doc/config.md#etcfinitd) and the familiar
# Fallback if /etc/hostname is missing
host myhostname
# Devices to fsck at boot
# Devices to fsck at boot, only needed if not in /etc/fstab
check /dev/vda1
# Runlevel to start after bootstrap, runlevel 'S'
-3
View File
@@ -6,9 +6,6 @@
module button
module evdev
# Devices to fsck at boot
check /dev/vda1
# Runlevel to start after bootstrap, runlevel 'S'
runlevel 2
-3
View File
@@ -8,9 +8,6 @@ host jessie
# with a different user, using the @username syntax
user root
# Devices to fsck at boot, /etc/fstab is not used
check /dev/vda1
# Linux kernel modules to load, /etc/modprobe is not used
module button
module evdev
+2 -1
View File
@@ -27,7 +27,8 @@ like what a SysV init start script usually does.
Syntax:
* `check <DEV>`
Run fsck on a file system before mounting it
Run fsck on a file system. Only needed if not listed in `/etc/fstab`,
Finit 3.0 and later check all file systems automatically at boot.
* `module <MODULE>`
Load a kernel module, with optional arguments
+43
View File
@@ -27,6 +27,7 @@
#include <ctype.h>
#include <glob.h>
#include <dirent.h>
#include <fstab.h>
#include <mntent.h>
#include <sys/mount.h>
#include <sys/stat.h> /* umask(), mkdir() */
@@ -71,6 +72,40 @@ static int banner(void)
return 0;
}
/*
* Check all filesystems in /etc/fstab with a fs_passno > 0
*/
static int fsck(int pass)
{
struct fstab *fs;
if (!setfsent()) {
_pe("Failed opening fstab");
return 1;
}
while ((fs = getfsent())) {
char cmd[80];
struct stat st;
if (fs->fs_passno < pass)
continue;
errno = 0;
if (stat(fs->fs_spec, &st) || !S_ISBLK(st.st_mode)) {
_d("Cannot fsck %s, not a block device: %s", fs->fs_spec, strerror(errno));
continue;
}
snprintf(cmd, sizeof(cmd), "/sbin/fsck -C -a %s", fs->fs_spec);
run_interactive(cmd, "Checking file system %s", fs->fs_spec);
}
endfsent();
return 0;
}
static void networking(void)
{
size_t i;
@@ -231,6 +266,14 @@ int main(int argc, char* argv[])
#endif
run_interactive(SETUP_DEVFS, "Populating device tree");
/*
* Check file filesystems in /etc/fstab
*/
for (int pass = 1; pass < 10; pass++) {
if (fsck(pass))
break;
}
/*
* Load plugins first, finit.conf may contain references to
* features implemented by plugins.