-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathkreboot
More file actions
executable file
·114 lines (103 loc) · 2.1 KB
/
kreboot
File metadata and controls
executable file
·114 lines (103 loc) · 2.1 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/sh
set -e
[ -n "$BASH" ] && set -o pipefail
set -u
# defaults
wait=10
detach_wait=3
usage() {
cat << EOF
Usage: kreboot [option ...] [kernel|boot-index]
Options are:
--wait, -w N wait N seconds before reboot (default $wait)
--nowait don't wait, reboot immediately
--detach Schedule reboot and return. Suitable to remote reboot.
--help, -h show this help message
--kargs, k additional kernel arguments
Example:
$0 0 Boot kernel with index 0
EOF
exit $1
}
uerr() {
echo "ERROR: $*" 2>&1
echo
usage 1
}
# Check that all programs we need are available, exit if not
# (relying on 'set -e' and hash returning non-zero for errors)
hash grubby kexec systemctl
# Process options and arguments
target=''
kargs=''
while test $# -gt 0; do
case $1 in
-w|--wait)
if [ "$#" -lt 2 ]; then
uerr "Option $1 requires an argument"
fi
wait=$2
if ! printf "%f" $wait > /dev/null 2>&1; then
uerr "Option $1 argument not a number"
fi
shift
;;
--nowait)
wait=0
;;
--detach)
detach=yes
;;
--detach_wait)
if [ "$#" -lt 2 ]; then
uerr "Option $1 requires an argument"
fi
detach_wait=$2
if ! printf "%f" $detach_wait > /dev/null 2>&1; then
uerr "Option $1 argument not a number"
fi
shift
;;
-h|--help)
usage 0
;;
-k|--kargs)
kargs=$2
shift
;;
-*)
uerr "Unrecognized option: $1"
;;
*)
if [ -n "$target" ]; then
uerr "Extra arguments: $*"
fi
target=$1
;;
esac
shift
done
if [ -z "$target" ]; then
if ! target=$(grubby --default-kernel); then
# grubby prints error to stdout
echo "grubby: $target" 1>&2
exit 1
fi
fi
if ! info=$(grubby --info=$target); then
# grubby prints error to stdout
echo "grubby: $info" 1>&2
exit 1
fi
eval $(echo "$info" | sed "s|^\(\S*\)=\([^'\"].*\)$|\1='\2'|")
echo Booting $title...
if [ "$wait" -ne 0 ]; then
echo Press Ctrl-C within $wait seconds to cancel
sleep $wait
fi
kexec -l "$kernel" --initrd="$initrd" --command-line="root=$root $args $kargs"
if [ -z "detach" ]; then
systemctl kexec
else
setsid bash -c "sleep $detach_wait; systemctl kexec" &>/dev/null < /dev/null &
fi