osimage phase2: genimage and packimage honor osimage table settings
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4217 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
fed8bbf89f
commit
0cc7ee9f5f
@ -560,7 +560,7 @@ sub update_tables_with_templates
|
||||
my $tmp1=$osimagetab->getAllEntries();
|
||||
if (defined($tmp1) && (@$tmp1 > 0)) {
|
||||
foreach my $rowdata(@$tmp1) {
|
||||
if (($osver eq $rowdata->{osvers}) && ($arch eq $rowdata->{osarch}) && ($rowdata->{imagetype} eq "install") && ($profile eq $rowdata->{profile})){
|
||||
if (($osver eq $rowdata->{osvers}) && ($arch eq $rowdata->{osarch}) && ($rowdata->{provmethod} eq "install") && ($profile eq $rowdata->{profile})){
|
||||
$found=1;
|
||||
last;
|
||||
}
|
||||
@ -700,13 +700,13 @@ sub update_tables_with_diskless_image
|
||||
my $tmp1=$osimagetab->getAllEntries();
|
||||
if (defined($tmp1) && (@$tmp1 > 0)) {
|
||||
foreach my $rowdata(@$tmp1) {
|
||||
if (($osver eq $rowdata->{osvers}) && ($arch eq $rowdata->{osarch}) && ($rowdata->{imagetype} eq "netboot") && ($profile eq $rowdata->{profile})){
|
||||
if (($osver eq $rowdata->{osvers}) && ($arch eq $rowdata->{osarch}) && ($rowdata->{provmethod} eq "netboot") && ($profile eq $rowdata->{profile})){
|
||||
$found=1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($found) { print "$profile already in\n"; return (0, ""); }
|
||||
if ($found) { print "The image is already in the db.\n"; return (0, ""); }
|
||||
|
||||
my $imagename=$osver . "-" . $arch . "-netboot-" . $profile;
|
||||
#TODO: check if there happen to be a row that has the same imagename but with different contents
|
||||
|
@ -1,4 +1,9 @@
|
||||
package xCAT_plugin::packimage;
|
||||
BEGIN
|
||||
{
|
||||
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
||||
}
|
||||
use lib "$::XCATROOT/lib/perl";
|
||||
use xCAT::Table;
|
||||
use Getopt::Long;
|
||||
use File::Path;
|
||||
@ -33,10 +38,16 @@ sub process_request {
|
||||
$callback->({info=>["packimage -h \npackimage -v \npackimage [-p profile] [-a architecture] [-o OS] [-m method]\n"]});
|
||||
return;
|
||||
}
|
||||
my $osver;
|
||||
my $arch;
|
||||
my $profile;
|
||||
my $method='cpio';
|
||||
my $osver;
|
||||
my $arch;
|
||||
my $profile;
|
||||
my $method='cpio';
|
||||
my $exlistloc;
|
||||
my $syncfile;
|
||||
my $rootimg_dir;
|
||||
my $destdir;
|
||||
my $imagename;
|
||||
|
||||
GetOptions(
|
||||
"profile|p=s" => \$profile,
|
||||
"arch|a=s" => \$arch,
|
||||
@ -54,6 +65,68 @@ sub process_request {
|
||||
$callback->({info=>["packimage -h \npackimage -v \npackimage [-p profile] [-a architecture] [-o OS] [-m method]\n"]});
|
||||
return;
|
||||
}
|
||||
|
||||
if (@ARGV > 0) {
|
||||
$imagename=$ARGV[0];
|
||||
if ($arch or $osver or $profile) {
|
||||
$callback->({error=>["-o, -p and -a options are not allowed when a image name is specified."],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
#load the module in memory
|
||||
eval {require("$::XCATROOT/lib/perl/xCAT/Table.pm")};
|
||||
if ($@) {
|
||||
$callback->({error=>[$@],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
|
||||
#get the info from the osimage and linux
|
||||
my $osimagetab=xCAT::Table->new('osimage', -create=>1);
|
||||
if (!$osimagetab) {
|
||||
$callback->({error=>["The osimage table cannot be opened."],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
my $linuximagetab=xCAT::Table->new('linuximage', -create=>1);
|
||||
if (!$linuximagetab) {
|
||||
$callback->({error=>["The linuximage table cannot be opened."],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
(my $ref) = $osimagetab->getAttribs({imagename => $imagename}, 'osvers', 'osarch', 'profile', 'provmethod', 'synclists');
|
||||
if (!$ref) {
|
||||
$callback->({error=>["Cannot find image \'$imagename\' from the osimage table."],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
(my $ref1) = $linuximagetab->getAttribs({imagename => $imagename}, 'exlist', 'rootimgdir');
|
||||
if (!$ref1) {
|
||||
$callback->({error=>["Cannot find $imagename from the linuximage table."],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
|
||||
$osver=$ref->{'osvers'};
|
||||
$arch=$ref->{'osarch'};
|
||||
$profile=$ref->{'profile'};
|
||||
$syncfile=$ref->{'synclists'};
|
||||
my $provmethod=$ref->{'provmethod'};
|
||||
|
||||
unless ($osver and $arch and $profile and $provmethod) {
|
||||
$callback->({error=>["osimage.osvers, osimage.osarch, osimage.profile and osimage.provmethod must be specified for the image $imagename in the database."],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
|
||||
if ($provmethod ne 'netboot') {
|
||||
$callback->({error=>["\'$imagename\' cannot be used to build diskless image. Make sure osimage.provmethod is 'netboot'."],errorcode=>[1]});
|
||||
return;
|
||||
}
|
||||
|
||||
$exlistloc =$ref1->{'exlist'};
|
||||
$destdir=$ref1->{'rootimgdir'};
|
||||
}
|
||||
|
||||
if (!$destdir)
|
||||
{
|
||||
$destdir="$installroot/netboot/$osver/$arch/$profile";
|
||||
}
|
||||
$rootimg_dir="$destdir/rootimg";
|
||||
|
||||
my $distname = $osver;
|
||||
until (-r "$::XCATROOT/share/xcat/netboot/$distname/" or not $distname) {
|
||||
chop($distname);
|
||||
@ -67,13 +140,15 @@ sub process_request {
|
||||
return;
|
||||
}
|
||||
my $oldpath=cwd();
|
||||
my $exlistloc=xCAT::SvrUtils->get_exlist_file_name("$installroot/custom/netboot/$distname", $profile, $osver, $arch);
|
||||
if (!$exlistloc) { $exlistloc=xCAT::SvrUtils->get_exlist_file_name("$::XCATROOT/share/xcat/netboot/$distname", $profile, $osver, $arch); }
|
||||
if (!$imagename) {
|
||||
$exlistloc=xCAT::SvrUtils->get_exlist_file_name("$installroot/custom/netboot/$distname", $profile, $osver, $arch);
|
||||
if (!$exlistloc) { $exlistloc=xCAT::SvrUtils->get_exlist_file_name("$::XCATROOT/share/xcat/netboot/$distname", $profile, $osver, $arch); }
|
||||
}
|
||||
|
||||
if (!$exlistloc)
|
||||
{
|
||||
$callback->({data=>["WARNING: Unable to find file exclusion list under $installroot/custom/netboot/$distname or $::XCATROOT/share/xcat/netboot/$distname/ for $profile/$arch/$osver\n"]});
|
||||
}
|
||||
#if (!$exlistloc)
|
||||
#{
|
||||
# $callback->({data=>["WARNING: Unable to find file exclusion list under $installroot/custom/netboot/$distname or $::XCATROOT/share/xcat/netboot/$distname/ for $profile/$arch/$osver\n"]});
|
||||
#}
|
||||
|
||||
my $excludestr = "find . ";
|
||||
my $includestr;
|
||||
@ -103,25 +178,25 @@ sub process_request {
|
||||
print "\nexcludestr=$excludestr\n\n includestr=$includestr\n\n";
|
||||
|
||||
# add the xCAT post scripts to the image
|
||||
if (! -d "$installroot/netboot/$osver/$arch/$profile/rootimg") {
|
||||
$callback->({error=>["$installroot/netboot/$osver/$arch/$profile/rootimg does not exist, run genimage -o $osver -p $profile on a server with matching architecture"]});
|
||||
if (! -d "$rootimg_dir") {
|
||||
$callback->({error=>["$rootimg_dir does not exist, run genimage -o $osver -p $profile on a server with matching architecture"]});
|
||||
return;
|
||||
}
|
||||
|
||||
#some rpms like atftp mount the rootimg/proc to /proc, we need to make sure rootimg/proc is free of junk
|
||||
#before packaging the image
|
||||
`umount $installroot/netboot/$osver/$arch/$profile/rootimg/proc`;
|
||||
copybootscript($installroot, $osver, $arch, $profile, $callback);
|
||||
`umount $rootimg_dir/proc`;
|
||||
copybootscript($installroot, $rootimg_dir, $osver, $arch, $profile, $callback);
|
||||
my $passtab = xCAT::Table->new('passwd');
|
||||
if ($passtab) {
|
||||
(my $pent) = $passtab->getAttribs({key=>'system',username=>'root'},'password');
|
||||
if ($pent and defined ($pent->{password})) {
|
||||
my $pass = $pent->{password};
|
||||
my $shadow;
|
||||
open($shadow,"<","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/shadow");
|
||||
open($shadow,"<","$rootimg_dir/etc/shadow");
|
||||
my @shadents = <$shadow>;
|
||||
close($shadow);
|
||||
open($shadow,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/shadow");
|
||||
open($shadow,">","$rootimg_dir/etc/shadow");
|
||||
unless ($pass =~ /^\$1\$/) {
|
||||
$pass = crypt($pass,'$1$'.genpassword(8));
|
||||
}
|
||||
@ -136,35 +211,37 @@ sub process_request {
|
||||
}
|
||||
|
||||
# sync fils configured in the synclist to the rootimage
|
||||
my $syncfile = xCAT::SvrUtils->getsynclistfile(undef, $osver, $arch, $profile, "netboot");
|
||||
if (defined ($syncfile) && -f $syncfile
|
||||
&& -d "$installroot/netboot/$osver/$arch/$profile/rootimg") {
|
||||
print "sync files from $syncfile to the $installroot/netboot/$osver/$arch/$profile/rootimg\n";
|
||||
`$::XCATROOT/bin/xdcp -i "$installroot/netboot/$osver/$arch/$profile/rootimg" -F $syncfile`;
|
||||
}
|
||||
if (!$imagename) {
|
||||
$syncfile = xCAT::SvrUtils->getsynclistfile(undef, $osver, $arch, $profile, "netboot");
|
||||
if (defined ($syncfile) && -f $syncfile
|
||||
&& -d $rootimg_dir) {
|
||||
print "sync files from $syncfile to the $rootimg_dir\n";
|
||||
`$::XCATROOT/bin/xdcp -i $rootimg_dir -F $syncfile`;
|
||||
}
|
||||
}
|
||||
|
||||
my $verb = "Packing";
|
||||
if ($method =~ /nfs/) {
|
||||
$verb = "Prepping";
|
||||
}
|
||||
if ($method =~ /nfs/) {
|
||||
$callback->({data=>["\nNOTE: Contents of $installroot/netboot/$osver/$arch/$profile/rootimg\nMUST be available on all service and management nodes and NFS exported."]});
|
||||
$callback->({data=>["\nNOTE: Contents of $rootimg_dir\nMUST be available on all service and management nodes and NFS exported."]});
|
||||
}
|
||||
my $temppath;
|
||||
my $oldumask;
|
||||
if (! -d "$installroot/netboot/$osver/$arch/$profile/rootimg") {
|
||||
$callback->({error=>["$installroot/netboot/$osver/$arch/$profile/rootimg does not exist, run genimage -o $osver -p $profile on a server with matching architecture"]});
|
||||
if (! -d $rootimg_dir) {
|
||||
$callback->({error=>["$rootimg_dir does not exist, run genimage -o $osver -p $profile on a server with matching architecture"]});
|
||||
return;
|
||||
}
|
||||
$callback->({data=>["$verb contents of $installroot/netboot/$osver/$arch/$profile/rootimg"]});
|
||||
unlink("$installroot/netboot/$osver/$arch/$profile/rootimg.gz");
|
||||
unlink("$installroot/netboot/$osver/$arch/$profile/rootimg.sfs");
|
||||
unlink("$installroot/netboot/$osver/$arch/$profile/rootimg.nfs");
|
||||
$callback->({data=>["$verb contents of $rootimg_dir"]});
|
||||
unlink("$destdir/rootimg.gz");
|
||||
unlink("$destdir/rootimg.sfs");
|
||||
unlink("$destdir/rootimg.nfs");
|
||||
if ($method =~ /cpio/) {
|
||||
if (!$exlistloc) {
|
||||
$excludestr = "find . |cpio -H newc -o | gzip -c - > ../rootimg.gz";
|
||||
}else {
|
||||
chdir("$installroot/netboot/$osver/$arch/$profile/rootimg");
|
||||
chdir("$rootimg_dir");
|
||||
system("$excludestr >> /tmp/xcat_packimg.txt");
|
||||
if ($includestr) {
|
||||
system("$includestr >> /tmp/xcat_packimg.txt");
|
||||
@ -176,7 +253,7 @@ sub process_request {
|
||||
} elsif ($method =~ /squashfs/) {
|
||||
$temppath = mkdtemp("/tmp/packimage.$$.XXXXXXXX");
|
||||
chmod 0755,$temppath;
|
||||
chdir("$installroot/netboot/$osver/$arch/$profile/rootimg");
|
||||
chdir("$rootimg_dir");
|
||||
system("$excludestr >> /tmp/xcat_packimg.txt");
|
||||
if ($includestr) {
|
||||
system("$includestr >> /tmp/xcat_packimg.txt");
|
||||
@ -187,10 +264,10 @@ sub process_request {
|
||||
} else {
|
||||
$callback->({error=>["Invalid method '$method' requested"],errorcode=>[1]});
|
||||
}
|
||||
chdir("$installroot/netboot/$osver/$arch/$profile/rootimg");
|
||||
chdir("$rootimg_dir");
|
||||
system($excludestr);
|
||||
if ($method =~ /cpio/) {
|
||||
chmod 0644,"$installroot/netboot/$osver/$arch/$profile/rootimg.gz";
|
||||
chmod 0644,"$destdir/rootimg.gz";
|
||||
umask $oldmask;
|
||||
} elsif ($method =~ /squashfs/) {
|
||||
my $flags;
|
||||
@ -216,9 +293,11 @@ sub process_request {
|
||||
chmod(0644,"../rootimg.sfs");
|
||||
}
|
||||
chdir($oldpath);
|
||||
my @ret=xCAT::SvrUtils->update_tables_with_diskless_image($osver, $arch, $profile);
|
||||
if ($ret[0] != 0) {
|
||||
$callback->({error=>["Error when updating the osimage tables: " . $ret[1]]});
|
||||
if (!$imagename) {
|
||||
my @ret=xCAT::SvrUtils->update_tables_with_diskless_image($osver, $arch, $profile);
|
||||
if ($ret[0] != 0) {
|
||||
$callback->({error=>["Error when updating the osimage tables: " . $ret[1]]});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,6 +309,7 @@ sub process_request {
|
||||
sub copybootscript {
|
||||
|
||||
my $installroot = shift;
|
||||
my $rootimg_dir = shift;
|
||||
my $osver = shift;
|
||||
my $arch = shift;
|
||||
my $profile = shift;
|
||||
@ -239,11 +319,11 @@ sub copybootscript {
|
||||
if ( -f "$installroot/postscripts/xcatdsklspost") {
|
||||
|
||||
# copy the xCAT diskless post script to the image
|
||||
mkpath("$installroot/netboot/$osver/$arch/$profile/rootimg/opt/xcat");
|
||||
mkpath("$rootimg_dir/opt/xcat");
|
||||
|
||||
copy ("$installroot/postscripts/xcatdsklspost", "$installroot/netboot/$osver/$arch/$profile/rootimg/opt/xcat/xcatdsklspost");
|
||||
copy ("$installroot/postscripts/xcatdsklspost", "$rootimg_dir/opt/xcat/xcatdsklspost");
|
||||
|
||||
chmod(0755,"$installroot/netboot/$osver/$arch/$profile/rootimg/opt/xcat/xcatdsklspost");
|
||||
chmod(0755,"$rootimg_dir/opt/xcat/xcatdsklspost");
|
||||
|
||||
} else {
|
||||
|
||||
@ -253,23 +333,23 @@ sub copybootscript {
|
||||
return 1;
|
||||
}
|
||||
if ( -f "$installroot/postscripts/xcatdsklspost.aix") {
|
||||
copy ("$installroot/postscripts/xcatdsklspost.aix", "$installroot/netboot/$osver/$arch/$profile/rootimg/opt/xcat/xcatdsklspost.aix");
|
||||
chmod(0755,"$installroot/netboot/$osver/$arch/$profile/rootimg/opt/xcat/xcatdsklspost.aix");
|
||||
copy ("$installroot/postscripts/xcatdsklspost.aix", "$rootimg_dir/opt/xcat/xcatdsklspost.aix");
|
||||
chmod(0755,"$rootimg_dir/opt/xcat/xcatdsklspost.aix");
|
||||
}
|
||||
|
||||
if ( -f "$installroot/postscripts/xcatpostinit") {
|
||||
|
||||
# copy the linux diskless init script to the image
|
||||
# - & set the permissions
|
||||
copy ("$installroot/postscripts/xcatpostinit","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/init.d/xcatpostinit");
|
||||
copy ("$installroot/postscripts/xcatpostinit","$rootimg_dir/etc/init.d/xcatpostinit");
|
||||
|
||||
chmod(0755,"$installroot/netboot/$osver/$arch/$profile/rootimg/etc/init.d/xcatpostinit");
|
||||
chmod(0755,"$rootimg_dir/etc/init.d/xcatpostinit");
|
||||
|
||||
# run chkconfig
|
||||
#my $chkcmd = "chroot $installroot/netboot/$osver/$arch/$profile/rootimg chkconfig --add xcatpostinit";
|
||||
symlink "/etc/init.d/xcatpostinit","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/rc3.d/S84xcatpostinit";
|
||||
symlink "/etc/init.d/xcatpostinit","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/rc4.d/S84xcatpostinit";
|
||||
symlink "/etc/init.d/xcatpostinit","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/rc5.d/S84xcatpostinit";
|
||||
#my $chkcmd = "chroot $rootimg_dir chkconfig --add xcatpostinit";
|
||||
symlink "/etc/init.d/xcatpostinit","$rootimg_dir/etc/rc3.d/S84xcatpostinit";
|
||||
symlink "/etc/init.d/xcatpostinit","$rootimg_dir/etc/rc4.d/S84xcatpostinit";
|
||||
symlink "/etc/init.d/xcatpostinit","$rootimg_dir/etc/rc5.d/S84xcatpostinit";
|
||||
#my $rc = system($chkcmd);
|
||||
#if ($rc) {
|
||||
#my $rsp;
|
||||
|
@ -18,7 +18,7 @@ Getopt::Long::Configure("bundling");
|
||||
Getopt::Long::Configure("pass_through");
|
||||
use File::Path;
|
||||
use File::Copy;
|
||||
use strict;
|
||||
#use strict;
|
||||
my @cpiopid;
|
||||
|
||||
sub handled_commands
|
||||
|
@ -1,4 +1,10 @@
|
||||
#!/usr/bin/env perl
|
||||
BEGIN
|
||||
{
|
||||
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
||||
}
|
||||
use lib "$::XCATROOT/lib/perl";
|
||||
|
||||
use File::Basename;
|
||||
use File::Path;
|
||||
use File::Copy;
|
||||
@ -13,11 +19,7 @@ my $prinic; #TODO be flexible on node primary nic
|
||||
my $othernics; #TODO be flexible on node primary nic
|
||||
my $netdriver;
|
||||
my @yumdirs;
|
||||
my $arch = `uname -m`;
|
||||
chomp($arch);
|
||||
if ($arch =~ /i.86$/) {
|
||||
$arch = x86;
|
||||
}
|
||||
my $arch;
|
||||
my %libhash;
|
||||
my @filestoadd;
|
||||
my $profile;
|
||||
@ -36,6 +38,14 @@ my $kernelver = ""; #`uname -r`;
|
||||
my $basekernelver; # = $kernelver;
|
||||
my $customdir=$fullpath;
|
||||
$customdir =~ s/.*share\/xcat/$installroot\/custom/;
|
||||
my $imagename;
|
||||
my $pkglist;
|
||||
my $srcdir;
|
||||
my $destdir;
|
||||
my $srcdir_otherpkgs;
|
||||
my $otherpkglist;
|
||||
my $postinstall_filename;
|
||||
my $rootimg_dir;
|
||||
|
||||
sub xdie {
|
||||
system("rm -rf /tmp/xcatinitrd.$$");
|
||||
@ -54,11 +64,98 @@ GetOptions(
|
||||
't=s' => \$tmplimit,
|
||||
'k=s' => \$kernelver
|
||||
);
|
||||
if (@ARGV > 0) {
|
||||
$imagename=$ARGV[0];
|
||||
if ($arch or $osver or $profile) {
|
||||
print "-o, -p and -a options are not allowed when a image name is specified.\n";
|
||||
exit 1;
|
||||
}
|
||||
#load the module in memory
|
||||
eval {require("$::XCATROOT/lib/perl/xCAT/Table.pm")};
|
||||
if ($@) {
|
||||
print $@;
|
||||
exit 1;
|
||||
}
|
||||
|
||||
#get the info from the osimage and linux
|
||||
my $osimagetab=xCAT::Table->new('osimage', -create=>1);
|
||||
if (!$osimagetab) {
|
||||
print "The osimage table cannot be opened.\n";
|
||||
exit 1;
|
||||
}
|
||||
my $linuximagetab=xCAT::Table->new('linuximage', -create=>1);
|
||||
if (!$linuximagetab) {
|
||||
print "The linuximage table cannot be opened.\n";
|
||||
exit 1;
|
||||
}
|
||||
(my $ref) = $osimagetab->getAttribs({imagename => $imagename}, 'osvers', 'osarch', 'profile', 'provmethod');
|
||||
if (!$ref) {
|
||||
print "Cannot find image \'$imagename\' from the osimage table.\n";
|
||||
exit 1;
|
||||
}
|
||||
(my $ref1) = $linuximagetab->getAttribs({imagename => $imagename}, 'pkglist', 'pkgdir', 'otherpkglist', 'otherpkgdir', 'postinstall', 'rootimgdir');
|
||||
if (!$ref1) {
|
||||
print "Cannot find $imagename from the linuximage table\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
$osver=$ref->{'osvers'};
|
||||
$arch=$ref->{'osarch'};
|
||||
$profile=$ref->{'profile'};
|
||||
my $provmethod=$ref->{'provmethod'};
|
||||
|
||||
unless ($osver and $arch and $profile and $provmethod) {
|
||||
print"osimage.osvers, osimage.osarch, osimage.profile and osimage.provmethod must be specified for the image $imagename in the database.\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
if ($provmethod ne 'netboot') {
|
||||
print "\'$imagename\' cannot be used to build diskless image. Make sure osimage.provmethod is 'netboot'.";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
if (! $ref1->{'pkglist'}) {
|
||||
print"A .pkglist file must be specified for image \'$imagename\' in the linuximage table.\n";
|
||||
exit 0;
|
||||
}
|
||||
$pkglist =$ref1->{'pkglist'};
|
||||
|
||||
$srcdir=$ref1->{'pkgdir'};
|
||||
$srcdir_otherpkgs=$ref1->{'otherpkgdir'};
|
||||
$otherpkglist=$ref1->{'otherpkglist'};
|
||||
$postinstall_filename=$ref1->{'postinstall'};
|
||||
$destdir=$ref1->{'rootimgdir'};
|
||||
}
|
||||
|
||||
if (!$arch) {
|
||||
$arch = `uname -m`;
|
||||
chomp($arch);
|
||||
if ($arch =~ /i.86$/) {
|
||||
$arch = "x86";
|
||||
}
|
||||
}
|
||||
|
||||
if (!$srcdir) {
|
||||
$srcdir="$installroot/$osver/$arch";
|
||||
}
|
||||
|
||||
if (!$srcdir_otherpkgs) {
|
||||
$srcdir_otherpkgs = "$installroot/post/otherpkgs/$osver/$arch";
|
||||
}
|
||||
|
||||
if (!$destdir)
|
||||
{
|
||||
$destdir="$installroot/netboot/$osver/$arch/$profile";
|
||||
}
|
||||
$rootimg_dir="$destdir/rootimg";
|
||||
|
||||
unless ($osver and $profile and $netdriver and $prinic) {
|
||||
print 'Usage: genimage -i <nodebootif> -n <nodenetdrivers> [-r <otherifaces>] -o <OSVER> -p <PROFILE> -k <KERNELVER>'."\n";
|
||||
print ' genimage -i <nodebootif> -n <nodenetdrivers> [-r <otherifaces>] -k <KERNELVER> <imagename>'."\n";
|
||||
print "Examples:\n";
|
||||
print " genimage -i eth0 -n tg3 -o centos5.1 -p compute\n";
|
||||
print " genimage -i eth0 -r eth1,eth2 -n tg3,bnx2 -o centos5.1 -p compute\n";
|
||||
print " genimage -i eth0 -n tg3 myimage\n";
|
||||
exit 1;
|
||||
}
|
||||
my @ndrivers;
|
||||
@ -73,7 +170,6 @@ foreach (split /,/,$netdriver) {
|
||||
}
|
||||
|
||||
unless ($onlyinitrd) {
|
||||
my $srcdir = "$installroot/$osver/$arch";
|
||||
@yumdirs=();
|
||||
find(\&isyumdir, <$installroot/$osver/$arch/>);
|
||||
unless (scalar(@yumdirs)) {
|
||||
@ -91,23 +187,25 @@ unless ($onlyinitrd) {
|
||||
}
|
||||
$repnum-=1;
|
||||
close($yumconfig);
|
||||
mkpath "$installroot/netboot/$osver/$arch/$profile/rootimg/etc";
|
||||
mkpath "$rootimg_dir/etc";
|
||||
my $fd;
|
||||
open($fd,">>","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/fstab");
|
||||
open($fd,">>","$rootimg_dir/etc/fstab");
|
||||
print $fd "#Dummy fstab for rpm postscripts to see\n";
|
||||
close($fd);
|
||||
my $yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$installroot/netboot/$osver/$arch/$profile/rootimg/ --disablerepo=* ";
|
||||
my $yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
|
||||
foreach (0..$repnum) {
|
||||
$yumcmd .= "--enablerepo=$osver-$arch-$_ ";
|
||||
}
|
||||
|
||||
$yumcmd .= "install ";
|
||||
mkpath("$installroot/netboot/$osver/$arch/$profile/rootimg/var/lib/yum");
|
||||
mkpath("$rootimg_dir/var/lib/yum");
|
||||
|
||||
my $pkglist= get_pkglist_file_name($customdir);
|
||||
if (!$pkglist) {
|
||||
$pkglist= get_pkglist_file_name($pathtofiles);
|
||||
}
|
||||
if (!$imagename) {
|
||||
$pkglist= get_pkglist_file_name($customdir);
|
||||
if (!$pkglist) {
|
||||
$pkglist= get_pkglist_file_name($pathtofiles);
|
||||
}
|
||||
}
|
||||
print "pkglist=$pkglist\n";
|
||||
|
||||
if (!$pkglist) {
|
||||
@ -135,7 +233,6 @@ unless ($onlyinitrd) {
|
||||
}
|
||||
|
||||
#Now let's handle extra packages
|
||||
my $srcdir_otherpkgs = "$installroot/post/otherpkgs/$osver/$arch";
|
||||
my %extra_hash=get_extra_package_names();
|
||||
my $extrapkgnames;
|
||||
|
||||
@ -151,7 +248,7 @@ unless ($onlyinitrd) {
|
||||
close($yumconfig);
|
||||
$index--;
|
||||
#enable extra package repo
|
||||
$yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$installroot/netboot/$osver/$arch/$profile/rootimg/ --disablerepo=* ";
|
||||
$yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
|
||||
foreach (0..$repnum) {
|
||||
$yumcmd .= "--enablerepo=$osver-$arch-$_ ";
|
||||
}
|
||||
@ -184,7 +281,7 @@ unless ($onlyinitrd) {
|
||||
#If specified, that takes precedence.
|
||||
#if image has one, that is used
|
||||
#if all else fails, resort to uname -r like this script did before
|
||||
my @KVERS= <$installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/*>;
|
||||
my @KVERS= <$rootimg_dir/lib/modules/*>;
|
||||
if (scalar(@KVERS)) {
|
||||
$basekernelver = basename($KVERS[0]);
|
||||
}
|
||||
@ -198,26 +295,26 @@ chomp($kernelver);
|
||||
unlink "/tmp/genimage.$$.yum.conf";
|
||||
|
||||
#-- run postinstall script
|
||||
if (-x "$pathtofiles/$profile.$osver.$arch.postinstall") {
|
||||
my $rc = system("$pathtofiles/$profile.$osver.$arch.postinstall", "$installroot/netboot/$osver/$arch/$profile/rootimg",$osver,$arch,$profile);
|
||||
if (!$imagename) {
|
||||
$postinstall_filename= get_postinstall_file_name($customdir);
|
||||
if (!$postinstall_filename) {
|
||||
$postinstall_filename= get_postinstall_file_name($pathtofiles);
|
||||
}
|
||||
}
|
||||
|
||||
if (($postinstall_filename) && (-x $postinstall_filename)) {
|
||||
my $rc = system($postinstall_filename, $rootimg_dir,$osver,$arch,$profile);
|
||||
if($rc) {
|
||||
print "postinstall script failed\n";
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
elsif (-x "$pathtofiles/$profile.postinstall") {
|
||||
my $rc = system("$pathtofiles/$profile.postinstall","$installroot/netboot/$osver/$arch/$profile/rootimg",$osver,$arch,$profile);
|
||||
if ($rc) {
|
||||
print "postinstall script failed\n";
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
|
||||
mkinitrd();
|
||||
|
||||
sub getlibs {
|
||||
my $file = shift;
|
||||
my $liblist = `chroot $installroot/netboot/$osver/$arch/$profile/rootimg ldd $file`;
|
||||
my $liblist = `chroot $rootimg_dir ldd $file`;
|
||||
my @libs = split/\n/,$liblist;
|
||||
my @return;
|
||||
foreach (@libs) {
|
||||
@ -240,13 +337,13 @@ sub getlibs {
|
||||
sub mkinitrd {
|
||||
mkpath("/tmp/xcatinitrd.$$/bin");
|
||||
if($basekernelver eq $kernelver) {
|
||||
rename(<$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinuz*>,"$installroot/netboot/$osver/$arch/$profile/kernel");
|
||||
rename(<$rootimg_dir/boot/vmlinuz*>,"$destdir/kernel");
|
||||
}
|
||||
else {
|
||||
if(-r "$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinuz-$kernelver") {
|
||||
rename("$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinuz-$kernelver","$installroot/netboot/$osver/$arch/$profile/kernel");
|
||||
if(-r "$rootimg_dir/boot/vmlinuz-$kernelver") {
|
||||
rename("$rootimg_dir/boot/vmlinuz-$kernelver","$destdir/kernel");
|
||||
} elsif(-r "/boot/vmlinuz-$kernelver") {
|
||||
copy("/boot/vmlinuz-$kernelver","$installroot/netboot/$osver/$arch/$profile/kernel");
|
||||
copy("/boot/vmlinuz-$kernelver","$destdir/kernel");
|
||||
}
|
||||
else {
|
||||
xdie("Cannot read /boot/vmlinuz-$kernelver");
|
||||
@ -445,22 +542,22 @@ EOMS
|
||||
}
|
||||
push @filestoadd,keys %libhash;
|
||||
if($basekernelver ne $kernelver) {
|
||||
system("rm -rf $installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/$basekernelver");
|
||||
unless (-d "$installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/$kernelver") {
|
||||
system("rm -rf $rootimg_dir/lib/modules/$basekernelver");
|
||||
unless (-d "$rootimg_dir/lib/modules/$kernelver") {
|
||||
if(-d "/lib/modules/$kernelver") {
|
||||
system("cd /lib/modules;cp -r $kernelver $installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/");
|
||||
system("cd /lib/modules;cp -r $kernelver $rootimg_dir/lib/modules/");
|
||||
}
|
||||
else {
|
||||
xdie("Cannot read /lib/modules/$kernelver");
|
||||
}
|
||||
}
|
||||
}
|
||||
find(\&isnetdriver, <$installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/$kernelver/*>);
|
||||
find(\&isnetdriver, <$rootimg_dir/lib/modules/$kernelver/*>);
|
||||
|
||||
foreach (@filestoadd) {
|
||||
if (ref($_)) {
|
||||
#print "$_->[0], $_->[1]\n";
|
||||
my $srcpath = "$installroot/netboot/$osver/$arch/$profile/rootimg/".$_->[0];
|
||||
my $srcpath = "$rootimg_dir/".$_->[0];
|
||||
if (-f "$customdir/".$_->[0]) {
|
||||
$srcpath="$customdir/".$_->[0];
|
||||
} elsif (-f "$pathtofiles/".$_->[0]) {
|
||||
@ -471,7 +568,7 @@ EOMS
|
||||
chmod 0755,"/tmp/xcatinitrd.$$/".$_->[1];
|
||||
} else {
|
||||
#print "$_\n";
|
||||
my $srcpath = "$installroot/netboot/$osver/$arch/$profile/rootimg/$_";
|
||||
my $srcpath = "$rootimg_dir/$_";
|
||||
if (-f "$customdir/$_") {
|
||||
$srcpath = "$customdir/$_";
|
||||
} elsif (-f "$pathtofiles/$_") {
|
||||
@ -483,8 +580,8 @@ EOMS
|
||||
}
|
||||
}
|
||||
|
||||
#copy("$installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/*d","/tmp/xcatinitrd.$$/$_");
|
||||
system("cd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|gzip -9 -c - > $installroot/netboot/$osver/$arch/$profile/initrd.gz");
|
||||
#copy("$rootimg_dir/lib/modules/*d","/tmp/xcatinitrd.$$/$_");
|
||||
system("cd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|gzip -9 -c - > $destdir/initrd.gz");
|
||||
system("rm -rf /tmp/xcatinitrd.$$");
|
||||
|
||||
}
|
||||
@ -501,7 +598,7 @@ sub isnetdriver {
|
||||
foreach (@ndrivers) {
|
||||
if ($File::Find::name =~ /\/$_/) {
|
||||
my $filetoadd = $File::Find::name;
|
||||
$filetoadd =~ s!$installroot/netboot/$osver/$arch/$profile/rootimg/!!;
|
||||
$filetoadd =~ s!$rootimg_dir/!!;
|
||||
push @filestoadd,[$filetoadd,"lib/$_"];
|
||||
}
|
||||
}
|
||||
@ -517,26 +614,26 @@ sub postscripts { # TODO: customized postscripts
|
||||
generic_post();
|
||||
if (-d "$installroot/postscripts/hostkeys") {
|
||||
for my $key (<$installroot/postscripts/hostkeys/*key>) {
|
||||
copy ($key,"$installroot/netboot/$osver/$arch/$profile/rootimg/etc/ssh/");
|
||||
copy ($key,"$rootimg_dir/etc/ssh/");
|
||||
}
|
||||
chmod 0600,</$installroot/netboot/$osver/$arch/$profile/rootimg/etc/ssh/*key>;
|
||||
chmod 0600,</$rootimg_dir/etc/ssh/*key>;
|
||||
}
|
||||
if (-d "/$installroot/postscripts/.ssh") {
|
||||
mkpath("/$installroot/netboot/$osver/$arch/$profile/rootimg/root/.ssh");
|
||||
chmod(0700,"/$installroot/netboot/$osver/$arch/$profile/rootimg/root/.ssh/");
|
||||
mkpath("/$rootimg_dir/root/.ssh");
|
||||
chmod(0700,"/$rootimg_dir/root/.ssh/");
|
||||
for my $file (</$installroot/postscripts/.ssh/*>) {
|
||||
copy ($file,"/$installroot/netboot/$osver/$arch/$profile/rootimg/root/.ssh/");
|
||||
copy ($file,"/$rootimg_dir/root/.ssh/");
|
||||
}
|
||||
chmod(0600,</$installroot/netboot/$osver/$arch/$profile/rootimg/root/.ssh/*>);
|
||||
chmod(0600,</$rootimg_dir/root/.ssh/*>);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub generic_post { #This function is meant to leave the image in a state approximating a normal install
|
||||
my $cfgfile;
|
||||
unlink("$installroot/netboot/$osver/$arch/$profile/rootimg/dev/null");
|
||||
system("mknod $installroot/netboot/$osver/$arch/$profile/rootimg/dev/null c 1 3");
|
||||
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/fstab");
|
||||
unlink("$rootimg_dir/dev/null");
|
||||
system("mknod $rootimg_dir/dev/null c 1 3");
|
||||
open($cfgfile,">","$rootimg_dir/etc/fstab");
|
||||
print $cfgfile "devpts /dev/pts devpts gid=5,mode=620 0 0\n";
|
||||
print $cfgfile "tmpfs /dev/shm tmpfs defaults 0 0\n";
|
||||
print $cfgfile "proc /proc proc defaults 0 0\n";
|
||||
@ -546,30 +643,30 @@ sub generic_post { #This function is meant to leave the image in a state approxi
|
||||
print $cfgfile "tmpfs /var/tmp tmpfs defaults 0 0\n";
|
||||
}
|
||||
close($cfgfile);
|
||||
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/sysconfig/network");
|
||||
open($cfgfile,">","$rootimg_dir/etc/sysconfig/network");
|
||||
print $cfgfile "NETWORKING=yes\n";
|
||||
close($cfgfile);
|
||||
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/resolv.conf");
|
||||
open($cfgfile,">","$rootimg_dir/etc/resolv.conf");
|
||||
print $cfgfile "#Dummy resolv.conf to make boot cleaner";
|
||||
close($cfgfile);
|
||||
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/sysconfig/network-scripts/ifcfg-$prinic");
|
||||
open($cfgfile,">","$rootimg_dir/etc/sysconfig/network-scripts/ifcfg-$prinic");
|
||||
print $cfgfile "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=$prinic\n";
|
||||
close($cfgfile);
|
||||
foreach (split /,/,$othernics) {
|
||||
if (/^$/) { next; }
|
||||
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/sysconfig/network-scripts/ifcfg-$_");
|
||||
open($cfgfile,">","$rootimg_dir/etc/sysconfig/network-scripts/ifcfg-$_");
|
||||
print $cfgfile "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=$_\n";
|
||||
close($cfgfile);
|
||||
}
|
||||
open($cfgfile,">>","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/securetty");
|
||||
open($cfgfile,">>","$rootimg_dir/etc/securetty");
|
||||
print $cfgfile "ttyS0\n";
|
||||
print $cfgfile "ttyS1\n";
|
||||
close($cfgfile);
|
||||
my @passwd;
|
||||
open($cfgfile,"<","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/passwd");
|
||||
open($cfgfile,"<","$rootimg_dir/etc/passwd");
|
||||
@passwd = <$cfgfile>;
|
||||
close($cfgfile);
|
||||
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/passwd");
|
||||
open($cfgfile,">","$rootimg_dir/etc/passwd");
|
||||
foreach (@passwd) {
|
||||
if (/^root:/) {
|
||||
s/^root:\*/root:x/
|
||||
@ -577,16 +674,16 @@ sub generic_post { #This function is meant to leave the image in a state approxi
|
||||
print $cfgfile $_;
|
||||
}
|
||||
close($cfgfile);
|
||||
foreach (<$installroot/netboot/$osver/$arch/$profile/rootimg/etc/skel/.*>) {
|
||||
foreach (<$rootimg_dir/etc/skel/.*>) {
|
||||
if (basename($_) eq '.' or basename($_) eq '..') {
|
||||
next;
|
||||
}
|
||||
copy $_,"$installroot/netboot/$osver/$arch/$profile/rootimg/root/";
|
||||
copy $_,"$rootimg_dir/root/";
|
||||
}
|
||||
unless ( -r <$installroot/netboot/$osver/$arch/$profile/rootimg/etc/rc3.d/S??network>) {
|
||||
symlink "/etc/init.d/network","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/rc3.d/S10network";
|
||||
unless ( -r <$rootimg_dir/etc/rc3.d/S??network>) {
|
||||
symlink "/etc/init.d/network","$rootimg_dir/etc/rc3.d/S10network";
|
||||
}
|
||||
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/rc3.d/S60gettyset");
|
||||
open($cfgfile,">","$rootimg_dir/etc/rc3.d/S60gettyset");
|
||||
print $cfgfile "#!/bin/bash\n";
|
||||
print $cfgfile "for i in `cat /proc/cmdline`; do\n";
|
||||
print $cfgfile ' KEY=`echo $i|cut -d= -f 1`'."\n";
|
||||
@ -606,16 +703,18 @@ sub generic_post { #This function is meant to leave the image in a state approxi
|
||||
print $cfgfile " fi\n";
|
||||
print $cfgfile "done\n";
|
||||
close($cfgfile);
|
||||
chmod(0755,"$installroot/netboot/$osver/$arch/$profile/rootimg/etc/rc3.d/S60gettyset");
|
||||
#link("$installroot/netboot/$osver/$arch/$profile/rootimg/sbin/init","$installroot/netboot/$osver/$arch/$profile/rootimg/init");
|
||||
chmod(0755,"$rootimg_dir/etc/rc3.d/S60gettyset");
|
||||
#link("$rootimg_dir/sbin/init","$rootimg_dir/init");
|
||||
|
||||
rename(<$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinuz*>,"$installroot/netboot/$osver/$arch/$profile/kernel");
|
||||
rename(<$rootimg_dir/boot/vmlinuz*>,"$destdir/kernel");
|
||||
}
|
||||
|
||||
#get th extra package name
|
||||
sub get_extra_package_names {
|
||||
my $otherpkglist=get_extra_pkglist_file_name($customdir);
|
||||
if (!$otherpkglist) { $otherpkglist=get_extra_pkglist_file_name($pathtofiles); }
|
||||
if (!$imagename) {
|
||||
$otherpkglist=get_extra_pkglist_file_name($customdir);
|
||||
if (!$otherpkglist) { $otherpkglist=get_extra_pkglist_file_name($pathtofiles); }
|
||||
}
|
||||
my %pkgnames=();
|
||||
my @tmp_array=();
|
||||
|
||||
@ -718,4 +817,18 @@ sub get_pkglist_file_name {
|
||||
return "";
|
||||
}
|
||||
|
||||
sub get_postinstall_file_name {
|
||||
my $base=shift;
|
||||
if (-x "$base/$profile.$osver.$arch.postinstall") {
|
||||
return "$base/$profile.$osver.$arch.postinstall";
|
||||
} elsif (-x "$base/$profile.$arch.postinstall") {
|
||||
return "$base/$profile.$arch.postinstall";
|
||||
} elsif (-x "$base/$profile.$osver.postinstall") {
|
||||
return "$base/$profile.$osver.postinstall";
|
||||
} elsif (-x "$base/$profile.postinstall") {
|
||||
return "$base/$profile.postinstall";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,10 @@
|
||||
#!/usr/bin/env perl
|
||||
BEGIN
|
||||
{
|
||||
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
||||
}
|
||||
use lib "$::XCATROOT/lib/perl";
|
||||
|
||||
use File::Basename;
|
||||
use File::Path;
|
||||
use File::Copy;
|
||||
@ -13,11 +19,7 @@ my $prinic; #TODO be flexible on node primary nic
|
||||
my $othernics; #TODO be flexible on node primary nic
|
||||
my $netdriver;
|
||||
my @yumdirs;
|
||||
my $arch = `uname -m`;
|
||||
chomp($arch);
|
||||
if ($arch =~ /i.86$/) {
|
||||
$arch = x86;
|
||||
}
|
||||
my $arch;
|
||||
my %libhash;
|
||||
my @filestoadd;
|
||||
my $profile;
|
||||
@ -36,6 +38,14 @@ my $kernelver = ""; #`uname -r`;
|
||||
my $basekernelver; # = $kernelver;
|
||||
my $customdir=$fullpath;
|
||||
$customdir =~ s/.*share\/xcat/$installroot\/custom/;
|
||||
my $imagename;
|
||||
my $pkglist;
|
||||
my $srcdir;
|
||||
my $destdir;
|
||||
my $srcdir_otherpkgs;
|
||||
my $otherpkglist;
|
||||
my $postinstall_filename;
|
||||
my $rootimg_dir;
|
||||
|
||||
sub xdie {
|
||||
system("rm -rf /tmp/xcatinitrd.$$");
|
||||
@ -69,12 +79,99 @@ GetOptions(
|
||||
't=s' => \$tmplimit,
|
||||
'k=s' => \$kernelver
|
||||
);
|
||||
if (@ARGV > 0) {
|
||||
$imagename=$ARGV[0];
|
||||
if ($arch or $osver or $profile) {
|
||||
print "-o, -p and -a options are not allowed when a image name is specified.\n";
|
||||
exit 1;
|
||||
}
|
||||
#load the module in memory
|
||||
eval {require("$::XCATROOT/lib/perl/xCAT/Table.pm")};
|
||||
if ($@) {
|
||||
print $@;
|
||||
exit 1;
|
||||
}
|
||||
|
||||
#get the info from the osimage and linux
|
||||
my $osimagetab=xCAT::Table->new('osimage', -create=>1);
|
||||
if (!$osimagetab) {
|
||||
print "The osimage table cannot be opened.\n";
|
||||
exit 1;
|
||||
}
|
||||
my $linuximagetab=xCAT::Table->new('linuximage', -create=>1);
|
||||
if (!$linuximagetab) {
|
||||
print "The linuximage table cannot be opened.\n";
|
||||
exit 1;
|
||||
}
|
||||
(my $ref) = $osimagetab->getAttribs({imagename => $imagename}, 'osvers', 'osarch', 'profile', 'provmethod');
|
||||
if (!$ref) {
|
||||
print "Cannot find image \'$imagename\' from the osimage table.\n";
|
||||
exit 1;
|
||||
}
|
||||
(my $ref1) = $linuximagetab->getAttribs({imagename => $imagename}, 'pkglist', 'pkgdir', 'otherpkglist', 'otherpkgdir', 'postinstall', 'rootimgdir');
|
||||
if (!$ref1) {
|
||||
print "Cannot find $imagename from the linuximage table\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
$osver=$ref->{'osvers'};
|
||||
$arch=$ref->{'osarch'};
|
||||
$profile=$ref->{'profile'};
|
||||
my $provmethod=$ref->{'provmethod'};
|
||||
|
||||
unless ($osver and $arch and $profile and $provmethod) {
|
||||
print"osimage.osvers, osimage.osarch, osimage.profile and osimage.provmethod must be specified for the image $imagename in the database.\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
if ($provmethod ne 'netboot') {
|
||||
print "\'$imagename\' cannot be used to build diskless image. Make sure osimage.provmethod is 'netboot'.";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
if (! $ref1->{'pkglist'}) {
|
||||
print"A .pkglist file must be specified for image \'$imagename\' in the linuximage table.\n";
|
||||
exit 0;
|
||||
}
|
||||
$pkglist =$ref1->{'pkglist'};
|
||||
|
||||
$srcdir=$ref1->{'pkgdir'};
|
||||
if ($srcdir) { $srcdir="$srcdir/1"; }
|
||||
$srcdir_otherpkgs=$ref1->{'otherpkgdir'};
|
||||
$otherpkglist=$ref1->{'otherpkglist'};
|
||||
$postinstall_filename=$ref1->{'postinstall'};
|
||||
$destdir=$ref1->{'rootimgdir'};
|
||||
}
|
||||
|
||||
if (!$arch) {
|
||||
my $arch = `uname -m`;
|
||||
chomp($arch);
|
||||
if ($arch =~ /i.86$/) {
|
||||
$arch = "x86";
|
||||
}
|
||||
}
|
||||
|
||||
if (!$srcdir) {
|
||||
$srcdir="$installroot/$osver/$arch/1";
|
||||
}
|
||||
|
||||
if (!$srcdir_otherpkgs) {
|
||||
$srcdir_otherpkgs = "$installroot/post/otherpkgs/$osver/$arch";
|
||||
}
|
||||
|
||||
if (!$destdir)
|
||||
{
|
||||
$destdir="$installroot/netboot/$osver/$arch/$profile";
|
||||
}
|
||||
$rootimg_dir="$destdir/rootimg";
|
||||
|
||||
|
||||
#Default to the first kernel found in the install image if nothing specified explicitly.
|
||||
#A more accurate guess than whatever the image build server happens to be running
|
||||
#If specified, that takes precedence.
|
||||
#if image has one, that is used
|
||||
#if all else fails, resort to uname -r like this script did before
|
||||
my @KVERS= <$installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/*>;
|
||||
my @KVERS= <$rootimg_dir/lib/modules/*>;
|
||||
if (scalar(@KVERS)) {
|
||||
$basekernelver = basename($KVERS[0]);
|
||||
}
|
||||
@ -86,10 +183,12 @@ unless ($kernelver) {
|
||||
}
|
||||
chomp($kernelver);
|
||||
unless ($osver and $profile and $netdriver and $prinic) {
|
||||
print 'Usage: genimage -i <nodebootif> -n <nodenetdrivers> [-r <otherifaces>] -o <OSVER> -p <PROFILE> -k <KERNELVER>'."\n";
|
||||
print 'Usage: genimage -i <nodebootif> -n <nodenetdrivers> [-r <otherifaces>] -k <KERNELVER> -o <OSVER> -p <PROFILE> -a <ARCH>'."\n";
|
||||
print ' genimage -i <nodebootif> -n <nodenetdrivers> [-r <otherifaces>] -k <KERNELVER> <imagename>'."\n";
|
||||
print "Examples:\n";
|
||||
print " genimage -i eth0 -n tg3 -o centos5.1 -p compute\n";
|
||||
print " genimage -i eth0 -r eth1,eth2 -n tg3,bnx2 -o centos5.1 -p compute\n";
|
||||
print " genimage -i eth0 -ntg3 myimagename\n";
|
||||
exit 1;
|
||||
}
|
||||
my @ndrivers;
|
||||
@ -113,60 +212,55 @@ if(`grep VERSION /etc/SuSE-release` =~ /VERSION = (\d+)/) {
|
||||
$osver_host=11;
|
||||
}
|
||||
|
||||
|
||||
unless ($onlyinitrd) {
|
||||
my $srcdir = "$installroot/$osver/$arch/1";
|
||||
my %extra_hash=get_extra_package_names();
|
||||
|
||||
|
||||
#this is for extra packages
|
||||
my $srcdir_otherpkgs = "$installroot/post/otherpkgs/$osver/$arch";
|
||||
my %extra_hash=get_extra_package_names();
|
||||
|
||||
|
||||
mkpath "$installroot/netboot/$osver/$arch/$profile/rootimg/etc";
|
||||
mkpath "$installroot/netboot/$osver/$arch/$profile/rootimg/dev";
|
||||
#system "mount -o bind /dev $installroot/netboot/$osver/$arch/$profile/rootimg/dev";
|
||||
system "mknod $installroot/netboot/$osver/$arch/$profile/rootimg/dev/zero c 1 5";
|
||||
system "mknod $installroot/netboot/$osver/$arch/$profile/rootimg/dev/null c 1 3"; #that's neccessary for SLES11
|
||||
open($fd,">>","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/fstab");
|
||||
mkpath "$rootimg_dir/etc";
|
||||
mkpath "$rootimg_dir/dev";
|
||||
#system "mount -o bind /dev $rootimg_dir/dev";
|
||||
system "mknod $rootimg_dir/dev/zero c 1 5";
|
||||
system "mknod $rootimg_dir/dev/null c 1 3"; #that's neccessary for SLES11
|
||||
open($fd,">>","$rootimg_dir/etc/fstab");
|
||||
print $fd "#Dummy fstab for rpm postscripts to see\n";
|
||||
close($fd);
|
||||
if($osver_host == 11) {#zypper in SLES11 is different
|
||||
my $rootimg_dir="$installroot/netboot/$osver/$arch/$profile/rootimg";
|
||||
if(-e "$rootimg_dir/etc/zypp/repos.d/$osver.repo") {
|
||||
system("rm -rf $rootimg_dir/etc/zypp/repos.d/$osver.repo");
|
||||
}
|
||||
system("zypper -R $rootimg_dir ar file:$srcdir $osver");
|
||||
}else {
|
||||
system("zypper -R $installroot/netboot/$osver/$arch/$profile/rootimg/ sa file:$srcdir");
|
||||
system("zypper -R $rootimg_dir sa file:$srcdir");
|
||||
}
|
||||
|
||||
#remove the old repository for extra packages
|
||||
my $result=`zypper -R /install/netboot/sles11/ppc64/test/rootimg/ sl |grep otherpkg|cut -f2 -d '|'|tr "\n" " "`;
|
||||
if ($result =~ /\S/) {
|
||||
system("zypper -R $installroot/netboot/$osver/$arch/$profile/rootimg/ sd $result");
|
||||
system("zypper -R $rootimg_dir sd $result");
|
||||
}
|
||||
|
||||
#add the new repository for extra packages
|
||||
my $extrapkgnames;
|
||||
if($osver_host == 11) { #SLES11
|
||||
if(-e "$installroot/netboot/$osver/$arch/$profile/rootimg/etc/zypp/repos.d/otherpkg.repo") {
|
||||
system("rm -rf $installroot/netboot/$osver/$arch/$profile/rootimg/etc/zypp/repos.d/otherpkg.repo");
|
||||
if(-e "$rootimg_dir/etc/zypp/repos.d/otherpkg.repo") {
|
||||
system("rm -rf $rootimg_dir/etc/zypp/repos.d/otherpkg.repo");
|
||||
}
|
||||
}
|
||||
my $index=1;
|
||||
foreach (keys(%extra_hash)) {
|
||||
$whole_path="$srcdir_otherpkgs/$_";
|
||||
my $whole_path="$srcdir_otherpkgs/$_";
|
||||
if (-r "$srcdir_otherpkgs/$_/repodata/repomd.xml") {
|
||||
if($osver_host == 11) {
|
||||
system("zypper -R $installroot/netboot/$osver/$arch/$profile/rootimg/ ar file:$srcdir_otherpkgs/$_ otherpkg$index");
|
||||
system("zypper -R $rootimg_dir ar file:$srcdir_otherpkgs/$_ otherpkg$index");
|
||||
}else {
|
||||
system("zypper -R $installroot/netboot/$osver/$arch/$profile/rootimg/ sa file:$srcdir_otherpkgs/$_");
|
||||
system("zypper -R $rootimg_dir sa file:$srcdir_otherpkgs/$_");
|
||||
}
|
||||
} else {
|
||||
if($osver_host == 11) {
|
||||
system("zypper -R $installroot/netboot/$osver/$arch/$profile/rootimg/ ar -t Plaindir file:$srcdir_otherpkgs/$_ otherpkg$index");
|
||||
system("zypper -R $rootimg_dir ar -t Plaindir file:$srcdir_otherpkgs/$_ otherpkg$index");
|
||||
}else {
|
||||
system("zypper -R $installroot/netboot/$osver/$arch/$profile/rootimg/ sa -t Plaindir file:$srcdir_otherpkgs/$_");
|
||||
system("zypper -R $rootimg_dir sa -t Plaindir file:$srcdir_otherpkgs/$_");
|
||||
}
|
||||
}
|
||||
$index++;
|
||||
@ -175,7 +269,9 @@ unless ($onlyinitrd) {
|
||||
$extrapkgnames .= " " . join(' ', @$pa);
|
||||
}
|
||||
|
||||
#-- add custom repositories to the image
|
||||
#-- add custom repositories to the image
|
||||
#TODO: should we add the support to otherpkgs for this? we have too many list files and it seems only SLES supports this
|
||||
my $repolist;
|
||||
if ( -r "$pathtofiles/$profile.$osver.$arch.repolist") {
|
||||
$repolist = "$pathtofiles/$profile.$osver.$arch.repolist";
|
||||
}elsif ( -r "$pathtofiles/$profile.$osver.repolist") {
|
||||
@ -190,24 +286,26 @@ unless ($onlyinitrd) {
|
||||
while (<$repoconfig>) {
|
||||
chomp;
|
||||
next if /^\s*#/;
|
||||
($repotype,$repourl,$repoalias) = split m/\|/;
|
||||
system("zypper -R $installroot/netboot/$osver/$arch/$profile/rootimg/ ar $repourl $repoalias");
|
||||
my ($repotype,$repourl,$repoalias) = split m/\|/;
|
||||
system("zypper -R $rootimg_dir ar $repourl $repoalias");
|
||||
}
|
||||
}
|
||||
|
||||
#my $yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$installroot/netboot/$osver/$arch/$profile/rootimg/ --disablerepo=* ";
|
||||
#my $yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir --disablerepo=* ";
|
||||
#$yumcmd .= "install ";
|
||||
#mkpath("$installroot/netboot/$osver/$arch/$profile/rootimg/var/lib/yum");
|
||||
#mkpath("$rootimg_dir/var/lib/yum");
|
||||
my $yumcmd;
|
||||
if($osver =~ /sles11/ && $osver_host == 11) {
|
||||
$yumcmd = "zypper -R $installroot/netboot/$osver/$arch/$profile/rootimg/ install -l "; #add -l for SLES11
|
||||
$yumcmd = "zypper -R $rootimg_dir install -l "; #add -l for SLES11
|
||||
}else {
|
||||
$yumcmd = "zypper -R $installroot/netboot/$osver/$arch/$profile/rootimg/ install ";
|
||||
$yumcmd = "zypper -R $rootimg_dir install ";
|
||||
}
|
||||
if (!$imagename) {
|
||||
$pkglist= get_pkglist_file_name($customdir);
|
||||
if (!$pkglist) {
|
||||
$pkglist= get_pkglist_file_name($pathtofiles);
|
||||
}
|
||||
}
|
||||
my $pkglist= get_pkglist_file_name($customdir);
|
||||
if (!$pkglist) {
|
||||
$pkglist= get_pkglist_file_name($pathtofiles);
|
||||
}
|
||||
#print "pkglist=$pkglist\n";
|
||||
|
||||
if (!$pkglist) {
|
||||
@ -249,13 +347,15 @@ unless ($onlyinitrd) {
|
||||
unlink "/tmp/genimage.$$.yum.conf";
|
||||
|
||||
#-- run postinstall script
|
||||
my $postinstall_filename= get_postinstall_file_name($customdir);
|
||||
if (!$postinstall_filename) {
|
||||
$postinstall_filename= get_postinstall_file_name($pathtofiles);
|
||||
if (!$imagename) {
|
||||
$postinstall_filename= get_postinstall_file_name($customdir);
|
||||
if (!$postinstall_filename) {
|
||||
$postinstall_filename= get_postinstall_file_name($pathtofiles);
|
||||
}
|
||||
}
|
||||
|
||||
if (($postinstall_filename) && (-x $postinstall_filename)) {
|
||||
my $rc = system($postinstall_filename, "$installroot/netboot/$osver/$arch/$profile/rootimg",$osver,$arch,$profile);
|
||||
my $rc = system($postinstall_filename, $rootimg_dir,$osver,$arch,$profile);
|
||||
if($rc) {
|
||||
print "postinstall script failed\n";
|
||||
exit 1;
|
||||
@ -271,9 +371,9 @@ open MTABFD, "/etc/mtab";
|
||||
my @lines = <MTABFD>;
|
||||
close MTABFD;
|
||||
|
||||
my $ret = grep m{$installroot/netboot/$osver/$arch/$profile/rootimg/proc}, @lines;
|
||||
my $ret = grep m{$rootimg_dir/proc}, @lines;
|
||||
if($ret > 0) {
|
||||
system("umount $installroot/netboot/$osver/$arch/$profile/rootimg/proc");
|
||||
system("umount $rootimg_dir/proc");
|
||||
}
|
||||
|
||||
mkinitrd();
|
||||
@ -281,7 +381,7 @@ mkinitrd();
|
||||
|
||||
sub getlibs {
|
||||
my $file = shift;
|
||||
my $liblist = `chroot $installroot/netboot/$osver/$arch/$profile/rootimg ldd $file`;
|
||||
my $liblist = `chroot $rootimg_dir ldd $file`;
|
||||
my @libs = split/\n/,$liblist;
|
||||
my @return;
|
||||
foreach (@libs) {
|
||||
@ -304,21 +404,21 @@ sub getlibs {
|
||||
sub mkinitrd {
|
||||
mkpath("/tmp/xcatinitrd.$$/bin");
|
||||
if($basekernelver eq $kernelver) {
|
||||
if (-f "$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinuz-$kernelver") {
|
||||
rename(<$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinuz*>,"$installroot/netboot/$osver/$arch/$profile/kernel");
|
||||
} elsif (-f "$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinux-$kernelver"){
|
||||
rename(<$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinux*>,"$installroot/netboot/$osver/$arch/$profile/kernel");
|
||||
if (-f "$rootimg_dir/boot/vmlinuz-$kernelver") {
|
||||
rename(<$rootimg_dir/boot/vmlinuz*>,"$destdir/kernel");
|
||||
} elsif (-f "$rootimg_dir/boot/vmlinux-$kernelver"){
|
||||
rename(<$rootimg_dir/boot/vmlinux*>,"$destdir/kernel");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(-r "$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinuz-$kernelver") {
|
||||
rename("$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinuz-$kernelver","$installroot/netboot/$osver/$arch/$profile/kernel");
|
||||
} elsif(-r "$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinux-$kernelver") {
|
||||
rename("$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinux-$kernelver","$installroot/netboot/$osver/$arch/$profile/kernel");
|
||||
if(-r "$rootimg_dir/boot/vmlinuz-$kernelver") {
|
||||
rename("$rootimg_dir/boot/vmlinuz-$kernelver","$destdir/kernel");
|
||||
} elsif(-r "$rootimg_dir/boot/vmlinux-$kernelver") {
|
||||
rename("$rootimg_dir/boot/vmlinux-$kernelver","$destdir/kernel");
|
||||
} elsif(-r "/boot/vmlinuz-$kernelver") {
|
||||
copy("/boot/vmlinuz-$kernelver","$installroot/netboot/$osver/$arch/$profile/kernel");
|
||||
copy("/boot/vmlinuz-$kernelver","$destdir/kernel");
|
||||
} elsif(-r "/boot/vmlinux-$kernelver") {#for SLES10,11
|
||||
copy("/boot/vmlinux-$kernelver","$installroot/netboot/$osver/$arch/$profile/kernel");
|
||||
copy("/boot/vmlinux-$kernelver","$destdir/kernel");
|
||||
}
|
||||
else {
|
||||
xdie("Cannot read /boot/vmlinuz-$kernelver");
|
||||
@ -531,21 +631,21 @@ END
|
||||
}
|
||||
push @filestoadd,keys %libhash;
|
||||
if($basekernelver ne $kernelver) {
|
||||
system("rm -rf $installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/$basekernelver");
|
||||
unless (-d "$installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/$kernelver") {
|
||||
system("rm -rf $rootimg_dir/lib/modules/$basekernelver");
|
||||
unless (-d "$rootimg_dir/lib/modules/$kernelver") {
|
||||
if(-d "/lib/modules/$kernelver") {
|
||||
system("cd /lib/modules;cp -r $kernelver $installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/");
|
||||
system("cd /lib/modules;cp -r $kernelver $rootimg_dir/lib/modules/");
|
||||
}
|
||||
else {
|
||||
xdie("Cannot read /lib/modules/$kernelver");
|
||||
}
|
||||
}
|
||||
}
|
||||
find(\&isnetdriver, <$installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/$kernelver/*>);
|
||||
find(\&isnetdriver, <$rootimg_dir/lib/modules/$kernelver/*>);
|
||||
foreach (@filestoadd) {
|
||||
if (ref($_)) {
|
||||
#print "$_->[0], $_->[1]\n";
|
||||
my $srcpath = "$installroot/netboot/$osver/$arch/$profile/rootimg/".$_->[0];
|
||||
my $srcpath = "$rootimg_dir".$_->[0];
|
||||
if (-f "$customdir/".$_->[0]) {
|
||||
$srcpath="$customdir/".$_->[0];
|
||||
} elsif (-f "$pathtofiles/".$_->[0]) {
|
||||
@ -555,7 +655,7 @@ END
|
||||
chmod 0755,"/tmp/xcatinitrd.$$/".$_->[1];
|
||||
} else {
|
||||
#print "$_\n";
|
||||
my $srcpath = "$installroot/netboot/$osver/$arch/$profile/rootimg/$_";
|
||||
my $srcpath = "$rootimg_dir/$_";
|
||||
if (-f "$customdir/$_") {
|
||||
$srcpath = "$customdir/$_";
|
||||
} elsif (-f "$pathtofiles/$_") {
|
||||
@ -566,9 +666,9 @@ END
|
||||
}
|
||||
}
|
||||
|
||||
#copy("$installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/*d","/tmp/xcatinitrd.$$/$_");
|
||||
#copy("$rootimg_dir/lib/modules/*d","/tmp/xcatinitrd.$$/$_");
|
||||
system("cd /tmp/xcatinitrd.$$/bin/; ln -sf bash sh"); #neccessary for SLES11
|
||||
system("cd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|gzip -9 -c - > $installroot/netboot/$osver/$arch/$profile/initrd.gz");
|
||||
system("cd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|gzip -9 -c - > $destdir/initrd.gz");
|
||||
system("rm -rf /tmp/xcatinitrd.$$");
|
||||
|
||||
}
|
||||
@ -585,7 +685,7 @@ sub isnetdriver {
|
||||
foreach (@ndrivers) {
|
||||
if ($File::Find::name =~ /\/$_/) {
|
||||
my $filetoadd = $File::Find::name;
|
||||
$filetoadd =~ s!$installroot/netboot/$osver/$arch/$profile/rootimg/!!;
|
||||
$filetoadd =~ s!$rootimg_dir!!;
|
||||
push @filestoadd,[$filetoadd,"lib/$_"];
|
||||
}
|
||||
}
|
||||
@ -601,26 +701,26 @@ sub postscripts { # TODO: customized postscripts
|
||||
generic_post();
|
||||
if (-d "$installroot/postscripts/hostkeys") {
|
||||
for my $key (<$installroot/postscripts/hostkeys/*key>) {
|
||||
copy ($key,"$installroot/netboot/$osver/$arch/$profile/rootimg/etc/ssh/");
|
||||
copy ($key,"$rootimg_dir/etc/ssh/");
|
||||
}
|
||||
chmod 0600,</$installroot/netboot/$osver/$arch/$profile/rootimg/etc/ssh/*key>;
|
||||
chmod 0600,<$rootimg_dir/etc/ssh/*key>;
|
||||
}
|
||||
if (-d "/$installroot/postscripts/.ssh") {
|
||||
mkpath("/$installroot/netboot/$osver/$arch/$profile/rootimg/root/.ssh");
|
||||
chmod(0700,"/$installroot/netboot/$osver/$arch/$profile/rootimg/root/.ssh/");
|
||||
mkpath("$rootimg_dir/root/.ssh");
|
||||
chmod(0700,"$rootimg_dir/root/.ssh/");
|
||||
for my $file (</$installroot/postscripts/.ssh/*>) {
|
||||
copy ($file,"/$installroot/netboot/$osver/$arch/$profile/rootimg/root/.ssh/");
|
||||
copy ($file,"$rootimg_dir/root/.ssh/");
|
||||
}
|
||||
chmod(0600,</$installroot/netboot/$osver/$arch/$profile/rootimg/root/.ssh/*>);
|
||||
chmod(0600,<$rootimg_dir/root/.ssh/*>);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub generic_post { #This function is meant to leave the image in a state approximating a normal install
|
||||
my $cfgfile;
|
||||
unlink("$installroot/netboot/$osver/$arch/$profile/rootimg/dev/null");
|
||||
system("mknod $installroot/netboot/$osver/$arch/$profile/rootimg/dev/null c 1 3");
|
||||
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/fstab");
|
||||
unlink("$rootimg_dir/dev/null");
|
||||
system("mknod $rootimg_dir/dev/null c 1 3");
|
||||
open($cfgfile,">","$rootimg_dir/etc/fstab");
|
||||
print $cfgfile "devpts /dev/pts devpts gid=5,mode=620 0 0\n";
|
||||
print $cfgfile "tmpfs /dev/shm tmpfs defaults 0 0\n";
|
||||
print $cfgfile "proc /proc proc defaults 0 0\n";
|
||||
@ -630,31 +730,31 @@ sub generic_post { #This function is meant to leave the image in a state approxi
|
||||
print $cfgfile "tmpfs /var/tmp tmpfs defaults 0 0\n";
|
||||
}
|
||||
close($cfgfile);
|
||||
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/sysconfig/network");
|
||||
open($cfgfile,">","$rootimg_dir/etc/sysconfig/network");
|
||||
print $cfgfile "NETWORKING=yes\n";
|
||||
close($cfgfile);
|
||||
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/resolv.conf");
|
||||
open($cfgfile,">","$rootimg_dir/etc/resolv.conf");
|
||||
print $cfgfile "#Dummy resolv.conf to make boot cleaner";
|
||||
close($cfgfile);
|
||||
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/sysconfig/network-scripts/ifcfg-$prinic");
|
||||
open($cfgfile,">","$rootimg_dir/etc/sysconfig/network-scripts/ifcfg-$prinic");
|
||||
print $cfgfile "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=$prinic\n";
|
||||
close($cfgfile);
|
||||
foreach (split /,/,$othernics) {
|
||||
if (/^$/) { next; }
|
||||
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/sysconfig/network-scripts/ifcfg-$_");
|
||||
open($cfgfile,">","$rootimg_dir/etc/sysconfig/network-scripts/ifcfg-$_");
|
||||
print $cfgfile "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=$_\n";
|
||||
close($cfgfile);
|
||||
}
|
||||
open($cfgfile,">>","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/securetty");
|
||||
open($cfgfile,">>","$rootimg_dir/etc/securetty");
|
||||
print $cfgfile "ttyS0\n";
|
||||
print $cfgfile "ttyS1\n";
|
||||
print $cfgfile "console\n";
|
||||
close($cfgfile);
|
||||
my @passwd;
|
||||
open($cfgfile,"<","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/passwd");
|
||||
open($cfgfile,"<","$rootimg_dir/etc/passwd");
|
||||
@passwd = <$cfgfile>;
|
||||
close($cfgfile);
|
||||
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/passwd");
|
||||
open($cfgfile,">","$rootimg_dir/etc/passwd");
|
||||
foreach (@passwd) {
|
||||
if (/^root:/) {
|
||||
s/^root:\*/root:x/
|
||||
@ -662,13 +762,13 @@ sub generic_post { #This function is meant to leave the image in a state approxi
|
||||
print $cfgfile $_;
|
||||
}
|
||||
close($cfgfile);
|
||||
foreach (<$installroot/netboot/$osver/$arch/$profile/rootimg/etc/skel/.*>) {
|
||||
foreach (<$rootimg_dir/etc/skel/.*>) {
|
||||
if (basename($_) eq '.' or basename($_) eq '..') {
|
||||
next;
|
||||
}
|
||||
copy $_,"$installroot/netboot/$osver/$arch/$profile/rootimg/root/";
|
||||
copy $_,"$rootimg_dir/root/";
|
||||
}
|
||||
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/init.d/gettyset");
|
||||
open($cfgfile,">","$rootimg_dir/etc/init.d/gettyset");
|
||||
print $cfgfile "#!/bin/bash\n";
|
||||
print $cfgfile "for i in `cat /proc/cmdline`; do\n";
|
||||
print $cfgfile ' KEY=`echo $i|cut -d= -f 1`'."\n";
|
||||
@ -686,29 +786,31 @@ sub generic_post { #This function is meant to leave the image in a state approxi
|
||||
print $cfgfile "/etc/init.d/boot.localnet start\n";
|
||||
print $cfgfile "/opt/xcat/xcatdsklspost\n";
|
||||
close($cfgfile);
|
||||
chmod(0755,"$installroot/netboot/$osver/$arch/$profile/rootimg/etc/init.d/gettyset");
|
||||
#link("$installroot/netboot/$osver/$arch/$profile/rootimg/sbin/init","$installroot/netboot/$osver/$arch/$profile/rootimg/init");
|
||||
my $rc = system("grep sshd $installroot/netboot/$osver/$arch/$profile/rootimg/etc/init.d/.depend.start");
|
||||
chmod(0755,"$rootimg_dir/etc/init.d/gettyset");
|
||||
#link("$rootimg_dir/sbin/init","$rootimg_dir/init");
|
||||
my $rc = system("grep sshd $rootimg_dir/etc/init.d/.depend.start");
|
||||
if ($rc) {
|
||||
system("sed -i '".'s/^\(TARGETS = .*\)$/\1 sshd/'."' $installroot/netboot/$osver/$arch/$profile/rootimg/etc/init.d/.depend.start");
|
||||
system("ln -s ../sshd $installroot/netboot/$osver/$arch/$profile/rootimg/etc/init.d/rc3.d/S20sshd");
|
||||
system("sed -i '".'s/^\(TARGETS = .*\)$/\1 sshd/'."' $rootimg_dir/etc/init.d/.depend.start");
|
||||
system("ln -s ../sshd $rootimg_dir/etc/init.d/rc3.d/S20sshd");
|
||||
}
|
||||
my $rc = system("grep gettyset $installroot/netboot/$osver/$arch/$profile/rootimg/etc/init.d/.depend.start");
|
||||
my $rc = system("grep gettyset $rootimg_dir/etc/init.d/.depend.start");
|
||||
if ($rc) {
|
||||
system("sed -i '".'s/^\(TARGETS = .*\)$/\1 gettyset/'."' $installroot/netboot/$osver/$arch/$profile/rootimg/etc/init.d/.depend.start");
|
||||
system("ln -s ../gettyset $installroot/netboot/$osver/$arch/$profile/rootimg/etc/init.d/rc3.d/S60gettyset");
|
||||
system("sed -i '".'s/^\(TARGETS = .*\)$/\1 gettyset/'."' $rootimg_dir/etc/init.d/.depend.start");
|
||||
system("ln -s ../gettyset $rootimg_dir/etc/init.d/rc3.d/S60gettyset");
|
||||
}
|
||||
if(($osver =~ /sles11/) || ($osver =~ /sles10/)) {#for sles11,sles10
|
||||
rename(<$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinux*>,"$installroot/netboot/$osver/$arch/$profile/kernel");
|
||||
rename(<$rootimg_dir/boot/vmlinux*>,"$destdir/kernel");
|
||||
}else {
|
||||
rename(<$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinuz*>,"$installroot/netboot/$osver/$arch/$profile/kernel");
|
||||
rename(<$rootimg_dir/boot/vmlinuz*>,"$destdir/kernel");
|
||||
}
|
||||
}
|
||||
|
||||
#get th extra package name
|
||||
sub get_extra_package_names {
|
||||
my $otherpkglist=get_extra_pkglist_file_name($customdir);
|
||||
if (!$otherpkglist) { $otherpkglist=get_extra_pkglist_file_name($pathtofiles); }
|
||||
if (!$imagename) {
|
||||
$otherpkglist=get_extra_pkglist_file_name($customdir);
|
||||
if (!$otherpkglist) { $otherpkglist=get_extra_pkglist_file_name($pathtofiles); }
|
||||
}
|
||||
my %pkgnames=();
|
||||
my @tmp_array=();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user