Skip to content

Commit 26df05a

Browse files
committed
kest.pl: Fix grub2 menu handling for rebooting
grub2 has submenus where to use grub-reboot, it requires: grub-reboot X>Y where X is the main index and Y is the submenu. Thus if you have: menuentry 'Debian GNU/Linux' --class debian --class gnu-linux ... [...] } submenu 'Advanced options for Debian GNU/Linux' $menuentry_id_option ... menuentry 'Debian GNU/Linux, with Linux 6.0.0-4-amd64' --class debian --class gnu-linux ... [...] } menuentry 'Debian GNU/Linux, with Linux 6.0.0-4-amd64 (recovery mode)' --class debian --class gnu-linux ... [...] } menuentry 'Debian GNU/Linux, with Linux test' --class debian --class gnu-linux ... [...] } And wanted to boot to the "Linux test" kernel, you need to run: # grub-reboot 1>2 As 1 is the second top menu (the submenu) and 2 is the third of the sub menu entries. Have the grub.cfg parsing for grub2 handle such cases. Cc: [email protected] Fixes: a15ba91 ("ktest: Add support for grub2") Reviewed-by: John 'Warthog9' Hawley (VMware) <[email protected]> Signed-off-by: Steven Rostedt <[email protected]>
1 parent ef784ee commit 26df05a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

tools/testing/ktest/ktest.pl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,7 +1963,7 @@ sub run_scp_mod {
19631963

19641964
sub _get_grub_index {
19651965

1966-
my ($command, $target, $skip) = @_;
1966+
my ($command, $target, $skip, $submenu) = @_;
19671967

19681968
return if (defined($grub_number) && defined($last_grub_menu) &&
19691969
$last_grub_menu eq $grub_menu && defined($last_machine) &&
@@ -1980,11 +1980,16 @@ sub _get_grub_index {
19801980

19811981
my $found = 0;
19821982

1983+
my $submenu_number = 0;
1984+
19831985
while (<IN>) {
19841986
if (/$target/) {
19851987
$grub_number++;
19861988
$found = 1;
19871989
last;
1990+
} elsif (defined($submenu) && /$submenu/) {
1991+
$submenu_number++;
1992+
$grub_number = -1;
19881993
} elsif (/$skip/) {
19891994
$grub_number++;
19901995
}
@@ -1993,6 +1998,9 @@ sub _get_grub_index {
19931998

19941999
dodie "Could not find '$grub_menu' through $command on $machine"
19952000
if (!$found);
2001+
if ($submenu_number > 0) {
2002+
$grub_number = "$submenu_number>$grub_number";
2003+
}
19962004
doprint "$grub_number\n";
19972005
$last_grub_menu = $grub_menu;
19982006
$last_machine = $machine;
@@ -2003,6 +2011,7 @@ sub get_grub_index {
20032011
my $command;
20042012
my $target;
20052013
my $skip;
2014+
my $submenu;
20062015
my $grub_menu_qt;
20072016

20082017
if ($reboot_type !~ /^grub/) {
@@ -2017,8 +2026,9 @@ sub get_grub_index {
20172026
$skip = '^\s*title\s';
20182027
} elsif ($reboot_type eq "grub2") {
20192028
$command = "cat $grub_file";
2020-
$target = '^menuentry.*' . $grub_menu_qt;
2021-
$skip = '^menuentry\s|^submenu\s';
2029+
$target = '^\s*menuentry.*' . $grub_menu_qt;
2030+
$skip = '^\s*menuentry';
2031+
$submenu = '^\s*submenu\s';
20222032
} elsif ($reboot_type eq "grub2bls") {
20232033
$command = $grub_bls_get;
20242034
$target = '^title=.*' . $grub_menu_qt;
@@ -2027,7 +2037,7 @@ sub get_grub_index {
20272037
return;
20282038
}
20292039

2030-
_get_grub_index($command, $target, $skip);
2040+
_get_grub_index($command, $target, $skip, $submenu);
20312041
}
20322042

20332043
sub wait_for_input {
@@ -2090,7 +2100,7 @@ sub reboot_to {
20902100
if ($reboot_type eq "grub") {
20912101
run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch)'";
20922102
} elsif (($reboot_type eq "grub2") or ($reboot_type eq "grub2bls")) {
2093-
run_ssh "$grub_reboot $grub_number";
2103+
run_ssh "$grub_reboot \"'$grub_number'\"";
20942104
} elsif ($reboot_type eq "syslinux") {
20952105
run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path";
20962106
} elsif (defined $reboot_script) {

0 commit comments

Comments
 (0)