Last active
February 3, 2024 17:29
-
-
Save TobleMiner/d85cc71709164b443cbbe42150875cde to your computer and use it in GitHub Desktop.
OpenWrt switch to ramfs
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 | |
. /lib/functions.sh | |
. /lib/functions/system.sh | |
kill_remaining() { # [ <signal> [ <loop> ] ] | |
local loop_limit=10 | |
local sig="${1:-TERM}" | |
local loop="${2:-0}" | |
local run=true | |
local stat | |
echo -n "Sending $sig to remaining processes ... " | |
while $run; do | |
run=false | |
for stat in /proc/[0-9]*/stat; do | |
[ -f "$stat" ] || continue | |
local pid name state ppid rest | |
read pid name state ppid rest < $stat | |
name="${name#(}"; name="${name%)}" | |
# Skip PID1, ourself and our children | |
[ $pid -ne 1 -a $pid -ne $$ -a $ppid -ne $$ ] || continue | |
local cmdline | |
read cmdline < /proc/$pid/cmdline | |
# Skip kernel threads | |
[ -n "$cmdline" ] || continue | |
echo -n "$name " | |
kill -$sig $pid 2>/dev/null | |
[ $loop -eq 1 ] && run=true | |
done | |
let loop_limit-- | |
[ $loop_limit -eq 0 ] && { | |
echo | |
echo "Failed to kill all processes." | |
exit 1 | |
} | |
done | |
echo | |
} | |
killall -9 telnetd | |
killall -9 dropbear | |
killall -9 ash | |
kill_remaining TERM | |
sleep 3 | |
kill_remaining KILL 1 | |
for service in /etc/init.d/*; do | |
$service stop | |
done | |
/etc/init.d/network restart | |
/etc/init.d/dropbear restart |
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 | |
mount -o remount,ro overlayfs:/overlay | |
mount -o remount,ro /overlay | |
mount -o remount,ro /dev/root |
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/ash | |
set -e | |
mkdir -p /newroot | |
mount -t tmpfs -o size=32m none /newroot | |
cp -rp /etc /lib /usr /root /www /bin /sbin /newroot | |
rm -f /newroot/var | |
ln -s /tmp /newroot/var | |
mkdir /newroot/oldroot | |
mkdir /newroot/proc | |
mount -o noatime,move /proc /newroot/proc | |
pivot_root /newroot /newroot/oldroot | |
mkdir -p /sys | |
mount -o noatime,move /oldroot/sys /sys | |
mkdir -p /dev | |
mount -o noatime,move /oldroot/dev /dev | |
mkdir -p /tmp | |
mount -o noatime,move /oldroot/tmp /tmp | |
mkdir -p /overlay | |
mount -o noatime,move /oldroot/overlay /overlay |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment