debian : mount /var as overlayfs at boot
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
andwork
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.
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.