Debian Codegraph @

linux-boot-probes/mounted/common/90fallback

raw
1 #!/bin/sh
2 # Fallback in case nothing else works. Look for vmlinu[xz] file in root and
3 # /boot, see if there is a matching initrd, and wing it.
4 . /usr/share/os-prober/common.sh
5 set -e
6
7 partition="$1"
8 bootpart="$2"
9 mpoint="$3"
10 type="$4"
11
12 mappedpartition=$(mapdevfs "$partition" 2>/dev/null) || mappedpartition="$partition"
13
14 exitcode=1
15 for kernpat in /vmlinuz /vmlinux /boot/vmlinuz /boot/vmlinux "/boot/vmlinuz*" \
16 "/boot/vmlinux*" "/vmlinuz*" "/vmlinux*" "/kernel-*" "/boot/kernel-*"; do
17 if echo "$kernpat" | grep -q boot/; then
18 kernbootpart="$bootpart"
19 else
20 kernbootpart="$partition"
21 fi
22 for kernfile in $(eval ls -vr "$mpoint$kernpat" 2>/dev/null); do
23 kernbasefile=$(echo "$kernfile" | sed "s!^$mpoint!!")
24 if [ -f "$kernfile" ] && [ ! -L "$kernfile" ]; then
25 initrdname=$(echo "$kernfile" | sed "s/vmlinu[zx]/initrd\*/")
26 # Yellow Dog Linux appends .img to it.
27 initrdname1="${initrdname}.img"
28 # Arch Linux names its initrds weirdly. We take
29 # some care here to avoid false positives on other
30 # systems, since kernel.img could conceivably be a
31 # kernel itself.
32 initrdname2=$(echo "$kernfile" | sed -n 's/vmlinu[zx]\([0-9][0-9]*\)/kernel\1/p' | sed 's/$/.img/')
33 # Dracut initramfses are named differently again.
34 initrdname3=$(echo "$kernfile" | sed "s/vmlinu[zx]/initramfs\*/" | sed 's/$/.img/')
35 # And Gentoo's also
36 initrdname4=$(echo "$kernfile" | sed "s/kernel/initramfs\*/")
37 # Also Alpine
38 initrdname5=$(echo "$kernfile" | sed "s/vmlinu[zx]/initramfs\*/")
39 foundinitrd=0
40 for initrd in $(eval ls "$initrdname" "$initrdname1" "$initrdname2" "$initrdname3" "$initrdname4" "$initrdname5" 2>/dev/null); do
41 if [ "$initrd" != "$kernfile" ] && [ -f "$initrd" ] && [ ! -L "$initrd" ]; then
42 initrd=$(echo "$initrd" | sed "s!^$mpoint!!")
43 result "$partition:$kernbootpart::$kernbasefile:$initrd:root=$mappedpartition"
44 exitcode=0
45 foundinitrd=1
46 fi
47 done
48 if [ "$foundinitrd" = 0 ]; then
49 result "$partition:$kernbootpart::$kernbasefile::root=$mappedpartition"
50 exitcode=0
51 fi
52 fi
53 done
54 done
55 exit "$exitcode"