Upstream: multiarch mirrors
[armband.git] / patches / fuel-astute / 0001-Erase-EFI-boot-entry-on-EFI-systems.patch
1 From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
2 Date: Mon, 18 Jul 2016 16:02:20 +0200
3 Subject: [PATCH] Erase EFI boot entry on EFI systems.
4
5 On EFI-enabled systemd, grub-install from grub-efi-* package
6 installs a boot entry named "ubuntu".
7
8 Since this boot entry is saved in board flash memory, erasing
9 the MBR bootloader code and/or partition signature will not
10 clear the ubuntu boot entry, leaving it pointing to a loader
11 on the ESP (EFI System Partition) that will try to load the
12 kernel/initrd from an erased partition.
13
14 In Fuel 8.0, the whole disk was erased, so the ubuntu EFI boot
15 entry was skipped due to missing ESP, while for Fuel 9.0 and
16 above we have to explicitly remove it to keep the system in a
17 sane state.
18
19 Note: efibootmgr is installed automatically on EFI systems
20 as a dependency of grub-efi-*.
21
22 Closes: ARMBAND-47
23
24 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
25 ---
26  mcagents/erase_node.rb | 4 ++++
27  1 file changed, 4 insertions(+)
28
29 diff --git a/mcagents/erase_node.rb b/mcagents/erase_node.rb
30 index 3eb98e8..3bac36f 100644
31 --- a/mcagents/erase_node.rb
32 +++ b/mcagents/erase_node.rb
33 @@ -112,6 +112,10 @@ module MCollective
34          File.open('/proc/sys/kernel/panic','w') {|file| file.write("10\n")}
35  
36          begin
37 +          # clear out EFI boot entry on EFI-enabled systems
38 +          system("(which efibootmgr > /dev/null 2>&1 && efibootmgr | "\
39 +                 "grep -oP '(?<=Boot)[0-9]+(?=.*ubuntu)' | "\
40 +                 "xargs -I{} efibootmgr --delete-bootnum --bootnum {}) || true")
41            get_devices(type='all').each do |dev|
42              debug_msg("erasing bootstrap code area in MBR of #{dev[:name]}")
43              # clear out the boot code in MBR