Skip to content

Instantly share code, notes, and snippets.

@lilydjwg
Created May 15, 2017 05:03
Show Gist options
  • Save lilydjwg/87c296682b3d0d9ba66d5ce8df67a8f7 to your computer and use it in GitHub Desktop.
Save lilydjwg/87c296682b3d0d9ba66d5ce8df67a8f7 to your computer and use it in GitHub Desktop.
readonlyroot: make / readonly but permit writes to some paths
#!/bin/bash -e
if [[ $EUID -ne 0 ]]; then
echo >&2 "Need to be root."
exit 1
fi
if ! mountpoint /mnt >/dev/null; then
exit 2
fi
systemctl start readonlyroot.service
pid=$(systemctl show readonlyroot.service | grep -oP '(?<=pid=)\d+')
nsenter -m -t "$pid" "$@"
[Unit]
Description=make a readonly root
[Service]
Type=simple
ExecStart=/usr/bin/sleep infinity
PrivateTmp=true
ReadOnlyPaths=/
ReadWritePaths=/run
ReadWritePaths=/mnt
ReadWritePaths=/home/lilydjwg/tmpfs/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment