Knowledge Base

Browse our knowledge base for free solutions to common problems

Delay Docker Starting Until CIFS Storage Is Mounted On Linux

Created On: 12 July 2024
Written by: Ben

Contents

Introduction / Background

In this example, a Jellyfin media server running on Docker requires an external Hetzner Storage box to be mounted.

Important considerations:

  • Jellyfin will only have access to storage that is already mounted once started.
  • Mounting external storage using FSTAB can be delayed until the network is available using _netdev but may not prevent Docker from starting first which will limit access to storage from within Jellyfin.

Plan:

  • Create a service for the Hetzner storage mount (mount it as a service).
  • Delay Docker start until the storage mount service is started.

Using the plan above will allow the server to reboot and ensure that the storage mount is available within Jellyfin.

Create Storage Mount as a Service

Create a Mount Point

First create a mount point for your CIFS storage share:

mkdir /root/jellyfin/media/storage

Create a Service For Mounting The Storage

Create a systemd service file mount file for the CIFS share:

nano /etc/systemd/system/root-jellyfin-media-storage.mount

The name of the systemd mount (service) file is very important and must be the same as the mount point. For example if your mount point is /tmp/mnt then the location and file name should be:

/etc/systemd/system/tmp-mnt.mount

Now paste the following within the file:

[Unit]
Description=Used to mount Hetzner Storage block as CIFS. Used by Jellyfin for media files.

[Mount]
What=//uXXXXXX.your-storagebox.de/uXXXXXX-sub5
Where=/root/jellyfin/media/storage
Type=cifs
Options=user=XXXXXX,password=XXXXXX,uid=0,gid=0

[Install]
WantedBy=multi-user.target

With the configuration above:

  • Replace the Description= with a description of the CIFS share
  • Replace What= with the name of your CIFS share address
  • Replace Where= with your mount point
  • On the Options= line replace:
    • user=XXXXXX with your CIFS share username
    • password=XXXXXX with your CIFS share password

Create an Auto Mount File For The CIFS Share

Create the following file:

 nano /etc/systemd/system/root-jellyfin-media-storage.automount                        

Like the previous step, the name of the systemd auto mount file is very important and must be the same as the mount point. For example if your mount point is /tmp/mnt then the location and file name should be:

/etc/systemd/system/tmp-mnt.automount

Paste the following within the file:

[Unit]
Description=Automount Remote Hetzner Storage as CIFS for use by Jellyfin

[Automount]
Where=/root/jellyfin/media/storage

[Install]
WantedBy=multi-user.target

With the configuration above:

  • Replace the Description= with a description of the CIFS share
  • Replace Where= with your mount point

Start The New Service

Now start the newly created service:

systemctl start root-jellyfin-media-storage.mount

Enable The New Service

Now enable the newly created service to start on boot:

systemctl enable root-jellyfin-media-storage.automount

Now you should have your CIFS storage mounting as a service. The next step is to prevent Docker from starting before the CIFS share service is started.

IMPORTANT NOTES FOR HETZNER CIFS SHARES

The usual CIFS share address for Hetzner Storage Box is the following:

//<username>.your-storagebox.de/backup

Ensure you use /backup, refer to this. The above ONLY applies if you are using the main account for your Hetzner Storage Box. If you are using a sub account the following applies:

//<username>.your-storagebox.de/<username>-subx

For example if your username is u187432 and your sub account is u187432-sub9 then your CIFS share address would be:

//u187432.your-storagebox.de/u187432-sub9

Delay Docker Start Until Storage Service Starts

To delay Docker starting until our storage service starts we need to edit the Docker systemd file:

nano /usr/lib/systemd/system/docker.service

Now we can ensure our storage mount service is listed as a Wants= service. Look for the following line:

Wants=network-online.target containerd.service

Now add the following to the line:

Wants=network-online.target containerd.service root-jellyfin-media-storage.mount

Replace the root-jellyfin-media-storage.mount with the name of your file.

Docker systemd file

This should ensure that after the server reboots Docker / Jellyfin will not be started until our storage mounts.

For more useful articles please visit our Knowledgebase home page.

ICTU LTD is a company registered England and Wales (Company No. 09344913) 15 Queen Square, Leeds, West Yorkshire, England, LS2 8AJ
Copyright © 2025 ICTU LTD, All Rights Reserved.
exit