summaryrefslogtreecommitdiffstats
path: root/perl-install/bootloader.pm
diff options
context:
space:
mode:
authorMartin Whitaker <mageia@martin-whitaker.me.uk>2020-12-21 14:07:22 +0000
committerMartin Whitaker <mageia@martin-whitaker.me.uk>2020-12-21 14:11:41 +0000
commit7a274f7c4dc7f2d88b2655ea3a151a0063ca3e39 (patch)
tree5885645c4cb92172e0057c25ce082155ac0b2da3 /perl-install/bootloader.pm
parente4219ae4165122c8fce9380cbf99363454b4586b (diff)
downloaddrakx-7a274f7c4dc7f2d88b2655ea3a151a0063ca3e39.tar
drakx-7a274f7c4dc7f2d88b2655ea3a151a0063ca3e39.tar.gz
drakx-7a274f7c4dc7f2d88b2655ea3a151a0063ca3e39.tar.bz2
drakx-7a274f7c4dc7f2d88b2655ea3a151a0063ca3e39.tar.xz
drakx-7a274f7c4dc7f2d88b2655ea3a151a0063ca3e39.zip
Factor out write to rEFInd PreviousBoot variable (prep. for next commit)
Diffstat (limited to 'perl-install/bootloader.pm')
-rw-r--r--perl-install/bootloader.pm37
1 files changed, 21 insertions, 16 deletions
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 {