Line 0
Link Here
|
0 |
- |
1 |
#!/sbin/runscript |
|
|
2 |
# Copyright 1999-2015 Gentoo Foundation |
3 |
# Distributed under the terms of the GNU General Public License v2 |
4 |
# $Id$ |
5 |
|
6 |
depend() { |
7 |
need localmount |
8 |
} |
9 |
|
10 |
image_path() { |
11 |
local x= kver=$(uname -r) karch=$(uname -m) |
12 |
BOOTPART="${BOOTPART:-/boot}" |
13 |
KNAME="${KNAME:-bzImage}" |
14 |
if [ -e "${KNAME}" ]; then |
15 |
echo "${KNAME}" |
16 |
return 0 |
17 |
fi |
18 |
for x in "${KNAME#${BOOTPART}}" vmlinuz \ |
19 |
bzImage-${kver} vmlinuz-${kver} \ |
20 |
kernel-genkernel-${karch}-${kver} \ |
21 |
kernel-${kver} kernel-${karch}; do |
22 |
if [ -e "${BOOTPART}/${x}" ]; then |
23 |
echo "${BOOTPART}/${x}" |
24 |
return 0 |
25 |
fi |
26 |
done |
27 |
|
28 |
return 1 |
29 |
} |
30 |
|
31 |
initrd_path() { |
32 |
local x= kver=$(uname -r) karch=$(uname -m) |
33 |
BOOTPART="${BOOTPART:-/boot}" |
34 |
INITRD="${INITRD:-initrd}" |
35 |
if [ -e "${INITRD}" ]; then |
36 |
echo "${INITRD}" |
37 |
return 0 |
38 |
fi |
39 |
for x in "${INITRD#${BOOTPART}}" \ |
40 |
initrd.img-${kver} initrd-${kver}.img \ |
41 |
initrd-${kver} initramfs-${kver}.img \ |
42 |
initramfs-genkernel-${karch}-${kver} ; do |
43 |
if [ -e "${BOOTPART}/${x}" ]; then |
44 |
echo "${BOOTPART}/${x}" |
45 |
return 0 |
46 |
fi |
47 |
done |
48 |
|
49 |
return 1 |
50 |
} |
51 |
|
52 |
mount_boot(){ |
53 |
local ret |
54 |
|
55 |
[ "${DONT_MOUNT_BOOT:-no}" = "no" ] || return 1 |
56 |
grep -q " ${BOOTPART:-/boot} " /proc/mounts && return 1 |
57 |
|
58 |
BOOTPART="${BOOTPART:-/boot}" |
59 |
ebegin "Mounting ${BOOTPART}" |
60 |
mount "${BOOTPART}"; ret=$? |
61 |
eend ${ret} |
62 |
return ${ret} |
63 |
} |
64 |
|
65 |
load_image() { |
66 |
local ret |
67 |
if [ "${KNAME}" = "-" ]; then |
68 |
ebegin "Disabling kexec" |
69 |
kexec -u; ret=$? |
70 |
eend ${ret} |
71 |
return ${ret} |
72 |
fi |
73 |
|
74 |
BOOTPART="${BOOTPART:-/boot}" |
75 |
local img= initrd="$(initrd_path)" mounted=false initrdopt= |
76 |
|
77 |
if ! img="$(image_path)"; then |
78 |
if mount_boot; then |
79 |
if img="$(image_path)"; then |
80 |
mounted=true |
81 |
initrd="$(initrd_path)" |
82 |
else |
83 |
eerror "No kernel image found in ${BOOTPART}!" |
84 |
umount "${BOOTPART}" |
85 |
return 1 |
86 |
fi |
87 |
else |
88 |
eerror "No kernel image found in ${BOOTPART}!" |
89 |
return 1 |
90 |
fi |
91 |
fi |
92 |
|
93 |
if [ -n "${INITRD}" ] && \ |
94 |
! [ "${BOOTPART}/${INITRD#${BOOTPART}}" = "${initrd}" ]; then |
95 |
eerror "Requested initrd: ${INITRD#${BOOTPART}}" |
96 |
eerror "could not be found" |
97 |
return 1 |
98 |
fi |
99 |
|
100 |
[ -n "${ROOTPART}" ] || \ |
101 |
ROOTPART="$(readlink -f "$(sed -n '/^\/[^ ]* \/ / s,^\([^ ]*\).*,\1,p' /proc/mounts)")" |
102 |
|
103 |
[ -n "${KPARAM}" ] || KEXEC_OPT_ARGS="${KEXEC_OPT_ARGS} --reuse-cmdline" |
104 |
|
105 |
[ -n "${initrd}" ] && [ -e "${initrd}" ] && initrdopt="--initrd=${initrd}" |
106 |
|
107 |
local msg= |
108 |
[ -n "${initrd}" ] && \ |
109 |
msg="with ${initrd}" |
110 |
einfo "Using kernel image ${img} ${msg} for kexec" |
111 |
|
112 |
ebegin "Setting kexec with ${KEXEC_OPT_ARGS} -l ${img} root=${ROOTPART} ${KPARAM} ${initrdopt}" |
113 |
kexec ${KEXEC_OPT_ARGS} -l "${img}" --append="root=${ROOTPART} ${KPARAM}" ${initrdopt} |
114 |
local res=$? |
115 |
|
116 |
${mounted} && umount "${BOOTPART}" |
117 |
eend ${res} |
118 |
return ${res} |
119 |
} |
120 |
|
121 |
start() { |
122 |
if [ "${LOAD_DURING_SHUTDOWN:-yes}" = "yes" ]; then |
123 |
local ret=0 |
124 |
BOOTPART="${BOOTPART:-/boot}" |
125 |
if mount_boot; then |
126 |
mounted=true |
127 |
fi |
128 |
if ! image_path > /dev/null; then |
129 |
ewarn "Cannot find kernel image!" |
130 |
ewarn "Please make sure a valid kernel image is present before reboot." |
131 |
return 0 |
132 |
fi |
133 |
if [ -n "${mounted}" ]; then |
134 |
ebegin "Unmounting ${BOOTPART}" |
135 |
umount "${BOOTPART}"; ret=$? |
136 |
eend ${ret} |
137 |
fi |
138 |
return ${ret} |
139 |
else |
140 |
ebegin "Configuring kexec" |
141 |
load_image |
142 |
eend $? |
143 |
fi |
144 |
} |
145 |
|
146 |
stop() { |
147 |
if ! yesno $RC_REBOOT; then |
148 |
einfo "Not rebooting, so disabling" |
149 |
kexec -u |
150 |
return 0 |
151 |
fi |
152 |
|
153 |
if [ -f /nokexec ]; then |
154 |
einfo "Not using kexec during reboot" |
155 |
rm -f /nokexec |
156 |
kexec -u |
157 |
return 0 |
158 |
fi |
159 |
|
160 |
[ "${LOAD_DURING_SHUTDOWN:-yes}" != "yes" ] && return 0 |
161 |
|
162 |
ebegin "Configuring kexec" |
163 |
load_image |
164 |
eend $? |
165 |
} |
1 |
load_image() |
166 |
load_image() |
2 |
# kexec -d start |
167 |
# kexec -d start |
3 |
[snip] |
168 |
[snip] |
4 |
+ '[' -n /boot/initramfs.cpio.gz ']' |
169 |
+ '[' -n /boot/initramfs.cpio.gz ']' |
5 |
+ '[' /boot//initramfs.cpio.gz = /boot/initramfs.cpio.gz ']' |
170 |
+ '[' /boot//initramfs.cpio.gz = /boot/initramfs.cpio.gz ']' |
6 |
+ eerror 'Requested initrd: /initramfs.cpio.gz' |
171 |
+ eerror 'Requested initrd: /initramfs.cpio.gz' |
7 |
* Requested initrd: /initramfs.cpio.gz |
172 |
* Requested initrd: /initramfs.cpio.gz |
8 |
+ eerror 'could not be found' |
173 |
+ eerror 'could not be found' |
9 |
* could not be found |
174 |
* could not be found |
10 |
+ return 1 |
175 |
+ return 1 |
11 |
-- |
|
|
12 |
sys-apps/kexec-tools/files/kexec.init-2.0.4-r3 | 2 +- |
176 |
sys-apps/kexec-tools/files/kexec.init-2.0.4-r3 | 2 +- |
13 |
1 file changed, 1 insertion(+), 1 deletion(-) |
177 |
1 file changed, 1 insertion(+), 1 deletion(-) |