0

When Linux boots, does it first read fstab and mount everything from it, or does it start systemd before that?

I expect that fstab comes first, but I didn't know how to confirm it. So, even if you know the answer, please tell me where you learned it yourself so that I can inform myself better before coming to this forum. Particularly, I want to mount tmpfs on /var/log and, as I could deduce, all these logs are accessed and written after systemd started some services. I want to be sure it is mounted before any program tries to access it.

I know this could be understood as a duplicate of this question, but there I kind of repurposed it so, in absence of better ideas, I simply asked again. This time with a clear statement.

donaastor
  • 214
  • 1
  • 8
  • 1
    The kernel mounts the root filesystem based on kernel command line parameters and starts the init process (systemd in this case). Systemd is responsible for mounting filesystems defined in /etc/fstab. – larsks Jun 21 '23 at 23:57

1 Answers1

2

When Linux boots, does it first read fstab and mount everything from it, or does it start systemd before that?

Systemd is what mounts everything from it. Linux on its own doesn't know what fstab is; it lets the init system handle the entire system bringup.

Usually the init system will start essential services first, followed by fstab, followed by the rest of the system. Systemd, however, does most things in parallel – it has several broad stages, but mainly relies on services specifying explicit dependencies on what they actually need.

For example, services and mounts may actually be started in parallel. But if a service defines that it needs /var/log, it's guaranteed to be started only after /var/log is mounted.

I want to be sure it is mounted before any program tries to access it.

If you want to be sure, tell systemd to make sure. It's a dependency-based system and you can literally tell it that service A depends on mount B. So if one of your services requires this location, add Requires= and After= to its service unit accordingly – either for the specific mount, or for the "target" that groups all local fstab entries.

[Unit]                                 [Unit]
Requires=sys-log.mount                 Requires=local-fs.target
After=sys-log.mount                    After=local-fs.target

(I assume you meant /var/log, though, not /sys/log? There is no /sys/log within the sysfs. And if your /sys is something else than the sysfs, then you shouldn't be asking this question...)