EFI: Move patches to Fuel@OPNFV, upstream prep
[armband.git] / patches / opnfv-fuel / 0051-EFI-Add-basic-support-for-U-EFI.patch
1 From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
2 Date: Sun, 28 Aug 2016 00:28:53 +0200
3 Subject: [PATCH] EFI: Add basic support for (U)EFI
4
5 This change introduces basic EFI support in <fuel-astute> and
6 <fuel-agent>, by patching them at build time with:
7 - ESP partition flag;
8 - VFAT filesytem on ESP;
9 - clearing "ubuntu" boot entry created by Trusty's grub-install;
10
11 This change DOES NOT provide an x86 (U)EFI netloader for integration
12 with cobbler.
13
14 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
15 ---
16  .../0010-EFI-Erase-boot-entry-on-EFI-systems.patch | 43 ++++++++++++++
17  .../0010-EFI-Add-esp-partition-flag.patch          | 48 ++++++++++++++++
18  .../0020-EFI-Add-fs-for-efi-partition.patch        | 66 ++++++++++++++++++++++
19  3 files changed, 157 insertions(+)
20  create mode 100644 build/patch-repos/build/repos/astute/0010-EFI-Erase-boot-entry-on-EFI-systems.patch
21  create mode 100644 build/patch-repos/build/repos/fuel-agent/0010-EFI-Add-esp-partition-flag.patch
22  create mode 100644 build/patch-repos/build/repos/fuel-agent/0020-EFI-Add-fs-for-efi-partition.patch
23
24 diff --git a/build/patch-repos/build/repos/astute/0010-EFI-Erase-boot-entry-on-EFI-systems.patch b/build/patch-repos/build/repos/astute/0010-EFI-Erase-boot-entry-on-EFI-systems.patch
25 new file mode 100644
26 index 0000000..fa925b0
27 --- /dev/null
28 +++ b/build/patch-repos/build/repos/astute/0010-EFI-Erase-boot-entry-on-EFI-systems.patch
29 @@ -0,0 +1,43 @@
30 +From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
31 +Date: Mon, 18 Jul 2016 16:02:20 +0200
32 +Subject: [PATCH] EFI: Erase boot entry on EFI systems.
33 +
34 +On EFI-enabled systemd, grub-install from grub-efi-* package
35 +installs a boot entry named "ubuntu".
36 +
37 +Since this boot entry is saved in board flash memory, erasing
38 +the MBR bootloader code and/or partition signature will not
39 +clear the ubuntu boot entry, leaving it pointing to a loader
40 +on the ESP (EFI System Partition) that will try to load the
41 +kernel/initrd from an erased partition.
42 +
43 +In Fuel 8.0, the whole disk was erased, so the ubuntu EFI boot
44 +entry was skipped due to missing ESP, while for Fuel 9.0 and
45 +above we have to explicitly remove it to keep the system in a
46 +sane state.
47 +
48 +Note: efibootmgr is installed automatically on EFI systems
49 +as a dependency of grub-efi-*.
50 +
51 +Closes: ARMBAND-47
52 +
53 +Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
54 +---
55 + mcagents/erase_node.rb | 4 ++++
56 + 1 file changed, 4 insertions(+)
57 +
58 +diff --git a/mcagents/erase_node.rb b/mcagents/erase_node.rb
59 +index 3eb98e8..3bac36f 100644
60 +--- a/mcagents/erase_node.rb
61 ++++ b/mcagents/erase_node.rb
62 +@@ -112,6 +112,10 @@ module MCollective
63 +         File.open('/proc/sys/kernel/panic','w') {|file| file.write("10\n")}
64
65 +         begin
66 ++          # clear out EFI boot entry on EFI-enabled systems
67 ++          system("(which efibootmgr > /dev/null 2>&1 && efibootmgr | "\
68 ++                 "grep -oP '(?<=Boot)[0-9]+(?=.*ubuntu)' | "\
69 ++                 "xargs -I{} efibootmgr --delete-bootnum --bootnum {}) || true")
70 +           get_devices(type='all').each do |dev|
71 +             debug_msg("erasing bootstrap code area in MBR of #{dev[:name]}")
72 +             # clear out the boot code in MBR
73 diff --git a/build/patch-repos/build/repos/fuel-agent/0010-EFI-Add-esp-partition-flag.patch b/build/patch-repos/build/repos/fuel-agent/0010-EFI-Add-esp-partition-flag.patch
74 new file mode 100644
75 index 0000000..ac94a4f
76 --- /dev/null
77 +++ b/build/patch-repos/build/repos/fuel-agent/0010-EFI-Add-esp-partition-flag.patch
78 @@ -0,0 +1,48 @@
79 +From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
80 +Date: Tue, 8 Mar 2016 16:29:39 +0100
81 +Subject: [PATCH] EFI: Add <esp> partition flag.
82 +
83 +Parted flag <esp> (see [1]) will mark EFI system partition, allowing us
84 +to properly format and mount it during do_partitioning deployment phase.
85 +
86 +[1] https://www.gnu.org/software/parted/manual/html_node/set.html
87 +---
88 + fuel_agent/drivers/nailgun.py | 2 +-
89 + fuel_agent/utils/partition.py | 4 ++--
90 + 2 files changed, 3 insertions(+), 3 deletions(-)
91 +
92 +diff --git a/fuel_agent/drivers/nailgun.py b/fuel_agent/drivers/nailgun.py
93 +index c2fef69..0ae81f9 100644
94 +--- a/fuel_agent/drivers/nailgun.py
95 ++++ b/fuel_agent/drivers/nailgun.py
96 +@@ -324,7 +324,7 @@ class Nailgun(BaseDataDriver):
97 +             # uefi partition (for future use)
98 +             LOG.debug('Adding UEFI partition on disk %s: size=200' %
99 +                       disk['name'])
100 +-            parted.add_partition(size=200)
101 ++            parted.add_partition(size=200, flags=['esp'])
102
103 +             LOG.debug('Looping over all volumes on disk %s' % disk['name'])
104 +             for volume in disk['volumes']:
105 +diff --git a/fuel_agent/utils/partition.py b/fuel_agent/utils/partition.py
106 +index acdd0b3..86349d2 100644
107 +--- a/fuel_agent/utils/partition.py
108 ++++ b/fuel_agent/utils/partition.py
109 +@@ -93,7 +93,7 @@ def set_partition_flag(dev, num, flag, state='on'):
110 +     :param dev: A device file, e.g. /dev/sda.
111 +     :param num: Partition number
112 +     :param flag: Flag name. Must be one of 'bios_grub', 'legacy_boot',
113 +-    'boot', 'raid', 'lvm'
114 ++    'boot', 'raid', 'lvm', 'esp'
115 +     :param state: Desiable flag state. 'on' or 'off'. Default is 'on'.
116
117 +     :returns: None
118 +@@ -103,7 +103,7 @@ def set_partition_flag(dev, num, flag, state='on'):
119 +     # parted supports more flags but we are interested in
120 +     # setting only this subset of them.
121 +     # not all of these flags are compatible with one another.
122 +-    if flag not in ('bios_grub', 'legacy_boot', 'boot', 'raid', 'lvm'):
123 ++    if flag not in ('bios_grub', 'legacy_boot', 'boot', 'raid', 'lvm', 'esp'):
124 +         raise errors.WrongPartitionSchemeError(
125 +             'Unsupported partition flag: %s' % flag)
126 +     if state not in ('on', 'off'):
127 diff --git a/build/patch-repos/build/repos/fuel-agent/0020-EFI-Add-fs-for-efi-partition.patch b/build/patch-repos/build/repos/fuel-agent/0020-EFI-Add-fs-for-efi-partition.patch
128 new file mode 100644
129 index 0000000..a3767a1
130 --- /dev/null
131 +++ b/build/patch-repos/build/repos/fuel-agent/0020-EFI-Add-fs-for-efi-partition.patch
132 @@ -0,0 +1,66 @@
133 +From: Stanislaw Kardach <stanislaw.kardach@cavium.com>
134 +Date: Tue, 8 Mar 2016 21:08:55 +0100
135 +Subject: [PATCH] EFI: Add fs for efi partition
136 +
137 +---
138 + debian/control                |  1 +
139 + fuel_agent/drivers/nailgun.py | 13 ++++++++++---
140 + specs/fuel-agent.spec         |  1 +
141 + 3 files changed, 12 insertions(+), 3 deletions(-)
142 +
143 +diff --git a/debian/control b/debian/control
144 +index 189dc00..acfda35 100644
145 +--- a/debian/control
146 ++++ b/debian/control
147 +@@ -39,6 +39,7 @@ Depends: bzip2,
148 +        qemu-user-static,
149 +        binfmt-support,
150 +        dmidecode,
151 ++       dosfstools,
152 +        ethtool,
153 +        gdisk,
154 +        genisoimage,
155 +diff --git a/fuel_agent/drivers/nailgun.py b/fuel_agent/drivers/nailgun.py
156 +index bc532b4..f092865 100644
157 +--- a/fuel_agent/drivers/nailgun.py
158 ++++ b/fuel_agent/drivers/nailgun.py
159 +@@ -81,6 +81,9 @@ class Nailgun(BaseDataDriver):
160 +         # was already allocated on first matching volume
161 +         # or not
162 +         self._boot_partition_done = False
163 ++        # this var states whether ESP partition was already
164 ++        # allocated on the first matching volume or not
165 ++        self._esp_partition_done = False
166 +         # this var is used as a flag that /boot fs
167 +         # has already been added. we need this to
168 +         # get rid of md over all disks for /boot partition.
169 +@@ -321,10 +324,14 @@ class Nailgun(BaseDataDriver):
170 +             LOG.debug('Adding bios_grub partition on disk %s: size=24' %
171 +                       disk['name'])
172 +             parted.add_partition(size=24, flags=['bios_grub'])
173 +-            # uefi partition (for future use)
174 +-            LOG.debug('Adding UEFI partition on disk %s: size=200' %
175 ++            # uefi partition - added only once.
176 ++            if self._is_boot_disk(disk) and not self._esp_partition_done:
177 ++                LOG.debug('Adding UEFI partition on disk %s: size=200' %
178 +                       disk['name'])
179 +-            parted.add_partition(size=200, flags=['esp'])
180 ++                prt = parted.add_partition(size=200, flags=['esp'])
181 ++                partition_scheme.add_fs(device=prt.name, mount='/boot/efi',
182 ++                                        fs_type='vfat')
183 ++                self._esp_partition_done = True
184
185 +             LOG.debug('Looping over all volumes on disk %s' % disk['name'])
186 +             for volume in disk['volumes']:
187 +diff --git a/specs/fuel-agent.spec b/specs/fuel-agent.spec
188 +index a43f693..c2b9b51 100644
189 +--- a/specs/fuel-agent.spec
190 ++++ b/specs/fuel-agent.spec
191 +@@ -50,6 +50,7 @@ Requires:    xfsprogs
192 + Requires:    pciutils
193 + Requires:    ethtool
194 + Requires:    debootstrap
195 ++Requires:    dosfstools
196 + Requires:    dpkg
197 + Requires:    qemu-user-static
198 + Requires:    xz