Mageia Bugzilla – Attachment 8126 Details for
Bug 15153
Patches to add support for the rEFInd boot manager in drakboot
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
[patch]
add support for rEFInd boot manager (mga#15153) (
0001-add-support-for-rEFInd-boot-manager-mga-15153.patch (text/plain), 7.05 KB, created by
Thierry Vignaud
on 2016-07-05 10:40:45 CEST
(
hide
)
Description:
add support for rEFInd boot manager (mga#15153) (
Filename:
MIME Type:
Creator:
Thierry Vignaud
Created:
2016-07-05 10:40:45 CEST
Size:
7.05 KB
patch
obsolete
>From 3ad62fc67aaabe80ec0b8f037ebe43986663add7 Mon Sep 17 00:00:00 2001 >From: Thierry Vignaud <thierry.vignaud@gmail.com> >Date: Tue, 14 Apr 2015 05:57:55 -0400 >Subject: [PATCH 1/2] add support for rEFInd boot manager (mga#15153) > >--- > perl-install/any.pm | 32 ++++++++++++++--- > perl-install/bootloader.pm | 90 ++++++++++++++++++++++++++++++++++++++++++++-- > 2 files changed, 116 insertions(+), 6 deletions(-) > >diff --git a/perl-install/any.pm b/perl-install/any.pm >index 85d454f..2a7565e 100644 >--- a/perl-install/any.pm >+++ b/perl-install/any.pm >@@ -496,7 +496,13 @@ sub setupBootloader__entries { > } @$fstab; > > my @l; >- if ($e->{type} eq "image") { >+ if ($b->{method} eq 'refind') { >+ @l = ( >+ { label => N("Append"), val => \$append }, >+ { label => N("Video mode"), val => \$vga, list => [ '', Xconfig::resolution_and_depth::bios_vga_modes() ], >+ format => \&Xconfig::resolution_and_depth::to_string, advanced => 1 }, >+ ); >+ } elsif ($e->{type} eq "image") { > @l = ( > { label => N("Image"), val => \$e->{kernel_or_dev}, list => [ map { "/boot/$_" } bootloader::installed_vmlinuz() ], not_edit => 0 }, > { label => N("Root"), val => \$e->{root}, list => [ map { fs::wild_device::from_part('', $_) } grep { !isSwap($_) } @$fstab ], format => sub { $root_descr{$_[0]} } }, >@@ -545,9 +551,15 @@ sub setupBootloader__entries { > my $Add = sub { > my @labels = map { $_->{label} } @{$b->{entries}}; > my ($e, $prefix); >- if ($in->ask_from_list_('', N("Which type of entry do you want to add?"), >- [ N_("Linux"), N_("Other OS (Windows...)") ] >- ) eq "Linux") { >+ if ($b->{method} eq 'refind') { >+ $e = { type => 'image', >+ kernel_or_dev => '/boot/vmlinuz', >+ root => '/dev/' . fs::get::root($fstab)->{device}, #- assume a good default. >+ }; >+ $prefix = "linux"; >+ } elsif ($in->ask_from_list_('', N("Which type of entry do you want to add?"), >+ [ N_("Linux"), N_("Other OS (Windows...)") ] >+ ) eq "Linux") { > $e = { type => 'image', > root => '/dev/' . fs::get::root($fstab)->{device}, #- assume a good default. > }; >@@ -593,6 +605,18 @@ sub setupBootloader__entries { > }; > > my @prev_entries = @{$b->{entries}}; >+ >+ #- the rEFInd configuration file just provides alternative kernel command lines >+ #- so we only want to display entries that relate to the default kernel. >+ if ($b->{method} eq 'refind') { >+ @{$b->{entries}} = >+ grep { >+ my $pb = $_->{type} ne 'image' || $_->{kernel_or_dev} ne '/boot/vmlinuz'; >+ log::l("dropping bootloader entry $_->{label} because it is not needed by rEFInd") if $pb; >+ !$pb; >+ } @{$b->{entries}}; >+ } >+ > if ($in->ask_from__add_modify_remove(N("Bootloader Configuration"), > N("Here are the entries on your boot menu so far. > You can create additional entries or change the existing ones."), [ { >diff --git a/perl-install/bootloader.pm b/perl-install/bootloader.pm >index 59172e1..13c64f8 100644 >--- a/perl-install/bootloader.pm >+++ b/perl-install/bootloader.pm >@@ -233,7 +233,7 @@ sub read { > my $f = $bootloader::{"read_$main_method"} or die "unknown bootloader method $main_method (read)"; > my $bootloader = $f->($fstab); > >- cleanup_entries($bootloader); >+ cleanup_entries($bootloader) if $main_method ne 'refind'; > > # handle raid-extra-boot (lilo) > my @devs = $bootloader->{boot}; >@@ -254,6 +254,8 @@ sub read { > } elsif (my $type = partition_table::raw::typeOfMBR($_)) { > warn "typeOfMBR $type on $_ for method $main_method\n" if $ENV{DEBUG}; > $type; >+ } elsif (-e "$::prefix/boot/EFI/EFI/refind" && -e "$::prefix/boot/refind_linux.conf") { >+ 'refind'; > } else { () } > } @devs; > >@@ -571,6 +573,35 @@ sub read_grub_menu_lst { > \%b; > } > >+=item read_refind ($fstab) >+ >+Read back rEFInd config + C</boot/refind_linux.conf> >+ >+=cut >+ >+sub read_refind() { >+ my %bootloader = (entries => []); >+ foreach (cat_utf8("$::prefix/boot/refind_linux.conf")) { >+ next if /^#/; >+ my ($label, $append) = /"(.*)"\s"(.*)"/; >+ my $root = $1 if $append =~ s/root=(\S*)\s*//; >+ my $vga = $1 if $append =~ s/vga=(\S*)\s*//; >+ if ($label && $root) { >+ push @{$bootloader{entries}}, { >+ type => 'image', >+ kernel_or_dev => '/boot/vmlinuz', >+ label => $label, >+ root => $root, >+ append => $append, >+ vga => $vga >+ }; >+ } >+ } >+ >+ $bootloader{method} = 'refind'; >+ \%bootloader; >+} >+ > # FIXME: actually read back previous conf > sub read_uboot() { > +{ method => 'uboot' }; >@@ -1296,6 +1327,7 @@ sub method2text { > 'grub2' => N("GRUB2 with text menu"), > 'grub-graphic' => N("GRUB with graphical menu"), > 'grub-menu' => N("GRUB with text menu"), >+ 'refind' => N("rEFInd"), > }->{$method}; > } > >@@ -1318,7 +1350,8 @@ sub method_choices_raw { > arch() =~ /arm/ ? 'uboot' : > if_(!$b_prefix_mounted || whereis_binary('grub2-reboot', $::prefix), > 'grub2-graphic', 'grub2'), >- # only grub2 works on UEFI: >+ if_(is_uefi() && (!$b_prefix_mounted || -e "$::prefix/boot/EFI/EFI/refind"), 'refind'), >+ # only grub2 & reFIND work on UEFI: > # lilo & grub-legacy do not suppport new ext4/xfs format and are unmainted so only allow them on upgrade: > if_(!is_uefi() && !($::isInstall && !$::o->{isUpgrade}), ( > if_(!$b_prefix_mounted || whereis_binary('grub', $::prefix) && -f "$::prefix/boot/grub/install.sh", >@@ -2195,6 +2228,59 @@ sub when_config_changed_grub { > update_copy_in_boot($_) foreach glob($::prefix . boot_copies_dir() . '/*.link'); > } > >+sub write_refind { >+ my ($bootloader, $_all_hds, $o_backup_extension) = @_; >+ >+ my @conf; >+ >+ foreach my $entry (@{$bootloader->{entries}}) { >+ if ($entry->{type} eq "image" && $entry->{kernel_or_dev} eq "/boot/vmlinuz") { >+ my $vga = $entry->{vga} || $bootloader->{vga}; >+ my $boot_params = join(' ', >+ "root=$entry->{root}", >+ $entry->{append}, >+ if_($entry->{'read-write'}, 'rw'), >+ if_($vga && $vga ne "normal", "vga=$vga") >+ ); >+ push @conf, '"' . simplify_label($entry->{label}) . '" "' . $boot_params . '"'; >+ } >+ } >+ if (@conf) { >+ my $f = "$::prefix/boot/refind_linux.conf"; >+ log::l("writing rEFInd config to $f"); >+ renamef($f, $f . ($o_backup_extension || '.old')); >+ output_with_perm($f, 0600, map { "$_\n" } @conf); >+ check_enough_space(); >+ } else { >+ log::l("config has no entries - rEFInd config file not written"); >+ } >+ >+ my $default_kernel = readlink("$::prefix/boot/vmlinuz"); >+ my $previous_boot = "/sys/firmware/efi/efivars/PreviousBoot-36d08fa7-cf0b-42f5-8f14-68df73ed3740"; >+ if ($default_kernel) { >+ unlink $previous_boot if -e $previous_boot; >+ if (open(my $efivar, ">:encoding(UTF16-LE)", $previous_boot)) { >+ print $efivar "\x{0007}"; >+ print $efivar "\x{0000}"; >+ print $efivar $default_kernel; >+ print $efivar "\x{0000}"; >+ } else { >+ log::l("failed to set up refind: $@ ($!)"); >+ } >+ } >+} >+ >+sub install_refind { >+ my ($bootloader, $all_hds) = @_; >+ >+ write_refind($bootloader, $all_hds); >+} >+ >+sub when_config_changed_refind { >+ my ($_bootloader) = @_; >+ #- do not do anything >+} >+ > =item action($bootloader, $action, @para) > > Calls the C<$action> function with @para parameters: >-- >2.9.0 >
From 3ad62fc67aaabe80ec0b8f037ebe43986663add7 Mon Sep 17 00:00:00 2001 From: Thierry Vignaud <thierry.vignaud@gmail.com> Date: Tue, 14 Apr 2015 05:57:55 -0400 Subject: [PATCH 1/2] add support for rEFInd boot manager (mga#15153) --- perl-install/any.pm | 32 ++++++++++++++--- perl-install/bootloader.pm | 90 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 116 insertions(+), 6 deletions(-) diff --git a/perl-install/any.pm b/perl-install/any.pm index 85d454f..2a7565e 100644 --- a/perl-install/any.pm +++ b/perl-install/any.pm @@ -496,7 +496,13 @@ sub setupBootloader__entries { } @$fstab; my @l; - if ($e->{type} eq "image") { + if ($b->{method} eq 'refind') { + @l = ( + { label => N("Append"), val => \$append }, + { label => N("Video mode"), val => \$vga, list => [ '', Xconfig::resolution_and_depth::bios_vga_modes() ], + format => \&Xconfig::resolution_and_depth::to_string, advanced => 1 }, + ); + } elsif ($e->{type} eq "image") { @l = ( { label => N("Image"), val => \$e->{kernel_or_dev}, list => [ map { "/boot/$_" } bootloader::installed_vmlinuz() ], not_edit => 0 }, { label => N("Root"), val => \$e->{root}, list => [ map { fs::wild_device::from_part('', $_) } grep { !isSwap($_) } @$fstab ], format => sub { $root_descr{$_[0]} } }, @@ -545,9 +551,15 @@ sub setupBootloader__entries { my $Add = sub { my @labels = map { $_->{label} } @{$b->{entries}}; my ($e, $prefix); - if ($in->ask_from_list_('', N("Which type of entry do you want to add?"), - [ N_("Linux"), N_("Other OS (Windows...)") ] - ) eq "Linux") { + if ($b->{method} eq 'refind') { + $e = { type => 'image', + kernel_or_dev => '/boot/vmlinuz', + root => '/dev/' . fs::get::root($fstab)->{device}, #- assume a good default. + }; + $prefix = "linux"; + } elsif ($in->ask_from_list_('', N("Which type of entry do you want to add?"), + [ N_("Linux"), N_("Other OS (Windows...)") ] + ) eq "Linux") { $e = { type => 'image', root => '/dev/' . fs::get::root($fstab)->{device}, #- assume a good default. }; @@ -593,6 +605,18 @@ sub setupBootloader__entries { }; my @prev_entries = @{$b->{entries}}; + + #- the rEFInd configuration file just provides alternative kernel command lines + #- so we only want to display entries that relate to the default kernel. + if ($b->{method} eq 'refind') { + @{$b->{entries}} = + grep { + my $pb = $_->{type} ne 'image' || $_->{kernel_or_dev} ne '/boot/vmlinuz'; + log::l("dropping bootloader entry $_->{label} because it is not needed by rEFInd") if $pb; + !$pb; + } @{$b->{entries}}; + } + if ($in->ask_from__add_modify_remove(N("Bootloader Configuration"), N("Here are the entries on your boot menu so far. You can create additional entries or change the existing ones."), [ { diff --git a/perl-install/bootloader.pm b/perl-install/bootloader.pm index 59172e1..13c64f8 100644 --- a/perl-install/bootloader.pm +++ b/perl-install/bootloader.pm @@ -233,7 +233,7 @@ sub read { my $f = $bootloader::{"read_$main_method"} or die "unknown bootloader method $main_method (read)"; my $bootloader = $f->($fstab); - cleanup_entries($bootloader); + cleanup_entries($bootloader) if $main_method ne 'refind'; # handle raid-extra-boot (lilo) my @devs = $bootloader->{boot}; @@ -254,6 +254,8 @@ sub read { } elsif (my $type = partition_table::raw::typeOfMBR($_)) { warn "typeOfMBR $type on $_ for method $main_method\n" if $ENV{DEBUG}; $type; + } elsif (-e "$::prefix/boot/EFI/EFI/refind" && -e "$::prefix/boot/refind_linux.conf") { + 'refind'; } else { () } } @devs; @@ -571,6 +573,35 @@ sub read_grub_menu_lst { \%b; } +=item read_refind ($fstab) + +Read back rEFInd config + C</boot/refind_linux.conf> + +=cut + +sub read_refind() { + my %bootloader = (entries => []); + foreach (cat_utf8("$::prefix/boot/refind_linux.conf")) { + next if /^#/; + my ($label, $append) = /"(.*)"\s"(.*)"/; + my $root = $1 if $append =~ s/root=(\S*)\s*//; + my $vga = $1 if $append =~ s/vga=(\S*)\s*//; + if ($label && $root) { + push @{$bootloader{entries}}, { + type => 'image', + kernel_or_dev => '/boot/vmlinuz', + label => $label, + root => $root, + append => $append, + vga => $vga + }; + } + } + + $bootloader{method} = 'refind'; + \%bootloader; +} + # FIXME: actually read back previous conf sub read_uboot() { +{ method => 'uboot' }; @@ -1296,6 +1327,7 @@ sub method2text { 'grub2' => N("GRUB2 with text menu"), 'grub-graphic' => N("GRUB with graphical menu"), 'grub-menu' => N("GRUB with text menu"), + 'refind' => N("rEFInd"), }->{$method}; } @@ -1318,7 +1350,8 @@ sub method_choices_raw { arch() =~ /arm/ ? 'uboot' : if_(!$b_prefix_mounted || whereis_binary('grub2-reboot', $::prefix), 'grub2-graphic', 'grub2'), - # only grub2 works on UEFI: + if_(is_uefi() && (!$b_prefix_mounted || -e "$::prefix/boot/EFI/EFI/refind"), 'refind'), + # only grub2 & reFIND work on UEFI: # lilo & grub-legacy do not suppport new ext4/xfs format and are unmainted so only allow them on upgrade: if_(!is_uefi() && !($::isInstall && !$::o->{isUpgrade}), ( if_(!$b_prefix_mounted || whereis_binary('grub', $::prefix) && -f "$::prefix/boot/grub/install.sh", @@ -2195,6 +2228,59 @@ sub when_config_changed_grub { update_copy_in_boot($_) foreach glob($::prefix . boot_copies_dir() . '/*.link'); } +sub write_refind { + my ($bootloader, $_all_hds, $o_backup_extension) = @_; + + my @conf; + + foreach my $entry (@{$bootloader->{entries}}) { + if ($entry->{type} eq "image" && $entry->{kernel_or_dev} eq "/boot/vmlinuz") { + my $vga = $entry->{vga} || $bootloader->{vga}; + my $boot_params = join(' ', + "root=$entry->{root}", + $entry->{append}, + if_($entry->{'read-write'}, 'rw'), + if_($vga && $vga ne "normal", "vga=$vga") + ); + push @conf, '"' . simplify_label($entry->{label}) . '" "' . $boot_params . '"'; + } + } + if (@conf) { + my $f = "$::prefix/boot/refind_linux.conf"; + log::l("writing rEFInd config to $f"); + renamef($f, $f . ($o_backup_extension || '.old')); + output_with_perm($f, 0600, map { "$_\n" } @conf); + check_enough_space(); + } else { + log::l("config has no entries - rEFInd config file not written"); + } + + my $default_kernel = readlink("$::prefix/boot/vmlinuz"); + my $previous_boot = "/sys/firmware/efi/efivars/PreviousBoot-36d08fa7-cf0b-42f5-8f14-68df73ed3740"; + if ($default_kernel) { + unlink $previous_boot if -e $previous_boot; + if (open(my $efivar, ">:encoding(UTF16-LE)", $previous_boot)) { + print $efivar "\x{0007}"; + print $efivar "\x{0000}"; + print $efivar $default_kernel; + print $efivar "\x{0000}"; + } else { + log::l("failed to set up refind: $@ ($!)"); + } + } +} + +sub install_refind { + my ($bootloader, $all_hds) = @_; + + write_refind($bootloader, $all_hds); +} + +sub when_config_changed_refind { + my ($_bootloader) = @_; + #- do not do anything +} + =item action($bootloader, $action, @para) Calls the C<$action> function with @para parameters: -- 2.9.0
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 15153
:
5844
|
5845
|
5932
|
5933
|
5936
|
5975
|
6187
|
6188
|
6308
|
8124
|
8125
|
8126
|
8127
|
8128
|
10371