Mageia Bugzilla – Attachment 5703 Details for
Bug 14779
part of boot order settings lost when updating grub2-efi
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
efibootmgr part of grub2-2.00-mga-git-9752.patch
efipart_of_Grub2_patch (text/plain), 2.76 KB, created by
Marja Van Waes
on 2014-12-12 22:36:29 CET
(
hide
)
Description:
efibootmgr part of grub2-2.00-mga-git-9752.patch
Filename:
MIME Type:
Creator:
Marja Van Waes
Created:
2014-12-12 22:36:29 CET
Size:
2.76 KB
patch
obsolete
>+ >+static void >+grub_install_remove_efi_entries_by_distributor (const char *efi_distributor) >+{ >+ int fd; >+ pid_t pid = grub_util_exec_pipe ((const char * []){ "efibootmgr", NULL }, &fd); >+ char *line = NULL; >+ size_t len = 0; >+ >+ if (!pid) >+ { >+ grub_util_warn (_("Unable to open stream from %s: %s"), >+ "efibootmgr", strerror (errno)); >+ return; >+ } >+ >+ FILE *fp = fdopen (fd, "r"); >+ if (!fp) >+ { >+ grub_util_warn (_("Unable to open stream from %s: %s"), >+ "efibootmgr", strerror (errno)); >+ return; >+ } >+ >+ line = xmalloc (80); >+ len = 80; >+ while (1) >+ { >+ int ret; >+ char *bootnum; >+ ret = getline (&line, &len, fp); >+ if (ret == -1) >+ break; >+ if (grub_memcmp (line, "Boot", sizeof ("Boot") - 1) != 0 >+ || line[sizeof ("Boot") - 1] < '0' >+ || line[sizeof ("Boot") - 1] > '9') >+ continue; >+ if (!strcasestr (line, efi_distributor)) >+ continue; >+ bootnum = line + sizeof ("Boot") - 1; >+ bootnum[4] = '\0'; >+ if (!verbosity) >+ grub_util_exec ((const char * []){ "efibootmgr", "-q", >+ "-b", bootnum, "-B", NULL }); >+ else >+ grub_util_exec ((const char * []){ "efibootmgr", >+ "-b", bootnum, "-B", NULL }); >+ } >+ >+ free (line); >+} >+ >+void >+grub_install_register_efi (grub_device_t efidir_grub_dev, >+ const char *efifile_path, >+ const char *efi_distributor) >+{ >+ const char * efidir_disk; >+ int efidir_part; >+ efidir_disk = grub_util_biosdisk_get_osdev (efidir_grub_dev->disk); >+ efidir_part = efidir_grub_dev->disk->partition ? efidir_grub_dev->disk->partition->number + 1 : 1; >+ >+ if (grub_util_exec_redirect_null ((const char * []){ "efibootmgr", "--version", NULL })) >+ { >+ /* TRANSLATORS: This message is shown when required executable `%s' >+ isn't found. */ >+ grub_util_error (_("%s: not found"), "efibootmgr"); >+ } >+ >+ /* On Linux, we need the efivars kernel modules. */ >+#ifdef __linux__ >+ grub_util_exec ((const char * []){ "modprobe", "-q", "efivars", NULL }); >+#endif >+ /* Delete old entries from the same distributor. */ >+ grub_install_remove_efi_entries_by_distributor (efi_distributor); >+ >+ char *efidir_part_str = xasprintf ("%d", efidir_part); >+ >+ if (!verbosity) >+ grub_util_exec ((const char * []){ "efibootmgr", "-q", >+ "-c", "-d", efidir_disk, >+ "-p", efidir_part_str, "-w", >+ "-L", efi_distributor, "-l", >+ efifile_path, NULL }); >+ else >+ grub_util_exec ((const char * []){ "efibootmgr", >+ "-c", "-d", efidir_disk, >+ "-p", efidir_part_str, "-w", >+ "-L", efi_distributor, "-l", >+ efifile_path, NULL }); >+ free (efidir_part_str); >+} >
+ +static void +grub_install_remove_efi_entries_by_distributor (const char *efi_distributor) +{ + int fd; + pid_t pid = grub_util_exec_pipe ((const char * []){ "efibootmgr", NULL }, &fd); + char *line = NULL; + size_t len = 0; + + if (!pid) + { + grub_util_warn (_("Unable to open stream from %s: %s"), + "efibootmgr", strerror (errno)); + return; + } + + FILE *fp = fdopen (fd, "r"); + if (!fp) + { + grub_util_warn (_("Unable to open stream from %s: %s"), + "efibootmgr", strerror (errno)); + return; + } + + line = xmalloc (80); + len = 80; + while (1) + { + int ret; + char *bootnum; + ret = getline (&line, &len, fp); + if (ret == -1) + break; + if (grub_memcmp (line, "Boot", sizeof ("Boot") - 1) != 0 + || line[sizeof ("Boot") - 1] < '0' + || line[sizeof ("Boot") - 1] > '9') + continue; + if (!strcasestr (line, efi_distributor)) + continue; + bootnum = line + sizeof ("Boot") - 1; + bootnum[4] = '\0'; + if (!verbosity) + grub_util_exec ((const char * []){ "efibootmgr", "-q", + "-b", bootnum, "-B", NULL }); + else + grub_util_exec ((const char * []){ "efibootmgr", + "-b", bootnum, "-B", NULL }); + } + + free (line); +} + +void +grub_install_register_efi (grub_device_t efidir_grub_dev, + const char *efifile_path, + const char *efi_distributor) +{ + const char * efidir_disk; + int efidir_part; + efidir_disk = grub_util_biosdisk_get_osdev (efidir_grub_dev->disk); + efidir_part = efidir_grub_dev->disk->partition ? efidir_grub_dev->disk->partition->number + 1 : 1; + + if (grub_util_exec_redirect_null ((const char * []){ "efibootmgr", "--version", NULL })) + { + /* TRANSLATORS: This message is shown when required executable `%s' + isn't found. */ + grub_util_error (_("%s: not found"), "efibootmgr"); + } + + /* On Linux, we need the efivars kernel modules. */ +#ifdef __linux__ + grub_util_exec ((const char * []){ "modprobe", "-q", "efivars", NULL }); +#endif + /* Delete old entries from the same distributor. */ + grub_install_remove_efi_entries_by_distributor (efi_distributor); + + char *efidir_part_str = xasprintf ("%d", efidir_part); + + if (!verbosity) + grub_util_exec ((const char * []){ "efibootmgr", "-q", + "-c", "-d", efidir_disk, + "-p", efidir_part_str, "-w", + "-L", efi_distributor, "-l", + efifile_path, NULL }); + else + grub_util_exec ((const char * []){ "efibootmgr", + "-c", "-d", efidir_disk, + "-p", efidir_part_str, "-w", + "-L", efi_distributor, "-l", + efifile_path, NULL }); + free (efidir_part_str); +}
View Attachment As Raw
Actions:
View
Attachments on
bug 14779
: 5703 |
5714
|
5773
|
5787
|
5788