Merge lp:~blake-rouse/maas-images/fix-centos-efi into lp:maas-images

Proposed by Blake Rouse
Status: Merged
Merged at revision: 361
Proposed branch: lp:~blake-rouse/maas-images/fix-centos-efi
Merge into: lp:maas-images
Diff against target: 68 lines (+43/-3)
1 file modified
curtin/centos7/curtin-hooks.py (+43/-3)
To merge this branch: bzr merge lp:~blake-rouse/maas-images/fix-centos-efi
Reviewer Review Type Date Requested Status
Andres Rodriguez (community) Approve
Review via email: mp+323594@code.launchpad.net

Commit message

Fix boot loader ordering for CentOS 7 UEFI.

Previously when deploying CentOS 7 the 'centos' efi loader would become the first loader in the boot order, which prevents re-deployments of any OS as the machine will no longer boot from the network first. This branch updates the boot order for EFI and places the currently booted entry as the first in the boot order. Since this is run in ephemeral mode this ensures that the NIC that the machine booted from will start first. 'centos' entry will be after the network, so if MAAS is down the machine will still boot from 'centos' if MAAS is down and the machine reboots. Previous \EFI entries are also removed from bios as those no longer exists as curtin creates a new \EFI partition on deployment.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

lgtm!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'curtin/centos7/curtin-hooks.py'
--- curtin/centos7/curtin-hooks.py 2017-04-25 01:26:36 +0000
+++ curtin/centos7/curtin-hooks.py 2017-05-04 03:03:00 +0000
@@ -143,13 +143,53 @@
143 in_chroot(['grub2-mkconfig', '-o', '/boot/grub2/grub.cfg'])143 in_chroot(['grub2-mkconfig', '-o', '/boot/grub2/grub.cfg'])
144144
145145
146def install_uefi(target):146def get_efibootmgr_value(output, key):
147 """Install the EFI data from /boot into efi partition."""147 """Parses the `output` from 'efibootmgr' to return value for `key`."""
148 for line in output.splitlines():
149 split = line.split(':')
150 if len(split) == 2:
151 curr_key = split[0].strip()
152 value = split[1].strip()
153 if curr_key == key:
154 return value
155
156
157def get_file_efi_loaders(output):
158 """Parses the `output` from 'efibootmgr' to return all loaders that exist
159 in '\EFI' path."""
160 return re.findall(
161 r"^Boot(?P<hex>[0-9a-fA-F]{4})\*?\s*\S+\s+.*File\(\\EFI.*$",
162 output, re.MULTILINE)
163
164
165def grub2_install_efi(target):
166 """Configure for EFI.
167
168 First capture the currently booted loader (normally a network device),
169 then perform grub installation (adds a new bootloader and adjusts the
170 boot order), finally re-adjust the boot order so that the currently booted
171 loader is set to boot first in the new order.
172 """
148 with util.RunInChroot(target) as in_chroot:173 with util.RunInChroot(target) as in_chroot:
174 stdout, _ = in_chroot(['efibootmgr', '-v'], capture=True)
175 currently_booted = get_efibootmgr_value(stdout, 'BootCurrent')
176 loaders = get_file_efi_loaders(stdout)
177 if currently_booted in loaders:
178 loaders.remove(currently_booted)
179 for loader in loaders:
180 in_chroot(['efibootmgr', '-B', '-b', loader], capture=True)
149 in_chroot([181 in_chroot([
150 'grub2-install', '--target=x86_64-efi',182 'grub2-install', '--target=x86_64-efi',
151 '--efi-directory', '/boot/efi',183 '--efi-directory', '/boot/efi',
152 '--recheck'])184 '--recheck'])
185 stdout, _ = in_chroot(['efibootmgr'], capture=True)
186 currently_booted = get_efibootmgr_value(stdout, 'BootCurrent')
187 boot_order = get_efibootmgr_value(stdout, 'BootOrder').split(',')
188 if currently_booted in boot_order:
189 boot_order.remove(currently_booted)
190 boot_order = [currently_booted] + boot_order
191 new_boot_order = ','.join(boot_order)
192 in_chroot(['efibootmgr', '-o', new_boot_order])
153193
154194
155def set_autorelabel(target):195def set_autorelabel(target):
@@ -283,7 +323,7 @@
283 target, extra=get_extra_kernel_parameters())323 target, extra=get_extra_kernel_parameters())
284 grub2_mkconfig(target)324 grub2_mkconfig(target)
285 if util.is_uefi_bootable():325 if util.is_uefi_bootable():
286 install_uefi(target)326 grub2_install_efi(target)
287 else:327 else:
288 for dev in devices:328 for dev in devices:
289 grub2_install(target, dev)329 grub2_install(target, dev)

Subscribers

People subscribed via source and target branches