forked from openSUSE/update-bootloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootloader_entry
More file actions
executable file
·353 lines (303 loc) · 10.7 KB
/
bootloader_entry
File metadata and controls
executable file
·353 lines (303 loc) · 10.7 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#!/bin/bash
#
# This script represents an interface between the postinstall and postuninstall
# scripts of kernel rpms and the update-bootloader script.
#
# Interface:
# ----------
# /usr/lib/bootloader/bootloader_entry [add|remove] <kernel-flavor> <kernel-release> <image-name> <initrd-name>
#
# Call Semantics:
# ---------------
# [ -x $cmd ] && $cmd <parameters>
#
#
# Author: aosthof@suse.de
#
# Print how to use this script correctly
function usage()
{
echo "Unknown or missing parameter."
echo "Usage: $0 [add|remove] <kernel-flavor> <kernel-release> <image-name> <initrd-name> [force-default]"
echo
echo "The old interface with 4 parameters is still supported, but deprecated."
echo "This interface will be dropped in the near future."
echo "Usage: $0 [add|remove] <kernel-package-name> <image-name> <initrd-name>"
exit 1
}
# Get all command line arguments
function getargs()
{
# old interface with 4 parameters
if [ $# -eq 4 ] ; then
action=${1} # contains the action to be executed, e.g. "add" or "remove"
flavor=${2#*-} # contains the kernel-flavor, e.g. "default" or "xen"
flavor=${flavor%%-*}
release=${2#*-*-} # contains the kernel-release, e.g. "2.6.18-4-default"
release=${release%.*.*}
release="${release}-${flavor}"
image=${3} # contains the full image name, e.g. "vmlinuz-2.6.18-4-default"
initrd=${4} # contains the full initrd name, e.g. "initrd-2.6.18-4-default"
# new interface with 5 or 6 parameters, depends whether option
# "force-default" is used or not
else
action=${1} # contains the action to be executed, e.g. "add" or "remove"
flavor=${2} # contains the kernel-flavor, e.g. "default" or "xen"
release=${3} # contains the kernel-release, e.g. "2.6.18-4-default"
image=${4} # contains the full image name, e.g. "vmlinuz-2.6.18-4-default"
initrd=${5} # contains the full initrd name, e.g. "initrd-2.6.18-4-default"
forcedefault=${6} # contains action which forces corresponding boot entry beeing the
# default boot entry, enabled by given parameter "force-default"
fi
}
# Wrapper for the update-bootloader function
function update_bootloader()
{
echo "bootloader_entry: This is (wrapper) function update_bootloader" >> $logname
[ -x /sbin/update-bootloader ] || return 0
# call update-bootloader and also append stderr to the log file
/sbin/update-bootloader "$@" 1>>$logname 2>&1
}
##############################
# Add a new bootloader entry #
##############################
function add_entry()
{
echo "bootloader_entry: This is function add_entry()" >> $logname
# If running in instsys, write command(s) to be executed in a file
# which will be executed by yast2-bootloader after installation of
# packages is finished.
#
# This is to prevent inconsistencies triggered by libata migration.
if [ "$YAST_IS_RUNNING" == instsys -a "$DELAYED_RUN_UPDATE_BOOTLOADER" != yes ]; then
cat - >> $delayed_exec_file <<-EOF
#!/bin/sh
export DELAYED_RUN_UPDATE_BOOTLOADER=yes
/usr/lib/bootloader/bootloader_entry $@
EOF
chmod 755 $delayed_exec_file
else
# Set up the new kernel
if [ -f $PERL_BOOTLOADER_TESTSUITE_PATH/etc/sysconfig/bootloader ] &&
[ -f $PERL_BOOTLOADER_TESTSUITE_PATH/boot/grub/menu.lst -o \
-f $PERL_BOOTLOADER_TESTSUITE_PATH/etc/lilo.conf -o \
-f $PERL_BOOTLOADER_TESTSUITE_PATH/etc/elilo.conf -o \
-f $PERL_BOOTLOADER_TESTSUITE_PATH/etc/zipl.conf ]; then
default=""
if test ! "$PBL_AUTOTEST"; then
default="--default"
fi
case $flavor in
(kdump|um)
;;
(xen*)
opt_xen_kernel=
if [ -e /proc/xen/xsd_port -o ! -e /proc/xen ]; then
set -- $flavor
set -- ${1#xen}
opt_xen_kernel=--xen-kernel=/boot/xen${1:+-$1}.gz
fi
if [ "$forcedefault" == "force-default" ]; then
# Add the new bootloader entry (xen kernel)
# and force it beeing the default entry
update_bootloader --image /boot/$image \
--initrd /boot/$initrd \
$default \
--force-default \
--add \
--force $opt_xen_kernel \
--name "$release" \
|| exit 1
else
# Add the new bootloader entry (xen kernel)
update_bootloader --image /boot/$image \
--initrd /boot/$initrd \
$default \
--add \
--force $opt_xen_kernel \
--name "$release" \
|| exit 1
fi
# Run the bootloader (e.g., lilo).
update_bootloader --refresh || exit 1
;;
(debug)
if [ "$forcedefault" == "force-default" ]; then
# Add the new bootloader entry (debug kernel)
# and force it beeing the default entry
update_bootloader --image /boot/$image \
--initrd /boot/$initrd \
--force-default \
--add \
--force \
--name "$release" \
|| exit 1
else
# Add the new bootloader entry (debug kernel)
update_bootloader --image /boot/$image \
--initrd /boot/$initrd \
--add \
--force \
--name "$release" \
|| exit 1
fi
# Run the bootloader (e.g., lilo).
update_bootloader --refresh || exit 1
;;
(*)
if [ "$forcedefault" == "force-default" ]; then
# Add the new bootloader entry
# and force it beeing the default entry
update_bootloader --image /boot/$image \
--initrd /boot/$initrd \
--default \
--force-default \
--add \
--force \
--name "$release" \
|| exit 1
else
# Add the new bootloader entry
update_bootloader --image /boot/$image \
--initrd /boot/$initrd \
$default \
--add \
--force \
--name "$release" \
|| exit 1
fi
# Run the bootloader (e.g., lilo).
update_bootloader --refresh || exit 1
;;
esac
elif [ -f $PERL_BOOTLOADER_TESTSUITE_PATH/etc/sysconfig/bootloader ] &&
[ -f $PERL_BOOTLOADER_TESTSUITE_PATH/boot/grub2/grub.cfg -o \
-f $PERL_BOOTLOADER_TESTSUITE_PATH/boot/grub2-efi/grub.cfg ]; then
update_bootloader --refresh || exit 1
fi
fi
}
#######################################
# Remove an existing bootloader entry #
#######################################
function remove_entry()
{
echo "bootloader_entry: This is function remove_entry()" >> $logname
# If running in instsys, write command(s) to be executed in a file
# which will be executed by yast2-bootloader after installation of
# packages is finished.
#
# This is to prevent inconsistencies triggered by libata migration.
if [ "$YAST_IS_RUNNING" == instsys -a "$DELAYED_RUN_UPDATE_BOOTLOADER" != yes ]; then
cat - >> $delayed_exec_file <<-EOF
#!/bin/sh
export DELAYED_RUN_UPDATE_BOOTLOADER=yes
/usr/lib/bootloader/bootloader_entry $@
EOF
chmod 755 $delayed_exec_file
else
if [ -f $PERL_BOOTLOADER_TESTSUITE_PATH/etc/sysconfig/bootloader ] &&
[ -f $PERL_BOOTLOADER_TESTSUITE_PATH/boot/grub/menu.lst -o \
-f $PERL_BOOTLOADER_TESTSUITE_PATH/etc/lilo.conf -o \
-f $PERL_BOOTLOADER_TESTSUITE_PATH/etc/elilo.conf -o \
-f $PERL_BOOTLOADER_TESTSUITE_PATH/etc/zipl.conf ]; then
# Do not specify the name of a bootloader entry when removing it, thus
# removing all sections matching the kernel image and initrd names
# (either both a "linux" and a "failsafe" section, or a section
# installed with the kernel postinstall script).
#
# Rationale: we do not know whether the old entry has
# - the product name as its name (when installed with
# yast-bootloader) or
# - "Kernel-<version>" (when installed with the kernel package's
# postinstall script and perl-Bootloader).
#
# So we cannot use the name to find the correct section.
# This is safe, because on grub, this does still not match other
# sections on other partitions with the same name for the kernel
# image and initrd (because they will still have the (hdx,y) prefix
# in perl-Bootloader). Other bootloaders do not specify other
# sections at all, or do only chainload them (BootLILO.ycp), and
# thus do not match either. (#223030)
if [[ "$flavor" =~ xen ]] && [ -e /proc/xen/xsd_port -o ! -e /proc/xen ]; then
update_bootloader --image /boot/$image \
--initrd /boot/$initrd \
--xen \
--remove \
--force \
|| exit 1
else
update_bootloader --image /boot/$image \
--initrd /boot/$initrd \
--remove \
--force \
|| exit 1
fi
# Run the bootloader (e.g., lilo).
update_bootloader --refresh || exit 1
elif [ -f $PERL_BOOTLOADER_TESTSUITE_PATH/etc/sysconfig/bootloader ] &&
[ -f $PERL_BOOTLOADER_TESTSUITE_PATH/boot/grub2/grub.cfg -o \
-f $PERL_BOOTLOADER_TESTSUITE_PATH/boot/grub2-efi/grub.cfg ]; then
update_bootloader --refresh || exit 1
fi
fi
}
##################### M A I N ###############################################
# Log how program was called
logname=$PERL_BOOTLOADER_TESTSUITE_PATH"/var/log/YaST2/perl-BL-standalone-log"
echo "bootloader_entry was called as: $*" >> $logname
# Log parts of the current system configuration
(
echo "/proc/mounts:"
cat /proc/mounts
echo
echo "/sys:"
ls -l /sys
echo
fstab="/etc/fstab"
if [ -e $fstab ] ; then
echo "fstab:"
cat $fstab
echo
fi
echo "excerpts of /dev:"
#if doesn't find anything you can be on strange architecture (like ps3) and dump all block devices
ls -l /dev/{[hs]d[ab]?,md[0-3],.udev,disk/by-*} 2>/dev/null || ls -l /dev | grep ^b
echo
device_map="/boot/grub/device.map"
if [ -e $device_map ] ; then
echo "device.map:"
cat $device_map
echo
fi
) >> $logname
if test ! "$PBL_SKIP_BOOT_TEST"; then
if test `grep -c "^[^#[:space:]]\+[[:space:]]\+/boot[[:space:]]" /etc/fstab` -ne \
`grep -c "^[^[:space:]]\+[[:space:]]\+/boot[[:space:]]" /proc/mounts`; then
echo "/boot directory is not mounted. If this is bad detection you can avoid it by 'export PBL_SKIP_BOOT_TEST=1'";
exit 1;
fi
fi
# File containing commands for later execution
delayed_exec_file="/boot/perl-BL_delayed_exec"
# Checks if correct amount of arguments is given
if [ "$#" -lt "4" -o "$#" -gt "6" ] ; then
usage
fi
# Get all given arguments
getargs $@
# Find out which action should be executed
case $action in
add)
# Add a new bootloader entry
add_entry "$@"
;;
remove)
# Remove an existing bootloader entry
remove_entry "$@"
;;
*)
# Unknown argument
usage
;;
esac