Last active
October 19, 2021 08:43
-
-
Save Daniel-Abrecht/3116ef47f8171b7e0706daabafa5592e to your computer and use it in GitHub Desktop.
Put this script at /sbin/mount.ovtmp . Script for tmpfs overlays. Put a line for mounting an "ovtmp" fs into fstab, and it'll use a tmpfs and overlayfs to mount over the target. Useful if the root is readonly, but changes need to be possible but don't need persistance.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
cleanup(){ | |
set +e | |
if [ -n "$tmp" ] | |
then | |
umount -l "$tmp" 2>/dev/null | |
rmdir "$tmp" | |
fi | |
} | |
die(){ | |
echo "Usage: $0 name target" >&2 | |
exit 1 | |
} | |
dir= | |
name= | |
options= | |
i=0 | |
while [ $# -gt 1 ] | |
do | |
arg="$1" | |
shift | |
case "$arg" in | |
-o*) | |
if [ "$arg" = -o ] | |
then arg="$1"; shift | |
else arg="${arg#-o}" | |
fi | |
options="$arg" | |
;; | |
-*) die ;; | |
*) | |
i=$(expr $i + 1) | |
case "$i" in | |
1) name="$arg" ;; | |
2) dir="$arg" ;; | |
*) die ;; | |
esac | |
;; | |
esac | |
done | |
arg= | |
if [ -z "$name" ] | |
then name="ovtmp" | |
fi | |
if [ -z "$dir" ] | |
then | |
echo "Usage: $0 name target" | |
exit 1 | |
fi | |
trap cleanup exit | |
tmp=$(mktemp -d /tmp/.ovtmp.XXXXXX) | |
mount -t tmpfs -o "$options" "$name.tmpfs" "$tmp" | |
mkdir -p "$tmp/u" "$tmp/w" | |
mount -t overlay "$name" -o lowerdir="$dir",upperdir="$tmp/u",workdir="$tmp/w" "$dir" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment