From 43ec8b55ef8a05659053c8e058391b7e2022e5cf Mon Sep 17 00:00:00 2001 From: immarvin Date: Fri, 10 Apr 2015 02:52:55 -0700 Subject: [PATCH] support persistent kernel cmdline after diskful installation --- perl-xCAT/xCAT/Schema.pm | 4 +- perl-xCAT/xCAT/Utils.pm | 27 ++++++++ xCAT-server/lib/perl/xCAT/Template.pm | 63 ++++++++++++++++++- xCAT-server/lib/xcat/plugins/grub2.pm | 16 ++++- xCAT-server/lib/xcat/plugins/pxe.pm | 10 +++ xCAT-server/lib/xcat/plugins/xnba.pm | 11 ++++ xCAT-server/lib/xcat/plugins/yaboot.pm | 26 ++++++-- .../share/xcat/install/rh/compute.rhels6.tmpl | 2 +- .../share/xcat/install/rh/compute.rhels7.tmpl | 3 +- .../xcat/install/rh/service.rhels6.ppc64.tmpl | 3 +- .../install/rh/service.rhels6.x86_64.tmpl | 3 +- .../share/xcat/install/rh/service.rhels7.tmpl | 3 +- .../xcat/install/sles/compute.sles11.tmpl | 2 +- .../install/sles/compute.sles12.ppc64le.tmpl | 2 +- .../xcat/install/sles/compute.sles12.tmpl | 2 +- .../xcat/install/sles/service.sles11.tmpl | 2 +- .../share/xcat/install/ubuntu/compute.tmpl | 5 ++ .../share/xcat/install/ubuntu/service.tmpl | 6 +- 18 files changed, 166 insertions(+), 24 deletions(-) diff --git a/perl-xCAT/xCAT/Schema.pm b/perl-xCAT/xCAT/Schema.pm index c1deed358..9cd3cea60 100755 --- a/perl-xCAT/xCAT/Schema.pm +++ b/perl-xCAT/xCAT/Schema.pm @@ -326,7 +326,7 @@ bootparams => { 'kernel' => 'The kernel that network boot actions should currently acquire and use. Note this could be a chained boot loader such as memdisk or a non-linux boot loader', 'initrd' => 'The initial ramdisk image that network boot actions should use (could be a DOS floppy or hard drive image if using memdisk as kernel)', 'kcmdline' => 'Arguments to be passed to the kernel', - 'addkcmdline' => 'User specified one or more parameters to be passed to the kernel', + 'addkcmdline' => 'User specified one or more parameters to be passed to the kernel. For the kernel options need to be persistent after installation, specify them with prefix "P::"', 'dhcpstatements' => 'xCAT manipulated custom dhcp statements (not intended for user manipulation)', 'adddhcpstatements' => 'Custom dhcp statements for administrator use (not implemneted yet)', comments => 'Any user-written notes.', @@ -754,7 +754,7 @@ linuximage => { imagename => 'The name of this xCAT OS image definition.', template => 'The fully qualified name of the template file that will be used to create the OS installer configuration file for stateful installations (e.g. kickstart for RedHat, autoyast for SLES).', boottarget => 'The name of the boottarget definition. When this attribute is set, xCAT will use the kernel, initrd and kernel params defined in the boottarget definition instead of the default.', - addkcmdline=> 'User specified arguments to be passed to the kernel. The user arguments are appended to xCAT.s default kernel arguments. This attribute is ignored if linuximage.boottarget is set.', + addkcmdline=> 'User specified arguments to be passed to the kernel. The user arguments are appended to xCAT.s default kernel arguments. For the kernel options need to be persistent after installation, specify them with prefix "P::". This attribute is ignored if linuximage.boottarget is set.', pkglist => 'The fully qualified name of the file that stores the distro packages list that will be included in the image. Make sure that if the pkgs in the pkglist have dependency pkgs, the dependency pkgs should be found in one of the pkgdir', pkgdir => 'The name of the directory where the distro packages are stored. It could be set multiple paths.The multiple paths must be seperated by ",". The first path in the value of osimage.pkgdir must be the OS base pkg dir path, such as pkgdir=/install/rhels6.2/x86_64,/install/updates . In the os base pkg path, there are default repository data. And in the other pkg path(s), the users should make sure there are repository data. If not, use "createrepo" command to create them. For ubuntu, multiple mirrors can be specified in the pkgdir attribute, the mirrors must be prefixed by the protocol(http/ssh) and delimited with "," between each other.', otherpkglist => 'The fully qualified name of the file that stores non-distro package lists that will be included in the image. It could be set multiple paths.The multiple paths must be seperated by ",".', diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index 4a65d713e..b71b956a6 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -4505,5 +4505,32 @@ sub parseMacTabEntry{ return $mac_ret; } +#The splitkcmdline subroutine is used to split the "persistent kernel options" +#and "provision-time kernel options" out of the kernel cmdline string +#Arguments: +# $kcmdline: the native kernel cmdline string +#Return value: +# a reference of hash with the following KEY-VALUE def: +# "persistent" ==> string of persistent kernel options,delimited with space " " +# "volatile" ==> string of provision-time kernel options,delimited with space " " +sub splitkcmdline{ + my $kcmdline=shift; + if( $kcmdline =~ /xCAT::Utils/) { + $kcmdline=shift; + } + my %cmdhash; + + my @cmdlist=split(/[, ]/,$kcmdline); + foreach my $cmd (@cmdlist){ + if($cmd =~ /^P::(.*)$/){ + $cmdhash{persistent}.="$1 "; + }else{ + $cmdhash{volatile}.="$cmd "; + } + + } + + return \%cmdhash; +} 1; diff --git a/xCAT-server/lib/perl/xCAT/Template.pm b/xCAT-server/lib/perl/xCAT/Template.pm index 404f531cb..f8b4d88bf 100644 --- a/xCAT-server/lib/perl/xCAT/Template.pm +++ b/xCAT-server/lib/perl/xCAT/Template.pm @@ -104,7 +104,7 @@ sub subvars { $ENV{NODESTATUS}=$tmp; } - + $ENV{PERSKCMDLINE}=getPersistentKcmdline($node); #replace the env with the right value so that correct include files can be found $inc =~ s/#ENV:([^#]+)#/envvar($1)/eg; @@ -250,6 +250,7 @@ sub subvars { $inc =~ s/#KICKSTARTNET#/kickstartnetwork()/eg; $inc =~ s/#MIRRORSPEC#/mirrorspec()/eg; $inc =~ s/#YAST2NET#/yast2network()/eg; + $inc =~ s/#KICKSTARTBOOTLOADER#/kickstartbootloader()/eg; $inc =~ s/#ESXIPV6SETUP#/esxipv6setup()/eg; $inc =~ s/#WINTIMEZONE#/xCAT::TZUtils::get_wintimezone()/eg; $inc =~ s/#WINPRODKEY:([^#]+)#/get_win_prodkey($1)/eg; @@ -662,6 +663,66 @@ sub get_node_domain { } + +#get persistent command options from node and osimage definition +sub getPersistentKcmdline { + my $lcnode=shift; + if ( $lcnode eq 'THISNODE' ){ + $lcnode=$node; + } + + my @nodes=($lcnode); + + my $bptab=xCAT::Table->new('bootparams',-create=>1); + my $bphash = $bptab->getNodesAttribs(\@nodes,['addkcmdline']); + + my $typetab=xCAT::Table->new('nodetype',-create=>1); + my $typehash=$typetab->getNodesAttribs(\@nodes,['provmethod']); + my $linuximgtab=xCAT::Table->new('linuximage',-create=>1); + + my $ent = $typehash->{$lcnode}->[0]; + my $osimgname = $ent->{'provmethod'}; + + my $linuximghash = $linuximgtab->getAttribs({imagename => $osimgname}, 'boottarget', 'addkcmdline'); + my $kern = $bphash->{$lcnode}->[0]; + + my $addkcmdline; + if ($kern->{addkcmdline}) { + $addkcmdline .= $kern->{addkcmdline}." "; + } + + if($linuximghash and $linuximghash->{'addkcmdline'}) + { + unless($linuximghash->{'boottarget'}) + { + $addkcmdline .= $linuximghash->{'addkcmdline'}." "; + } + } + + my $cmdhashref; + if($addkcmdline){ + $cmdhashref=xCAT::Utils->splitkcmdline($addkcmdline); + } + + my $ret=""; + if($cmdhashref and $cmdhashref->{persistent}) + { + $ret=$cmdhashref->{persistent}; + } + + return $ret; +} + + +sub kickstartbootloader { + my $line="bootloader"; + if($ENV{PERSKCMDLINE}){ + $line.=" --append=\"".$ENV{PERSKCMDLINE}."\""; + } + return $line; +} + + sub esxipv6setup { if (not $::XCATSITEVALS{managedaddressmode} or $::XCATSITEVALS{managedaddressmode} =~ /v4/) { return ""; } # blank line for ipv4 schemes my $v6addr; diff --git a/xCAT-server/lib/xcat/plugins/grub2.pm b/xCAT-server/lib/xcat/plugins/grub2.pm index 57f91500e..1b75a24a0 100644 --- a/xCAT-server/lib/xcat/plugins/grub2.pm +++ b/xCAT-server/lib/xcat/plugins/grub2.pm @@ -132,17 +132,29 @@ sub setstate { $kern->{kcmdline} =~ s/!myipfn!/$ipfn/g; } } + + my $addkcmdline; if ($kern->{addkcmdline}) { - $kern->{kcmdline} .= " ".$kern->{addkcmdline}; + $addkcmdline .= $kern->{addkcmdline}." "; } if($linuximghash and $linuximghash->{'addkcmdline'}) { unless($linuximghash->{'boottarget'}) { - $kern->{kcmdline} .= " ".$linuximghash->{'addkcmdline'}; + $addkcmdline .= $linuximghash->{'addkcmdline'}." "; } } + + my $cmdhashref; + if($addkcmdline){ + $cmdhashref=xCAT::Utils->splitkcmdline($addkcmdline); + } + + if($cmdhashref and $cmdhashref->{volatile}) + { + $kern->{kcmdline}.=" ".$cmdhashref->{volatile}; + } my $pcfg; unless (-d "$tftpdir/boot/grub2") { diff --git a/xCAT-server/lib/xcat/plugins/pxe.pm b/xCAT-server/lib/xcat/plugins/pxe.pm index 6a804d220..bdeb8034f 100644 --- a/xCAT-server/lib/xcat/plugins/pxe.pm +++ b/xCAT-server/lib/xcat/plugins/pxe.pm @@ -108,6 +108,16 @@ sub setstate { my $kcmdlinehack = ($imgaddkcmdline)?$kern->{addkcmdline}." ".$imgaddkcmdline : $kern->{addkcmdline}; + my $cmdhashref; + if($kcmdlinehack){ + $cmdhashref=xCAT::Utils->splitkcmdline($kcmdlinehack); + } + + if($cmdhashref and $cmdhashref->{volatile}) + { + $kcmdlinehack=$cmdhashref->{volatile}; + } + while ($kcmdlinehack =~ /#NODEATTRIB:([^:#]+):([^:#]+)#/) { my $natab = xCAT::Table->new($1); diff --git a/xCAT-server/lib/xcat/plugins/xnba.pm b/xCAT-server/lib/xcat/plugins/xnba.pm index aee9ba9e1..8ed6da148 100644 --- a/xCAT-server/lib/xcat/plugins/xnba.pm +++ b/xCAT-server/lib/xcat/plugins/xnba.pm @@ -119,6 +119,17 @@ sub setstate { my $kcmdlinehack = ($imgaddkcmdline)?$kern->{addkcmdline}." ".$imgaddkcmdline : $kern->{addkcmdline}; + my $cmdhashref; + if($kcmdlinehack){ + $cmdhashref=xCAT::Utils->splitkcmdline($kcmdlinehack); + } + + if($cmdhashref and $cmdhashref->{volatile}) + { + $kcmdlinehack=$cmdhashref->{volatile}; + } + + while ($kcmdlinehack =~ /#NODEATTRIB:([^:#]+):([^:#]+)#/) { my $natab = xCAT::Table->new($1); my $naent = $natab->getNodeAttribs($node,[$2]); diff --git a/xCAT-server/lib/xcat/plugins/yaboot.pm b/xCAT-server/lib/xcat/plugins/yaboot.pm index 381e6a8bb..91321c6fb 100644 --- a/xCAT-server/lib/xcat/plugins/yaboot.pm +++ b/xCAT-server/lib/xcat/plugins/yaboot.pm @@ -127,18 +127,32 @@ sub setstate { $kern->{kcmdline} =~ s/!myipfn!/$ipfn/g; } } + + + my $addkcmdline; if ($kern->{addkcmdline}) { - $kern->{kcmdline} .= " ".$kern->{addkcmdline}; + $addkcmdline .= $kern->{addkcmdline}." "; } - + if($linuximghash and $linuximghash->{'addkcmdline'}) { - unless($linuximghash->{'boottarget'}) + unless($linuximghash->{'boottarget'}) { - $kern->{kcmdline} .= " ".$linuximghash->{'addkcmdline'}; - } + $addkcmdline .= $linuximghash->{'addkcmdline'}." "; + } } - + + + my $cmdhashref; + if($addkcmdline){ + $cmdhashref=xCAT::Utils->splitkcmdline($addkcmdline); + } + + if($cmdhashref and $cmdhashref->{volatile}) + { + $kern->{kcmdline}.=" ".$cmdhashref->{volatile}; + } + my $pcfg; unless (-d "$tftpdir/etc") { diff --git a/xCAT-server/share/xcat/install/rh/compute.rhels6.tmpl b/xCAT-server/share/xcat/install/rh/compute.rhels6.tmpl index 5adfce92d..3d9ec8f2a 100644 --- a/xCAT-server/share/xcat/install/rh/compute.rhels6.tmpl +++ b/xCAT-server/share/xcat/install/rh/compute.rhels6.tmpl @@ -75,7 +75,7 @@ key --skip # --useLilo # --md5pass # -bootloader +#KICKSTARTBOOTLOADER# # # install or upgrade diff --git a/xCAT-server/share/xcat/install/rh/compute.rhels7.tmpl b/xCAT-server/share/xcat/install/rh/compute.rhels7.tmpl index b1ac4c9b8..0f69955bd 100644 --- a/xCAT-server/share/xcat/install/rh/compute.rhels7.tmpl +++ b/xCAT-server/share/xcat/install/rh/compute.rhels7.tmpl @@ -76,7 +76,8 @@ clearpart --all --initlabel # --useLilo # --md5pass # -bootloader +#KICKSTARTBOOTLOADER# + # # install or upgrade diff --git a/xCAT-server/share/xcat/install/rh/service.rhels6.ppc64.tmpl b/xCAT-server/share/xcat/install/rh/service.rhels6.ppc64.tmpl index 6407a664f..7fa82fbeb 100644 --- a/xCAT-server/share/xcat/install/rh/service.rhels6.ppc64.tmpl +++ b/xCAT-server/share/xcat/install/rh/service.rhels6.ppc64.tmpl @@ -78,8 +78,7 @@ part / --size 1 --grow --fstype ext4 --ondisk sda # --useLilo # --md5pass # -bootloader - +#KICKSTARTBOOTLOADER# # # install or upgrade # diff --git a/xCAT-server/share/xcat/install/rh/service.rhels6.x86_64.tmpl b/xCAT-server/share/xcat/install/rh/service.rhels6.x86_64.tmpl index 9f0fddf60..4ccebc3f4 100644 --- a/xCAT-server/share/xcat/install/rh/service.rhels6.x86_64.tmpl +++ b/xCAT-server/share/xcat/install/rh/service.rhels6.x86_64.tmpl @@ -74,8 +74,7 @@ key --skip # --useLilo # --md5pass # -bootloader - +#KICKSTARTBOOTLOADER# # # install or upgrade # diff --git a/xCAT-server/share/xcat/install/rh/service.rhels7.tmpl b/xCAT-server/share/xcat/install/rh/service.rhels7.tmpl index b1ac4c9b8..9e6e91652 100644 --- a/xCAT-server/share/xcat/install/rh/service.rhels7.tmpl +++ b/xCAT-server/share/xcat/install/rh/service.rhels7.tmpl @@ -76,8 +76,7 @@ clearpart --all --initlabel # --useLilo # --md5pass # -bootloader - +#KICKSTARTBOOTLOADER# # # install or upgrade # diff --git a/xCAT-server/share/xcat/install/sles/compute.sles11.tmpl b/xCAT-server/share/xcat/install/sles/compute.sles11.tmpl index b343a4fbe..657ff8d45 100644 --- a/xCAT-server/share/xcat/install/sles/compute.sles11.tmpl +++ b/xCAT-server/share/xcat/install/sles/compute.sles11.tmpl @@ -5,7 +5,7 @@ true true - + #XCATVAR:PERSKCMDLINE# false false mbr diff --git a/xCAT-server/share/xcat/install/sles/compute.sles12.ppc64le.tmpl b/xCAT-server/share/xcat/install/sles/compute.sles12.ppc64le.tmpl index 71f55dbdc..f7cc1ecff 100644 --- a/xCAT-server/share/xcat/install/sles/compute.sles12.ppc64le.tmpl +++ b/xCAT-server/share/xcat/install/sles/compute.sles12.ppc64le.tmpl @@ -5,7 +5,7 @@ true true - + #XCATVAR:PERSKCMDLINE# false false mbr diff --git a/xCAT-server/share/xcat/install/sles/compute.sles12.tmpl b/xCAT-server/share/xcat/install/sles/compute.sles12.tmpl index 53e0e7df4..e499336aa 100644 --- a/xCAT-server/share/xcat/install/sles/compute.sles12.tmpl +++ b/xCAT-server/share/xcat/install/sles/compute.sles12.tmpl @@ -5,7 +5,7 @@ true true - + #XCATVAR:PERSKCMDLINE# false false mbr diff --git a/xCAT-server/share/xcat/install/sles/service.sles11.tmpl b/xCAT-server/share/xcat/install/sles/service.sles11.tmpl index 21df8ef8f..e2f44d75c 100644 --- a/xCAT-server/share/xcat/install/sles/service.sles11.tmpl +++ b/xCAT-server/share/xcat/install/sles/service.sles11.tmpl @@ -5,7 +5,7 @@ true true - + #XCATVAR:PERSKCMDLINE# false false mbr diff --git a/xCAT-server/share/xcat/install/ubuntu/compute.tmpl b/xCAT-server/share/xcat/install/ubuntu/compute.tmpl index a0d3fa0cc..285890e51 100644 --- a/xCAT-server/share/xcat/install/ubuntu/compute.tmpl +++ b/xCAT-server/share/xcat/install/ubuntu/compute.tmpl @@ -24,6 +24,11 @@ d-i netcfg/dhcp_timeout string 120 #d-i mirror/udeb/suite string testing +# Use the following option to add additional boot parameters for the +# installed system (if supported by the bootloader installer). +# Note: options passed to the installer will be added automatically. +d-i debian-installer/add-kernel-opts string #XCATVAR:PERSKCMDLINE# + ### Partitioning # This creates a small /boot partition, suitable # swap, and uses the rest of the space for the root partition: diff --git a/xCAT-server/share/xcat/install/ubuntu/service.tmpl b/xCAT-server/share/xcat/install/ubuntu/service.tmpl index ec6ef2d77..7690cd96c 100644 --- a/xCAT-server/share/xcat/install/ubuntu/service.tmpl +++ b/xCAT-server/share/xcat/install/ubuntu/service.tmpl @@ -22,7 +22,11 @@ d-i netcfg/dhcp_timeout string 120 #d-i mirror/suite string testing # Suite to use for loading installer components (optional). #d-i mirror/udeb/suite string testing - + +# Use the following option to add additional boot parameters for the +# installed system (if supported by the bootloader installer). +# Note: options passed to the installer will be added automatically. +d-i debian-installer/add-kernel-opts string #XCATVAR:PERSKCMDLINE# ### Partitioning # This creates a small /boot partition, suitable