2007-10-26 22:44:33 +00:00
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
2008-04-03 13:27:16 +00:00
package xCAT_plugin::anaconda ;
2008-09-12 22:40:15 +00:00
BEGIN
{
$ ::XCATROOT = $ ENV { 'XCATROOT' } ? $ ENV { 'XCATROOT' } : '/opt/xcat' ;
}
use lib "$::XCATROOT/lib/perl" ;
2007-10-26 22:44:33 +00:00
use Storable qw( dclone ) ;
use Sys::Syslog ;
2008-04-21 18:31:27 +00:00
use Thread qw( yield ) ;
use POSIX qw( WNOHANG nice ) ;
2007-10-26 22:44:33 +00:00
use xCAT::Table ;
2008-04-03 13:27:16 +00:00
use xCAT::Utils ;
2010-05-10 06:36:43 +00:00
use xCAT::NetworkUtils ;
2008-04-03 13:27:16 +00:00
use xCAT::MsgUtils ;
2009-09-19 17:03:14 +00:00
use xCAT::SvrUtils ;
2009-09-18 19:53:48 +00:00
#use Data::Dumper;
2007-10-26 22:44:33 +00:00
use Getopt::Long ;
Getopt::Long:: Configure ( "bundling" ) ;
Getopt::Long:: Configure ( "pass_through" ) ;
use File::Path ;
use File::Copy ;
2010-08-23 08:00:51 +00:00
use File::Temp qw/mkdtemp/ ;
2010-04-02 09:19:02 +00:00
use Socket ;
2009-09-23 01:34:03 +00:00
#use strict;
2008-06-02 23:58:15 +00:00
my @ cpiopid ;
2007-10-26 22:44:33 +00:00
my % distnames = (
2011-07-12 20:18:36 +00:00
"1310229985.226287" = > "centos6" ,
2008-05-05 19:34:58 +00:00
"1176234647.982657" = > "centos5" ,
"1156364963.862322" = > "centos4.4" ,
"1178480581.024704" = > "centos4.5" ,
"1195929648.203590" = > "centos5.1" ,
"1195929637.060433" = > "centos5.1" ,
2008-06-26 19:12:56 +00:00
"1213888991.267240" = > "centos5.2" ,
"1214240246.285059" = > "centos5.2" ,
2009-04-01 15:02:33 +00:00
"1237641529.260981" = > "centos5.3" ,
2010-05-16 14:31:49 +00:00
"1272326751.405938" = > "centos5.5" ,
2008-05-05 19:34:58 +00:00
"1195488871.805863" = > "centos4.6" ,
"1195487524.127458" = > "centos4.6" ,
2011-07-28 10:21:12 +00:00
"1301444731.448392" = > "centos5.6" ,
2008-05-05 19:34:58 +00:00
"1170973598.629055" = > "rhelc5" ,
"1170978545.752040" = > "rhels5" ,
"1192660014.052098" = > "rhels5.1" ,
"1192663619.181374" = > "rhels5.1" ,
2008-05-22 19:23:24 +00:00
"1209608466.515430" = > "rhels5.2" ,
"1209603563.756628" = > "rhels5.2" ,
"1209597827.293308" = > "rhels5.2" ,
2009-08-07 07:24:58 +00:00
"1231287803.932941" = > "rhels5.3" ,
"1231285121.960246" = > "rhels5.3" ,
2009-09-10 14:34:08 +00:00
"1250668122.507797" = > "rhels5.4" , #x86-64
"1250663123.136977" = > "rhels5.4" , #x86
"1250666120.105861" = > "rhels5.4" , #ppc
2010-03-30 11:13:15 +00:00
"1269262918.904535" = > "rhels5.5" , #ppc
2010-03-30 11:24:24 +00:00
"1269260915.992102" = > "rhels5.5" , #i386
"1269263646.691048" = > "rhels5.5" , #x86_64
2010-11-03 15:11:56 +00:00
"1285193176.460470" = > "rhels6" , #x86_64
2010-11-30 06:22:51 +00:00
"1285192093.430930" = > "rhels6" , #ppc64
2011-07-12 11:54:35 +00:00
"1305068199.328169" = > "rhels6.1" , #x86_64
"1305067911.467189" = > "rhels6.1" , #ppc64
2010-11-11 15:06:22 +00:00
"1285193176.593806" = > "rhelhpc6" ,
2008-05-05 19:34:58 +00:00
"1194015916.783841" = > "fedora8" ,
2008-05-15 17:30:13 +00:00
"1194015385.299901" = > "fedora8" ,
"1210112435.291709" = > "fedora9" ,
"1210111941.792844" = > "fedora9" ,
2009-02-09 17:17:55 +00:00
"1227147467.285093" = > "fedora10" ,
"1227142402.812888" = > "fedora10" ,
2010-06-28 13:46:51 +00:00
"1243981097.897160" = > "fedora11" , #x86_64 DVD ISO
"1257725234.740991" = > "fedora12" , #x86_64 DVD ISO
"1273712675.937554" = > "fedora13" , #x86_64 DVD ISO
2010-12-17 17:52:53 +00:00
"1287685820.403779" = > "fedora14" , #x86_64 DVD ISO
2011-09-21 06:47:20 +00:00
"1305315870.828212" = > "fedora15" , #x86_64 DVD ISO
2009-12-17 21:40:14 +00:00
2008-05-05 19:34:58 +00:00
"1194512200.047708" = > "rhas4.6" ,
"1194512327.501046" = > "rhas4.6" ,
2010-03-15 02:43:17 +00:00
"1241464993.830723" = > "rhas4.8" , #x86-64
2010-06-28 13:46:51 +00:00
"1273608367.051780" = > "SL5.5" , #x86_64 DVD ISO
2011-06-27 08:22:26 +00:00
"1299104542.844706" = > "SL6" , #x86_64 DVD ISO
2008-05-05 19:34:58 +00:00
) ;
2007-10-26 22:44:33 +00:00
my % numdiscs = (
2008-05-05 19:34:58 +00:00
"1156364963.862322" = > 4 ,
"1178480581.024704" = > 3
) ;
sub handled_commands
{
return {
copycd = > "anaconda" ,
2010-06-28 13:46:51 +00:00
mknetboot = > "nodetype:os=(centos.*)|(rh.*)|(fedora.*)|(SL.*)" ,
2010-07-30 21:43:51 +00:00
mkinstall = > "nodetype:os=(esxi4.1)|(esx[34].*)|(centos.*)|(rh.*)|(fedora.*)|(SL.*)" ,
2010-06-28 13:46:51 +00:00
mkstatelite = > "nodetype:os=(esx[34].*)|(centos.*)|(rh.*)|(fedora.*)|(SL.*)" ,
2009-12-04 00:59:24 +00:00
2008-05-05 19:34:58 +00:00
} ;
2007-10-26 22:44:33 +00:00
}
2008-05-05 19:34:58 +00:00
2008-04-03 13:27:16 +00:00
sub preprocess_request
{
2008-05-05 19:34:58 +00:00
my $ req = shift ;
my $ callback = shift ;
2009-04-22 23:05:47 +00:00
return [ $ req ] ; #calls are only made from pre-farmed out scenarios
2008-05-05 19:34:58 +00:00
if ( $ req - > { command } - > [ 0 ] eq 'copycd' )
{ #don't farm out copycd
return [ $ req ] ;
}
2008-05-06 14:39:57 +00:00
my $ stab = xCAT::Table - > new ( 'site' ) ;
my $ sent ;
( $ sent ) = $ stab - > getAttribs ( { key = > 'sharedtftp' } , 'value' ) ;
unless ( $ sent
and defined ( $ sent - > { value } )
and ( $ sent - > { value } =~ /no/i or $ sent - > { value } =~ /0/ ) )
{
#unless requesting no sharedtftp, don't make hierarchical call
return [ $ req ] ;
}
2008-05-05 19:34:58 +00:00
my % localnodehash ;
2008-05-06 14:39:57 +00:00
my % dispatchhash ;
my $ nrtab = xCAT::Table - > new ( 'noderes' ) ;
2008-07-11 19:02:39 +00:00
my $ nrents = $ nrtab - > getNodesAttribs ( $ req - > { node } , [ qw( tftpserver servicenode ) ] ) ;
2008-05-05 19:34:58 +00:00
foreach my $ node ( @ { $ req - > { node } } )
{
2008-05-06 14:39:57 +00:00
my $ nodeserver ;
2008-07-11 19:02:39 +00:00
my $ tent = $ nrents - > { $ node } - > [ 0 ] ; #$nrtab->getNodeAttribs($node, ['tftpserver']);
2008-05-06 14:39:57 +00:00
if ( $ tent ) { $ nodeserver = $ tent - > { tftpserver } }
unless ( $ tent and $ tent - > { tftpserver } )
{
2008-07-11 19:02:39 +00:00
$ tent = $ nrents - > { $ node } - > [ 0 ] ; #$nrtab->getNodeAttribs($node, ['servicenode']);
2008-05-06 14:39:57 +00:00
if ( $ tent ) { $ nodeserver = $ tent - > { servicenode } }
}
if ( $ nodeserver )
{
$ dispatchhash { $ nodeserver } - > { $ node } = 1 ;
}
else
{
$ localnodehash { $ node } = 1 ;
}
2008-05-05 19:34:58 +00:00
}
my @ requests ;
my $ reqc = { %$ req } ;
$ reqc - > { node } = [ keys % localnodehash ] ;
if ( scalar ( @ { $ reqc - > { node } } ) ) { push @ requests , $ reqc }
2008-05-06 14:39:57 +00:00
foreach my $ dtarg ( keys % dispatchhash )
{ #iterate dispatch targets
my $ reqcopy = { %$ req } ; #deep copy
$ reqcopy - > { '_xcatdest' } = $ dtarg ;
$ reqcopy - > { node } = [ keys % { $ dispatchhash { $ dtarg } } ] ;
push @ requests , $ reqcopy ;
}
2008-05-05 19:34:58 +00:00
return \ @ requests ;
2008-04-03 13:27:16 +00:00
}
2008-05-05 19:34:58 +00:00
sub process_request
{
my $ request = shift ;
my $ callback = shift ;
my $ doreq = shift ;
my $ distname = undef ;
my $ arch = undef ;
my $ path = undef ;
if ( $ request - > { command } - > [ 0 ] eq 'copycd' )
{
return copycd ( $ request , $ callback , $ doreq ) ;
}
elsif ( $ request - > { command } - > [ 0 ] eq 'mkinstall' )
{
return mkinstall ( $ request , $ callback , $ doreq ) ;
}
2009-12-04 00:59:24 +00:00
elsif ( $ request - > { command } - > [ 0 ] eq 'mknetboot' or
$ request - > { command } - > [ 0 ] eq 'mkstatelite' )
2008-05-05 19:34:58 +00:00
{
return mknetboot ( $ request , $ callback , $ doreq ) ;
}
2007-10-26 22:44:33 +00:00
}
2011-09-21 06:47:20 +00:00
# Check whether the dracut is supported by this os
sub using_dracut
{
my $ os = shift ;
if ( $ os =~ /(rhels|rhel)(\d+)/ ) {
if ( $ 2 >= 6 ) {
return 1 ;
}
} elsif ( $ os =~ /fedora(\d+)/ ) {
if ( $ 1 >= 12 ) {
return 1 ;
}
} elsif ( $ os =~ /SL(\d+)/ ) {
if ( $ 1 >= 6 ) {
return 1 ;
}
}
return 0 ;
}
2008-05-05 19:34:58 +00:00
sub mknetboot
{
2009-02-21 14:25:29 +00:00
my $ xenstyle = 0 ;
2008-05-05 19:34:58 +00:00
my $ req = shift ;
2007-11-05 22:12:39 +00:00
my $ callback = shift ;
2008-05-05 19:34:58 +00:00
my $ doreq = shift ;
2009-12-04 00:59:24 +00:00
my $ statelite = 0 ;
if ( $ req - > { command } - > [ 0 ] =~ 'mkstatelite' ) {
$ statelite = "true" ;
}
2008-05-05 19:34:58 +00:00
my $ tftpdir = "/tftpboot" ;
2009-09-23 01:34:03 +00:00
my $ nodes = @ { $ req - > { node } } ;
2008-05-05 19:34:58 +00:00
my @ args = @ { $ req - > { arg } } ;
my @ nodes = @ { $ req - > { node } } ;
my $ ostab = xCAT::Table - > new ( 'nodetype' ) ;
my $ sitetab = xCAT::Table - > new ( 'site' ) ;
2009-09-23 01:34:03 +00:00
my $ linuximagetab ;
my $ osimagetab ;
my % img_hash = ( ) ;
2008-04-03 13:27:16 +00:00
my $ installroot ;
$ installroot = "/install" ;
2009-12-15 20:37:40 +00:00
my $ xcatdport = "3001" ;
2008-04-14 13:32:45 +00:00
2008-05-05 19:34:58 +00:00
if ( $ sitetab )
{
2009-09-23 01:34:03 +00:00
( my $ ref ) = $ sitetab - > getAttribs ( { key = > 'installdir' } , 'value' ) ;
2008-05-05 19:34:58 +00:00
if ( $ ref and $ ref - > { value } )
{
2007-11-05 22:12:39 +00:00
$ installroot = $ ref - > { value } ;
}
2009-12-15 20:37:40 +00:00
( $ ref ) = $ sitetab - > getAttribs ( { key = > 'xcatdport' } , 'value' ) ;
if ( $ ref and $ ref - > { value } )
{
$ xcatdport = $ ref - > { value } ;
}
2010-08-17 08:56:31 +00:00
( $ ref ) = $ sitetab - > getAttribs ( { key = > 'tftpdir' } , 'value' ) ;
if ( $ ref and $ ref - > { value } )
{
$ tftpdir = $ ref - > { value } ;
}
2007-11-05 22:12:39 +00:00
}
2008-05-13 23:40:05 +00:00
my % donetftp = ( ) ;
2009-09-23 01:34:03 +00:00
my % oents = % { $ ostab - > getNodesAttribs ( \ @ nodes , [ qw( os arch profile provmethod ) ] ) } ;
2008-07-11 19:02:39 +00:00
my $ restab = xCAT::Table - > new ( 'noderes' ) ;
my $ bptab = xCAT::Table - > new ( 'bootparams' , - create = > 1 ) ;
my $ hmtab = xCAT::Table - > new ( 'nodehm' ) ;
2010-09-17 09:54:47 +00:00
my $ mactab = xCAT::Table - > new ( 'mac' ) ;
my $ machash = $ mactab - > getNodesAttribs ( \ @ nodes , [ 'interface' , 'mac' ] ) ;
2010-12-15 08:49:55 +00:00
my $ reshash = $ restab - > getNodesAttribs ( \ @ nodes , [ 'primarynic' , 'tftpserver' , 'xcatmaster' , 'nfsserver' , 'nfsdir' , 'installnic' ] ) ;
2008-07-11 19:02:39 +00:00
my $ hmhash =
$ hmtab - > getNodesAttribs ( \ @ nodes ,
[ 'serialport' , 'serialspeed' , 'serialflow' ] ) ;
2009-12-15 20:37:40 +00:00
my $ statetab ;
my $ stateHash ;
if ( $ statelite ) {
$ statetab = xCAT::Table - > new ( 'statelite' , - create = > 1 ) ;
2010-04-22 18:04:08 +00:00
$ stateHash = $ statetab - > getNodesAttribs ( \ @ nodes , [ 'statemnt' ] ) ;
2009-12-15 20:37:40 +00:00
}
2009-06-29 18:41:00 +00:00
#my $addkcmdhash =
# $bptab->getNodesAttribs(\@nodes, ['addkcmdline']);
2009-09-23 01:34:03 +00:00
foreach my $ node ( @ nodes )
2008-05-05 19:34:58 +00:00
{
2009-09-23 01:34:03 +00:00
my $ osver ;
my $ arch ;
my $ profile ;
2010-09-17 09:54:47 +00:00
my $ platform ;
2009-09-23 01:34:03 +00:00
my $ rootimgdir ;
2010-09-17 09:54:47 +00:00
my $ nodebootif ; # nodebootif will be used if noderes.installnic is not set
2010-12-14 07:15:45 +00:00
my $ dump ; # for kdump, its format is "nfs://<nfs_server_ip>/<kdump_path>"
2011-06-27 08:22:26 +00:00
my $ crashkernelsize ;
2011-01-06 06:54:06 +00:00
my $ rootfstype ;
2009-09-23 01:34:03 +00:00
2008-07-11 14:12:05 +00:00
my $ ent = $ oents { $ node } - > [ 0 ] ; #ostab->getNodeAttribs($node, ['os', 'arch', 'profile']);
2009-12-04 00:59:24 +00:00
if ( $ ent and $ ent - > { provmethod } and ( $ ent - > { provmethod } ne 'install' ) and ( $ ent - > { provmethod } ne 'netboot' ) and ( $ ent - > { provmethod } ne 'statelite' ) ) {
2010-09-17 09:54:47 +00:00
my $ imagename = $ ent - > { provmethod } ;
#print "imagename=$imagename\n";
if ( ! exists ( $ img_hash { $ imagename } ) ) {
if ( ! $ osimagetab ) {
$ osimagetab = xCAT::Table - > new ( 'osimage' , - create = > 1 ) ;
}
2011-01-06 06:54:06 +00:00
( my $ ref ) = $ osimagetab - > getAttribs ( { imagename = > $ imagename } , 'osvers' , 'osarch' , 'profile' , 'provmethod' , 'rootfstype' ) ;
2010-09-17 09:54:47 +00:00
if ( $ ref ) {
$ img_hash { $ imagename } - > { osver } = $ ref - > { 'osvers' } ;
$ img_hash { $ imagename } - > { osarch } = $ ref - > { 'osarch' } ;
$ img_hash { $ imagename } - > { profile } = $ ref - > { 'profile' } ;
$ img_hash { $ imagename } - > { provmethod } = $ ref - > { 'provmethod' } ;
2011-01-06 06:54:06 +00:00
$ img_hash { $ imagename } - > { rootfstype } = $ ref - > { rootfstype } ;
2010-09-17 09:54:47 +00:00
if ( ! $ linuximagetab ) {
$ linuximagetab = xCAT::Table - > new ( 'linuximage' , - create = > 1 ) ;
}
2011-06-27 08:22:26 +00:00
( my $ ref1 ) = $ linuximagetab - > getAttribs ( { imagename = > $ imagename } , 'rootimgdir' , 'nodebootif' , 'dump' , 'crashkernelsize' ) ;
2010-09-17 09:54:47 +00:00
if ( ( $ ref1 ) && ( $ ref1 - > { 'rootimgdir' } ) ) {
$ img_hash { $ imagename } - > { rootimgdir } = $ ref1 - > { 'rootimgdir' } ;
}
if ( ( $ ref1 ) && ( $ ref1 - > { 'nodebootif' } ) ) {
$ img_hash { $ imagename } - > { nodebootif } = $ ref1 - > { 'nodebootif' } ;
}
2010-12-14 07:15:45 +00:00
if ( $ ref1 ) {
if ( $ ref1 - > { 'dump' } ) {
$ img_hash { $ imagename } - > { dump } = $ ref1 - > { 'dump' } ;
}
}
2011-06-27 08:22:26 +00:00
if ( ( $ ref1 ) && ( $ ref1 - > { 'crashkernelsize' } ) ) {
$ img_hash { $ imagename } - > { crashkernelsize } = $ ref1 - > { 'crashkernelsize' } ;
}
2010-09-17 09:54:47 +00:00
} else {
$ callback - > (
{ error = > [ "The os image $imagename does not exists on the osimage table for $node" ] ,
errorcode = > [ 1 ] } ) ;
next ;
}
}
my $ ph = $ img_hash { $ imagename } ;
2010-12-14 07:15:45 +00:00
2010-09-17 09:54:47 +00:00
$ osver = $ ph - > { osver } ;
$ arch = $ ph - > { osarch } ;
$ profile = $ ph - > { profile } ;
2010-12-14 07:15:45 +00:00
2011-01-06 06:54:06 +00:00
$ rootfstype = $ ph - > { rootfstype } ;
2010-09-17 09:54:47 +00:00
$ rootimgdir = $ ph - > { rootimgdir } ;
unless ( $ rootimgdir ) {
$ rootimgdir = "$installroot/netboot/$osver/$arch/$profile" ;
}
$ nodebootif = $ ph - > { nodebootif } ;
2011-06-27 08:22:26 +00:00
$ crashkernelsize = $ ph - > { crashkernelsize } ;
2010-12-14 07:15:45 +00:00
$ dump = $ ph - > { dump } ;
2009-09-23 01:34:03 +00:00
}
2010-09-17 09:54:47 +00:00
else {
$ osver = $ ent - > { os } ;
$ arch = $ ent - > { arch } ;
$ profile = $ ent - > { profile } ;
$ rootimgdir = "$installroot/netboot/$osver/$arch/$profile" ;
2011-01-06 06:54:06 +00:00
$ rootfstype = "nfs" ; # TODO: try to get it from the option or table
2011-02-28 07:21:30 +00:00
my $ imgname ;
if ( $ statelite ) {
$ imgname = "$osver-$arch-statelite-$profile" ;
} else {
$ imgname = "$osver-$arch-netboot-$profile" ;
}
2011-05-09 02:45:24 +00:00
if ( ! $ osimagetab ) {
$ osimagetab = xCAT::Table - > new ( 'osimage' ) ;
}
if ( $ osimagetab ) {
my ( $ ref1 ) = $ osimagetab - > getAttribs ( { imagename = > $ imgname } , 'rootfstype' ) ;
if ( ( $ ref1 ) && ( $ ref1 - > { 'rootfstype' } ) ) {
$ rootfstype = $ ref1 - > { 'rootfstype' } ;
}
} else {
$ callback - > (
{ error = > [ qq{ Cannot find the linux image called "$osver-$arch-$provmethod-$profile", maybe you need to use the "nodeset <nr> osimage=<osimage name>" command to set the boot state } ] ,
errorcode = > [ 1 ] }
) ;
}
2011-02-28 07:21:30 +00:00
if ( ! $ linuximagetab ) {
$ linuximagetab = xCAT::Table - > new ( 'linuximage' ) ;
}
if ( $ linuximagetab ) {
2011-06-27 08:22:26 +00:00
( my $ ref1 ) = $ linuximagetab - > getAttribs ( { imagename = > $ imgname } , 'dump' , 'crashkernelsize' ) ;
2011-02-28 07:21:30 +00:00
if ( $ ref1 and $ ref1 - > { 'dump' } ) {
$ dump = $ ref1 - > { 'dump' } ;
}
2011-06-27 08:22:26 +00:00
if ( $ ref1 and $ ref1 - > { 'crashkernelsize' } ) {
$ crashkernelsize = $ ref1 - > { 'crashkernelsize' } ;
}
2011-02-28 07:21:30 +00:00
} else {
$ callback - > (
{ error = > [ qq{ Cannot find the linux image called "$osver-$arch-$provmethod-$profile", maybe you need to use the "nodeset <nr> osimage=<your_image_name>" command to set the boot state } ] ,
errorcode = > [ 1 ] }
) ;
}
2010-09-17 09:54:47 +00:00
}
2009-09-23 01:34:03 +00:00
#print"osvr=$osver, arch=$arch, profile=$profile, imgdir=$rootimgdir\n";
unless ( $ osver and $ arch and $ profile )
2008-05-05 19:34:58 +00:00
{
$ callback - > (
{
2009-09-23 01:34:03 +00:00
error = > [ "Insufficient nodetype entry or osimage entry for $node" ] ,
2008-05-05 19:34:58 +00:00
errorcode = > [ 1 ]
}
) ;
2007-11-06 21:28:02 +00:00
next ;
}
2008-04-14 13:32:45 +00:00
2009-09-23 01:34:03 +00:00
$ platform = xCAT_plugin::anaconda:: getplatform ( $ osver ) ;
2008-05-05 19:34:58 +00:00
my $ suffix = 'gz' ;
2010-09-17 09:54:47 +00:00
$ suffix = 'sfs' if ( - r "$rootimgdir/rootimg.sfs" ) ;
# statelite images are not packed.
if ( $ statelite ) {
2010-09-22 15:21:16 +00:00
unless ( - r "$rootimgdir/kernel" ) {
2010-09-17 09:54:47 +00:00
$ callback - > ( {
2010-09-22 15:21:16 +00:00
error = > [ qq{ Did you run "genimage" before running "liteimg"? kernel cannot be found... } ] ,
2010-09-17 09:54:47 +00:00
errorcode = > [ 1 ]
} ) ;
next ;
}
2011-01-06 06:54:06 +00:00
if ( ! - r "$rootimgdir/initrd-statelite.gz" ) {
2010-09-22 15:21:16 +00:00
if ( ! - r "$rootimgdir/initrd.gz" ) {
$ callback - > ( {
error = > [ qq{ Did you run "genimage" before running "liteimg"? initrd.gz or initrd-statelite.gz cannot be found } ] ,
errorcode = > [ 1 ]
2011-01-06 06:54:06 +00:00
} ) ;
2010-09-22 15:21:16 +00:00
next ;
}
2011-01-06 06:54:06 +00:00
else {
copy ( "$rootimgdir/initrd.gz" , "$rootimgdir/initrd-statelite.gz" ) ;
2010-09-22 15:21:16 +00:00
}
2011-01-06 06:54:06 +00:00
}
if ( $ rootfstype eq "ramdisk" and ! - r "$rootimgdir/rootimg-statelite.gz" ) {
$ callback - > ( {
error = > [ qq{ No packed image for platform $osver, architecture $arch and profile $profile, please run "liteimg" to create it. } ] ,
errorcode = > [ 1 ]
} ) ;
next ;
}
2010-09-17 09:54:47 +00:00
} else {
2010-09-22 15:21:16 +00:00
unless ( - r "$rootimgdir/kernel" ) {
2010-09-17 09:54:47 +00:00
$ callback - > ( {
2010-09-22 15:21:16 +00:00
error = > [ qq{ Did you run "genimage" before running "packimage"? kernel cannot be found } ] ,
errorcode = > [ 1 ]
} ) ;
2010-09-17 09:54:47 +00:00
next ;
2011-01-06 06:54:06 +00:00
}
if ( ! - r "$rootimgdir/initrd-stateless.gz" ) {
2010-09-22 15:21:16 +00:00
if ( ! - r "$rootimgdir/initrd.gz" ) {
$ callback - > ( {
error = > [ qq{ Did you run "genimage" before running "packimage"? initrd.gz or initrd-stateless.gz cannot be found } ] ,
errorcode = > [ 1 ]
2011-01-06 06:54:06 +00:00
} ) ;
2010-09-22 15:21:16 +00:00
next ;
}
2011-01-06 06:54:06 +00:00
else {
copy ( "$rootimgdir/initrd.gz" , "$rootimgdir/initrd-stateless.gz" ) ;
2010-09-22 15:21:16 +00:00
}
2010-09-17 09:54:47 +00:00
}
2011-01-06 06:54:06 +00:00
unless ( - r "$rootimgdir/rootimg.gz" or - r "$rootimgdir/rootimg.sfs" ) {
2010-09-17 09:54:47 +00:00
$ callback - > ( {
2010-09-22 15:47:21 +00:00
error = > [ "No packed image for platform $osver, architecture $arch, and profile $profile, please run packimage (e.g. packimage -o $osver -p $profile -a $arch" ] ,
2010-09-17 09:54:47 +00:00
errorcode = > [ 1 ] } ) ;
next ;
}
2007-11-06 21:28:02 +00:00
}
2008-04-14 13:32:45 +00:00
2008-05-05 19:34:58 +00:00
# create the node-specific post scripts
#mkpath "/install/postscripts/";
#xCAT::Postage->writescript($node,"/install/postscripts/".$node, "netboot", $callback);
2008-04-14 13:32:45 +00:00
2008-02-11 20:35:22 +00:00
mkpath ( "/$tftpdir/xcat/netboot/$osver/$arch/$profile/" ) ;
2008-05-05 19:34:58 +00:00
2009-12-04 00:59:24 +00:00
#TODO: only copy if newer...
2008-05-13 23:40:05 +00:00
unless ( $ donetftp { $ osver , $ arch , $ profile } ) {
2010-09-17 09:54:47 +00:00
if ( - f "$rootimgdir/hypervisor" ) {
copy ( "$rootimgdir/hypervisor" , "/$tftpdir/xcat/netboot/$osver/$arch/$profile/" ) ;
$ xenstyle = 1 ;
}
copy ( "$rootimgdir/kernel" , "/$tftpdir/xcat/netboot/$osver/$arch/$profile/" ) ;
if ( $ statelite ) {
2011-03-02 11:05:29 +00:00
if ( $ rootfstype eq "ramdisk" ) {
copy ( "$rootimgdir/initrd-stateless.gz" , "/$tftpdir/xcat/netboot/$osver/$arch/$profile/" ) ;
} else {
copy ( "$rootimgdir/initrd-statelite.gz" , "/$tftpdir/xcat/netboot/$osver/$arch/$profile/" ) ;
}
2010-09-17 09:54:47 +00:00
} else {
copy ( "$rootimgdir/initrd-stateless.gz" , "/$tftpdir/xcat/netboot/$osver/$arch/$profile/" ) ;
}
2009-12-04 00:59:24 +00:00
$ donetftp { $ osver , $ arch , $ profile } = 1 ;
2008-05-13 23:40:05 +00:00
}
2010-09-17 09:54:47 +00:00
if ( $ statelite ) {
2011-03-02 11:05:29 +00:00
my $ initrdloc = "/$tftpdir/xcat/netboot/$osver/$arch/$profile/" ;
if ( $ rootfstype eq "ramdisk" ) {
$ initrdloc . = "initrd-stateless.gz" ;
} else {
$ initrdloc . = "initrd-statelite.gz" ;
}
2010-09-17 09:54:47 +00:00
unless ( - r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/kernel"
2011-03-02 11:05:29 +00:00
and - r $ initrdloc ) {
2010-09-17 09:54:47 +00:00
$ callback - > ( {
error = > [ qq{ copying to /$tftpdir/xcat/netboot/$osver/$arch/$profile failed } ] ,
errorcode = > [ 1 ]
} ) ;
next ;
}
} else {
unless ( - r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/kernel"
and - r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/initrd-stateless.gz" ) {
$ callback - > ( {
error = > [ qq{ copying to /$tftpdir/xcat/netboot/$osver/$arch/$profile failed } ] ,
errorcode = > [ 1 ]
} ) ;
next ;
}
2007-11-06 21:28:02 +00:00
}
2010-09-17 09:54:47 +00:00
2010-05-04 14:24:08 +00:00
$ ent = $ reshash - > { $ node } - > [ 0 ] ; #$restab->getNodeAttribs($node, ['primarynic']);
2008-07-11 19:02:39 +00:00
my $ sent = $ hmhash - > { $ node } - > [ 0 ] ;
# $hmtab->getNodeAttribs($node,
# ['serialport', 'serialspeed', 'serialflow']);
2008-05-05 19:34:58 +00:00
# determine image server, if tftpserver use it, else use xcatmaster
2009-03-12 16:34:54 +00:00
# last resort use self
2008-05-05 19:34:58 +00:00
my $ imgsrv ;
my $ ient ;
2010-03-01 03:18:05 +00:00
my $ xcatmaster ;
2008-07-11 19:02:39 +00:00
$ ient = $ reshash - > { $ node } - > [ 0 ] ; #$restab->getNodeAttribs($node, ['tftpserver']);
2010-03-01 03:18:05 +00:00
if ( $ ient and $ ient - > { xcatmaster } )
{
$ xcatmaster = $ ient - > { xcatmaster } ;
} else {
2010-03-03 14:24:27 +00:00
$ xcatmaster = '!myipfn!' ; #allow service nodes to dynamically nominate themselves as a good contact point, this is of limited use in the event that xcat is not the dhcp/tftp server
2010-03-01 03:18:05 +00:00
}
2008-05-05 19:34:58 +00:00
if ( $ ient and $ ient - > { tftpserver } )
{
$ imgsrv = $ ient - > { tftpserver } ;
}
else
{
2009-09-01 17:50:13 +00:00
$ ient = $ reshash - > { $ node } - > [ 0 ] ; #$restab->getNodeAttribs($node, ['xcatmaster']);
2010-03-01 03:18:05 +00:00
#if ($ient and $ient->{xcatmaster})
#{
# $imgsrv = $ient->{xcatmaster};
#}
#else
#{
2009-03-12 16:34:54 +00:00
# master not correct for service node pools
#$ient = $sitetab->getAttribs({key => master}, value);
#if ($ient and $ient->{value})
#{
# $imgsrv = $ient->{value};
#}
#else
#{
2010-03-01 03:18:05 +00:00
# $imgsrv = '!myipfn!';
2009-03-12 16:34:54 +00:00
#}
2010-03-01 03:18:05 +00:00
#}
$ imgsrv = $ xcatmaster ;
2008-05-05 19:34:58 +00:00
}
unless ( $ imgsrv )
{
$ callback - > (
{
error = > [
"Unable to determine or reasonably guess the image server for $node"
] ,
errorcode = > [ 1 ]
}
) ;
next ;
2008-02-11 20:35:22 +00:00
}
2010-09-17 09:54:47 +00:00
my $ kcmdline ; # add two more arguments: XCAT=xcatmaster:xcatport and ifname=<eth0>:<mac address>
if ( $ statelite ) {
2011-01-06 06:54:06 +00:00
if ( $ rootfstype ne "ramdisk" ) {
# get entry for nfs root if it exists:
# have to get nfssvr and nfsdir from noderes table
my $ nfssrv = $ imgsrv ;
my $ nfsdir = $ rootimgdir ;
if ( $ ient - > { nfsserver } ) {
$ nfssrv = $ ient - > { nfsserver } ;
}
if ( $ ient - > { nfsdir } ne '' ) {
$ nfsdir = $ ient - > { nfsdir } . "/netboot/$osver/$arch/$profile" ;
2010-03-01 16:32:22 +00:00
#this code sez, "if nfsdir starts with //, then
#use a absolute path, i.e. do not append xCATisms"
#this is required for some statelite envs.
#still open for debate.
2011-01-06 06:54:06 +00:00
if ( $ ient - > { nfsdir } =~ m !^//! ) {
$ nfsdir = $ ient - > { nfsdir } ;
$ nfsdir =~ s!^/!! ;
}
}
2009-12-15 20:37:40 +00:00
2011-01-13 08:58:41 +00:00
# special case for redhat6, fedora12/13/14
2011-09-21 06:47:20 +00:00
if ( & using_dracut ( $ osver ) ) {
2011-01-06 06:54:06 +00:00
$ kcmdline = "root=nfs:$nfssrv:$nfsdir/rootimg:ro STATEMNT=" ;
} else {
$ kcmdline = "NFSROOT=$nfssrv:$nfsdir STATEMNT=" ;
}
2010-09-17 09:54:47 +00:00
} else {
2011-01-06 06:54:06 +00:00
$ kcmdline = "imgurl=http://$imgsrv/$rootimgdir/rootimg-statelite.gz STATEMNT=" ;
2010-09-17 09:54:47 +00:00
}
2010-02-26 07:14:59 +00:00
2010-09-17 09:54:47 +00:00
# add support for subVars in the value of "statemnt"
my $ statemnt = "" ;
if ( exists ( $ stateHash - > { $ node } ) ) {
$ statemnt = $ stateHash - > { $ node } - > [ 0 ] - > { statemnt } ;
if ( grep /\$/ , $ statemnt ) {
my ( $ server , $ dir ) = split ( /:/ , $ statemnt ) ;
2010-02-26 07:14:59 +00:00
2010-09-17 09:54:47 +00:00
#if server is blank, then its the directory
unless ( $ dir ) {
$ dir = $ server ;
$ server = '' ;
}
if ( grep /\$|#CMD/ , $ dir ) {
$ dir = xCAT::SvrUtils - > subVars ( $ dir , $ node , 'dir' , $ callback ) ;
2011-05-10 11:32:51 +00:00
$ dir =~ s/\/\//\//g ;
2010-09-17 09:54:47 +00:00
}
if ( $ server ) {
$ server = xCAT::SvrUtils - > subVars ( $ server , $ node , 'server' , $ callback ) ;
}
$ statemnt = $ server . ":" . $ dir ;
2010-02-26 07:14:59 +00:00
}
2010-09-17 09:54:47 +00:00
}
$ kcmdline . = $ statemnt . " " ;
$ kcmdline . =
"XCAT=$xcatmaster:$xcatdport " ;
2011-01-06 06:54:06 +00:00
if ( $ rootfstype ne "ramdisk" ) {
# BEGIN service node
my $ isSV = xCAT::Utils - > isServiceNode ( ) ;
my $ res = xCAT::Utils - > runcmd ( "hostname" , 0 ) ;
my $ sip = xCAT::NetworkUtils - > getipaddr ( $ res ) ; # this is the IP of service node
if ( $ isSV and ( ( $ xcatmaster eq $ sip ) or ( $ xcatmaster eq $ res ) ) ) {
# if the NFS directory in litetree is on the service node,
# and it is not exported, then it will be mounted automatically
xCAT::SvrUtils - > setupNFSTree ( $ node , $ sip , $ callback ) ;
# then, export the statemnt directory if it is on the service node
if ( $ statemnt ) {
xCAT::SvrUtils - > setupStatemnt ( $ sip , $ statemnt , $ callback ) ;
}
2010-02-26 07:14:59 +00:00
}
2011-01-06 06:54:06 +00:00
# END service node
2010-02-26 07:14:59 +00:00
}
2010-09-17 09:54:47 +00:00
}
else {
2008-05-05 19:34:58 +00:00
$ kcmdline =
2011-07-28 10:21:12 +00:00
"imgurl=http://$imgsrv/$rootimgdir/rootimg.$suffix " ;
2010-09-17 09:54:47 +00:00
$ kcmdline . = "XCAT=$xcatmaster:$xcatdport " ;
}
# add one parameter: ifname=<eth0>:<mac address>
# which is used for dracut
# the redhat5.x os will ignore it
2010-09-21 20:42:12 +00:00
my $ useifname = 0 ;
2010-12-08 08:31:28 +00:00
2010-11-23 12:15:54 +00:00
if ( $ reshash - > { $ node } - > [ 0 ] and $ reshash - > { $ node } - > [ 0 ] - > { installnic } and $ reshash - > { $ node } - > [ 0 ] - > { installnic } ne "mac" ) {
$ useifname = 1 ;
$ kcmdline . = "ifname=" . $ reshash - > { $ node } - > [ 0 ] - > { installnic } . ":" ;
2010-09-17 09:54:47 +00:00
} elsif ( $ nodebootif ) {
2010-09-21 20:42:12 +00:00
$ useifname = 1 ;
$ kcmdline . = "ifname=$nodebootif:" ;
2010-12-08 08:31:28 +00:00
} elsif ( $ reshash - > { $ node } - > [ 0 ] and $ reshash - > { $ node } - > [ 0 ] - > { primarynic } and $ reshash - > { $ node } - > [ 0 ] - > { primarynic } ne "mac" ) {
2010-09-21 20:42:12 +00:00
$ useifname = 1 ;
$ kcmdline . = "ifname=" . $ reshash - > { $ node } - > [ 0 ] - > { primarynic } . ":" ;
2010-09-17 09:54:47 +00:00
}
2010-09-21 20:42:12 +00:00
#else { #no, we autodetect and don't presume anything
# $kcmdline .="eth0:";
# print "eth0 is used as the default booting network devices...\n";
#}
2010-09-17 09:54:47 +00:00
# append the mac address
my $ mac ;
2011-04-29 17:24:50 +00:00
if ( $ useifname && $ machash - > { $ node } - > [ 0 ] && $ machash - > { $ node } - > [ 0 ] - > { 'mac' } ) {
2010-09-17 09:54:47 +00:00
# TODO: currently, only "mac" attribute with classic style is used, the "|" delimited string of "macaddress!hostname" format is not used
$ mac = $ machash - > { $ node } - > [ 0 ] - > { 'mac' } ;
2011-05-05 15:41:39 +00:00
# if ( (index($mac, "|") eq -1) and (index($mac, "!") eq -1) ) {
2010-10-04 20:47:07 +00:00
#convert to linux format
if ( $ mac !~ /:/ ) {
$ mac =~ s/(..)(..)(..)(..)(..)(..)/$1:$2:$3:$4:$5:$6/ ;
}
2011-05-05 15:41:39 +00:00
# } else {
# $callback->({ error=>[ qq{In the "mac" table, the "|" delimited string of "macaddress!hostname" format is not supported by "nodeset <nr> netboot|statelite if installnic/primarynic is set".}], errorcode=>[1]});
# return;
# }
2008-04-24 17:32:18 +00:00
}
2010-09-17 09:54:47 +00:00
2010-11-23 12:15:54 +00:00
if ( $ useifname && $ mac ) {
$ kcmdline . = "$mac " ;
}
# add "netdev=<eth0>" or "BOOTIF=<mac>"
# which are used for other scenarios
2010-09-17 09:54:47 +00:00
my $ netdev = "" ;
2010-11-23 12:15:54 +00:00
if ( $ reshash - > { $ node } - > [ 0 ] and $ reshash - > { $ node } - > [ 0 ] - > { installnic } and $ reshash - > { $ node } - > [ 0 ] - > { installnic } ne "mac" ) {
$ kcmdline . = "netdev=" . $ reshash - > { $ node } - > [ 0 ] - > { installnic } . " " ;
2010-09-17 09:54:47 +00:00
} elsif ( $ nodebootif ) {
$ kcmdline . = "netdev=" . $ nodebootif . " " ;
2010-12-08 08:31:28 +00:00
} elsif ( $ reshash - > { $ node } - > [ 0 ] and $ reshash - > { $ node } - > [ 0 ] - > { primarynic } and $ reshash - > { $ node } - > [ 0 ] - > { primarynic } ne "mac" ) {
2010-09-17 09:54:47 +00:00
$ kcmdline . = "netdev=" . $ reshash - > { $ node } - > [ 0 ] - > { primarynic } . " " ;
} else {
2011-05-05 15:41:39 +00:00
if ( $ useifname && $ mac ) {
2010-09-17 09:54:47 +00:00
$ kcmdline . = "BOOTIF=" . $ mac . " " ;
}
}
2010-12-13 07:33:33 +00:00
if ( grep /hf/ , $ reshash - > { $ node } - > [ 0 ] - > { installnic } )
{
$ kcmdline . = "rdloaddriver=hf_if " ;
}
2010-09-17 09:54:47 +00:00
2008-05-05 19:34:58 +00:00
if ( defined $ sent - > { serialport } )
{
#my $sent = $hmtab->getNodeAttribs($node,['serialspeed','serialflow']);
unless ( $ sent - > { serialspeed } )
{
$ callback - > (
{
error = > [
"serialport defined, but no serialspeed for $node in nodehm table"
] ,
errorcode = > [ 1 ]
}
) ;
next ;
}
$ kcmdline . =
2009-09-15 17:59:11 +00:00
"console=tty0 console=ttyS" . $ sent - > { serialport } . "," . $ sent - > { serialspeed } ;
2008-05-05 19:34:58 +00:00
if ( $ sent - > { serialflow } =~ /(hard|tcs|ctsrts)/ )
{
$ kcmdline . = "n8r" ;
}
}
2010-07-14 11:54:19 +00:00
# turn off the selinux
if ( $ osver =~ m/fedora12/ || $ osver =~ m/fedora13/ ) {
2010-12-14 07:15:45 +00:00
$ kcmdline . = " selinux=0 " ;
}
# if kdump service is enbaled, add "crashkernel=" and "kdtarget="
if ( $ dump ) {
2011-02-28 07:21:30 +00:00
if ( $ arch eq "ppc64" ) { # for ppc64, the crashkernel paramter should be "128M@32M", otherwise, some kernel crashes will be met
2011-06-27 08:22:26 +00:00
if ( $ crashkernelsize ) {
$ kcmdline . = " crashkernel=$crashkernelsize\@32M dump=$dump " ;
} else {
$ kcmdline . = " crashkernel=256M\@32M dump=$dump " ;
}
2011-02-28 07:21:30 +00:00
}
2010-07-14 11:54:19 +00:00
}
2008-10-14 19:27:40 +00:00
# add the addkcmdline attribute to the end
# of the command, if it exists
2009-06-29 18:41:00 +00:00
#my $addkcmd = $addkcmdhash->{$node}->[0];
2008-10-14 19:27:40 +00:00
# add the extra addkcmd command info, if in the table
2009-06-29 18:41:00 +00:00
#if ($addkcmd->{'addkcmdline'}) {
# $kcmdline .= " ";
# $kcmdline .= $addkcmd->{'addkcmdline'};
2008-10-14 19:27:40 +00:00
2009-06-29 18:41:00 +00:00
#}
2008-10-14 19:27:40 +00:00
2010-09-17 09:54:47 +00:00
my $ kernstr = "xcat/netboot/$osver/$arch/$profile/kernel" ;
if ( $ xenstyle ) {
$ kernstr . = "!xcat/netboot/$osver/$arch/$profile/hypervisor" ;
}
my $ initrdstr = "xcat/netboot/$osver/$arch/$profile/initrd-stateless.gz" ;
$ initrdstr = "xcat/netboot/$osver/$arch/$profile/initrd-statelite.gz" if ( $ statelite ) ;
2011-01-06 06:54:06 +00:00
# special case for the dracut-enabled OSes
2011-09-21 06:47:20 +00:00
if ( & using_dracut ( $ osver ) ) {
2011-01-06 06:54:06 +00:00
if ( $ statelite and $ rootfstype eq "ramdisk" ) {
$ initrdstr = "xcat/netboot/$osver/$arch/$profile/initrd-stateless.gz" ;
}
}
2011-06-16 12:37:23 +00:00
if ( $ statelite )
{
my $ statelitetb = xCAT::Table - > new ( 'statelite' ) ;
2011-08-31 13:00:18 +00:00
my $ mntopts = $ statelitetb - > getNodeAttribs ( $ node , [ 'mntopts' ] ) ;
2011-06-16 12:37:23 +00:00
my $ mntoptions = $ mntopts - > { 'mntopts' } ;
unless ( defined ( $ mntoptions ) )
{
$ kcmdline . = " MNTOPTS=" ;
}
else
{
$ kcmdline . = " MNTOPTS=$mntoptions" ;
}
}
2008-05-05 19:34:58 +00:00
$ bptab - > setNodeAttribs (
2010-09-17 09:54:47 +00:00
$ node ,
{
kernel = > $ kernstr ,
initrd = > $ initrdstr ,
kcmdline = > $ kcmdline
}
) ;
2007-11-06 21:28:02 +00:00
}
2008-05-05 19:34:58 +00:00
#my $rc = xCAT::Utils->create_postscripts_tar();
#if ( $rc != 0 ) {
# xCAT::MsgUtils->message( "S", "Error creating postscripts tar file." );
#}
2007-11-06 21:28:02 +00:00
}
2007-11-05 22:12:39 +00:00
2008-05-05 19:34:58 +00:00
sub mkinstall
{
my $ request = shift ;
my $ callback = shift ;
my $ doreq = shift ;
my @ nodes = @ { $ request - > { node } } ;
2009-09-23 01:34:03 +00:00
my $ sitetab = xCAT::Table - > new ( 'site' ) ;
my $ linuximagetab ;
my $ osimagetab ;
my % img_hash = ( ) ;
2008-05-05 19:34:58 +00:00
my $ installroot ;
2010-08-17 08:56:31 +00:00
my $ tftpdir ;
2008-05-05 19:34:58 +00:00
$ installroot = "/install" ;
2010-08-17 08:56:31 +00:00
$ tftpdir = "/tftpboot" ;
2010-07-27 20:18:06 +00:00
2009-09-23 01:34:03 +00:00
if ( $ sitetab )
{
( my $ ref ) = $ sitetab - > getAttribs ( { key = > 'installdir' } , 'value' ) ;
if ( $ ref and $ ref - > { value } )
{
$ installroot = $ ref - > { value } ;
}
2010-08-17 08:56:31 +00:00
( $ ref ) = $ sitetab - > getAttribs ( { key = > 'tftpdir' } , 'value' ) ;
if ( $ ref and $ ref - > { value } )
{
$ tftpdir = $ ref - > { value } ;
}
2009-09-23 01:34:03 +00:00
}
2008-05-05 19:34:58 +00:00
my $ node ;
my $ ostab = xCAT::Table - > new ( 'nodetype' ) ;
my % doneimgs ;
2008-07-11 14:12:05 +00:00
my $ restab = xCAT::Table - > new ( 'noderes' ) ;
my $ bptab = xCAT::Table - > new ( 'bootparams' , - create = > 1 ) ;
my $ hmtab = xCAT::Table - > new ( 'nodehm' ) ;
2009-09-23 01:34:03 +00:00
my % osents = % { $ ostab - > getNodesAttribs ( \ @ nodes , [ 'profile' , 'os' , 'arch' , 'provmethod' ] ) } ;
2008-07-11 14:12:05 +00:00
my % rents =
% { $ restab - > getNodesAttribs ( \ @ nodes ,
[ 'nfsserver' , 'primarynic' , 'installnic' ] ) } ;
my % hents =
% { $ hmtab - > getNodesAttribs ( \ @ nodes ,
[ 'serialport' , 'serialspeed' , 'serialflow' ] ) } ;
2009-06-29 18:41:00 +00:00
#my $addkcmdhash =
# $bptab->getNodesAttribs(\@nodes, ['addkcmdline']);
2009-03-14 16:14:29 +00:00
require xCAT::Template ;
2008-05-05 19:34:58 +00:00
foreach $ node ( @ nodes )
{
2009-09-23 01:34:03 +00:00
my $ os ;
my $ arch ;
my $ profile ;
my $ tmplfile ;
my $ pkgdir ;
2010-07-27 20:18:06 +00:00
my $ pkglistfile ;
2009-09-23 01:34:03 +00:00
my $ imagename ;
my $ platform ;
2008-05-05 19:34:58 +00:00
my $ osinst ;
2008-07-11 14:12:05 +00:00
my $ ent = $ osents { $ node } - > [ 0 ] ; #$ostab->getNodeAttribs($node, ['profile', 'os', 'arch']);
2010-02-19 18:39:56 +00:00
if ( $ ent and $ ent - > { provmethod } and ( $ ent - > { provmethod } ne 'install' ) and ( $ ent - > { provmethod } ne 'netboot' ) and ( $ ent - > { provmethod } ne 'statelite' ) ) {
2009-09-23 01:34:03 +00:00
$ imagename = $ ent - > { provmethod } ;
#print "imagename=$imagename\n";
if ( ! exists ( $ img_hash { $ imagename } ) ) {
if ( ! $ osimagetab ) {
$ osimagetab = xCAT::Table - > new ( 'osimage' , - create = > 1 ) ;
}
( my $ ref ) = $ osimagetab - > getAttribs ( { imagename = > $ imagename } , 'osvers' , 'osarch' , 'profile' , 'provmethod' ) ;
if ( $ ref ) {
$ img_hash { $ imagename } - > { osver } = $ ref - > { 'osvers' } ;
$ img_hash { $ imagename } - > { osarch } = $ ref - > { 'osarch' } ;
$ img_hash { $ imagename } - > { profile } = $ ref - > { 'profile' } ;
$ img_hash { $ imagename } - > { provmethod } = $ ref - > { 'provmethod' } ;
if ( ! $ linuximagetab ) {
$ linuximagetab = xCAT::Table - > new ( 'linuximage' , - create = > 1 ) ;
}
2010-07-27 20:18:06 +00:00
( my $ ref1 ) = $ linuximagetab - > getAttribs ( { imagename = > $ imagename } , 'template' , 'pkgdir' , 'pkglist' ) ;
2009-09-23 01:34:03 +00:00
if ( $ ref1 ) {
if ( $ ref1 - > { 'template' } ) {
$ img_hash { $ imagename } - > { template } = $ ref1 - > { 'template' } ;
}
if ( $ ref1 - > { 'pkgdir' } ) {
$ img_hash { $ imagename } - > { pkgdir } = $ ref1 - > { 'pkgdir' } ;
}
2010-07-27 20:18:06 +00:00
if ( $ ref1 - > { 'pkglist' } ) {
$ img_hash { $ imagename } - > { pkglist } = $ ref1 - > { 'pkglist' } ;
}
2009-09-23 01:34:03 +00:00
}
2010-04-27 15:54:13 +00:00
# if the install template wasn't found, then lets look for it in the default locations.
unless ( $ img_hash { $ imagename } - > { template } ) {
my $ pltfrm = xCAT_plugin::anaconda:: getplatform ( $ ref - > { 'osvers' } ) ;
my $ tmplfile = xCAT::SvrUtils:: get_tmpl_file_name ( "$installroot/custom/install/$pltfrm" ,
$ ref - > { 'profile' } , $ ref - > { 'osvers' } , $ ref - > { 'osarch' } , $ ref - > { 'osvers' } ) ;
if ( ! $ tmplfile ) { $ tmplfile = xCAT::SvrUtils:: get_tmpl_file_name ( "$::XCATROOT/share/xcat/install/$pltfrm" ,
$ ref - > { 'profile' } , $ ref - > { 'osvers' } , $ ref - > { 'osarch' } , $ ref - > { 'osvers' } ) ;
}
# if we managed to find it, put it in the hash:
if ( $ tmplfile ) {
$ img_hash { $ imagename } - > { template } = $ tmplfile ;
}
}
2010-07-27 20:18:06 +00:00
#if the install pkglist wasn't found, then lets look for it in the default locations
unless ( $ img_hash { $ imagename } - > { pkglist } ) {
my $ pltfrm = xCAT_plugin::anaconda:: getplatform ( $ ref - > { 'osvers' } ) ;
my $ pkglistfile = xCAT::SvrUtils:: get_pkglist_file_name ( "$installroot/custom/install/$pltfrm" ,
$ ref - > { 'profile' } , $ ref - > { 'osvers' } , $ ref - > { 'osarch' } , $ ref - > { 'osvers' } ) ;
if ( ! $ pkglistfile ) { $ pkglistfile = xCAT::SvrUtils:: get_pkglist_file_name ( "$::XCATROOT/share/xcat/install/$pltfrm" ,
$ ref - > { 'profile' } , $ ref - > { 'osvers' } , $ ref - > { 'osarch' } , $ ref - > { 'osvers' } ) ;
}
# if we managed to find it, put it in the hash:
if ( $ pkglistfile ) {
$ img_hash { $ imagename } - > { pkglist } = $ pkglistfile ;
}
}
2009-09-23 01:34:03 +00:00
} else {
$ callback - > (
{ error = > [ "The os image $imagename does not exists on the osimage table for $node" ] ,
errorcode = > [ 1 ] } ) ;
next ;
}
}
my $ ph = $ img_hash { $ imagename } ;
$ os = $ ph - > { osver } ;
$ arch = $ ph - > { osarch } ;
$ profile = $ ph - > { profile } ;
$ platform = xCAT_plugin::anaconda:: getplatform ( $ os ) ;
$ tmplfile = $ ph - > { template } ;
$ pkgdir = $ ph - > { pkgdir } ;
if ( ! $ pkgdir ) {
$ pkgdir = "$installroot/$os/$arch" ;
}
2010-07-27 20:18:06 +00:00
$ pkglistfile = $ ph - > { pkglist } ;
2009-09-23 01:34:03 +00:00
}
else {
$ os = $ ent - > { os } ;
$ arch = $ ent - > { arch } ;
$ profile = $ ent - > { profile } ;
$ platform = xCAT_plugin::anaconda:: getplatform ( $ os ) ;
my $ genos = $ os ;
$ genos =~ s/\..*// ;
2010-11-11 15:06:22 +00:00
if ( $ genos =~ /rh.*(\d+)\z/ )
2009-09-23 01:34:03 +00:00
{
unless ( - r "$installroot/custom/install/$platform/$profile.$genos.$arch.tmpl"
or - r "/install/custom/install/$platform/$profile.$genos.tmpl"
or - r "$::XCATROOT/share/xcat/install/$platform/$profile.$genos.$arch.tmpl"
or - r "$::XCATROOT/share/xcat/install/$platform/$profile.$genos.tmpl" )
{
$ genos = "rhel$1" ;
}
}
$ tmplfile = xCAT::SvrUtils:: get_tmpl_file_name ( "$installroot/custom/install/$platform" , $ profile , $ os , $ arch , $ genos ) ;
if ( ! $ tmplfile ) { $ tmplfile = xCAT::SvrUtils:: get_tmpl_file_name ( "$::XCATROOT/share/xcat/install/$platform" , $ profile , $ os , $ arch , $ genos ) ; }
2010-07-27 20:18:06 +00:00
$ pkglistfile = xCAT::SvrUtils:: get_pkglist_file_name ( "$installroot/custom/install/$platform" , $ profile , $ os , $ arch , $ genos ) ;
if ( ! $ pkglistfile ) { $ pkglistfile = xCAT::SvrUtils:: get_pkglist_file_name ( "$::XCATROOT/share/xcat/install/$platform" , $ profile , $ os , $ arch , $ genos ) ; }
2009-09-23 01:34:03 +00:00
$ pkgdir = "$installroot/$os/$arch" ;
}
2008-05-22 14:12:05 +00:00
my @ missingparms ;
2009-09-23 01:34:03 +00:00
unless ( $ os ) {
if ( $ imagename ) { push @ missingparms , "osimage.osvers" ; }
else { push @ missingparms , "nodetype.os" ; }
2008-05-22 14:12:05 +00:00
}
2009-09-23 01:34:03 +00:00
unless ( $ arch ) {
if ( $ imagename ) { push @ missingparms , "osimage.osarch" ; }
else { push @ missingparms , "nodetype.arch" ; }
2008-05-22 14:12:05 +00:00
}
2009-09-23 01:34:03 +00:00
unless ( $ profile ) {
if ( $ imagename ) { push @ missingparms , "osimage.profile" ; }
else { push @ missingparms , "nodetype.profile" ; }
2008-05-22 14:12:05 +00:00
}
2009-09-23 01:34:03 +00:00
unless ( $ os and $ arch and $ profile )
2008-05-05 19:34:58 +00:00
{
$ callback - > (
{
2008-05-22 14:12:05 +00:00
error = > [ "Missing " . join ( ',' , @ missingparms ) . " for $node" ] ,
2008-05-05 19:34:58 +00:00
errorcode = > [ 1 ]
}
) ;
next ; #No profile
}
2009-09-23 01:34:03 +00:00
2008-09-12 22:40:15 +00:00
unless ( - r "$tmplfile" )
2008-05-05 19:34:58 +00:00
{
$ callback - > (
{
error = > [
"No $platform kickstart template exists for "
2009-09-23 01:34:03 +00:00
. $ profile
2010-08-26 06:04:23 +00:00
. " in directory $installroot/custom/install/$platform or $::XCATROOT/share/xcat/install/$platform"
2008-05-05 19:34:58 +00:00
] ,
errorcode = > [ 1 ]
}
) ;
next ;
}
2010-07-27 20:18:06 +00:00
2008-05-05 19:34:58 +00:00
#Call the Template class to do substitution to produce a kickstart file in the autoinst dir
2009-09-23 01:34:03 +00:00
my $ tmperr ;
if ( $ imagename ) {
$ tmperr = "Unable to find template file: $tmplfile" ;
} else {
$ tmperr = "Unable to find template in /install/custom/install/$platform or $::XCATROOT/share/xcat/install/$platform (for $profile/$os/$arch combination)" ;
}
2010-08-06 14:22:28 +00:00
if ( - r "$tmplfile" )
2008-05-05 19:34:58 +00:00
{
$ tmperr =
xCAT::Template - > subvars (
2010-08-06 14:22:28 +00:00
$ tmplfile ,
2008-05-05 19:34:58 +00:00
"/$installroot/autoinst/" . $ node ,
2010-08-06 14:22:28 +00:00
$ node ,
$ pkglistfile
2008-05-05 19:34:58 +00:00
) ;
}
2010-07-27 20:18:06 +00:00
2008-05-05 19:34:58 +00:00
if ( $ tmperr )
{
$ callback - > (
{
node = >
[ { name = > [ $ node ] , error = > [ $ tmperr ] , errorcode = > [ 1 ] } ]
}
) ;
next ;
}
2009-09-23 01:34:03 +00:00
#my $installdir="/install"; #TODO: not hardcode installdir
2010-08-17 08:56:31 +00:00
#my $tftpdir = "/tftpboot";
2008-05-05 19:34:58 +00:00
# create the node-specific post scripts
#mkpath "/install/postscripts/";
#xCAT::Postage->writescript($node,"/install/postscripts/".$node, "install", $callback);
2009-06-16 18:57:12 +00:00
my $ kernpath ;
my $ initrdpath ;
my $ maxmem ;
2010-07-30 21:43:51 +00:00
my $ esxi = 0 ;
2008-05-05 19:34:58 +00:00
if (
(
2009-06-16 18:57:12 +00:00
$ arch =~ /x86/ and
(
2009-09-23 01:34:03 +00:00
- r "$pkgdir/images/pxeboot/vmlinuz"
and $ kernpath = "$pkgdir/images/pxeboot/vmlinuz"
2009-09-24 20:13:33 +00:00
and - r "$pkgdir/images/pxeboot/initrd.img"
2009-09-23 01:34:03 +00:00
and $ initrdpath = "$pkgdir/images/pxeboot/initrd.img"
2009-06-16 18:57:12 +00:00
) or ( #Handle the case seen in VMWare 4.0 ESX media
#In VMWare 4.0 they dropped the pxe-optimized initrd
#leaving us no recourse but the rather large optical disk
#initrd, but perhaps we can mitigate with gPXE
2009-09-23 01:34:03 +00:00
- d "$pkgdir/VMware"
and - r "$pkgdir/isolinux/vmlinuz"
and $ kernpath = "$pkgdir/isolinux/vmlinuz"
and - r "$pkgdir/isolinux/initrd.img"
and $ initrdpath = "$pkgdir/isolinux/initrd.img"
2009-06-16 18:57:12 +00:00
and $ maxmem = "512M" #Have to give up linux room to make room for vmware hypervisor evidently
2010-07-30 21:43:51 +00:00
) or ( #Handle the case seen in VMware ESXi 4.1 media scripted installs.
- r "$pkgdir/mboot.c32"
and - r "$pkgdir/vmkboot.gz"
and - r "$pkgdir/vmkernel.gz"
and - r "$pkgdir/sys.vgz"
and - r "$pkgdir/cim.vgz"
and - r "$pkgdir/ienviron.vgz"
and - r "$pkgdir/install.vgz"
and $ esxi = 'true'
2009-06-16 18:57:12 +00:00
)
) or ( $ arch =~ /ppc/
2009-09-23 01:34:03 +00:00
and - r "$pkgdir/ppc/ppc64/vmlinuz"
and $ kernpath = "$pkgdir/ppc/ppc64/vmlinuz"
and - r "$pkgdir/ppc/ppc64/ramdisk.image.gz"
and $ initrdpath = "$pkgdir/ppc/ppc64/ramdisk.image.gz" )
2008-05-05 19:34:58 +00:00
)
{
#TODO: driver slipstream, targetted for network.
unless ( $ doneimgs { "$os|$arch" } )
{
2010-08-17 08:56:31 +00:00
mkpath ( "$tftpdir/xcat/$os/$arch" ) ;
2010-07-30 21:43:51 +00:00
if ( $ esxi ) {
copyesxiboot ( $ pkgdir , "$tftpdir/xcat/$os/$arch" ) ;
} else {
copy ( $ kernpath , "$tftpdir/xcat/$os/$arch" ) ;
copy ( $ initrdpath , "$tftpdir/xcat/$os/$arch/initrd.img" ) ;
2010-08-12 09:06:31 +00:00
& insert_dd ( $ callback , $ os , $ arch , "$tftpdir/xcat/$os/$arch/initrd.img" ) ;
2010-07-30 21:43:51 +00:00
}
2008-05-05 19:34:58 +00:00
$ doneimgs { "$os|$arch" } = 1 ;
}
#We have a shot...
2008-07-11 14:12:05 +00:00
my $ ent = $ rents { $ node } - > [ 0 ] ;
# $restab->getNodeAttribs($node,
# ['nfsserver', 'primarynic', 'installnic']);
my $ sent = $ hents { $ node } - > [ 0 ] ;
# $hmtab->getNodeAttribs(
# $node,
# [
# 'serialport', 'serialspeed', 'serialflow'
# ]
# );
2011-11-15 19:29:16 +00:00
my $ instserver = '!myipfn!' ; #default to autodetect from boot server
if ( $ ent and $ ent - > { nfsserver } ) {
$ instserver = $ ent - > { nfsserver } ;
}
2008-05-05 19:34:58 +00:00
my $ kcmdline =
2011-11-22 16:01:53 +00:00
"quiet repo=http://$instserver/install/$os/$arch/ ks=http://"
2011-11-15 19:29:16 +00:00
. $ instserver
2008-05-05 19:34:58 +00:00
. "/install/autoinst/"
. $ node ;
2009-06-16 18:57:12 +00:00
if ( $ maxmem ) {
$ kcmdline . = " mem=$maxmem" ;
}
2010-03-03 03:28:18 +00:00
my $ ksdev = "" ;
2008-05-05 19:34:58 +00:00
if ( $ ent - > { installnic } )
{
2010-03-03 03:28:18 +00:00
if ( $ ent - > { installnic } eq "mac" )
{
my $ mactab = xCAT::Table - > new ( "mac" ) ;
my $ macref = $ mactab - > getNodeAttribs ( $ node , [ 'mac' ] ) ;
$ ksdev = $ macref - > { mac } ;
}
else
{
$ ksdev = $ ent - > { installnic } ;
}
2008-05-05 19:34:58 +00:00
}
elsif ( $ ent - > { primarynic } )
{
2010-03-03 03:28:18 +00:00
if ( $ ent - > { primarynic } eq "mac" )
{
my $ mactab = xCAT::Table - > new ( "mac" ) ;
my $ macref = $ mactab - > getNodeAttribs ( $ node , [ 'mac' ] ) ;
$ ksdev = $ macref - > { mac } ;
}
else
{
$ ksdev = $ ent - > { primarynic } ;
}
2008-05-05 19:34:58 +00:00
}
else
{
2010-05-03 20:37:39 +00:00
$ ksdev = "bootif" ; #if not specified, fall back to bootif
2008-05-05 19:34:58 +00:00
}
2010-03-03 03:28:18 +00:00
if ( $ ksdev eq "" )
{
$ callback - > (
{
error = > [ "No MAC address defined for " . $ node ] ,
errorcode = > [ 1 ]
}
) ;
}
2010-07-30 21:43:51 +00:00
if ( $ esxi ) {
$ ksdev =~ s/eth/vmnic/g ;
}
2010-03-03 03:28:18 +00:00
$ kcmdline . = " ksdevice=" . $ ksdev ;
2008-05-05 19:34:58 +00:00
#TODO: dd=<url> for driver disks
if ( defined ( $ sent - > { serialport } ) )
{
unless ( $ sent - > { serialspeed } )
{
$ callback - > (
{
error = > [
"serialport defined, but no serialspeed for $node in nodehm table"
] ,
errorcode = > [ 1 ]
}
) ;
next ;
}
2011-10-18 17:45:51 +00:00
#go cmdline if serial console is requested, the shiny ansi is just impractical
2008-05-05 19:34:58 +00:00
$ kcmdline . =
2011-10-18 17:45:51 +00:00
"cmdline console=tty0 console=ttyS"
2008-05-05 19:34:58 +00:00
. $ sent - > { serialport } . ","
. $ sent - > { serialspeed } ;
if ( $ sent - > { serialflow } =~ /(hard|cts|ctsrts)/ )
{
$ kcmdline . = "n8r" ;
}
}
2011-11-17 20:56:23 +00:00
#$kcmdline .= " noipv6";
2009-05-07 14:13:36 +00:00
# add the addkcmdline attribute to the end
# of the command, if it exists
2009-06-29 18:41:00 +00:00
#my $addkcmd = $addkcmdhash->{$node}->[0];
2009-05-07 14:13:36 +00:00
# add the extra addkcmd command info, if in the table
2009-06-29 18:41:00 +00:00
#if ($addkcmd->{'addkcmdline'}) {
# $kcmdline .= " ";
# $kcmdline .= $addkcmd->{'addkcmdline'};
#}
2010-07-30 21:43:51 +00:00
my $ k ;
my $ i ;
if ( $ esxi ) {
$ k = "xcat/$os/$arch/mboot.c32" ;
$ i = "" ;
2010-10-28 06:47:14 +00:00
my @ addfiles = qw( vmkernel.gz sys.vgz cim.vgz ienviron.vgz install.vgz mod.tgz ) ;
2010-07-30 21:43:51 +00:00
$ kcmdline = "xcat/$os/$arch/vmkboot.gz " . $ kcmdline ;
foreach ( @ addfiles ) {
$ kcmdline . = " --- xcat/$os/$arch/$_" ;
}
} else {
$ k = "xcat/$os/$arch/vmlinuz" ;
$ i = "xcat/$os/$arch/initrd.img" ;
}
2008-05-05 19:34:58 +00:00
$ bptab - > setNodeAttribs (
2010-07-30 21:43:51 +00:00
$ node ,
{
kernel = > $ k ,
initrd = > $ i ,
kcmdline = > $ kcmdline
}
) ;
2008-05-05 19:34:58 +00:00
}
else
{
$ callback - > (
{
2010-09-28 02:34:58 +00:00
error = > [ "Install image not found in $installroot/$os/$arch" ] ,
2008-05-05 19:34:58 +00:00
errorcode = > [ 1 ]
}
) ;
}
2007-10-26 22:44:33 +00:00
}
2008-05-07 20:33:35 +00:00
#my $rc = xCAT::Utils->create_postscripts_tar();
#if ($rc != 0)
#{
# xCAT::MsgUtils->message("S", "Error creating postscripts tar file.");
#}
2008-05-05 19:34:58 +00:00
}
sub copycd
{
my $ request = shift ;
my $ callback = shift ;
my $ doreq = shift ;
2011-11-14 19:31:50 +00:00
my $ installroot = "/install" ;
2008-05-05 19:34:58 +00:00
my $ sitetab = xCAT::Table - > new ( 'site' ) ;
if ( $ sitetab )
{
2009-09-23 01:34:03 +00:00
( my $ ref ) = $ sitetab - > getAttribs ( { key = > 'installdir' } , 'value' ) ;
2009-09-18 19:53:48 +00:00
#print Dumper($ref);
2008-05-05 19:34:58 +00:00
if ( $ ref and $ ref - > { value } )
{
$ installroot = $ ref - > { value } ;
}
2008-04-29 17:39:28 +00:00
}
2009-09-23 01:34:03 +00:00
my $ distname ;
my $ arch ;
my $ path ;
2008-05-05 19:34:58 +00:00
@ ARGV = @ { $ request - > { arg } } ;
GetOptions (
'n=s' = > \ $ distname ,
'a=s' = > \ $ arch ,
'p=s' = > \ $ path
) ;
unless ( $ path )
{
2008-04-29 17:39:28 +00:00
2008-05-05 19:34:58 +00:00
#this plugin needs $path...
return ;
2007-10-26 22:44:33 +00:00
}
2008-05-05 19:34:58 +00:00
if ( $ distname
and $ distname !~ /^centos/
and $ distname !~ /^fedora/
2010-06-28 13:46:51 +00:00
and $ distname !~ /^SL/
2008-05-05 19:34:58 +00:00
and $ distname !~ /^rh/ )
{
#If they say to call it something unidentifiable, give up?
return ;
2008-04-03 13:27:16 +00:00
}
2008-05-05 19:34:58 +00:00
unless ( - r $ path . "/.discinfo" )
{
return ;
2008-03-10 14:20:47 +00:00
}
2008-05-05 19:34:58 +00:00
my $ dinfo ;
open ( $ dinfo , $ path . "/.discinfo" ) ;
my $ did = <$dinfo> ;
chomp ( $ did ) ;
my $ desc = <$dinfo> ;
chomp ( $ desc ) ;
my $ darch = <$dinfo> ;
chomp ( $ darch ) ;
2008-04-14 13:32:45 +00:00
2008-05-05 19:34:58 +00:00
if ( $ darch and $ darch =~ /i.86/ )
{
$ darch = "x86" ;
}
close ( $ dinfo ) ;
if ( $ distnames { $ did } )
{
unless ( $ distname )
{
$ distname = $ distnames { $ did } ;
}
}
elsif ( $ desc =~ /^Final$/ )
{
unless ( $ distname )
{
$ distname = "centos5" ;
}
}
elsif ( $ desc =~ /^Fedora 8$/ )
{
unless ( $ distname )
{
$ distname = "fedora8" ;
}
}
elsif ( $ desc =~ /^CentOS-4 .*/ )
{
unless ( $ distname )
{
$ distname = "centos4" ;
}
}
elsif ( $ desc =~ /^Red Hat Enterprise Linux Client 5$/ )
{
unless ( $ distname )
{
$ distname = "rhelc5" ;
}
}
elsif ( $ desc =~ /^Red Hat Enterprise Linux Server 5$/ )
{
unless ( $ distname )
{
$ distname = "rhels5" ;
}
2007-10-26 22:44:33 +00:00
}
2010-06-28 13:46:51 +00:00
elsif ( $ desc =~ /^LTS$/ )
{
unless ( $ distname )
{
$ distname = "SL5" ;
}
}
2007-10-26 22:44:33 +00:00
2008-05-05 19:34:58 +00:00
unless ( $ distname )
{
return ; #Do nothing, not ours..
2007-10-26 22:44:33 +00:00
}
2008-05-05 19:34:58 +00:00
if ( $ darch )
{
unless ( $ arch )
{
$ arch = $ darch ;
}
if ( $ arch and $ arch ne $ darch )
{
$ callback - > (
{
error = >
"Requested distribution architecture $arch, but media is $darch"
}
) ;
return ;
}
if ( $ arch =~ /ppc/ ) { $ arch = "ppc64" }
2007-10-26 22:44:33 +00:00
}
2008-05-05 19:34:58 +00:00
% { $ request } = ( ) ; #clear request we've got it.
$ callback - > ( { data = > "Copying media to $installroot/$distname/$arch/" } ) ;
my $ omask = umask 0022 ;
mkpath ( "$installroot/$distname/$arch" ) ;
umask $ omask ;
my $ rc ;
my $ reaped = 0 ;
$ SIG { INT } = $ SIG { TERM } = sub {
2008-06-02 23:58:15 +00:00
foreach ( @ cpiopid ) {
kill 2 , $ _ ;
}
2008-05-15 15:48:34 +00:00
if ( $ ::CDMOUNTPATH ) {
2008-08-11 18:36:10 +00:00
chdir ( "/" ) ;
2008-05-15 15:48:34 +00:00
system ( "umount $::CDMOUNTPATH" ) ;
}
2008-05-05 19:34:58 +00:00
} ;
my $ KID ;
chdir $ path ;
2008-06-02 20:27:02 +00:00
my $ numFiles = `find . -print | wc -l` ;
2008-05-05 19:34:58 +00:00
my $ child = open ( $ KID , "|-" ) ;
unless ( defined $ child )
{
$ callback - > ( { error = > "Media copy operation fork failure" } ) ;
return ;
2007-10-26 22:44:33 +00:00
}
2008-05-05 19:34:58 +00:00
if ( $ child )
{
2008-06-02 23:58:15 +00:00
push @ cpiopid , $ child ;
2008-05-05 19:34:58 +00:00
my @ finddata = `find .` ;
for ( @ finddata )
{
print $ KID $ _ ;
}
close ( $ KID ) ;
$ rc = $? ;
2007-10-26 22:44:33 +00:00
}
2008-05-05 19:34:58 +00:00
else
{
nice 10 ;
2008-06-02 20:27:02 +00:00
my $ c = "nice -n 20 cpio -vdump $installroot/$distname/$arch" ;
2008-06-02 23:58:15 +00:00
my $ k2 = open ( PIPE , "$c 2>&1 |" ) ||
2008-06-02 20:27:02 +00:00
$ callback - > ( { error = > "Media copy operation fork failure" } ) ;
2008-06-02 23:58:15 +00:00
push @ cpiopid , $ k2 ;
2008-06-02 20:27:02 +00:00
my $ copied = 0 ;
my ( $ percent , $ fout ) ;
while ( <PIPE> ) {
next if /^cpio:/ ;
$ percent = $ copied / $ numFiles ;
$ fout = sprintf "%0.2f%%" , $ percent * 100 ;
$ callback - > ( { sinfo = > "$fout" } ) ;
+ + $ copied ;
}
exit ;
2008-05-05 19:34:58 +00:00
}
#my $rc = system("cd $path; find . | nice -n 20 cpio -dump $installroot/$distname/$arch");
#my $rc = system("cd $path;rsync -a . $installroot/$distname/$arch/");
chmod 0755 , "$installroot/$distname/$arch" ;
2009-03-14 16:00:35 +00:00
require xCAT::Yum ;
2011-07-01 11:27:04 +00:00
xCAT::Yum - > localize_yumrepo ( $ installroot , $ distname , $ arch ) ;
if ( $ rc != 0 )
2008-05-05 19:34:58 +00:00
{
$ callback - > ( { error = > "Media copy operation failed, status $rc" } ) ;
2007-10-26 22:44:33 +00:00
}
2008-05-05 19:34:58 +00:00
else
{
$ callback - > ( { data = > "Media copy operation successful" } ) ;
2009-09-19 17:03:14 +00:00
my @ ret = xCAT::SvrUtils - > update_tables_with_templates ( $ distname , $ arch ) ;
if ( $ ret [ 0 ] != 0 ) {
$ callback - > ( { data = > "Error when updating the osimage tables: " . $ ret [ 1 ] } ) ;
}
2011-07-21 06:26:13 +00:00
my @ ret = xCAT::SvrUtils - > update_tables_with_diskless_image ( $ distname , $ arch , undef , "netboot" ) ;
if ( $ ret [ 0 ] != 0 ) {
$ callback - > ( { data = > "Error when updating the osimage tables for stateless: " . $ ret [ 1 ] } ) ;
}
my @ ret = xCAT::SvrUtils - > update_tables_with_diskless_image ( $ distname , $ arch , undef , "statelite" ) ;
if ( $ ret [ 0 ] != 0 ) {
$ callback - > ( { data = > "Error when updating the osimage tables for statelite: " . $ ret [ 1 ] } ) ;
}
2007-10-26 22:44:33 +00:00
}
}
2008-09-12 22:40:15 +00:00
2009-09-23 01:34:03 +00:00
sub getplatform {
my $ os = shift ;
my $ platform ;
if ( $ os =~ /rh.*/ )
{
$ platform = "rh" ;
}
elsif ( $ os =~ /centos.*/ )
{
$ platform = "centos" ;
}
elsif ( $ os =~ /fedora.*/ )
{
$ platform = "fedora" ;
}
elsif ( $ os =~ /esx.*/ )
{
$ platform = "esx" ;
}
2010-06-28 13:46:51 +00:00
elsif ( $ os =~ /SL.*/ )
{
$ platform = "SL" ;
}
2009-09-23 01:34:03 +00:00
return $ platform ;
}
2008-09-12 22:40:15 +00:00
2010-07-30 21:43:51 +00:00
sub copyesxiboot {
my $ srcdir = shift ;
my $ targetdir = shift ;
2010-08-10 23:04:19 +00:00
# this just does the same thing that the stateless version does.
unless ( - f "$targetdir/mod.tgz" ) {
xCAT_plugin::esx:: makecustomizedmod ( 'esxi' , $ targetdir ) ;
}
2010-07-30 21:43:51 +00:00
my @ files = qw( mboot.c32 vmkboot.gz vmkernel.gz sys.vgz cim.vgz ienviron.vgz install.vgz ) ;
foreach my $ f ( @ files ) {
copy ( "$srcdir/$f" , "$targetdir" ) ;
}
}
2010-08-12 09:06:31 +00:00
# Get the driver update disk from /install/driverdisk/<os>/<arch>
# Take out the drivers from driver update disk and insert them
# into the initrd
sub insert_dd {
my $ callback = shift ;
my $ os = shift ;
my $ arch = shift ;
my $ img = shift ;
my $ install_dir = xCAT::Utils - > getInstallDir ( ) ;
# Find out the dirver disk which need to be inserted into initrd
if ( ! - d "$install_dir/driverdisk/$os/$arch" ) {
return ( ) ;
}
my $ cmd = "find $install_dir/driverdisk/$os/$arch -type f" ;
my @ dd_list = xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
chomp ( @ dd_list ) ;
if ( ! @ dd_list ) {
return ( ) ;
}
# Create the tmp dir for dd hack
2010-08-23 08:00:51 +00:00
my $ dd_dir = mkdtemp ( "/tmp/ddtmpXXXXXXX" ) ;
2010-08-12 09:06:31 +00:00
mkpath "$dd_dir/initrd_img" ; # The dir for the new initrd
# unzip the initrd image
$ cmd = "gunzip -c $img > $dd_dir/initrd" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update disk failed. Could not gunzip the initial initrd." ;
xCAT::MsgUtils - > message ( "E" , $ rsp , $ callback ) ;
return undef ;
}
# Extract the files from original initrd
$ cmd = "cd $dd_dir/initrd_img; cpio -id --quiet < ../initrd" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update disk failed. Could not extract files from the initial initrd." ;
xCAT::MsgUtils - > message ( "E" , $ rsp , $ callback ) ;
return undef ;
}
# Create directory for the driver modules hack
mkpath "$dd_dir/modules" ;
my @ inserted_dd = ( ) ;
my @ dd_drivers = ( ) ;
# The rh6 has different initrd format with old version (rh 5.x)
# The new format of initrd is made by dracut, it has the /lib/modules/<kernel>
# directory like the root image
# If the os has dracut rpm packet, then copy the drivers to the /lib/modules/<kernel>
# and recreate the dependency by the depmod command
$ cmd = "find $install_dir/$os/$arch/ | grep dracut" ;
my @ dracut = xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( grep ( /dracut-.*\.rpm/ , @ dracut ) ) { #dracut mode, for rh6, fedora13 ...
#copy the firmware into the initrd
if ( - d "$dd_dir/mnt/firmware" ) {
$ cmd = "cp -rf $dd_dir/mnt/firmware/* $dd_dir/initrd_img/lib/firmware" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
}
# Figure out the kernel version of the initrd
my $ kernelver ;
opendir ( KERNEL , "$dd_dir/initrd_img/lib/modules" ) ;
while ( $ kernelver = readdir ( KERNEL ) ) {
if ( $ kernelver =~ /^\./ || $ kernelver !~ /^\d/ ) {
$ kernelver = "" ;
next ;
}
if ( - d "$dd_dir/initrd_img/lib/modules/$kernelver" ) {
last ;
}
$ kernelver = "" ;
}
# The initrd has problem
if ( $ kernelver eq "" ) {
return ( ) ;
}
# Copy the drivers to the lib/modules/<$kernelver>/
if ( ! - d "$dd_dir/initrd_img/lib/modules/$kernelver/kernel/drivers/driverdisk" ) {
mkpath "$dd_dir/initrd_img/lib/modules/$kernelver/kernel/drivers/driverdisk" ;
}
foreach my $ dd ( @ dd_list ) {
mkpath "$dd_dir/mnt" ;
mkpath "$dd_dir/dd_modules" ;
$ cmd = "mount -o loop $dd $dd_dir/mnt" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update disk failed. Could not mount the driver update disk." ;
xCAT::MsgUtils - > message ( "E" , $ rsp , $ callback ) ;
return undef ;
}
$ cmd = "cd $dd_dir/dd_modules; gunzip -c $dd_dir/mnt/modules.cgz | cpio -id" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update disk failed. Could not gunzip the modules.cgz from the driver update disk." ;
xCAT::MsgUtils - > message ( "E" , $ rsp , $ callback ) ;
system ( "umount -f $dd_dir/mnt" ) ;
return undef ;
}
# Get all the drivers which belong to $kernelver/$arch
$ cmd = "find $dd_dir/dd_modules/$kernelver/$arch/ -type f" ;
my @ drivers = xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
foreach my $ d ( @ drivers ) {
chomp ( $ d ) ;
# The drivers in the initrd is in zip format
$ cmd = "gzip $d" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
$ d . = ".gz" ;
my $ driver_name = $ d ;
$ driver_name =~ s/.*\/// ;
# If the driver file existed, then over write
$ cmd = "find $dd_dir/initrd_img/lib/modules/$kernelver -type f -name $driver_name" ;
my @ exist_file = xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( ! @ exist_file ) {
$ cmd = "cp $d $dd_dir/initrd_img/lib/modules/$kernelver/kernel/drivers/driverdisk" ;
} else {
$ cmd = "cp $d $exist_file[0]" ;
}
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
}
$ cmd = "umount -f $dd_dir/mnt" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update disk failed. Could not unmount the driver update disk." ;
xCAT::MsgUtils - > message ( "E" , $ rsp , $ callback ) ;
system ( "umount -f $dd_dir/mnt" ) ;
return undef ;
}
# Clean the env
rmtree "$dd_dir/mnt" ;
rmtree "$dd_dir/dd_modules" ;
push @ inserted_dd , $ dd ;
}
# Generate the dependency relationship
$ cmd = "chroot $dd_dir/initrd_img/ depmod $kernelver" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
} else {
# Extract files from the modules.cgz of initrd
$ cmd = "cd $dd_dir/modules; gunzip -c $dd_dir/initrd_img/modules/modules.cgz | cpio -id" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update disk failed. Could not gunzip modules.cgz from the initial initrd." ;
xCAT::MsgUtils - > message ( "E" , $ rsp , $ callback ) ;
return undef ;
}
my @ modinfo = ( ) ;
foreach my $ dd ( @ dd_list ) {
mkpath "$dd_dir/mnt" ;
mkpath "$dd_dir/dd_modules" ;
$ cmd = "mount -o loop $dd $dd_dir/mnt" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update disk failed. Could not mount the driver update disk." ;
xCAT::MsgUtils - > message ( "E" , $ rsp , $ callback ) ;
return undef ;
}
$ cmd = "cd $dd_dir/dd_modules; gunzip -c $dd_dir/mnt/modules.cgz | cpio -id" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update disk failed. Could not gunzip the modules.cgz from the driver update disk." ;
xCAT::MsgUtils - > message ( "E" , $ rsp , $ callback ) ;
system ( "umount -f $dd_dir/mnt" ) ;
return undef ;
}
# Copy all the driver files out
$ cmd = "cp -rf $dd_dir/dd_modules/* $dd_dir/modules" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
# Copy the firmware into the initrd
mkpath "$dd_dir/initrd_img/firmware" ;
$ cmd = "cp -rf $dd_dir/dd_modules/firmware/* $dd_dir/initrd_img/firmware" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
# Get the entries from modinfo
open ( DDMODINFO , "<" , "$dd_dir/mnt/modinfo" ) ;
while ( <DDMODINFO> ) {
if ( $ _ =~ /^Version/ ) { next ; }
if ( $ _ =~ /^(\S*)/ ) {
push @ dd_drivers , $ 1 ;
}
push @ modinfo , $ _ ;
}
close ( DDMODINFO ) ;
# Append the modules.alias
$ cmd = "cat $dd_dir/mnt/modules.alias >> $dd_dir/initrd_img/modules/modules.alias" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
# Append the modules.dep
$ cmd = "cat $dd_dir/mnt/modules.dep >> $dd_dir/initrd_img/modules/modules.dep" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
# Append the pcitable
$ cmd = "cat $dd_dir/mnt/pcitable >> $dd_dir/initrd_img/modules/pcitable" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
$ cmd = "umount -f $dd_dir/mnt" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update disk failed. Could not unmount the driver update disk." ;
xCAT::MsgUtils - > message ( "E" , $ rsp , $ callback ) ;
system ( "umount -f $dd_dir/mnt" ) ;
return undef ;
}
# Clean the env
rmtree "$dd_dir/mnt" ;
rmtree "$dd_dir/dd_modules" ;
push @ inserted_dd , $ dd ;
}
# Append the modinfo into the module-info
open ( MODINFO , "<" , "$dd_dir/initrd_img/modules/module-info" ) ;
open ( MODINFONEW , ">" , "$dd_dir/initrd_img/modules/module-info.new" ) ;
my $ removeflag = 0 ;
while ( <MODINFO> ) {
my $ line = $ _ ;
if ( $ line =~ /^(\S+)/ ) {
if ( grep /$1/ , @ dd_drivers ) {
$ removeflag = 1 ;
next ;
} else {
$ removeflag = 0 ;
}
}
if ( $ removeflag == 1 ) { next ; }
print MODINFONEW $ line ;
}
print MODINFONEW @ modinfo ;
close ( MODINFONEW ) ;
close ( MODINFO ) ;
move ( "$dd_dir/initrd_img/modules/module-info.new" , "$dd_dir/initrd_img/modules/module-info" ) ;
# Repack the modules
$ cmd = "cd $dd_dir/modules; find . -print | cpio -o -H crc | gzip -9 > $dd_dir/initrd_img/modules/modules.cgz" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update disk failed. Could not pack the hacked modules.cgz." ;
xCAT::MsgUtils - > message ( "E" , $ rsp , $ callback ) ;
return undef ;
}
} # End of non dracut
# Repack the initrd
$ cmd = "cd $dd_dir/initrd_img; find .|cpio -H newc -o|gzip -9 -c - > $dd_dir/initrd.img" ;
xCAT::Utils - > runcmd ( $ cmd , - 1 ) ;
if ( $ ::RUNCMD_RC != 0 ) {
my $ rsp ;
push @ { $ rsp - > { data } } , "Handle the driver update disk failed. Could not pack the hacked initrd." ;
xCAT::MsgUtils - > message ( "E" , $ rsp , $ callback ) ;
return undef ;
}
copy ( "$dd_dir/initrd.img" , $ img ) ;
rmtree $ dd_dir ;
my $ rsp ;
push @ { $ rsp - > { data } } , "Inserted the driver update disk:" . join ( ',' , @ inserted_dd ) . "." ;
xCAT::MsgUtils - > message ( "I" , $ rsp , $ callback ) ;
return @ inserted_dd ;
}
2010-07-30 21:43:51 +00:00
2007-10-26 22:44:33 +00:00
1 ;