Debian Codegraph @

conf/boot-local-efi.cfg

raw symbols SCIP
1 # License: GPL
2 # Author: Steven Shiau <steven _at_ clonezilla org>
3 # Description:
4 # Grub2 config file to find the EFI boot loader in 1st hard drive, then boot
5 # Ref: git repository, docs/{osdetect.cfg,autoiso.cfg}
6 # https://lists.gnu.org/archive/html/grub-devel/2013-11/msg00259.html
7 # This file is used by gen-grub-efi-nb-menu and ocs-live-boot-menu.
8 # Not intended to be used directly.
9
10 # Possible EFI boot loader file:
11 # /EFI/redhat/grub.efi
12 # /EFI/fedora/shim.efi
13 # /EFI/fedora/grubx64.efi
14 # /EFI/centos/grubx64.efi
15 # /EFI/debian/grubx64.efi
16 # /EFI/ubuntu/grubx64.efi
17 # /EFI/mageia/grubx64.efi
18 # /EFI/opensuse/grubx64.efi
19 # /EFI/sled12/grubx64.efi
20 # /EFI/SuSE/elilo.efi
21 # /EFI/Boot/bootx64.efi
22 # /EFI/Microsoft/Boot/bootmgfw.efi
23 # /EFI/centos/grubaa64.efi
24 # /EFI/debian/grubaa64.efi
25 # /EFI/ubuntu/grubaa64.efi
26 # /EFI/fedora/grubaa64.efi
27 # /EFI/redhat/grubaa64.efi
28 # /EFI/opensuse/grubaa64.efi
29 # /EFI/Boot/bootaa64.efi
30
31 # efidirs is only used in backup plan. If Ubuntu fixes regexp issue:
32 # https://bugs.launchpad.net/bugs/1829331
33 # then actually the backup plan can be removed in the future.
34 efidirs="redhat fedora centos debian ubuntu mageia opensuse sled12 SuSE Boot boot Microsoft/Boot"
35 # //NOTE// Rememer to sync the variable efiblfiles in clonezilla/sbin/update-efi-nvram-boot-entry.
36 efiblfiles="shimx64.efi shim.efi grubx64.efi grub.efi elilo.efi bootx64.efi Boot/bootmgfw.efi grubaa64.efi bootaa64.efi bootarm.efi"
37 # Disk and parts list are for the backup plan. List the possible ones, default 3 disks and 4 parts.
38 disk_list="hd0 hd1 hd2"
39 parts_list="gpt1 gpt2 gpt3 gpt4"
40
41 function scan_dev {
42 dev="$1" # e.g., (hd0), (hd0,gpt1)
43 partition="$2" # e.g., (hd0,gpt1)
44 fstype="$3" # e.g., fat
45 use_efidirs="$4" # e.g., yes
46 echo "Processing dev: $dev"
47 dirs_list=""
48 vendor_list=""
49 rc="1"
50 if [ -z "$partition" ]; then
51 # $partition: parenthesis removed from $dev
52 regexp -s partition '\((hd.*,.*)\)' $dev
53 if [ -z "$partition" ]; then
54 # Not hd0, continue searching the next one
55 echo "No any partition was found on device $dev. Continue to the next one if available."
56 return 1
57 fi
58 fi
59 if [ -z "$fstype" ]; then
60 # $fstype: filesystem type identified
61 probe -s fstype -f $partition
62 fi
63 if test $fstype = "fat"; then
64 # Found possible EFI partition since it definitely has to be FAT.
65 # Search /EFI/*/*.efi
66 obreak="no"
67 efi_boot="no"
68 set root=$partition
69 efi_boot_append=""
70 # Due to this bug (regexp issue), we have to explicitly show vendor dir
71 # https://bugs.launchpad.net/bugs/1829331
72 if [ "$use_efidirs" = "yes" ]; then
73 for ivend in $efidirs; do
74 # prepend /EFI/
75 vendor_list="$vendor_list /EFI/$ivend"
76 done
77 else
78 vendor_list="/EFI/*"
79 fi
80 for idir in $vendor_list; do
81 # We only need dir in 2nd level of path
82 if [ ! -d "$idir" ]; then
83 continue
84 fi
85 if [ "$idir" = "/EFI/boot" -o "$idir" = "/EFI/Boot" ]; then
86 # Should not add /EFI/{boot,Boot} now, make it as the last one later.
87 efi_boot="yes"
88 efi_boot_append="$idir"
89 continue
90 fi
91 dirs_list="$dirs_list $idir"
92 done
93 if [ "$efi_boot" = "yes" ]; then
94 dirs_list="$dirs_list $efi_boot_append"
95 fi
96 for dir in $dirs_list; do
97 for file in $efiblfiles; do
98 if test -f $dir/$file; then
99 echo "Found EFI boot loader: $dir/$file"
100 set timeout=10
101 menuentry "$dir (on $partition)" $partition "$dir/$file" {
102 set root=$2
103 set efibl=$3
104 chainloader $efibl
105 boot
106 }
107 obreak="yes"
108 break
109 fi
110 done
111 if [ "$obreak" = "yes" ]; then
112 break
113 rc=0
114 fi
115 done
116 fi
117 return $rc
118 echo "End creating menu..."
119 }
120
121 insmod regexp
122 auto_detect="yes"
123 for dev in (*); do
124 if [ "$dev" = "(*)" ]; then
125 # Encounter this issue (regexp fails):
126 # https://bugs.launchpad.net/bugs/1829331
127 # i.e., (*) cannot be expanded as (hd0), (cd0), (hd0,gpt1)...
128 auto_detect="no"
129 break
130 fi
131 echo "Now checking the device $dev..."
132 scan_dev $dev
133 done
134 # Using backup plan if auto gen fails.
135 if [ "$auto_detect" = "no" ]; then
136 echo "Using backup plan..."
137 for disk in $disk_list; do
138 for part in $parts_list; do
139 scan_dev ($disk,$part) ($disk,$part) fat yes
140 done
141 done
142 fi