1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: package/*/grub2/stone_mod_grub2.sh
3 # Copyright (C) 2004 - 2021 The T2 SDE Project
4 # Copyright (C) 1998 - 2003 ROCK Linux Project
6 # This Copyright note is generated by scripts/Create-CopyPatch,
7 # more information can be found in the files COPYING and README.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2.
11 # --- T2-COPYRIGHT-NOTE-END ---
13 # [MAIN] 70 grub2 GRUB2 Boot Loader Setup
17 # void efibootmgr duplicates :-/
19 # impl. & test direct sparc, direct i386-pc-mbr, mips-arc, ...
20 # unify non-crypt, and direct non-EFI BIOS install
23 arch
=${arch/i?86/i386}
24 arch
=${arch/aarch/arm}
26 create_kernel_list
() {
28 for x
in `(cd /boot/; ls vmlinux-* ) | sort -r`; do
30 [[ $arch = *86* ]] && x
=${x/vmlinux/vmlinuz}
31 [[ $arch = *arm
* ]] && x
=${x/vmlinux/Image}.gz
32 if [ $first = 1 ]; then
40 menuentry "T2/Linux $label" {
41 linux $bootpath/$x root=$rootdev ro
42 initrd $bootpath/initrd-${ver}
50 # determine /boot path, relative to the boot device
51 # (non local as used by create_kernel_list() ...)
53 [ "$rootdev" = "$bootdev" ] && bootpath
="/boot" || bootpath
=""
56 cat << EOT > /boot/grub/grub.cfg
61 if [ "\$grub_platform" = "efi" ]; then
66 if loadfont \${prefix}/unicode.pf2; then
70 terminal_output gfxterm
75 if [ -z "$cryptdev" ]; then
76 cat << EOT >> /boot/grub/grub.cfg
78 search --set=root --no-floppy --fs-uuid \$uuid
82 cat << EOT >> /boot/grub/grub.cfg
88 create_kernel_list
>> /boot
/grub
/grub.cfg
90 gui_message
"This is the new /boot/grub/grub.cfg file:
92 $( cat /boot/grub/grub.cfg )"
96 grubmods
="normal boot configfile linux part_msdos part_gpt \
97 fat ext2 iso9660 reiserfs xfs jfs lvm \
98 crypto cryptodisk luks all_video sleep reboot \
99 search search_fs_file search_label search_fs_uuid"
102 ppc
*) grubmods
="$grubmods part_apple hfs hfsplus suspend" ;;
103 sparc
*) grubmods
="$grubmods part_sun" ;;
104 x86
*) grubmods
="$grubmods ntfs ntfscomp" ;;
108 if [[ $arch != ppc
* ]]; then
109 if [ -z "$cryptdev" -a ! -d /sys
/firmware
/efi
]; then
110 if [[ "$arch" != sparc
* ]]; then
111 grub2-install
$instdev
113 grub2-install
--skip-fs-probe --force $instdev
116 for efi
in /boot
/efi
*; do
117 mkdir
-p $efi/EFI
/boot
119 if [ -z "$cryptdev" ]; then
120 cat << EOT > $efi/EFI/boot/grub.cfg
122 search --set=root --no-floppy --fs-uuid \$uuid
123 configfile (\$root)/boot/grub/grub.cfg
126 cat << EOT > $efi/EFI/boot/grub.cfg
128 cryptomount -u \$uuid
129 configfile (crypto0)/boot/grub/grub.cfg
133 local exe
=BOOTX64.EFI
134 [ $arch = i386
] && exe
=${exe/X64/IA32}
135 [ $arch = arm64
] && exe
=${exe/X/AA}
136 [[ $arch = riscv
* ]] && exe
={exe
/X64
/${arch^^}}
138 grub-mkimage
-O $arch-efi -o $efi/EFI
/boot
/$exe \
139 -p /efi
/boot
-d /usr
/lib
*/grub
/$arch-efi/ \
142 efibootmgr
-c -L "T2 Linux" -l "\\EFI\\boot\\$exe"
145 # Apple PowerPC - install into FW read-able HFS partition
146 local bootstrap
=$instdev$
(disktype
$instdev |
grep Apple_Bootstrap
-B 1 |
147 sed -n 's/Partition \(.*\):.*/\1/p')
148 if [ "$bootstrap" = "$instdev" ]; then
149 echo "No HFS bootstrap partition found!"
153 umount
/mnt
2>/dev
/null
154 hformat
-l bootstrap
$bootstrap
155 if ! mount
$bootstrap /mnt
; then
156 echo "Error mounting HFS bootstrap partition"
158 mkdir
-p /mnt
/boot
/grub
159 if [ -z "$cryptdev" ]; then
160 cat << EOT > /mnt/boot/grub/grub.cfg
162 search --set=root --no-floppy --fs-uuid \$uuid
163 configfile (\$root)/boot/grub/grub.cfg
166 cat << EOT > /mnt/boot/grub/grub.cfg
168 cryptomount -u \$uuid
169 configfile (crypto0)/boot/grub/grub.cfg
172 grub-mkimage
-O powerpc-ieee1275
-p /boot
/grub \
173 -o /mnt
/boot
/grub.elf
-d /usr
/lib
*/grub
/powerpc-ieee1275 \
176 cat > /mnt
/ofboot.b
<<-EOT
179 MacRISC MacRISC3 MacRISC4
186 load-base release-load-area
187 boot hd:2,\\boot\\grub.elf
191 000000000000F8FEACF6000000000000
192 0000000000F5FFFFFEFEF50000000000
193 00000000002BFAFEFAFCF70000000000
194 0000000000F65D5857812B0000000000
195 0000000000F5350B2F88560000000000
196 0000000000F6335708F8FE0000000000
197 00000000005600F600F5FD8100000000
198 00000000F9F8000000F5FAFFF8000000
199 000000008100F5F50000F6FEFE000000
200 000000F8F700F500F50000FCFFF70000
201 00000088F70000F50000F5FCFF2B0000
202 0000002F582A00F5000008ADE02C0000
203 00090B0A35A62B0000002D3B350A0000
204 000A0A0B0B3BF60000505E0B0A0B0A00
205 002E350B0B2F87FAFCF45F0B2E090000
206 00000007335FF82BF72B575907000000
207 000000000000ACFFFF81000000000000
208 000000000081FFFFFFFF810000000000
209 0000000000FBFFFFFFFFAC0000000000
210 000000000081DFDFDFFFFB0000000000
211 000000000081DD5F83FFFD0000000000
212 000000000081DDDF5EACFF0000000000
213 0000000000FDF981F981FFFF00000000
214 00000000FFACF9F9F981FFFFAC000000
215 00000000FFF98181F9F981FFFF000000
216 000000ACACF981F981F9F9FFFFAC0000
217 000000FFACF9F981F9F981FFFFFB0000
218 00000083DFFBF981F9F95EFFFFFC0000
219 005F5F5FDDFFFBF9F9F983DDDD5F0000
220 005F5F5F5FDD81F9F9E7DF5F5F5F5F00
221 0083DD5F5F83FFFFFFFFDF5F835F0000
222 000000FBDDDFACFBACFBDFDFFB000000
223 000000000000FFFFFFFF000000000000
224 0000000000FFFFFFFFFFFF0000000000
225 0000000000FFFFFFFFFFFF0000000000
226 0000000000FFFFFFFFFFFF0000000000
227 0000000000FFFFFFFFFFFF0000000000
228 0000000000FFFFFFFFFFFF0000000000
229 0000000000FFFFFFFFFFFFFF00000000
230 00000000FFFFFFFFFFFFFFFFFF000000
231 00000000FFFFFFFFFFFFFFFFFF000000
232 000000FFFFFFFFFFFFFFFFFFFFFF0000
233 000000FFFFFFFFFFFFFFFFFFFFFF0000
234 000000FFFFFFFFFFFFFFFFFFFFFF0000
235 00FFFFFFFFFFFFFFFFFFFFFFFFFF0000
236 00FFFFFFFFFFFFFFFFFFFFFFFFFFFF00
237 00FFFFFFFFFFFFFFFFFFFFFFFFFF0000
238 000000FFFFFFFFFFFFFFFFFFFF000000
245 hattrib
-b bootstrap
:
246 hattrib
-c UNIX
-t tbxi bootstrap
:ofboot.b
254 gui_cmd
'Installing GRUB2' "grub_inst"
259 local devnode
=$
(stat
-c "%t:%T" $dev)
260 for d
in /dev
/dm-
*; do
261 [ "$(stat -c "%t
:%T
" "$d")" = "$devnode" ] && echo $d && return
268 [ -e /sys
/block
/$dev/dm
/uuid
] && cat /sys
/block
/$dev/dm
/uuid
275 for _dev
in /dev
/disk
/by-uuid
/*; do
276 local d
=$
(readlink
$_dev)
278 if [ "$d" = $dev ]; then
288 [ "$dev" ] && echo /dev
/${dev##*/} ||
echo $1
292 rootdev
="`grep ' / ' /proc/mounts | tail -n 1 | sed 's, .*,,'`"
293 bootdev
="`grep ' /boot ' /proc/mounts | tail -n 1 | sed 's, .*,,'`"
295 # if device-mapper, get backing device
296 if [[ "$rootdev" = *mapper
* ]]; then
297 rootdev2
=$
(get_dm_dev
$rootdev)
299 if [[ "$(get_dm_type $rootdev2)" = CRYPT
* ]]; then
301 realroot
=$
(cd /sys
/block
/${rootdev##*/}/slaves
/; ls -d [a-z
]*)
302 if [ "$realroot" ]; then
303 rootdev
="/dev/$realroot"
307 cryptdev
="lvm/${rootdev#/dev/mapper/}"
312 uuid
=$
(get_uuid
$rootdev)
313 [ "$uuid" ] && rootdev
=$uuid
314 if [ "$bootdev" ]; then
315 uuid
=$
(get_uuid
$bootdev)
316 [ "$uuid" ] && bootdev
=$uuid
319 [ "$bootdev" ] || bootdev
="$rootdev"
320 instdev
=$
(get_realdev
$bootdev); instdev
="${instdev%%[0-9*]}"
321 [ "$grubdev" ] || grubdev
="${bootdev##*/}"
323 if [ ! -f /boot
/grub
/grub.cfg
]; then
324 if gui_yesno
"GRUB2 does not appear to be configured.
325 Automatically install GRUB2 now?"; then
327 if ! grub_install
; then
328 gui_message
"There was an error while installing GRUB2."
335 gui_menu grub
'GRUB2 Boot Loader Setup' \
336 "Root device ... $rootdev" "" \
337 "Boot device ... $bootdev" "" \
338 "Crypt device .. $cryptdev" "" \
339 "Grub device ... $grubdev" "" \
340 "Inst device ... $instdev" "" \
342 '(Re-)Create boot menu with installed kernels' 'create_boot_menu' \
343 "(Re-)Install GRUB2 in boot record ($instdev)" 'grub_install' \
345 "Edit /boot/grub/grub.cfg (Boot Menu)" \
346 "gui_edit 'GRUB2 Boot Menu' /boot/grub/grub.cfg"