Skip to content

Commit d7e5f72

Browse files
authored
[fix] efibootorderfix (#16)
Previous efibootorderfix versions were incorrectly specifying the partition number being passed to `efibootmgr`. This change makes that more dynamic. Also, in cases where `/boot/efi` is an actual md mirror, this PR adds the logic to add EFI boot targets for each of the mirror plexes, instead of just a single plex of the mirror, so better repliates EFI boot targets as set up by OS distro installs which automatically make use of multiple plexes. Example output after a successful upgrade - note the duplicate (mirrored) boot entries for "Rocky Linux": ``` BootCurrent: 0005 Timeout: 3 seconds BootOrder: 0005,0004,0002,0003 Boot0002* UEFI: Built-in EFI Shell VenMedia(5023b95c-db26-429b-a648-bd47664c8012)..BO Boot0003* UEFI: PXE IP4 Cisco 1GigE I350 LOM PciRoot(0x0)/Pci(0x1c,0x0)/Pci(0x0,0x0)/MAC(d4789b4a161c,1)/IPv4(0.0.0.00.0.0.0,0,0)..BO Boot0004* Rocky Linux HD(3,GPT,3566f194-fa71-4539-9687-2b20f67841ed,0xa00800,0x80000)/File(\EFI\rocky\shimx64.efi) Boot0005* Rocky Linux HD(3,GPT,ad6e8abc-5728-4435-9b84-1c28cb5a18cf,0xa00800,0x80000)/File(\EFI\rocky\shimx64.efi) ```
1 parent 7633faf commit d7e5f72

File tree

1 file changed

+20
-6
lines changed
  • repos/system_upgrade/common/actors/efibootorderfix/finalization

1 file changed

+20
-6
lines changed

repos/system_upgrade/common/actors/efibootorderfix/finalization/actor.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import re
23

34
from leapp.libraries.stdlib import run, api
45
from leapp.actors import Actor
@@ -38,6 +39,11 @@ def process(self):
3839
'aarch64': 'shimaa64.efi'
3940
}
4041

42+
def devparts(dev):
43+
part = next(re.finditer(r'\d+$', dev)).group(0)
44+
dev = dev[:-len(part)]
45+
return [dev, part];
46+
4147
with open('/etc/system-release', 'r') as sr:
4248
release_line = next(line for line in sr if 'release' in line)
4349
distro = release_line.split(' release ', 1)[0]
@@ -69,19 +75,27 @@ def process(self):
6975
break
7076

7177
if is_system_efi and has_shim:
78+
efidevlist = []
7279
with open('/proc/mounts', 'r') as fp:
7380
for line in fp:
7481
if '/boot/efi' in line:
7582
efidevpath = line.split(' ', 1)[0]
76-
efidev = efidevpath.split('/')[-1]
83+
efidevpart = efidevpath.split('/')[-1]
7784
if os.path.exists('/proc/mdstat'):
7885
with open('/proc/mdstat', 'r') as mds:
7986
for line in mds:
80-
if line.startswith(efidev):
81-
mddev = line.split(' ')[-1]
82-
newefidev = mddev.split('[', 1)[0]
83-
efidevpath = efidevpath.replace(efidev, newefidev)
84-
run(['/sbin/efibootmgr', '-c', '-d', efidevpath, '-p 1', '-l', bootmgr_path, '-L', efi_bootentry_label])
87+
if line.startswith(efidevpart):
88+
mddev = line.split(' ')
89+
for md in mddev:
90+
if '[' in md:
91+
efimd = md.split('[', 1)[0]
92+
efidp = efidevpath.replace(efidevpart, efimd)
93+
efidevlist.append(efidp)
94+
if len(efidevlist) == 0:
95+
efidevlist.append(efidevpath)
96+
for devpath in efidevlist:
97+
efidev, efipart = devparts(devpath)
98+
run(['/sbin/efibootmgr', '-c', '-d', efidev, '-p', efipart, '-l', bootmgr_path, '-L', efi_bootentry_label])
8599

86100
if not has_grub_cfg:
87101
run(['/sbin/grub2-mkconfig', '-o', grub_cfg_path])

0 commit comments

Comments
 (0)