Mageia Bugzilla – Attachment 6308 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 to add support for rEFInd boot manager in drakboot (updated)
refind.patch (text/plain), 8.28 KB, created by
Martin Whitaker
on 2015-04-18 00:42:53 CEST
(
hide
)
Description:
Patch to add support for rEFInd boot manager in drakboot (updated)
Filename:
MIME Type:
Creator:
Martin Whitaker
Created:
2015-04-18 00:42:53 CEST
Size:
8.28 KB
patch
obsolete
>--- any.pm.orig 2015-04-15 21:12:48.000000000 +0100 >+++ any.pm 2015-04-17 00:05:21.558562952 +0100 >@@ -464,6 +464,19 @@ > log::l("switching for lilo to grub, ensure we don't read lilo.conf anymore"); > renamef("$::prefix/etc/lilo.conf", "$::prefix/etc/lilo.conf.unused"); > } >+ >+ if (bootloader::main_method($b->{method}) eq 'refind' && >+ bootloader::main_method($prev_method) eq 'grub2') { >+ #- grub2 doesn't provide any entries we can use, so revert to the defaults >+ %{$b} = (); >+ setupBootloaderBeforeStandalone($in->do_pkgs, $b, $all_hds, $fstab); >+ $b->{method} = 'refind'; >+ } >+ if (bootloader::main_method($prev_method) eq 'refind' && >+ bootloader::main_method($b->{method}) ne 'refind') { >+ log::l("switching from refind, moving refind_linux.conf to refind_linux.conf.old"); >+ renamef("$::prefix/boot/refind_linux.conf", "$::prefix/boot/refind_linux.conf.old"); >+ } > 1; > } > >@@ -489,7 +502,13 @@ > } @$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('', $_) } @$fstab ], format => sub { $root_descr{$_[0]} } }, >@@ -538,9 +557,15 @@ > 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. > }; >@@ -586,6 +611,18 @@ > }; > > 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."), [ { >--- bootloader.pm.orig 2015-04-15 21:12:48.000000000 +0100 >+++ bootloader.pm 2015-04-16 11:27:11.889906804 +0100 >@@ -233,7 +233,7 @@ > 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 @@ > } 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; > >@@ -543,6 +545,36 @@ > \%b; > } > >+=item read_refind ($fstab) >+ >+Read back rEFInd config + C</boot/refind_linux.conf> >+ >+=cut >+ >+sub read_refind() { >+ my (%bootloader, $entry); >+ $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_pmon2000() { > +{ method => 'pmon2000' }; >@@ -1278,6 +1310,7 @@ > 'grub2' => N("GRUB2 with graphical menu"), > 'grub-graphic' => N("GRUB with graphical menu"), > 'grub-menu' => N("GRUB with text menu"), >+ 'refind' => N("rEFInd"), > }->{$method}; > } > >@@ -1288,12 +1321,15 @@ > arch() =~ /arm/ ? 'uboot' : > if_(!$b_prefix_mounted || whereis_binary('grub2-reboot', $::prefix), > 'grub2'), >- if_(!is_uefi(), ( >+ is_uefi() ? >+ if_(!$b_prefix_mounted || -e "$::prefix/boot/EFI/EFI/refind", >+ 'refind') >+ : ( > if_(!$b_prefix_mounted || whereis_binary('grub', $::prefix), > 'grub-graphic', 'grub-menu'), > if_(!$b_prefix_mounted || whereis_binary('lilo', $::prefix), > 'lilo-menu'), >- )); >+ ); > } > sub method_choices { > my ($all_hds, $b_prefix_mounted) = @_; >@@ -2073,6 +2109,72 @@ > 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 = "$::prefix/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}"; >+ close $efivar; >+ } >+ } >+ >+ my @bootvars = run_program::rooted_get_stdout($::prefix, 'efibootmgr') or die "couldn't read EFI boot variables"; >+ if (my ($bootvar) = grep {/rEFInd Boot Manager/} @bootvars) { >+ my $bootnum = substr($bootvar, 4, 4); >+ ($bootvar) = grep {/BootOrder/} @bootvars or die "couldn't find EFI boot order"; >+ my @bootorder = split(/[\s,]+/, $bootvar); >+ return if @bootorder[1] eq $bootnum; >+ run_program::rooted($::prefix, 'efibootmgr', '-b', $bootnum, '-B') or die "failed to delete old rEFInd boot entry"; >+ } >+ log::l("Setting rEFInd as default boot manager"); >+ my $part = fs::get::has_mntpoint("/boot/EFI", $all_hds) or die "couldn't find ESP partition"; >+ my @efs = devices::simple_partition_scan($part); >+ run_program::rooted($::prefix, 'efibootmgr', '-c', '-L', 'rEFInd Boot Manager', '-l', 'EFI/refind/refind_x64.efi', '-d', '/dev/' . @efs[0], '-p', @efs[1]) >+ or die "failed to create new rEFInd boot entry"; >+} >+ >+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: >@@ -2120,6 +2222,9 @@ > $do_pkgs->ensure_is_installed('mageia-gfxboot-theme', '/usr/share/gfxboot/themes/Mageia/boot/message', 1) or return 0; > } > } >+ if ($bootloader->{method} eq 'refind') { >+ $do_pkgs->ensure_is_installed('efibootmgr', '/sbin/efibootmgr', 1) or return 0; >+ } > 1; > } >
--- any.pm.orig 2015-04-15 21:12:48.000000000 +0100 +++ any.pm 2015-04-17 00:05:21.558562952 +0100 @@ -464,6 +464,19 @@ log::l("switching for lilo to grub, ensure we don't read lilo.conf anymore"); renamef("$::prefix/etc/lilo.conf", "$::prefix/etc/lilo.conf.unused"); } + + if (bootloader::main_method($b->{method}) eq 'refind' && + bootloader::main_method($prev_method) eq 'grub2') { + #- grub2 doesn't provide any entries we can use, so revert to the defaults + %{$b} = (); + setupBootloaderBeforeStandalone($in->do_pkgs, $b, $all_hds, $fstab); + $b->{method} = 'refind'; + } + if (bootloader::main_method($prev_method) eq 'refind' && + bootloader::main_method($b->{method}) ne 'refind') { + log::l("switching from refind, moving refind_linux.conf to refind_linux.conf.old"); + renamef("$::prefix/boot/refind_linux.conf", "$::prefix/boot/refind_linux.conf.old"); + } 1; } @@ -489,7 +502,13 @@ } @$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('', $_) } @$fstab ], format => sub { $root_descr{$_[0]} } }, @@ -538,9 +557,15 @@ 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. }; @@ -586,6 +611,18 @@ }; 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."), [ { --- bootloader.pm.orig 2015-04-15 21:12:48.000000000 +0100 +++ bootloader.pm 2015-04-16 11:27:11.889906804 +0100 @@ -233,7 +233,7 @@ 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 @@ } 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; @@ -543,6 +545,36 @@ \%b; } +=item read_refind ($fstab) + +Read back rEFInd config + C</boot/refind_linux.conf> + +=cut + +sub read_refind() { + my (%bootloader, $entry); + $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_pmon2000() { +{ method => 'pmon2000' }; @@ -1278,6 +1310,7 @@ 'grub2' => N("GRUB2 with graphical menu"), 'grub-graphic' => N("GRUB with graphical menu"), 'grub-menu' => N("GRUB with text menu"), + 'refind' => N("rEFInd"), }->{$method}; } @@ -1288,12 +1321,15 @@ arch() =~ /arm/ ? 'uboot' : if_(!$b_prefix_mounted || whereis_binary('grub2-reboot', $::prefix), 'grub2'), - if_(!is_uefi(), ( + is_uefi() ? + if_(!$b_prefix_mounted || -e "$::prefix/boot/EFI/EFI/refind", + 'refind') + : ( if_(!$b_prefix_mounted || whereis_binary('grub', $::prefix), 'grub-graphic', 'grub-menu'), if_(!$b_prefix_mounted || whereis_binary('lilo', $::prefix), 'lilo-menu'), - )); + ); } sub method_choices { my ($all_hds, $b_prefix_mounted) = @_; @@ -2073,6 +2109,72 @@ 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 = "$::prefix/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}"; + close $efivar; + } + } + + my @bootvars = run_program::rooted_get_stdout($::prefix, 'efibootmgr') or die "couldn't read EFI boot variables"; + if (my ($bootvar) = grep {/rEFInd Boot Manager/} @bootvars) { + my $bootnum = substr($bootvar, 4, 4); + ($bootvar) = grep {/BootOrder/} @bootvars or die "couldn't find EFI boot order"; + my @bootorder = split(/[\s,]+/, $bootvar); + return if @bootorder[1] eq $bootnum; + run_program::rooted($::prefix, 'efibootmgr', '-b', $bootnum, '-B') or die "failed to delete old rEFInd boot entry"; + } + log::l("Setting rEFInd as default boot manager"); + my $part = fs::get::has_mntpoint("/boot/EFI", $all_hds) or die "couldn't find ESP partition"; + my @efs = devices::simple_partition_scan($part); + run_program::rooted($::prefix, 'efibootmgr', '-c', '-L', 'rEFInd Boot Manager', '-l', 'EFI/refind/refind_x64.efi', '-d', '/dev/' . @efs[0], '-p', @efs[1]) + or die "failed to create new rEFInd boot entry"; +} + +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: @@ -2120,6 +2222,9 @@ $do_pkgs->ensure_is_installed('mageia-gfxboot-theme', '/usr/share/gfxboot/themes/Mageia/boot/message', 1) or return 0; } } + if ($bootloader->{method} eq 'refind') { + $do_pkgs->ensure_is_installed('efibootmgr', '/sbin/efibootmgr', 1) or return 0; + } 1; }
View Attachment As Raw
Actions:
View
Attachments on
bug 15153
:
5844
|
5845
|
5932
|
5933
|
5936
|
5975
|
6187
|
6188
|
6308
|
8124
|
8125
|
8126
|
8127
|
8128
|
10371