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
|
From 0cc00b53d8e918699413dbe1ddd1989bb4ddec4a Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Wed, 15 Jul 2015 15:10:42 +0200
Subject: [PATCH] setup-bootable: warn and fix kernel name change
---
setup-bootable.in | 103 +++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 94 insertions(+), 9 deletions(-)
diff --git a/setup-bootable.in b/setup-bootable.in
index 116f776..35a5f73 100644
--- a/setup-bootable.in
+++ b/setup-bootable.in
@@ -84,10 +84,87 @@ find_disk_dev() {
return 1
}
+find_syslinux_cfg() {
+ # find where new syslinux.cfg is
+ for i in boot/syslinux/syslinux.cfg syslinux.cfg; do
+ if [ -e "$1"/$i ]; then
+ syslinux_cfg=$i
+ vecho "Found $syslinux_cfg"
+ break
+ fi
+ done
+}
+
+fix_syslinux_kernel() {
+ echo "Fixing $syslinux_cfg: kernel $1 -> $2"
+ sed -i -e "/^\s*[Kk][Ee][Rr][Nn][Ee][Ll]\s/s|$1|$2|" \
+ "$destdir/$syslinux_cfg"
+}
+
+fix_syslinux_initrd() {
+ echo "Fixing $syslinux_cfg: initrd $1 -> $2"
+ sed -i -e "/^\s*[Ii][Nn][Ii][Tt][Rr][Dd]\s/s|$1|$2|" \
+ -e "/^\s*[Aa][Pp][Pp][Ee][Nn][Dd]\s/s|initrd=$1|initrd=$2|" \
+ "$destdir/$syslinux_cfg"
+}
+
+check_syslinux() {
+ if [ -z "$syslinux_cfg" ]; then
+ find_syslinux_cfg "$destdir"
+ fi
+ if [ -z "$syslinux_cfg" ]; then
+ die "Could not find any syslinux.cfg. Aborting"
+ fi
+
+ # kernels
+ for i in $(awk 'tolower($1) == "kernel" {print $2}' "$destdir"/$syslinux_cfg); do
+ k="${destdir%/}/${i#/}"
+ f=${k##*/}
+
+ if [ -e "$k" ] && [ "${f#vmlinuz}" != "$f" ]; then
+ continue
+ fi
+
+ if [ -e "${k%/*}"/vmlinuz-$f ] && [ -n "$fix_syslinux_cfg" ]; then
+ fix_syslinux_kernel "$i" "${i%/*}"/vmlinuz-$f
+ elif ! [ -e "$k" ]; then
+ echo "Warning: $syslinux_cfg: kernel $k was not found"
+ echo " Run $0 -c -f "$destdir" to fix"
+ fi
+ done
+
+ #initramfs
+ initrds=$(awk 'tolower($1) == "initrd" {print $2}' \
+ "$destdir"/$syslinux_cfg)
+ for i in $(awk 'tolower($1) == "append" {print $0}' \
+ "$destdir"/$syslinux_cfg); do
+ case $i in
+ initrd=*) initrds=${i#initrd=};;
+ esac
+ done
+
+ for i in $initrds; do
+ if [ -e "$destdir"/$i ]; then
+ continue
+ fi
+ fname=${i##*/}
+ flavor=${fname%.gz}
+
+ new=${i%/*}/initramfs-$flavor
+ if [ -e "$destdir"/$new ] && [ -n "$fix_syslinux_cfg" ]; then
+ fix_syslinux_initrd "$i" "$new"
+ else
+ echo "Warning: initrd $i was not found. System will likely not boot"
+ echo " Run $0 -f -c "$destdir" to fix"
+ fi
+ done
+}
+
usage() {
cat <<__EOF__
$prog $version
usage: $prog [-fhUusv] SOURCE [DEST]
+ $prog -c DIR
Copy the contents of SOURCE to DEST and make DEST bootable.
@@ -97,19 +174,24 @@ or a device. If DEST is ommitted /media/usb will be used.
Options:
-f Force overwrite existing files. Will overwrite syslinux.cfg if upgrade.
-h Show this help.
+ -k fix kernel and initrd name in syslinux.cfg if needed.
-U Replace current alpine_dev in syslinux.cfg with UUID if UUID found.
-u Upgrade mode. Keep existing syslinux.cfg and don't run syslinux.
-s Force run syslinux, even if upgrade mode.
-v Verbose mode. Display whats going on.
+ -c Check syslinux.cfg in destination DIR. Use with -f to fix.
+
__EOF__
exit 1
}
-while getopts "fhUusv" opt; do
+while getopts "c:fhkUusv" opt; do
case "$opt" in
- f) force=1;;
+ c) check_syslinux="$OPTARG";;
+ f) force=1; fix_syslinux_cfg=1;;
h) usage;;
+ k) fix_syslinux_cfg=1;;
U) replace_alpine_dev=1;;
u) upgrade=1;;
s) syslinux=1;;
@@ -122,6 +204,11 @@ shift $(($OPTIND - 1))
src=${1}
dest=${2:-/media/usb}
+if [ -n "$check_syslinux" ]; then
+ destdir="$check_syslinux"
+ check_syslinux
+ exit 0
+fi
[ -z "$src" ] && usage
@@ -235,13 +322,8 @@ elif [ -n "$srcurl" ]; then
fi
# find where new syslinux.cfg is
-for i in boot/syslinux/syslinux.cfg syslinux.cfg; do
- if [ -e "$destdir"/.new/$i ]; then
- syslinux_cfg=$i
- vecho "Found $syslinux_cfg"
- break
- fi
-done
+find_syslinux_cfg "$destdir"/.new
+
# abort early in case unexpected trouble
if [ -z "$syslinux_cfg" ]; then
die "Could not find any syslinux.cfg on new iso?"
@@ -288,6 +370,9 @@ if [ -n "$replace_alpine_dev" -o -z "$upgrade" ] && [ -n "$UUID" ]; then
"$destdir"/$syslinux_cfg
fi
+# verify syslinux.cfg
+check_syslinux
+
# cleanup
[ -z "$keep_old" ] && rm -rf "$destdir"/.old "$destdir"/.new
--
2.4.5
|