From 9e344f50a7e01d7fce2ed1ab9472afd5e131fa02 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 6 May 2020 13:31:02 +0200 Subject: [PATCH] [bootloader] Refactor efi-next-boot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - move the setup-next-boot code to a function on its own - credit to Gaë --- CHANGES | 3 ++- src/modules/bootloader/main.py | 34 ++++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/CHANGES b/CHANGES index a541d7380..f430a7910 100644 --- a/CHANGES +++ b/CHANGES @@ -16,7 +16,8 @@ This release contains contributions from (alphabetically by first name): - The *productWallpaper* setting is documented and works. (Thanks Bill) ## Modules ## - - No module changes yet + - The *bootloader* module can force a UEFI-based machine to boot into + the newly-installed system. #1394 (Thanks Gaël) # 3.2.23 (2020-04-17) # diff --git a/src/modules/bootloader/main.py b/src/modules/bootloader/main.py index 786b5e7da..674484527 100644 --- a/src/modules/bootloader/main.py +++ b/src/modules/bootloader/main.py @@ -237,6 +237,25 @@ def efi_word_size(): return efi_bitness +def efi_boot_next(): + """ + Tell EFI to definitely boot into the just-installed + system next time. + """ + boot_mgr = libcalamares.job.configuration["efiBootMgr"] + boot_entry = None + efi_bootvars = subprocess.check_output([boot_mgr], text=True) + for line in efi_bootvars.split('\n'): + if not line: + continue + words = line.split() + if len(words) >= 2 and words[0] == "BootOrder:": + boot_entry = words[1].split(',')[0] + break + if boot_entry: + subprocess.call([boot_mgr, "-n", boot_entry]) + + def install_systemd_boot(efi_directory): """ Installs systemd-boot as bootloader for EFI setups. @@ -403,20 +422,7 @@ def install_secureboot(efi_directory): "-p", efi_partition_number, "-l", install_efi_directory + "/" + install_efi_bin]) - boot_entry = None - efi_bootvars = subprocess.check_output( - [libcalamares.job.configuration["efiBootMgr"]], text=True) - for line in efi_bootvars.split('\n'): - if not line: - continue - words = line.split() - if len(words) >= 2 and words[0] == "BootOrder:": - boot_entry = words[1].split(',')[0] - break - if boot_entry: - subprocess.call([ - libcalamares.job.configuration["efiBootMgr"], - "-n", boot_entry]) + efi_boot_next() # The input file /etc/default/grub should already be filled out by the # grubcfg job module.