0

I'm trying to mount /var with an overlayfs (with a tmpfs) at boot but don't manage to make it works.

Here is what I've done :

# creating tmpfs
mkdir /var.tmpfs
mount -t tmpfs -o rw,nosuid,nodev,noexec,noatime,size=512m,mode=0775 tmpfs /var.tmpfs
chmod -R u=rwX,g=rX,o=rX /var.tmpfs

# creating overlay
mkdir /var.tmpfs/{work,upper} /var.overlay
mount -t overlay -o rw,lowerdir=/var,upperdir=/var.tmpfs/upper,workdir=/var.tmpfs/work overlay /var.overlay
chmod -R u=rwX,g=rX,o=rX /var.overlay

# binding to /var
mount --bind /var.overlay /var

# filling /etc/fstab
[...]
tmpfs           /var.tmpfs      tmpfs   rw,nosuid,noatime,size=512m          0  0
overlayfs       /var.overlay    overlay rw,lowerdir=/var,upperdir=/var.tmpfs/upper,workdir=/var.tmpfs/work    0   0
/var.overlay    /var            none    bind    0   0  

When the system boot I face the following error :

overlayfs: failed to resolve '/var.tmpfs/upper' -2

Which is normal since tmpfs is empty when mounted.

  • How to create upper and work directories at boot
    • after mounting /var.tmpfs
    • before mounting /var.overlay
  • Or is there any other solution with directories already present at boot ?

Thanks in advance.

1

The folders /var.tmpfs/upper and /var.tmpfs/work are located in tmpfs and will no longer present after reboot.

One option is to create both of them in fstab.

-1

I do something similar with https://github.com/StuartIanNaylor/zram-config but use zram rather than tmpfs.

I bind mount the target directory somewhere else. Create and mount zram and mkdir overlayfs dirs. Then mount the overlay

mount --verbose --types overlay -o lowerdir=$BIND_DIR,upperdir=/opt/zram$RAM_DEV/upper,workdir=/opt/zram$RAM_DEV/workdir overlay $ZRAM_DIR

$ZRAM_DIR is the target dir that gets bind mounted elsewhere so on stop I can sync changes. Rather than the complete /var you might have to just add a collection of lowerdir as maybe tmpfs over tmpfs is not working and really why?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.