pushinitrd is finished, for now
This commit is contained in:
parent
c2e2cefd9f
commit
c159000f94
@ -132,13 +132,11 @@ sub getipaddr {
|
||||
sub updateGrub {
|
||||
my $args = shift @_;
|
||||
|
||||
# this is the entry we want in the grub file
|
||||
my @entry = (
|
||||
"title $XCATNETBOOTTITLE\n",
|
||||
"\troot (hd0,0)\n",
|
||||
"\tkernel " . $args->{kernelpath} . ' ' . $args->{kernelparms} . "\n",
|
||||
"\tinitrd " . $args->{initrdpath} . "\n",
|
||||
);
|
||||
# how we specify the path for the kernel and initrd is different on redhat and suse
|
||||
my $fileprefix;
|
||||
if (isRedhat()) { $fileprefix = '/'; }
|
||||
elsif (isSuse()) { $fileprefix = '/boot/'; }
|
||||
else { die "Error: currently only support red hat or suse distros.\n"; }
|
||||
|
||||
# open the grub file and see if it is in there or if we have to add it
|
||||
my $grubfile = findGrubPath();
|
||||
@ -147,6 +145,17 @@ sub updateGrub {
|
||||
my @lines = <FILE>;
|
||||
close FILE;
|
||||
|
||||
# this is the entry we want in the grub file
|
||||
my @rootlines = grep(/^\s+root\s+/, @lines); # copy one of the existing root lines
|
||||
if (!scalar(@rootlines)) { die "Error: can't find an existing line for 'root' in the grub config file\n"; }
|
||||
my ($rootline) = $rootlines[0] =~ m/^\s*(.*?)\s*$/;
|
||||
my @entry = (
|
||||
"title $XCATNETBOOTTITLE\n",
|
||||
"\t$rootline\n",
|
||||
"\tkernel " . $fileprefix . $args->{kernelpath} . ' ' . $args->{kernelparms} . "\n",
|
||||
"\tinitrd " . $fileprefix . $args->{initrdpath} . "\n",
|
||||
);
|
||||
|
||||
my $needtowritefile = 1;
|
||||
if (grep(/^title\s+$XCATNETBOOTTITLE/, @lines)) { $needtowritefile = updateGrubEntry(\@lines, \@entry); } # there is already an entry in there
|
||||
else { addGrubEntry (\@lines, \@entry); }
|
||||
@ -179,15 +188,17 @@ sub addGrubEntry {
|
||||
# check the xcat entry in the grub file and see if it needs to be updated. Return 1 if it does.
|
||||
sub updateGrubEntry {
|
||||
my ($lines, $entry) = @_;
|
||||
#print Dumper($lines), Dumper($entry);
|
||||
# find the index of the xcat stanza
|
||||
my $i;
|
||||
for ($i=0; $i++; $i<scalar(@$lines)) {
|
||||
for ($i=0; $i<scalar(@$lines); $i++) {
|
||||
if ($lines->[$i] =~ m/^title\s+$XCATNETBOOTTITLE/) { last; } # found it
|
||||
}
|
||||
|
||||
# compare the next few lines with the corresponding line in @$entries and replace if different
|
||||
my $replaced = 0;
|
||||
for (my $j=0; $j++; $j<scalar(@$entry)) {
|
||||
for (my $j=0; $j<scalar(@$entry); $j++) {
|
||||
#print "comparing:\n ", $lines->[$i+$j], "\n ", $entry->[$j], "\n";
|
||||
if ($lines->[$i+$j] ne $entry->[$j]) { # this line was different
|
||||
$lines->[$i+$j] = $entry->[$j];
|
||||
$replaced = 1;
|
||||
@ -216,6 +227,10 @@ sub findGrubPath {
|
||||
# Pring msg only if -v was specified
|
||||
sub verbose { if ($VERBOSE) { print shift, "\n"; } }
|
||||
|
||||
# Check the distro we are running on
|
||||
sub isSuse { return (-e '/etc/SuSE-release'); }
|
||||
sub isRedhat { return (-e '/etc/redhat-release' || -e '/etc/centos-release' || -e '/etc/fedora-release'); } # add chk for fedora
|
||||
|
||||
|
||||
|
||||
# Run a command. If called in the context of return an array, it will capture the output
|
||||
|
@ -66,6 +66,7 @@ sub getBootParms {
|
||||
|
||||
# get the mgmt node cluster-facing ip addr
|
||||
@output = runcmd('lsdef -t site -i master -c');
|
||||
chomp($output[0]);
|
||||
my ($junk, $ip) = split(/=/, $output[0]);
|
||||
$bootparms{mnip} = $ip;
|
||||
|
||||
@ -82,16 +83,22 @@ sub copyFilesToNodes {
|
||||
foreach my $a (qw(kernel initrd)) {
|
||||
my $file = $bootparms->{$a};
|
||||
my $localfile = "/tftpboot/$file";
|
||||
# for the remote file name, use the last 2 parts of the path, separated by "-"
|
||||
my $remotefile = $file;
|
||||
$remotefile =~ s|^.*/([^/]+)/([^/]+)$|$1-$2|;
|
||||
$remotefile = "/boot/$remotefile";
|
||||
# for the
|
||||
my $remotefile = '/boot/' . remoteFilename($file);
|
||||
print "Copying $localfile to $nr:$remotefile\n";
|
||||
runcmd("xdcp $nr -p $localfile $remotefile");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Form the remote file name, using the last 2 parts of the path, separated by "-"
|
||||
sub remoteFilename {
|
||||
my $f = shift @_;
|
||||
$f =~ s|^.*/([^/]+)/([^/]+)$|$1-$2|;
|
||||
return $f;
|
||||
}
|
||||
|
||||
|
||||
# Run the modifygrub script on the nodes to update the grub config file
|
||||
# Args: noderange, reference to the bootparms hash
|
||||
sub updateGrubOnNodes {
|
||||
@ -101,7 +108,7 @@ sub updateGrubOnNodes {
|
||||
my @output = runcmd('which modifygrub');
|
||||
my $modifygrub = $output[0];
|
||||
chomp($modifygrub);
|
||||
my $cmd = "xdsh $nr -e $modifygrub $vtxt " . $bootparms->{kernel} . ' ' . $bootparms->{initrd} . ' ';
|
||||
my $cmd = "xdsh $nr -e $modifygrub $vtxt " . remoteFilename($bootparms->{kernel}) . ' ' . remoteFilename($bootparms->{initrd}) . ' ';
|
||||
# we need to quote the kernel parms, both here when passing it to xdsh, and on the node
|
||||
# when xdsh is passing it to modifygrub. The way to get single quotes inside single quotes
|
||||
# is to quote each of the outer single quotes with double quotes.
|
||||
|
Loading…
x
Reference in New Issue
Block a user