From: Alexandru Avadanii Date: Sun, 28 Aug 2016 00:28:53 +0200 Subject: [PATCH] EFI: Add basic support for (U)EFI This change introduces basic EFI support in and , by patching them at build time with: - ESP partition flag; - VFAT filesytem on ESP; - clearing "ubuntu" boot entry created by Trusty's grub-install; This change DOES NOT provide an x86 (U)EFI netloader for integration with cobbler. Signed-off-by: Alexandru Avadanii --- .../0010-EFI-Erase-boot-entry-on-EFI-systems.patch | 43 ++++++++++++++ .../0010-EFI-Add-esp-partition-flag.patch | 48 ++++++++++++++++ .../0020-EFI-Add-fs-for-efi-partition.patch | 66 ++++++++++++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 build/patch-repos/build/repos/astute/0010-EFI-Erase-boot-entry-on-EFI-systems.patch create mode 100644 build/patch-repos/build/repos/fuel-agent/0010-EFI-Add-esp-partition-flag.patch create mode 100644 build/patch-repos/build/repos/fuel-agent/0020-EFI-Add-fs-for-efi-partition.patch 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 new file mode 100644 index 0000000..fa925b0 --- /dev/null +++ b/build/patch-repos/build/repos/astute/0010-EFI-Erase-boot-entry-on-EFI-systems.patch @@ -0,0 +1,43 @@ +From: Alexandru Avadanii +Date: Mon, 18 Jul 2016 16:02:20 +0200 +Subject: [PATCH] EFI: Erase boot entry on EFI systems. + +On EFI-enabled systemd, grub-install from grub-efi-* package +installs a boot entry named "ubuntu". + +Since this boot entry is saved in board flash memory, erasing +the MBR bootloader code and/or partition signature will not +clear the ubuntu boot entry, leaving it pointing to a loader +on the ESP (EFI System Partition) that will try to load the +kernel/initrd from an erased partition. + +In Fuel 8.0, the whole disk was erased, so the ubuntu EFI boot +entry was skipped due to missing ESP, while for Fuel 9.0 and +above we have to explicitly remove it to keep the system in a +sane state. + +Note: efibootmgr is installed automatically on EFI systems +as a dependency of grub-efi-*. + +Closes: ARMBAND-47 + +Signed-off-by: Alexandru Avadanii +--- + mcagents/erase_node.rb | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/mcagents/erase_node.rb b/mcagents/erase_node.rb +index 3eb98e8..3bac36f 100644 +--- a/mcagents/erase_node.rb ++++ b/mcagents/erase_node.rb +@@ -112,6 +112,10 @@ module MCollective + File.open('/proc/sys/kernel/panic','w') {|file| file.write("10\n")} + + begin ++ # clear out EFI boot entry on EFI-enabled systems ++ system("(which efibootmgr > /dev/null 2>&1 && efibootmgr | "\ ++ "grep -oP '(?<=Boot)[0-9]+(?=.*ubuntu)' | "\ ++ "xargs -I{} efibootmgr --delete-bootnum --bootnum {}) || true") + get_devices(type='all').each do |dev| + debug_msg("erasing bootstrap code area in MBR of #{dev[:name]}") + # clear out the boot code in MBR 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 new file mode 100644 index 0000000..ac94a4f --- /dev/null +++ b/build/patch-repos/build/repos/fuel-agent/0010-EFI-Add-esp-partition-flag.patch @@ -0,0 +1,48 @@ +From: Alexandru Avadanii +Date: Tue, 8 Mar 2016 16:29:39 +0100 +Subject: [PATCH] EFI: Add partition flag. + +Parted flag (see [1]) will mark EFI system partition, allowing us +to properly format and mount it during do_partitioning deployment phase. + +[1] https://www.gnu.org/software/parted/manual/html_node/set.html +--- + fuel_agent/drivers/nailgun.py | 2 +- + fuel_agent/utils/partition.py | 4 ++-- + 2 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/fuel_agent/drivers/nailgun.py b/fuel_agent/drivers/nailgun.py +index c2fef69..0ae81f9 100644 +--- a/fuel_agent/drivers/nailgun.py ++++ b/fuel_agent/drivers/nailgun.py +@@ -324,7 +324,7 @@ class Nailgun(BaseDataDriver): + # uefi partition (for future use) + LOG.debug('Adding UEFI partition on disk %s: size=200' % + disk['name']) +- parted.add_partition(size=200) ++ parted.add_partition(size=200, flags=['esp']) + + LOG.debug('Looping over all volumes on disk %s' % disk['name']) + for volume in disk['volumes']: +diff --git a/fuel_agent/utils/partition.py b/fuel_agent/utils/partition.py +index acdd0b3..86349d2 100644 +--- a/fuel_agent/utils/partition.py ++++ b/fuel_agent/utils/partition.py +@@ -93,7 +93,7 @@ def set_partition_flag(dev, num, flag, state='on'): + :param dev: A device file, e.g. /dev/sda. + :param num: Partition number + :param flag: Flag name. Must be one of 'bios_grub', 'legacy_boot', +- 'boot', 'raid', 'lvm' ++ 'boot', 'raid', 'lvm', 'esp' + :param state: Desiable flag state. 'on' or 'off'. Default is 'on'. + + :returns: None +@@ -103,7 +103,7 @@ def set_partition_flag(dev, num, flag, state='on'): + # parted supports more flags but we are interested in + # setting only this subset of them. + # not all of these flags are compatible with one another. +- if flag not in ('bios_grub', 'legacy_boot', 'boot', 'raid', 'lvm'): ++ if flag not in ('bios_grub', 'legacy_boot', 'boot', 'raid', 'lvm', 'esp'): + raise errors.WrongPartitionSchemeError( + 'Unsupported partition flag: %s' % flag) + if state not in ('on', 'off'): 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 new file mode 100644 index 0000000..a3767a1 --- /dev/null +++ b/build/patch-repos/build/repos/fuel-agent/0020-EFI-Add-fs-for-efi-partition.patch @@ -0,0 +1,66 @@ +From: Stanislaw Kardach +Date: Tue, 8 Mar 2016 21:08:55 +0100 +Subject: [PATCH] EFI: Add fs for efi partition + +--- + debian/control | 1 + + fuel_agent/drivers/nailgun.py | 13 ++++++++++--- + specs/fuel-agent.spec | 1 + + 3 files changed, 12 insertions(+), 3 deletions(-) + +diff --git a/debian/control b/debian/control +index 189dc00..acfda35 100644 +--- a/debian/control ++++ b/debian/control +@@ -39,6 +39,7 @@ Depends: bzip2, + qemu-user-static, + binfmt-support, + dmidecode, ++ dosfstools, + ethtool, + gdisk, + genisoimage, +diff --git a/fuel_agent/drivers/nailgun.py b/fuel_agent/drivers/nailgun.py +index bc532b4..f092865 100644 +--- a/fuel_agent/drivers/nailgun.py ++++ b/fuel_agent/drivers/nailgun.py +@@ -81,6 +81,9 @@ class Nailgun(BaseDataDriver): + # was already allocated on first matching volume + # or not + self._boot_partition_done = False ++ # this var states whether ESP partition was already ++ # allocated on the first matching volume or not ++ self._esp_partition_done = False + # this var is used as a flag that /boot fs + # has already been added. we need this to + # get rid of md over all disks for /boot partition. +@@ -321,10 +324,14 @@ class Nailgun(BaseDataDriver): + LOG.debug('Adding bios_grub partition on disk %s: size=24' % + disk['name']) + parted.add_partition(size=24, flags=['bios_grub']) +- # uefi partition (for future use) +- LOG.debug('Adding UEFI partition on disk %s: size=200' % ++ # uefi partition - added only once. ++ if self._is_boot_disk(disk) and not self._esp_partition_done: ++ LOG.debug('Adding UEFI partition on disk %s: size=200' % + disk['name']) +- parted.add_partition(size=200, flags=['esp']) ++ prt = parted.add_partition(size=200, flags=['esp']) ++ partition_scheme.add_fs(device=prt.name, mount='/boot/efi', ++ fs_type='vfat') ++ self._esp_partition_done = True + + LOG.debug('Looping over all volumes on disk %s' % disk['name']) + for volume in disk['volumes']: +diff --git a/specs/fuel-agent.spec b/specs/fuel-agent.spec +index a43f693..c2b9b51 100644 +--- a/specs/fuel-agent.spec ++++ b/specs/fuel-agent.spec +@@ -50,6 +50,7 @@ Requires: xfsprogs + Requires: pciutils + Requires: ethtool + Requires: debootstrap ++Requires: dosfstools + Requires: dpkg + Requires: qemu-user-static + Requires: xz