-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrub.cfg
94 lines (79 loc) · 2.85 KB
/
grub.cfg
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
serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
set timeout=3
set timeout_style=menu
# Load GRUB environment variables
load_env -f /EFI/BOOT/grub.env
# Reset or decrement boot counter based on 'ustate'
if [ "${ustate}" != "1" ]; then
set boot_counter=3
else
if [ -z "${boot_counter}" ]; then
set boot_counter=2
else
if [ "${boot_counter}" == "1" ]; then
set boot_counter=0
elif [ "${boot_counter}" == "2" ]; then
set boot_counter=1
elif [ "${boot_counter}" == "3" ]; then
set boot_counter=2
fi
fi
fi
# Check if boot counter is '0' which means fallback is needed
if [ "${boot_counter}" == "0" ]; then
set ustate=3
# Swap the 'rootfs' variable to the other partition, simulating a fallback
if [ "${rootfs}" == "A" ]; then
set rootfs="B"
set rootfs_status_A="Fail"
set rootfs_status_B="Fallback"
else
set rootfs="A"
set rootfs_status_A="Fallback"
set rootfs_status_B="Fail"
fi
set boot_counter=3 # reset boot counter after fallback
else
# Determine the default boot entry and set status messages based on 'rootfs'
if [ "${rootfs}" == "A" ]; then
set default=0
set rootfs_status_A="Default"
set rootfs_status_B="Inactive"
elif [ "${rootfs}" == "B" ]; then
set default=1
set rootfs_status_A="Inactive"
set rootfs_status_B="Default"
fi
# Adjust status based on boot attempt
if [ "${ustate}" == "1" ]; then
if [ "${rootfs}" == "A" ]; then
set rootfs_status_A="Attempt ${boot_counter}"
else
set rootfs_status_B="Attempt ${boot_counter}"
fi
fi
fi
if [ -z "${device_a}" ]; then
## we loose labels when updating, make sure we remember them
## remove this when grub search supports partlabel
## disadvantage is that you cannot boot the disk anymore when you change it to another pc
search --no-floppy --label rootfsA --set=device_a
fi
if [ -z "${device_b}" ]; then
search --no-floppy --label rootfsB --set=device_b
fi
# Save all changes to necessary environment variables at once
save_env -f /EFI/BOOT/grub.env ustate boot_counter rootfs device_a device_b
menuentry "A - ${rootfs_status_A}" {
#search --no-floppy --label rootfsA --set=root
set root="${device_a}"
linux /boot/bzImage root=PARTLABEL=rootfsA rootwait rw oprofile.timer=1 rootfstype=ext4 console=tty console=ttyS0
}
menuentry "B - ${rootfs_status_B}" {
#search --no-floppy --label rootfsB --set=root
set root="${device_b}"
linux /boot/bzImage root=PARTLABEL=rootfsB rootwait rw oprofile.timer=1 rootfstype=ext4 console=tty console=ttyS0
}
menuentry "A with kernel from boot partition" {
linux /bzImage root=PARTLABEL=rootfsA rootwait rw oprofile.timer=1 rootfstype=ext4 console=tty console=ttyS0
}