1

Can someone please tell me which runlevel systemd is running in when you're prompted for a filesystem check after a power loss? Is it emergency or rescue or does it depend? I have some systemd units that need to run if/when the system prompts for a filesystem check at boot. I'd rather not modify the minimal emergency.target shell to load the script if I don't need to so I was hoping that it was running in rescue mode.

Also, if anyone has a nifty way of temporarily breaking the filesystem so I can invoke the fsck prompt for testing, I'd greatly appreciate it. I've tried changing /etc/fstab, however that specifically boots into emergency mode.

Thank you very much for any help.

0

Usually neither – it's part of the regular boot process.

For filesystems listed in /etc/fstab with the "check" flag set to non-zero, the corresponding .mount unit automatically gets a dependency on systemd-fsck@<dev>.service. When that service finishes, systemd continues with mounting the filesystem (starting the .mount unit). This is not a special state, but part of the regular job queue.

If the fsck service fails (e.g. some kind of manual repair is required), the .mount unit also fails and only this finally triggers a switch from the regular boot target into emergency.target.

As you can see, fsck is being run on every boot, and the only thing affected by power loss is how long it'll take. (Some filesystems have a "dirty" bit that is set on mount and cleared on umount; others detect the state based on unprocessed entries in the update journal.) To change this behavior, you'd have to change the fsck.<fstype> program or completely disable checking for that filesystem in fstab.

To start additional services before systemd-fsck@<dev> runs (which would happen on every boot, before it decides whether extended checking is needed) use the regular methods of extending a systemd unit.

Note that the root filesystem is a special case: in some distributions it is actually checked in the initramfs (early boot phase), while the main systemd process is not running yet. (Depending on distro, the initramfs may have its own systemd, or a different init entirely.) Again, fsck is always run, whether the poweroff was clean or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.