diff --git a/xCAT-server/lib/xcat/plugins/xnba.pm b/xCAT-server/lib/xcat/plugins/xnba.pm index 88702a0e6..a72b90df6 100644 --- a/xCAT-server/lib/xcat/plugins/xnba.pm +++ b/xCAT-server/lib/xcat/plugins/xnba.pm @@ -91,6 +91,25 @@ sub getstate { } } +my %efistubcache; +sub has_efistub { + my $kern = shift; + my $node = shift; + my $filename = $globaltftpdir . "/" . $kern; + if (defined $efistubcache{$filename}) { + return $efistubcache{$filename}; + } + open my $kernel, '<:raw', $filename; + read $kernel, my $bytes, 512; + my $match = pack 'H*', '504500006486'; + if ($bytes =~ m/$match/) { + $efistubcache{$filename} = 1; + return 1; + } else { + $efistubcache{$filename} = 0; + return 0; + } +} sub setstate { =pod @@ -304,23 +323,36 @@ sub setstate { print $pcfg "imgargs kernel BOOTIF=" . '${netX/mac}' . "\n"; } if ($kern->{initrd}) { - print $pcfg "imgfetch http://" . '${next-server}:' . "$httpport/tftpboot/" . $kern->{initrd} . "\n"; + print $pcfg "imgfetch -n initrd http://" . '${next-server}:' . "$httpport/tftpboot/" . $kern->{initrd} . "\n"; } print $pcfg "imgexec kernel\n"; if ($kern->{kcmdline} and $kern->{initrd}) { #only a linux kernel/initrd pair should land here, write elilo config and uefi variant of xnba config file my $ucfg; open($ucfg, '>', $tftpdir . "/xcat/xnba/nodes/" . $node . ".uefi"); - print $ucfg "#!gpxe\n"; - print $ucfg 'chain http://${next-server}:'.$httpport.'/tftpboot/xcat/elilo-x64.efi -C /tftpboot/xcat/xnba/nodes/' . $node . ".elilo\n"; - close($ucfg); - open($ucfg, '>', $tftpdir . "/xcat/xnba/nodes/" . $node . ".elilo"); - print $ucfg 'default="xCAT"' . "\n"; - print $ucfg "delay=0\n\n"; - print $ucfg "image=/tftpboot/" . $kern->{kernel} . "\n"; - print $ucfg " label=\"xCAT\"\n"; - print $ucfg " initrd=/tftpboot/" . $kern->{initrd} . "\n"; - print $ucfg " append=\"" . $elilokcmdline . ' BOOTIF=%B"' . "\n"; - close($ucfg); + if (has_efistub($kern->{kernel}, $node)) { + print $ucfg "#!gpxe\n"; + print $ucfg "imgfetch -n kernel http://" . '${next-server}:' . $httpport.'/tftpboot/' . $kern->{kernel} . "\n"; + print $ucfg "imgload kernel\n"; + if ($kern->{kcmdline}) { + print $ucfg "imgargs kernel " . $kern->{kcmdline} . ' BOOTIF=01-${netX/mac:hexhyp} initrd=initrd' . "\n"; + } else { + print $ucfg "imgargs kernel BOOTIF=" . '${netX/mac} initrd=initrd' . "\n"; + } + print $ucfg "imgfetch -n initrd http://" . '${next-server}:' . "$httpport/tftpboot/" . $kern->{initrd} . "\n"; + print $ucfg "imgexec kernel\n"; + close($ucfg); + } else { + print $ucfg "#!gpxe\n"; + print $ucfg 'chain http://${next-server}:'.$httpport.'/tftpboot/xcat/elilo-x64.efi -C /tftpboot/xcat/xnba/nodes/' . $node . ".elilo\n"; + close($ucfg); + open($ucfg, '>', $tftpdir . "/xcat/xnba/nodes/" . $node . ".elilo"); + print $ucfg 'default="xCAT"' . "\n"; + print $ucfg "delay=0\n\n"; + print $ucfg "image=/tftpboot/" . $kern->{kernel} . "\n"; + print $ucfg " label=\"xCAT\"\n"; + print $ucfg " initrd=/tftpboot/" . $kern->{initrd} . "\n"; + print $ucfg " append=\"" . $elilokcmdline . ' BOOTIF=%B"' . "\n"; + } } } }