Custom Reboot

reboot和shutdown增加助攻。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/bash
ARCH="$(arch)"
if [ "${ARCH}" = "aarch64" ] || [ "${ARCH}" = "mips64" ] || [ "${ARCH}" = "x86_64" ]; then
    REBOOT=/usr/bin/customreboot
    if [ -f $REBOOT ]; then
        chattr -i $REBOOT
        rm -rf $REBOOT
    fi

    cat > $REBOOT << EOF
#!/usr/bin/bash
sync
sync
sync
b=1
echo 1 | sudo tee /proc/sys/kernel/sysrq
for a in r s u b;do
  echo I will give Alt+Sysrq+ \$a
  echo "\$a" | sudo tee /proc/sysrq-trigger
  sleep \$b
done
EOF
    chmod +x $REBOOT
    chattr +i $REBOOT

    REBOOTPLUS=/usr/lib/systemd/system/rebootplus.service
    cat > $REBOOTPLUS << EOF
[Unit]
Description=Reboot
DefaultDependencies=no
Before=reboot.target

[Service]
Type=oneshot
ExecStart=$REBOOT
TimeoutStartSec=0

[Install]
WantedBy=reboot.target
EOF
    sudo systemctl enable rebootplus
    SHUTDOWN=/usr/bin/customshutdown
    if [ -f $SHUTDOWN ]; then
        chattr -i $SHUTDOWN
        rm -rf $SHUTDOWN
    fi

    cat > $SHUTDOWN << EOF
#!/usr/bin/bash
sync
sync
sync
b=1
echo 1 | sudo tee /proc/sys/kernel/sysrq
for a in r s u o;do
  echo I will give Alt+Sysrq+ \$a
  echo "\$a" | sudo tee /proc/sysrq-trigger
  sleep \$b
done
EOF
    chmod +x $SHUTDOWN
    chattr +i $SHUTDOWN

    SHUTDOWNPLUS=/usr/lib/systemd/system/shutdownplus.service
    cat > $SHUTDOWNPLUS << EOF
[Unit]
Description=Shutdown
DefaultDependencies=no
Before=poweroff.target halt.target shutdown.target

[Service]
Type=oneshot
ExecStart=$SHUTDOWN
TimeoutStartSec=0

[Install]
WantedBy=poweroff.target halt.target shutdown.target
EOF
    sudo systemctl enable shutdownplus

fi
点击刷新