Skip to content

Instantly share code, notes, and snippets.

@Informatic
Created April 16, 2021 18:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Informatic/db387d512bf4ae5512d9f644c4d219d2 to your computer and use it in GitHub Desktop.
Save Informatic/db387d512bf4ae5512d9f644c4d219d2 to your computer and use it in GitHub Desktop.
simple tool to apply overlayfs over specific directories
#!/bin/sh
# Directory to store overlays in (one directory structure is created per overlay configured down below)
OVERLAY_BASE=/home/root/overlays
overlay() {
set -e
overlay_id="$(echo $1 | sed 's;/;__;g')"
unset TARGET SOURCE FSTYPE OPTIONS
eval $(findmnt -P $1)
if [[ "$FSTYPE" == "overlay" ]]; then
echo "[-] Overlay '$1' already mounted"
else
echo "[ ] Preparing overlay for '$1' -> $OVERLAY_BASE/$overlay_id"
mkdir -p "$OVERLAY_BASE/$overlay_id/upper" "$OVERLAY_BASE/$overlay_id/work"
mount -t overlay -o lowerdir=$1,upperdir=$OVERLAY_BASE/$overlay_id/upper/,workdir=$OVERLAY_BASE/$overlay_id/work/ overlay-$overlay_id $1
echo "[+] Overlay '$1' mounted"
fi
}
# Usage:
overlay /usr/share/im
# now /usr/share/im is read-writable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment