From 7a274f7c4dc7f2d88b2655ea3a151a0063ca3e39 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Mon, 21 Dec 2020 14:07:22 +0000 Subject: Factor out write to rEFInd PreviousBoot variable (prep. for next commit) --- perl-install/bootloader.pm | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'perl-install') diff --git a/perl-install/bootloader.pm b/perl-install/bootloader.pm index d4533da39..a9f3077a8 100644 --- a/perl-install/bootloader.pm +++ b/perl-install/bootloader.pm @@ -2426,23 +2426,28 @@ sub write_refind { my $default_kernel = readlink("$::prefix/boot/vmlinuz"); if ($default_kernel) { - my $efivars = '/sys/firmware/efi/efivars'; - my $already_mounted = cat_('/proc/mounts') =~ /$efivars/; - run_program::run('mount', '-t', 'efivarfs', 'none', $efivars) if !$already_mounted; - my $previous_boot = "$efivars/PreviousBoot-36d08fa7-cf0b-42f5-8f14-68df73ed3740"; - run_program::run('chattr', '-i', $previous_boot) if -e $previous_boot; - if (open(my $efivar, '>:raw', $previous_boot)) { - require Encode; - log::l("writing rEFInd PreviousBoot variable"); - print $efivar "\x07\x00\x00\x00"; - print $efivar Encode::encode('UTF16-LE', $default_kernel); - print $efivar "\x00\x00"; - close($efivar); - } else { - log::l("failed to write rEFInd PreviousBoot variable: $@ ($!)"); - } - run_program::run('umount', $efivars) if !$already_mounted; + write_refind_previous_boot_var($default_kernel); + } +} + +sub write_refind_previous_boot_var { + my ($kernel) = @_; + my $efivars = '/sys/firmware/efi/efivars'; + my $already_mounted = cat_('/proc/mounts') =~ /$efivars/; + run_program::run('mount', '-t', 'efivarfs', 'none', $efivars) if !$already_mounted; + my $previous_boot = "$efivars/PreviousBoot-36d08fa7-cf0b-42f5-8f14-68df73ed3740"; + run_program::run('chattr', '-i', $previous_boot) if -e $previous_boot; + if (open(my $efivar, '>:raw', $previous_boot)) { + require Encode; + log::l("writing rEFInd PreviousBoot variable"); + print $efivar "\x07\x00\x00\x00"; + print $efivar Encode::encode('UTF16-LE', $kernel); + print $efivar "\x00\x00"; + close($efivar); + } else { + log::l("failed to write rEFInd PreviousBoot variable: $@ ($!)"); } + run_program::run('umount', $efivars) if !$already_mounted; } sub install_refind { -- cgit v1.2.1