Gentoo Archives: gentoo-commits

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