forked from openSUSE/suse-module-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
regenerate-initrd-posttrans
130 lines (116 loc) · 3.61 KB
/
regenerate-initrd-posttrans
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
#!/bin/sh
# Local variables:
# indent-tabs-mode: t
# sh-basic-offset: 8
# End:
#
# Packages that install kernels or kernel-modules create a flag
#
# /run/regenerate-initrd/<kernel version>
#
# to have the initrd for <kernel version> generated, or
#
# /run/regenerate-initrd/all
#
# to have all initrds generated. This script is called from posttrans
# and takes care of generating the initrds
# get the configured INITRD_GENERATOR from /etc/sysconfig/bootloader
INITRD_GENERATOR="$(. /etc/sysconfig/bootloader 2>/dev/null && echo "$INITRD_GENERATOR")"
[ "$INITRD_GENERATOR" = "mkosi" ] && INITRD_GENERATOR="mkosi-initrd"
# dracut is the default initrd generator
: "${INITRD_GENERATOR:=dracut}"
# check if the configured initrd generator is supported
[ "$INITRD_GENERATOR" = "dracut" ] || [ "$INITRD_GENERATOR" = "mkosi-initrd" ] || {
echo "${0##*/}: the initrd generator \"$INITRD_GENERATOR\" configured in /etc/sysconfig/bootloader is not supported." >&2
echo "${0##*/}: valid options are \"dracut\" or \"mkosi-initrd\"." >&2
exit 1
}
# check if the specific posttrans script is available
[ -x "/usr/lib/module-init-tools/${INITRD_GENERATOR}-posttrans" ] || {
echo "${0##*/}: missing required /usr/lib/module-init-tools/${INITRD_GENERATOR}-posttrans." >&2
exit 1
}
. /usr/lib/module-init-tools/"${INITRD_GENERATOR}"-posttrans
if [ -e "/usr/bin/sdbootutil" ] && /usr/bin/sdbootutil is-installed; then
is_sdbootutil=1
fi
dir=/run/regenerate-initrd
if ! test -d "$dir"; then
exit 0
fi
# If we are inside a transaction and using a separate /boot/efi
# partition (ESP) then we cannot touch it, as we will escape the
# atomicity promise. We need to delay the call to this script after
# the transaction has been completed. The component that will call
# again regenerate-initrd-posttrans to generate the new initrd is the
# sdbootutil snapper plugin (this time outside the live transaction),
# and the tukit plugin will migrate the signal from inside the
# transaction to outside.
if [ -n "$is_sdbootutil" ] && [ -n "$TRANSACTIONAL_UPDATE" ]; then
exit 0
fi
for f in "$dir"/*; do
case $f in
"$dir/*")
[ -e "$f" ] || break;;
esac
# check if we are in a build chroot
if [ ! -f /etc/fstab ] || [ -e /.buildenv ]; then
initrd_warn_chroot_build
rm "$dir"/*
exit 0
fi
break
done
err=0
work_done=
if test -e "$dir/all"; then
if [ "$SKIP_REGENERATE_INITRD_ALL" = 1 ]; then
rm "$dir/all"
else
rm "$dir"/*
if [ -n "$is_sdbootutil" ]; then
/usr/bin/sdbootutil --no-reuse-initrd --default-snapshot add-all-kernels
else
initrd_regenerate_all
fi
work_done=yes
fi
fi
for f in "$dir"/*; do
case $f in
"$dir/*")
[ -e "$f" ] || break;;
esac
rm -f "$f"
kver=${f##*/}
case "$kver" in
vmlinuz-*|image-*|vmlinux-*|linux-*|bzImage-*|uImage-*|Image-*|zImage-*)
kver=${kver#*-}
;;
esac
[ -d /lib/modules/"$kver" ] || {
echo "$0: skipping invalid kernel version $dir/$kver"
continue
}
if [ -n "$is_sdbootutil" ]; then
/usr/bin/sdbootutil --no-reuse-initrd --default-snapshot add-kernel "$kver"
err=$?
[ $err -eq 0 ] && work_done=yes
else
initrd_regenerate "$kver"
err=$?
[ $err -eq 0 ] && work_done=yes
fi
done
# Clean-up before exit
trap 'initrd_cleanup' EXIT
# For XEN/grub2 configurations, make sure the updated initrds are copied
# to the EFI system partition. See /etc/grub.d/20_linux_xen.
# The test for xen*.gz is simplistic but should be correct here.
# 20_linux_xen will apply more sophisticated heuristics to detect XEN.
[ ! "$work_done" ] || [ ! -d /sys/firmware/efi ] || \
[ ! -x /sbin/update-bootloader ] || \
[ "$(echo /boot/xen*.gz)" = "/boot/xen*.gz" ] || \
/sbin/update-bootloader --refresh
exit $err