In this lesson, you will learn how to configure systemd to recognize and initialize your Logical Volumes (LV) as reliable system storage before your applications attempt to use them.
Why Integration Matters
In a modern Linux system, the boot process happens in parallel. If you have an application (like a database or a web server) configured to store data on an LVM-managed partition, you face a potential "race condition": if the service tries to start before the LVM subsystem has finished scanning your physical disks and assembling the Logical Volume, the service will crash because its data directory is missing.
systemd manages this through its dependency system. By properly defining mount points in your /etc/fstab file, systemd automatically translates those entries into "mount units."
Controlling the Order
When you add an entry to /etc/fstab for a logical volume, systemd creates an implicit dependency. For example:
/dev/mapper/vg_data-lv_app /var/lib/myapp xfs defaults 0 2
Because this entry exists, systemd realizes that the service responsible for /var/lib/myapp (usually defined by a systemd unit file) must wait for the logical volume to be activated and mounted.
If you are writing your own custom service unit file, you should explicitly define this requirement to ensure total reliability. You can add these lines to the [Unit] section of your service file:
[Unit]
Description=My Database Service
Requires=var-lib-myapp.mount
After=var-lib-myapp.mount
How It Works
- LVM Discovery: During early boot,
systemd-udevdmonitors the hardware. When it sees the Physical Volumes (PV), it triggers the LVM tools to activate the Volume Group (VG). - Mount Unit Generation:
systemdlooks at/etc/fstaband generates a temporary "unit" for the mount point. - Synchronization: By using
Requires=andAfter=in your service files, you force the system to hold the service in a "pending" state until the LVM-backed mount unit reports that it is successfully active.
This ensures that your application never encounters a "directory not found" error during a reboot, regardless of how fast or slow your physical disks are.
Key Takeaway: By defining logical volumes in /etc/fstab and referencing their mount units in your service files, you guarantee that LVM storage is fully initialized and ready before your services start.