Created
May 15, 2017 05:03
-
-
Save lilydjwg/87c296682b3d0d9ba66d5ce8df67a8f7 to your computer and use it in GitHub Desktop.
readonlyroot: make / readonly but permit writes to some paths
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/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" "$@" |
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
[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