Course contentsShow
← Linux
Lesson 772 of 1,8197. Storage Management and Logical VolumesFree lesson

Filesystem mount order dependencies

Configure systemd mount units for correct service startup sequences.

In this lesson, you will learn how to use systemd mount units to ensure that specific filesystems are ready before the services that depend on them attempt to start.

The Dependency Challenge

When your Linux system boots, services often expect data to be available at specific mount points (like /var/lib/database or /mnt/data). If a service starts before the storage device has finished mounting, the service will crash or fail to initialize because the directory appears empty. While the legacy /etc/fstab file handles basic mounting, systemd provides a more robust way to enforce ordering through declarative mount units.

Creating a Mount Unit

Instead of relying solely on fstab, systemd treats every mount point as a unit. For a mount point located at /mnt/storage, systemd looks for a file named mnt-storage.mount. You can explicitly define the relationship between your storage and your applications by modifying your service unit file.

Suppose you have a service called myapp.service that requires data inside /mnt/storage. You can ensure the filesystem is mounted first by adding a Requires and After directive to your service file:

[Unit]
Description=My Application Service
Requires=mnt-storage.mount
After=mnt-storage.mount

[Service]
ExecStart=/usr/bin/myapp

Why This Matters

By using Requires=, you tell systemd that your service absolutely cannot function without this mount. By using After=, you tell systemd to explicitly wait until the mnt-storage.mount unit has reached the "active" state before launching your application.

This approach is superior to simple timing-based delays because it is event-driven. If the disk takes an extra three seconds to spin up or the NVMe controller requires a longer initialization, systemd simply waits. Your service will only attempt to start once the filesystem is verified as mounted and ready for I/O operations, preventing "directory not found" errors and ensuring a predictable boot sequence for your storage-dependent infrastructure.

Key Takeaway: Use Requires and After in your systemd service units to create an explicit synchronization gate between filesystem mount units and the services that rely on them.