Initialize for efibootmgr

This commit is contained in:
zyppe 2024-02-07 22:50:56 +08:00
commit 854ccd8dc4
5 changed files with 561 additions and 0 deletions

1
.efibootmgr.metadata Normal file
View file

@ -0,0 +1 @@
0dc99daa83806ae2b64c53006a889688471a2c647fde352631e67bb602c8e134 efibootmgr-17.tar.gz

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
efibootmgr-17.tar.gz

View file

@ -0,0 +1,303 @@
From 21741160071c83e4ae6b9fa268947abfd0d3405f Mon Sep 17 00:00:00 2001
From: Raymund Will <rw@suse.com>
Date: Fri, 3 Mar 2017 18:47:44 +0100
Subject: [PATCH] Extended Delete
References: bsc#870211, bsc#945705
Delete boot entries not only by number. but alse based on
- partition UUID, optionally restricted by loader
or
- disk and partition, again optionally restricted by loader.
This does unfortunately require an API-change of efivar!
Signed-off-by: Raymund Will <rw@suse.com>
---
diff -ru old/src/efibootmgr.c new/src/efibootmgr.c
--- old/src/efibootmgr.c 2018-06-10 22:12:10.000000000 +0200
+++ new/src/efibootmgr.c 2021-08-03 11:57:25.435196489 +0200
@@ -617,6 +617,146 @@
return 0;
}
+static int
+delete_by_uuid(const char *prefix, char *uuid_str, char *loader)
+{
+ int count = 0;
+ list_t *pos, *tmp;
+ var_entry_t *entry;
+ const unsigned char *description;
+ efi_load_option *load_option;
+ efidp path = NULL;
+ char text_path[1024];
+
+ list_for_each_safe(pos, tmp, &entry_list) {
+ uint16_t pathlen;
+ ssize_t rc;
+
+ entry = list_entry(pos, var_entry_t, list);
+ load_option = (efi_load_option *)entry->data;
+ pathlen = efi_loadopt_pathlen(load_option,
+ entry->data_size);
+ path = efi_loadopt_path(load_option, entry->data_size);
+ rc = efidp_format_device_path(text_path, 1024,
+ path, pathlen);
+
+ if (rc < 0 || rc > 1024)
+ error(20, "Could not parse device path");
+
+ if (strlen(text_path) == 0)
+ continue;
+ if (strcasestr(text_path, uuid_str) == NULL)
+ continue;
+ if (loader && strcasestr(text_path, loader) == NULL)
+ continue;
+ /* found! */
+ if (opts.verbose) {
+ description = efi_loadopt_desc(load_option,
+ entry->data_size);
+ printf("Delete %s%04X %s\t%s\n",
+ prefix, entry->num, description, text_path);
+ }
+ if (delete_var(prefix, entry->num) != 0)
+ return -1;
+ count++;
+ }
+ if (count==0) {
+ /* Nothing changed => exit early */
+ exit(0);
+ }
+ return 0;
+}
+
+static int
+delete_by_dpl(const char *prefix, char *disk, uint32_t part, char *loader)
+{
+ int fd, rc;
+ uint64_t start, size;
+ efi_guid_t signature;
+ char sigstr[40];
+ char *sigstrp = sigstr;
+ uint8_t mbr_type, signature_type;
+
+ if (disk == NULL && part == 0 && loader == NULL)
+ errx(42, "Cowardly refusing to delete ALL %s entries.",
+ prefix);
+ if (disk == NULL) {
+ /* foreach d in gpt_disks
+ * delete_by_dpl(prefix, d, part, loader)
+ */
+ errx(42, "Future extension.");
+ }
+ if (part == 0) {
+ /* foreach p in partions_on_gpt_disk
+ * delete_by_dpl(prefix, disk, p, loader)
+ */
+ errx(42, "Future extension.");
+ }
+ memset((char *)&signature, 0, sizeof(signature));
+
+ fd = open(disk, O_RDONLY|O_DIRECT);
+ if (fd == -1)
+ error(42, "Could not open disk %s", disk);
+ rc = efi_disk_get_partition_info(fd, part, &start, &size,
+ (uint8_t*)&signature, &mbr_type, &signature_type);
+ close(fd);
+
+ if (rc)
+ return -1;
+ if (mbr_type != 0x02) {
+ errx(42, "Cowardly refusing non-GPT disk %s", disk);
+ }
+
+ efi_guid_to_str(&signature, &sigstrp);
+
+ if (opts.verbose && !loader) {
+ printf("About to delete all entries referring to UUID %s\n",
+ sigstr);
+ } else if ( opts.delete != 15) {
+ printf("About to delete all entries referring to loader %s\n"
+ " on UUID %s\n",
+ loader, sigstr);
+ }
+ return delete_by_uuid(prefix,sigstr,loader);
+}
+
+/* verbatim copy of same function in efivar/src/creator.c */
+static char *
+tilt_slashes(char *s)
+{
+ char *p;
+ for (p = s; *p; p++)
+ if (*p == '/')
+ *p = '\\';
+ return s;
+}
+
+static int
+check_uuid(const char *s)
+{
+ /* algorithm derived from efivar/src/guid.h */
+ size_t len = 36;
+ unsigned int i;
+ if (strlen(s) != len)
+ return -1;
+ for (i = 0; i < len; i++) {
+ if (i == 8 || i == 13 || i == 18 || i == 23) {
+ if (s[i] != '-')
+ return -1;
+ continue;
+ }
+ if (s[i] >= '0' && s[i] <= '9')
+ continue;
+ /* "| 0x20" is tolower() without having to worry about
+ * locale concerns, since we know everything here must
+ * be within traditional ascii space. */
+ if ((s[i] | 0x20) >= 'a' && (s[i] | 0x20) <= 'f')
+ continue;
+ return -1;
+ }
+ return 0;
+}
+
static void
set_var_nums(const char *prefix, list_t *list)
{
@@ -1236,7 +1376,9 @@
printf("\t-a | --active sets bootnum active\n");
printf("\t-A | --inactive sets bootnum inactive\n");
printf("\t-b | --bootnum XXXX modify BootXXXX (hex)\n");
- printf("\t-B | --delete-bootnum delete bootnum\n");
+ printf("\t-B | --delete-bootnum delete bootnum (specified with -b)\n");
+ printf("\t --delete delete entry by bootnum (-b), by UUID (-P)\n");
+ printf("\t or by disk+partition[+file] (-d -p -l)\n");
printf("\t-c | --create create new variable bootnum and add to bootorder\n");
printf("\t-C | --create-only create new variable bootnum and do not add to bootorder\n");
printf("\t-D | --remove-dups remove duplicate values from BootOrder\n");
@@ -1263,6 +1405,7 @@
printf("\t-o | --bootorder XXXX,YYYY,ZZZZ,... explicitly set BootOrder (hex)\n");
printf("\t-O | --delete-bootorder delete BootOrder\n");
printf("\t-p | --part part partition containing loader (defaults to 1 on partitioned devices)\n");
+ printf("\t-P | --part-uuid UUID select all variables for given partition UUID\n");
printf("\t-q | --quiet be quiet\n");
printf("\t-t | --timeout seconds set boot manager timeout waiting for user input.\n");
printf("\t-T | --delete-timeout delete Timeout.\n");
@@ -1288,6 +1431,7 @@
opts.label = (unsigned char *)"Linux";
opts.disk = "/dev/sda";
opts.part = -1;
+ opts.part_uuid = NULL;
}
static void
@@ -1310,6 +1454,7 @@
{"delete-bootnum", no_argument, 0, 'B'},
{"create", no_argument, 0, 'c'},
{"create-only", no_argument, 0, 'C'},
+ {"delete", no_argument, 0, 2},
{"remove-dups", no_argument, 0, 'D'},
{"disk", required_argument, 0, 'd'},
{"iface", required_argument, 0, 'i'},
@@ -1342,7 +1487,7 @@
};
c = getopt_long (argc, argv,
- "AaBb:cCDd:e:E:gH:i:l:L:M:m:n:No:Op:qt:TuU:v::Vw"
+ "AaBb:cCDd:e:E:gH:i:l:L:M:m:n:No:Op:P:qt:TuU:v::Vw"
"@:hry",
long_options, &option_index);
if (c == -1)
@@ -1390,11 +1535,16 @@
opts.create = 1;
opts.no_order = 1;
break;
+ case 2:
+ opts.delete |= 1;
+ break;
case 'D':
opts.deduplicate = 1;
break;
case 'd':
opts.disk = optarg;
+ if (opts.delete)
+ opts.delete |= 2;
break;
case 'e':
rc = sscanf(optarg, "%d", &snum);
@@ -1434,6 +1584,9 @@
break;
case 'l':
opts.loader = optarg;
+ tilt_slashes(opts.loader);
+ if (opts.delete)
+ opts.delete |= 8;
break;
case 'L':
opts.label = (unsigned char *)optarg;
@@ -1498,6 +1651,17 @@
else
errorx(37, "invalid numeric value %s\n",
optarg);
+ if (opts.delete)
+ opts.delete |= 4;
+ break;
+ case 'P':
+ if ((rc=check_uuid(optarg)) < 0) {
+ fprintf(stderr,
+ "malformed partition UUID: %s (%d)\n",
+ optarg, rc);
+ exit(1);
+ }
+ opts.part_uuid = optarg;
break;
case 'q':
opts.quiet = 1;
@@ -1622,9 +1786,24 @@
set_var_nums(prefices[mode], &entry_list);
if (opts.delete) {
- if (opts.num == -1)
+ if (opts.part_uuid) {
+ ret = delete_by_uuid(prefices[mode], opts.part_uuid,
+ (opts.delete & 8) ? opts.loader : NULL);
+ if (ret < 0)
+ error(42, "Could not delete variable(s)");
+ } else if (opts.delete & 2) {
+ ret = delete_by_dpl(prefices[mode],
+ (opts.delete & 2) ? opts.disk : NULL,
+ (opts.delete & 4) ? opts.part : 0,
+ (opts.delete & 8) ? opts.loader : NULL);
+ if (ret < 0)
+ error(42, "Could not delete variable(s)");
+ } else if (opts.delete > 1)
+ errorx(3, "Disk and partition must be specified "
+ "(see the --delete option).");
+ else if (opts.num == -1)
errorx(3, "You must specify an entry to delete "
- "(see the -b option).");
+ "(e.g. with the -b option).");
else {
ret = delete_var(prefices[mode], opts.num);
if (ret < 0)
Only in new/src: efibootmgr.c.orig
Only in new/src: efibootmgr.c.rej
diff -ru old/src/include/efibootmgr.h new/src/include/efibootmgr.h
--- old/src/include/efibootmgr.h 2018-06-10 22:12:10.000000000 +0200
+++ new/src/include/efibootmgr.h 2021-08-03 11:56:14.638896535 +0200
@@ -60,6 +60,7 @@
int keep_old_entries;
char *testfile;
char *extra_opts_file;
+ char *part_uuid;
uint32_t part;
int edd_version;
uint32_t edd10_devicenum;
@@ -70,7 +71,7 @@
int below4g;
int above4g;
int deduplicate;
- unsigned int delete:1;
+ unsigned int delete:4;
unsigned int delete_order:1;
unsigned int delete_bootnext:1;
unsigned int quiet:1;

191
efibootmgr.changes Normal file
View file

@ -0,0 +1,191 @@
* Tue Aug 3 2021 info@paolostivanin.com
- Update to v17: [jsc#SLE-22542]
* use efivar's logging facility more (more info in -v2 , -v3, etc)
* Various bug fixes
* Better -e parsing
* fix pkg-config invocation for ldflags
* Make efibootmgr use EFIDIR / efibootmgr.efidir like fwupdate does
* make --loader default build-time configurable
* sanitize set_mirror()/get_mirror()
* Add support for parsing loader options as UCS2
* GCC 7 fixes
* Don't use -fshort-wchar since we don't run on EFI machines.
- Drop 0001-Don-t-use-fshort-wchar-when-building-63.patch (upstreamed)
- Drop 0002-Remove-extra-const-keywords-gcc-7-gripes-about.patch
(upstreamed)
- Drop 0003-Add-support-for-parsing-optional-data-as-ucs2.patch
(upstreamed)
- Drop MARM-sanitize-set_mirror.diff (upstreamed)
- Drop efibootmgr-derhat.diff (upstreamed)
- Rebase efibootmgr-delete-multiple.diff
* Tue Apr 3 2018 kukuk@suse.de
- Use %%license instead of %%doc [bsc#1082318]
* Sat Jun 10 2017 meissner@suse.com
- forcefully enable PIE
* Fri Mar 3 2017 rw@suse.com
- Update to 14 plus upstream fixes. [fate#322108]
(0001-Don-t-use-fshort-wchar-when-building-63.patch,
0002-Remove-extra-const-keywords-gcc-7-gripes-about.patch,
0003-Add-support-for-parsing-optional-data-as-ucs2.patch)
- Forward port and refresh SLE patches
(efibootmgr-derhat.diff, MARM-sanitize-set_mirror.diff
efibootmgr-delete-multiple.diff)
- Drop upstreamed patches
(efibootmgr-check-boot-order.diff,
efibootmgr-fix-efivar-0.24.patch,
efibootmgr-fix-usage-of-efi_loadopt_path-again.patch,
MARM-add-m-and-M-options.diff,
MARM-extend-man-for-M-option.diff,
MARM-fix-insufficient-validation-check-of-M-option.diff,
MARM-introduce-man-for-m-and-M-option.diff)
* Thu Feb 16 2017 msuchanek@suse.com
- Build on all archs. There is no reason not to. [boo#1025520]
- Depend on new enough efivar. Build fails otherwise.
* Sat Aug 20 2016 arvidjaar@gmail.com
- add efibootmgr-fix-usage-of-efi_loadopt_path-again.patch - fix
efibootmgr -v with new efivar (boo#993458)
* Thu Jul 14 2016 rw@suse.com
- Add support for Memory Address Range Mirroring.
[fate#320999, bsc#987599]
(add MARM-add-m-and-M-options.diff,
MARM-fix-insufficient-validation-check-of-M-option.diff,
MARM-introduce-man-for-m-and-M-option.diff,
MARM-extend-man-for-M-option.diff,
MARM-sanitize-set_mirror.diff)
* Wed Jul 13 2016 glin@suse.com
- Add efibootmgr-fix-efivar-0.24.patch fix the compilation errors
caused by the efivar update
* Tue Sep 15 2015 rw@suse.com
- Properly latch long to short option for delete. [bsc#945705]
(efibootmgr-delete-multiple.diff)
* Fri Jul 24 2015 rw@suse.com
- Refresh for SLE12. [bsc#929677]
(efibootmgr-gcc-Wall.diff, efibootmgr-delete-multiple.diff)
* Fri Jun 12 2015 mpluskal@suse.com
- Update to 0.12
* This release is mostly a maintenance release that uses
libefivar's new library API for creating device paths and load
options.
* Also DHCPv4 network boot entries are now something you can
create without knowing an awful lot about ACPI.
- Refresh patches
efibootmgr-0.11.0-derhat.diff as efibootmgr-derhat.diff
efibootmgr-0.11.0-check-boot-order.diff as
efibootmgr-check-boot-order.diff
- Update project and download url
* Wed Mar 11 2015 rw@suse.com
- Allow disk/partition as selector for delete as well. [bsc#870211]
(efibootmgr-delete-multiple.diff)
- Remove version number from patches.
(add efibootmgr-derhat.diff, efibootmgr-fail-visibly.diff,
efibootmgr-gcc-Wall.diff, efibootmgr-set_boot_order.diff,
efibootmgr-write-unique-id-once.diff;
drop efibootmgr-0.6.0-check-boot-order.diff,
efibootmgr-0.6.0-delete-by-uuid.diff, efibootmgr-0.6.0-derhat.diff,
efibootmgr-0.6.0-fail-visibly.diff, efibootmgr-0.6.0-gcc-Wall.diff,
efibootmgr-0.6.0-set_boot_order.diff,
efibootmgr-0.6.0-write-unique-id-once.diff)
Note: this entry reflects obsoleted, SLE-only changes!
* Fri Jan 30 2015 rw@suse.com
- Introduce partition UUID as selector for delete. [bsc#870211]
(efibootmgr-0.6.0-delete-by-uuid.diff)
* Mon Dec 22 2014 mpluskal@suse.com
- Enable i586 build
* Fri Oct 31 2014 dmueller@suse.com
- efibootmgr-0.6.0-check-boot-order.diff, efibootmgr-0.6.0-derhat.diff:
pass source validator check
- switch homepage to https://github.com/vathpela/efibootmgr
* Wed Oct 29 2014 glin@suse.com
- Update version number to 0.11.0
- Rebase patches
(efibootmgr-0.11.0-derhat.diff,
efibootmgr-0.11.0-check-boot-order.diff)
- Drop efibootmgr-0.6.0-set_boot_order.diff since the data size of
the variable is handled properly now
- Drop efibootmgr-0.6.0-fail-visibly.diff since err() and warn()
are introduced to show more meaningful messages
- Drop upstreamed patch
(efibootmgr-0.6.0-gcc-Wall.diff,
efibootmgr-0.6.0-write-unique-id-once.diff)
* Tue Sep 9 2014 schwab@suse.de
- Enable for aarch64 [fate#318444]
* Mon Jul 7 2014 glin@suse.com
- Add efibootmgr-0.6.0-check-boot-order.diff to delete BootOrder
if there is no more boot option. [bnc#883545]
* Thu Dec 19 2013 rw@suse.com
- Update version number to 0.6.0,
- Integrate SLE11 patches. [bnc#830784]
(efibootmgr-0.6.0-fail-visibly.diff,
efibootmgr-0.6.0-set_boot_order.diff)
- Fix gcc warnings.
(efibootmgr-0.6.0-gcc-Wall.diff)
- Make default '--loader' build-time configurable.
(efibootmgr-0.6.0-derhat.diff)
- Don't let '--write-signature' overwrite unique signatures.
(efibootmgr-0.6.0-write-unique-id-once.diff)
- Drop obsolete patches
(efibootmgr-0.5.4.diff,
efibootmgr-0.5.4-catchup.diff,
efibootmgr-0.5.4-sector-size.diff)
* Wed Mar 27 2013 rw@suse.com
- Print EFI status for failed '--create' as well. [bnc#811767]
(efibootmgr-0.5.4-fail-visibly.diff)
* Wed Mar 27 2013 rw@suse.com
- Fix '--bootorder' handling. [bnc#810899]
(efibootmgr-0.5.4-set_boot_order.diff)
- Print EFI status in case of failure. [bnc#811767]
(efibootmgr-0.5.4-fail-visibly.diff)
* Tue Feb 12 2013 rw@suse.com
- Apply critical upstream fixes
o for memory leaking variable creation. [bnc#746324]
o to improve spec conformance by removing device path padding.
o to work around broken Apple firmware.
(efibootmgr-0.5.4-catchup.diff)
- Allow hard disk sector sizes not equal to 512. [bnc#711830]
(efibootmgr-0.5.4-sector-size.diff)
* Tue Jun 12 2012 mgorse@suse.com
- Add zlib-devel to BuildRequires
* Sun Sep 18 2011 jengelh@medozas.de
- Remove redundant/obsolete tags/sections from specfile
(cf. packaging guidelines)
* Wed Oct 15 2008 ro@suse.de
- added ExclusiveArch
* Thu Jul 31 2008 rw@suse.de
- Update to efibootmgr 0.5.4. [FATE#301882]
* Fri Jan 18 2008 rw@suse.de
- Return non-zero exit code on errors. [#307965, FATE#302608]
* Tue Dec 19 2006 rw@suse.de
- Use '&' instead of '&&' to mask bits. [#219735]
- Fix compilation for STABLE.
* Wed Jan 25 2006 mls@suse.de
- converted neededforbuild to BuildRequires
* Wed Nov 9 2005 schwab@suse.de
- Update to efibootmgr 0.5.3.
* Mon Sep 19 2005 schwab@suse.de
- Update to efibootmgr 0.5.2.2.
* Wed Aug 10 2005 schwab@suse.de
- Update to efibootmgr 0.5.2 [#102441].
* Tue May 10 2005 schwab@suse.de
- Fix parsing of bus info for network boot entry [#82882].
* Wed Mar 9 2005 schwab@suse.de
- Update to efibootmgr 0.5.1.
* Thu Aug 26 2004 schwab@suse.de
- Update to efibootmgr 0.5.0.
* Wed Jun 9 2004 schwab@suse.de
- Update to efibootmgr 0.5.0-test4.
* Mon May 3 2004 schwab@suse.de
- Update to efibootmgr 0.5.0-test3.
* Fri Sep 5 2003 schwab@suse.de
- Update to efibootmgr 0.4.2.
* Wed Oct 23 2002 schwab@suse.de
- Update to efibootmgr 0.4.1.
* Sun May 5 2002 schwab@suse.de
- Update to efibootmgr 0.4.0.
* Fri Aug 10 2001 schwab@suse.de
- Update to efibootmgr 0.3.4.
* Wed May 23 2001 schwab@suse.de
- Update to efibootmgr 0.3.2.
* Tue May 22 2001 schwab@suse.de
- Fix uninitialized variable.
* Sat May 19 2001 schwab@suse.de
- Initial version 0.3.1.

65
efibootmgr.spec Normal file
View file

@ -0,0 +1,65 @@
#
# spec file for package efibootmgr
#
# Copyright (c) 2022-2023 ZhuningOS
#
Name: efibootmgr
Version: 17
Release: 150400.3.2.2
Summary: EFI Boot Manager
License: GPL-2.0-or-later
Group: System/Boot
URL: https://github.com/rhinstaller/efibootmgr
Source: https://github.com/rhboot/efibootmgr/archive/refs/tags/%{version}.tar.gz#/%{name}-%{version}.tar.gz
Patch0: %{name}-delete-multiple.diff
BuildRequires: pkgconfig
BuildRequires: pkgconfig(efiboot) >= 31
BuildRequires: pkgconfig(efivar) >= 31
BuildRequires: pkgconfig(libpci)
BuildRequires: pkgconfig(popt)
BuildRequires: pkgconfig(zlib)
%description
The EFI Boot Manager allows the user to edit the Intel Extensible
Firmware Interface (EFI) Boot Manager variables. Additional
information about the EFI can be found at
<http://developer.intel.com/technology/efi/efi.htm>.
%prep
%autosetup -p1
%build
# removing hotfix function declaration:
# https://github.com/rhboot/efibootmgr/issues/128
sed -e '/extern int efi_set_verbose/d' -i "src/efibootmgr.c"
LOADER="grub.efi" # default loader
[ "$RPM_ARCH" != ia64 ] || LOADER="elilo.efi" # except Itanium
case "%{_repository}" in
(openSUSE*) VENDOR="openSUSE";;
(SLE_11_SP*) VENDOR="SuSE" LOADER="elilo.efi";;
(SUSE*|SLE*) VENDOR="SUSE";;
(*) VENDOR="linux";;
esac
%make_build CFLAGS="%{optflags} -flto -fPIE -pie" \
OS_VENDOR="$VENDOR" EFI_LOADER="$LOADER" EFIDIR="$VENDOR"
%install
case "%{_repository}" in
(openSUSE*) VENDOR="openSUSE";;
(SLE_11_SP*) VENDOR="SuSE" LOADER="elilo.efi";;
(SUSE*|SLE*) VENDOR="SUSE";;
(*) VENDOR="linux";;
esac
make DESTDIR=%{buildroot} sbindir=%{_sbindir} EFIDIR="$VENDOR" install
%files
%license COPYING
%doc README
%{_sbindir}/efiboot*
%{_mandir}/man8/*.gz
%changelog