Longhorn fails to start and displays 'failed to generate spec: path "/tmp/longhorn-environment-check" is mounted on "/tmp" but it is not a shared mount' in the pod Events table

During the install, one of the first things Longhorn does is to make sure it has read-write access to the node. It does this by creating a pod that has HostPath mount for the file /tmp/longhorn-environment-check. If the pod is successfully created, that means it can create a read/write directory on the host. The install script starts looping, looking for the pod. But, the pod is stuck in a CreateContainerError state (since it can’t create the rw volume mount).

We see in the Longhorn pod’s events table:

Warning Failed 26s kubelet Error: failed to generate container "..." spec: failed to generate spec: path "/tmp/longhorn-environment-check" is mounted on "/tmp" but it is not a shared mount
Normal Pulled 0s (x11 over 114s) kubelet Container image "replicated/kurl-util:v2022.06.14-0" already present on machine
Warning Failed 0s (x2 over 12s) kubelet (combined from similar events): Error: failed to generate container "..." spec: failed to generate spec: path "/tmp/longhorn-environment-check" is mounted on "/tmp" but it is not a shared mount

Most distributions of Linux configure containerd to use shared mounts by default, but to resolve this on some distributions, set:

[Service]
MountFlags=shared

in containerd’s SystemD service file.