How to mount a local GlusterFS volume at boot (fstab/systemd fix)

How to mount a local GlusterFS volume at boot (fstab/systemd fix)

When running a GlusterFS cluster, you may want to use the volume(s) on the servers themselves.

During the boot process, GlusterFS will take a bit of time to start. systemd-mount, which handles the mount points from /etc/fstab, will run before the glusterfs-server service finishes to start.

The mount will fail so you will end up without your mounted volume after a reboot.

After doing to some research to fix this issue, I stumbled upon this Ubuntu bug report from 2011 (!). At the time, systemd wasn't the init system, but in 2016 someone posted a pretty good solution for systemd systems.

In my case, I want my GlusterFS volume to be mounted to /srv/.

In my /etc/fstab, I have this line (gv0 is my volume):

localhost:/gv0 /srv glusterfs defaults,_netdev 0 0

The solution is to create the /etc/systemd/system/srv.mount.d/ directory, then /etc/systemd/system/srv.mount.d/override.conf with the following content:

[Unit]
After=glusterfs-server.service
Wants=glusterfs-server.service

Since the /etc/fstab mount points are translated to unit files by systemd-mount, we can override them as shown above. In our case, systemd will only mount the volume if glusterfs-server is started.

Stanislas
Author
Stanislas
I like building things with code and computers

Comments

9Atom feed
Markdown supported
  1. Rene

    Works great!

  2. Timofey Drozhzhin

    Good thinking there. A simpler solution for Ubuntu/Debian is to use the x-systemd.automount service. So the command becomes localhost:/gv0 /srv glusterfs defaults,_netdev,noauto,x-systemd.automount 0 0. No need to do anything else. More info on https://serverfault.com/a/823582.

    1. Rich

      Amazing thanks for this!!!

    2. Dennis

      Thank you! This worked for me on Ubuntu 22.04

    3. Adarsha

      The difference between the solution here vs the one you mentioned is your solution tries to mount it when its first accessed, which may be before the glusterfs-server has started (since you don't know the order of startup services). This solution makes the dependency explicit.

    4. LGDS

      Still working in 2024 ! Thisssss is the real solution <3 thank's bro You can reboot your servers in any order, it will work

  3. Todd

    This worked like a charm for me. Was consistently having to monitor the GlusterFS volumes after reboots on my Docker Swarm with each and every reboot to ensure the fstab mount was mounted. It became incredibly frustrating. THANKS!!!

  4. ORZ

    I modified command, so works on Rocky Linux 9.4

    Step 1: add mount in /etc/fstab

    Step 2: add+edit this file

    /etc/systemd/system/glusterd.service.d/override.conf

    [Unit]

    After=glusterd.service

    Wants=glusterd.service

    [Service]

    Restart=on-failure

    StartLimitBurst=1

    StartLimitInterval=60

    ExecStopPost=/bin/mount -t glusterfs -o defaults,_netdev localhost:/gv0 /srv

    [Install]

    WantedBy=multi-user.target

    Step 3: enable every service (haven't tested yet, probably redundant)

    systemctl daemon-reload

    systemctl enable glusterd

    systemctl enable glusterfsd

    systemctl enable glusterfssharedstorage.service

    It might doesn't work when just rebooted, but after few seconds it just mounted.