diff --git a/perl-xCAT/xCAT/BootUtils.pm b/perl-xCAT/xCAT/BootUtils.pm index 29ff5016a9..177327a263 100644 --- a/perl-xCAT/xCAT/BootUtils.pm +++ b/perl-xCAT/xCAT/BootUtils.pm @@ -56,14 +56,18 @@ sub volatile_addkcmdline { "can't find command `linuxefi'" and never asks for the kernel. Arguments: $image the path of the grub2 image served to the node + $arch the architecture of the node Returns: the kernel command and the initial ramdisk command =cut #------------------------------------------------------------------------------- sub grub2_kernel_commands { - my ($image) = @_; + my ($image, $arch) = @_; + # linuxefi loads an EFI binary. x86 is the architecture whose grub2 loader is one, so + # a ppc node takes linux whatever its image carries. + return ('linux', 'initrd') unless defined($arch) && $arch =~ /x86/i; return ('linux', 'initrd') unless grub2_image_provides($image, 'linuxefi'); return ('linuxefi', 'initrdefi'); } diff --git a/xCAT-server/lib/xcat/plugins/grub2.pm b/xCAT-server/lib/xcat/plugins/grub2.pm index 6e65aeeb9b..f784a919fe 100644 --- a/xCAT-server/lib/xcat/plugins/grub2.pm +++ b/xCAT-server/lib/xcat/plugins/grub2.pm @@ -358,7 +358,7 @@ sub setstate { # The commands come from the image served to this node, not from its # architecture: an image built from upstream grub has no linuxefi. my ($kernelcmd, $initrdcmd) = - xCAT::BootUtils::grub2_kernel_commands($grub2bin); + xCAT::BootUtils::grub2_kernel_commands($grub2bin, $nodearch); if ($kern and $kern->{kcmdline}) { my $kcmdline = quote_kcmdline($kern->{kcmdline}); diff --git a/xCAT-test/unit/grub2_kernel_command.t b/xCAT-test/unit/grub2_kernel_command.t index 12eca3b32a..e5e8b8bb9f 100644 --- a/xCAT-test/unit/grub2_kernel_command.t +++ b/xCAT-test/unit/grub2_kernel_command.t @@ -13,7 +13,7 @@ use warnings; use File::Spec; use File::Temp qw(tempdir); use FindBin; -use Test::More tests => 8; +use Test::More tests => 9; use lib "$FindBin::Bin/../../perl-xCAT"; use xCAT::BootUtils; @@ -36,19 +36,19 @@ sub write_image { my $downstream = write_image('grub2.downstream', qw(linux linuxefi initrd initrdefi)); my $upstream = write_image('grub2.upstream', qw(linux initrd)); -is_deeply( [ xCAT::BootUtils::grub2_kernel_commands($downstream) ], +is_deeply( [ xCAT::BootUtils::grub2_kernel_commands($downstream, 'x86_64') ], [ 'linuxefi', 'initrdefi' ], 'an image that carries linuxefi is given linuxefi and initrdefi' ); -is_deeply( [ xCAT::BootUtils::grub2_kernel_commands($upstream) ], +is_deeply( [ xCAT::BootUtils::grub2_kernel_commands($upstream, 'x86_64') ], [ 'linux', 'initrd' ], 'an image built from upstream grub is given linux and initrd' ); # A missing or unreadable image must not produce a command the node cannot run. linux is # carried by every grub2 image, so it is the safe answer. -is_deeply( [ xCAT::BootUtils::grub2_kernel_commands( File::Spec->catfile($dir, 'absent') ) ], +is_deeply( [ xCAT::BootUtils::grub2_kernel_commands( File::Spec->catfile($dir, 'absent'), 'x86_64' ) ], [ 'linux', 'initrd' ], 'a missing image is given linux and initrd' ); -is_deeply( [ xCAT::BootUtils::grub2_kernel_commands(undef) ], +is_deeply( [ xCAT::BootUtils::grub2_kernel_commands(undef, 'x86_64') ], [ 'linux', 'initrd' ], 'an undefined image is given linux and initrd' ); ok( xCAT::BootUtils::grub2_image_provides($downstream, 'linuxefi'), @@ -62,3 +62,8 @@ ok( xCAT::BootUtils::grub2_image_provides($upstream, 'linux'), # would look downstream. ok( !xCAT::BootUtils::grub2_image_provides( write_image('grub2.efionly', 'linuxefi'), 'linux' ), 'a longer command name does not satisfy a shorter one' ); + +# linuxefi loads an EFI binary, and a ppc loader is not one. The image is irrelevant there. +is_deeply( [ xCAT::BootUtils::grub2_kernel_commands($downstream, 'ppc64le') ], + [ 'linux', 'initrd' ], + 'a ppc node takes linux even from an image that carries linuxefi' ); diff --git a/xCAT-test/unit/grub2_netboot_protocol.t b/xCAT-test/unit/grub2_netboot_protocol.t index 7f7fd4d75c..f60b8eedd9 100644 --- a/xCAT-test/unit/grub2_netboot_protocol.t +++ b/xCAT-test/unit/grub2_netboot_protocol.t @@ -54,7 +54,11 @@ for my $arch (qw(x86_64 ppc64le aarch64 riscv64)) { my $bootdir = "$tftpdir/boot/grub2"; make_path($bootdir); my $loader_arch = $arch eq 'ppc64le' ? 'ppc' : $arch; - write_text("$bootdir/grub2.$loader_arch", "fixture loader\n"); + # The kernel command follows the image, not the architecture, so the fixture + # has to say which commands it carries. grub records the name of each command + # its modules register. This one stands for a downstream image. + write_text("$bootdir/grub2.$loader_arch", + "fixture loader\0linux\0linuxefi\0initrd\0initrdefi\0\n"); local $::XCATSITEVALS{httpport} = $port; delete $::XCATSITEVALS{httpport} unless defined $port; my %noderes = (tftpserver => 'server'); @@ -89,6 +93,8 @@ for my $arch (qw(x86_64 ppc64le aarch64 riscv64)) { my @roots = $entry =~ /^\s*set root=(.*)$/mg; is_deeply(\@roots, [$expected_root], 'transfer protocol and port are correct'); my $prefix = $http_paths ? $tftpdir : ''; + # x86_64 is the architecture whose loader is an EFI binary, and the fixture + # above carries linuxefi, so that is what the configuration must use. my $efi = $arch eq 'x86_64' ? 'efi' : ''; my @kernels = $entry =~ /^\s*(linux\S* .*)$/mg; is_deeply(\@kernels,