Skip to content

Instantly share code, notes, and snippets.

@sulincix
Created September 19, 2022 12:35
Show Gist options
  • Save sulincix/56b693790bdb4fbd0fca9ce668343e87 to your computer and use it in GitHub Desktop.
Save sulincix/56b693790bdb4fbd0fca9ce668343e87 to your computer and use it in GitHub Desktop.
Universal deepfreeze linux
#!/bin/bash
if [[ -e /sbin/init-normal ]] ; then
exit
fi
mv /sbin/init /sbin/init-normal
cat > /sbin/init <<EOF
#!/bin/bash
mount -t tmpfs tmpfs /tmp || true
mkdir -p /tmp/work/source /tmp/work/a /tmp/work/b /tmp/work/target || true
mount --bind / /tmp/work/source
mount -t overlay -o lowerdir=/tmp/work/source,upperdir=/tmp/work/a,workdir=/tmp/work/b overlay /tmp/work/target
exec chroot /tmp/work/target /sbin/init-normal
EOF
chmod 755 /sbin/init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment