summaryrefslogtreecommitdiffstats
path: root/perl-install/bootloader.pm
diff options
context:
space:
mode:
authorThierry Vignaud <thierry.vignaud@gmail.com>2016-06-22 02:09:34 +0200
committerThierry Vignaud <thierry.vignaud@gmail.com>2016-06-22 02:24:24 +0200
commit5d85cc4dba16dbf5cd219c21d47677e4b8ad3df8 (patch)
tree23e01e180669e4ed18af93a4c8c82d6741f4916a /perl-install/bootloader.pm
parent9e49ca02c5207d900ce75132b1311a082e604736 (diff)
downloaddrakx-5d85cc4dba16dbf5cd219c21d47677e4b8ad3df8.tar
drakx-5d85cc4dba16dbf5cd219c21d47677e4b8ad3df8.tar.gz
drakx-5d85cc4dba16dbf5cd219c21d47677e4b8ad3df8.tar.bz2
drakx-5d85cc4dba16dbf5cd219c21d47677e4b8ad3df8.tar.xz
drakx-5d85cc4dba16dbf5cd219c21d47677e4b8ad3df8.zip
fix setting default entry when in a submenu
default entry must be selected by its full path (mga#18560) eg: "submenu1>submenu2>title": See http://www.gnu.org/software/grub/manual/html_node/default.html#default
Diffstat (limited to 'perl-install/bootloader.pm')
-rw-r--r--perl-install/bootloader.pm18
1 files changed, 15 insertions, 3 deletions
diff --git a/perl-install/bootloader.pm b/perl-install/bootloader.pm
index 2f379bd0b..ef0237323 100644
--- a/perl-install/bootloader.pm
+++ b/perl-install/bootloader.pm
@@ -313,10 +313,11 @@ sub read_grub2() {
$bootloader{entries} = [];
my $entry;
my $f = "$::prefix/boot/grub2/grub.cfg";
+ my @menus;
foreach (cat_utf8($f)) {
next if /^#/;
if (/menuentry\s+['"]([^']+)["']/) {
- $entry = { label => $1 };
+ $entry = { label => $1, real_label => join('>', @menus, $1) };
} elsif (/linux\s+(\S+)\s+(.*)?/ || /module\s+(\S+vmlinu\S+)\s+(.*)?/) {
$entry->{type} = 'image';
@$entry{qw(kernel_or_dev append)} = ($1, $2);
@@ -327,10 +328,14 @@ sub read_grub2() {
}
} elsif (/initrd\s+(\S+)/ || /module\s+(\S+initrd\S+)\s+(.*)?/) {
$entry->{initrd} = $1;
+ } elsif (/^submenu\s+['"]([^']+)["']/) {
+ push @menus, $1;
} elsif (/}/) {
if ($entry) {
- push @{$bootloader{entries}}, $entry ;
+ push @{$bootloader{entries}}, $entry;
undef $entry;
+ } else {
+ pop @menus;
}
}
}
@@ -338,6 +343,7 @@ sub read_grub2() {
# get default entry:
foreach (run_program::rooted_get_stdout($::prefix, qw(grub2-editenv list))) {
$bootloader{default} = $1 if /saved_entry=(.*)/;
+ $bootloader{default} =~ s/.*>//; # strip full menu entry path
}
# Get password prior to run update-grub2:
@@ -1876,11 +1882,17 @@ sub write_grub2 {
run_program::rooted($::prefix, 'update-grub2', '2>', \$error) or die "update-grub2 failed: $error";
log::l("update-grub2 logs: $error");
+ my $default = $bootloader->{default};
+ # menu entry must be identified by its full path. eg: "submenu1>submenu2>title":
+ if (my $def = find { $_->{label} eq $bootloader->{default} } @{$bootloader->{entries}}) {
+ $default = $def->{real_label} if $def->{real_label};
+ }
+
# set default entry:
eval {
my $f2 = "$::prefix/boot/grub2/grubenv";
cp_af($f2, $f2 . ($o_backup_extension || '.old'));
- run_program::rooted($::prefix, 'grub2-set-default', '2>', \$error, $bootloader->{default}) or die "grub2-set-default failed: $error";
+ run_program::rooted($::prefix, 'grub2-set-default', '2>', \$error, $default) or die "grub2-set-default failed: $error";
};
if (my $err = $@) {
log::l("error while running grub2-set-default: $err");