Relocating data directories with bind mounts

NOTE: this post is no longer relevant as of Embedded Cluster version 1.15.0. Please see the comment below for more details.

When you need to redirect directories on a Linux system, bind mounts are generally preferred over symlinks. Here’s why you should use bind mounts and how to implement them:

Why Use Bind Mounts Instead of Symlinks:

  1. Consistency: Bind mounts ensure consistent behavior across different applications and scenarios.
  2. Permissions: Bind mounts preserve the original directory permissions and ownership.
  3. Performance: Bind mounts have less overhead compared to symlinks for frequently accessed directories.

How to Use Bind Mounts:

The basic syntax for creating a bind mount is:

sudo mount --bind /source/directory /target/directory

Example:
Let’s say you want to redirect /var/lib/docker to /mnt/docker:

sudo mkdir /mnt/docker
sudo mount --bind /mnt/docker /var/lib/docker

To make the bind mount persistent across reboots, add an entry to /etc/fstab:

/mnt/docker /var/lib/docker none bind 0 0

Practical Use Case:
For embedded cluster installations where you need to redirect directories due to space constraints:

sudo mkdir -p /mnt/openebs /mnt/embedded-cluster /mnt/k0s
sudo mount --bind /mnt/openebs /var/openebs
sudo mount --bind /mnt/embedded-cluster /var/lib/embedded-cluster
sudo mount --bind /mnt/k0s /var/lib/k0s

Add to /etc/fstab for persistence:

/mnt/openebs /var/openebs none bind 0 0
/mnt/embedded-cluster /var/lib/embedded-cluster none bind 0 0
/mnt/k0s /var/lib/k0s none bind 0 0

Remember to:

  1. create the source directories before mounting.
  2. do the mounts before installing. If you already installed, it’s best to reset, do the mounts, and then install again. If you have data you need to keep contact us for support so we can give you guidance without data loss if possible.

Also for this example, you might find that /tmp is also to small. Rather than bind mounting /tmp for all applications Just set the environment variable TMPDIR so you’re only impacting your session or install. For example sudo TMPDIR=/mnt/new-tmp ./my-app install ...

Using bind mounts instead of symlinks will provide a more robust and secure solution for directory redirection in most scenarios.

Starting with embedded cluster version 1.15.0, bind mounts are no longer needed or recommended and the data directory can be configured using the --data-dir flag to the install command. For more information see Change the Default Data Directory in the docs. The data directory cannot be relocated after installation.

Additionally, the k0s and openebs data directories have been consolidated under /var/lib/embedded-cluster in the directories /var/lib/embedded-cluster/k0s and /var/lib/embedded-cluster/openebs-local respectively.