You are not logged in Sign in | Register

FreeBSD, openrc, and fsck.

Published on 2011-07-19 07:10 By Villavicencio, Javier in categories Gentoo FreeBSD

It's annoying to wait for fsck, right? Well, it can be skipped to a point, where some filesystems get mounted after OpenRC loads part of the 'default' runlevel.

First things first, we have to decide which filesystems can be 'skipped' at boot. Meaning, they will not be immediately mounted if they require a check/repair.

/etc/fstab:
# <fs>             <mountpoint>  <type>     <opts>           <dump/pass>
/dev/mirror/gm0s1a /             ufs        rw,noatime       1 1
/dev/mirror/gm1s1b none          swap       sw               0 0
/dev/mirror/gm0s1d /tmp          ufs        rw,noatime       1 1
/dev/mirror/gm0s1e /var          ufs        rw,noatime       1 1
/dev/mirror/gm0s1f /usr          ufs        rw,noatime       2 2
/dev/mirror/gm0s1g /home         ufs        rw,noatime       3 3
/dev/mirror/gm1s1a /mnt/big      ufs        rw,noatime       3 3

That fstab basically says `/`, `/tmp`, and `/var` should be checked/mounted on the first pass. `/usr` can be checked on the second pass, and then `/home` plus `/mnt/big` are done on the third pass.

This modification alone will give no benefits at all. /etc/init.d/fsck will still go through all the filesystems immediately at boot time.

Next thing is to modify /etc/conf.d/fsck

# Pass any arguments to fsck.
# By default we preen.
# Linux systems also force -C0 and -T.
# If fsck_args is not specified then Linux systems also use -A
# (and -R if / is rw)
fsck_args="-p -F"

# We can also specify the passno in /etc/fstab to check
# If you multiplex fsck (ie ln -s fsck /etc/init.d/fsck.late) then you can
# do an fsck outside of the normal scope, say for /home.
# Here are some exampes:-
#fsck_passno="=1 =2"
#fsck_passno=">1"
#fsck_passno="<2"

# fsck_shutdown causes fsck to trigger during shutdown as well as startup.
# The end result of this is that if any periodic non-root filesystem checks are
# scheduled, under normal circumstances the actual check will happen during
# shutdown rather than at next boot.
# This is useful when periodic filesystem checks are causing undesirable
# delays at startup, but such delays at shutdown are acceptable.
fsck_shutdown="NO"


That's the whole file, but I've only modified `fsck_args` to use `-p -F` which on fsck(8) means *preen* and *foreground*.
Automagically, the first fsck runs only on the foreground for the filesystems that have `passno=1` (in my example above these are `/`, `/tmp` and `/var`), that's why I didn't modify fsck_passno (that would be required on Linux tho)

But what about the other filesystems? For them we make the 'late' fsck: create a /etc/conf.d/fsck.late symlink to /etc/init.d/fsck or create a copy to /etc/init.d/fsck.late (if you need fine control on when fsck.late should be run, copy fsck to fsck.late and edit the deps), then add fsck.late to the default runlevel (fsck must already be on the boot runlevel)

Now on /etc/conf.d/fsck.late:

# Run the late fsck on the background:
fsck_args="-p -B"

Here I have only changed -F for -B which stands for background, which will make fsck.late run for every other filesystem that has `passno > 1` in the background, but it will also use the order of fstab's passno to run fsck, meaning that /usr will be checked alone in the background, and after that's complete, /home and /mnt/big will be checked in parallel also in the background.

This setup is mostly a speedup, since /usr and /home are on the same disk (a gmirror in this case) checking them both at the same time will be a waste of time, but then /mnt/big is separated and 'not so important* to be checked that soon, so fsck checks it with /home in parallel/background after /usr is completed.

And that's it. now instead of having to wait several minutes for fsck to finish the whole 30Gb (20 + 10) of data, to load my firewall/router pf rules, it just takes seconds to fsck the smaller "/" and "/var" filesystems, leaving the big ones for later.

This article was updated on Tuesday, July 19, 2011 at 07:28 AM in categories Gentoo FreeBSD .
No comments loaded yet!. If persist enable javascript or update your browser.