2008-05-24 17:29:40 +00:00
|
|
|
#!/usr/bin/env perl
|
2009-09-24 18:51:53 +00:00
|
|
|
BEGIN
|
|
|
|
{
|
|
|
|
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
|
|
|
}
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
|
|
|
|
2008-05-24 17:29:40 +00:00
|
|
|
use File::Basename;
|
|
|
|
use File::Path;
|
|
|
|
use File::Copy;
|
|
|
|
use File::Find;
|
|
|
|
use Getopt::Long;
|
2008-09-11 22:03:01 +00:00
|
|
|
use Cwd qw(realpath);
|
2008-05-24 17:29:40 +00:00
|
|
|
#use strict;
|
|
|
|
Getopt::Long::Configure("bundling");
|
|
|
|
Getopt::Long::Configure("pass_through");
|
|
|
|
|
|
|
|
my $prinic; #TODO be flexible on node primary nic
|
|
|
|
my $othernics; #TODO be flexible on node primary nic
|
|
|
|
my $netdriver;
|
|
|
|
my @yumdirs;
|
2009-09-24 18:51:53 +00:00
|
|
|
my $arch;
|
2008-05-24 17:29:40 +00:00
|
|
|
my %libhash;
|
|
|
|
my @filestoadd;
|
|
|
|
my $profile;
|
|
|
|
my $osver;
|
|
|
|
my $pathtofiles=dirname($0);
|
2008-09-11 22:03:01 +00:00
|
|
|
my $fullpath=realpath($pathtofiles);
|
2008-05-24 17:29:40 +00:00
|
|
|
my $name = basename($0);
|
|
|
|
my $onlyinitrd=0;
|
|
|
|
if ($name =~ /geninitrd/) {
|
|
|
|
$onlyinitrd=1;
|
|
|
|
}
|
|
|
|
my $rootlimit;
|
|
|
|
my $tmplimit;
|
|
|
|
my $installroot = "/install";
|
|
|
|
my $kernelver = ""; #`uname -r`;
|
|
|
|
my $basekernelver; # = $kernelver;
|
2008-09-11 22:03:01 +00:00
|
|
|
my $customdir=$fullpath;
|
|
|
|
$customdir =~ s/.*share\/xcat/$installroot\/custom/;
|
2009-09-24 18:51:53 +00:00
|
|
|
my $imagename;
|
|
|
|
my $pkglist;
|
|
|
|
my $srcdir;
|
|
|
|
my $destdir;
|
|
|
|
my $srcdir_otherpkgs;
|
|
|
|
my $otherpkglist;
|
|
|
|
my $postinstall_filename;
|
|
|
|
my $rootimg_dir;
|
2008-05-24 17:29:40 +00:00
|
|
|
|
|
|
|
sub xdie {
|
|
|
|
system("rm -rf /tmp/xcatinitrd.$$");
|
|
|
|
die @_;
|
|
|
|
}
|
|
|
|
|
2008-09-10 14:59:34 +00:00
|
|
|
#-- fetch current version form CVS (overwrite locally changed versions)
|
|
|
|
# if (opendir(CVS,"$pathtofiles/CVS")){
|
|
|
|
# close CVS;
|
|
|
|
# my $cvsout = qx/cd $pathtofiles; cvs update -C 2>&1/;
|
|
|
|
# chomp $cvsout;
|
|
|
|
# if ( $cvsout ne "cvs update: Updating ." ) {
|
|
|
|
# print "Difference of local copy from CVS detected\n";
|
|
|
|
# print $cvsout,"\n";
|
|
|
|
# print "Trying to re-run $name\n";
|
|
|
|
# print("$pathtofiles/$name ",join(" ",@ARGV),"\n");
|
|
|
|
# exec("$pathtofiles/$name",@ARGV);
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
2008-05-24 17:29:40 +00:00
|
|
|
$SIG{INT} = $SIG{TERM} = sub { xdie "Interrupted" };
|
|
|
|
GetOptions(
|
|
|
|
'a=s' => \$arch,
|
|
|
|
'p=s' => \$profile,
|
|
|
|
'o=s' => \$osver,
|
|
|
|
'n=s' => \$netdriver,
|
|
|
|
'i=s' => \$prinic,
|
|
|
|
'r=s' => \$othernics,
|
|
|
|
'l=s' => \$rootlimit,
|
|
|
|
't=s' => \$tmplimit,
|
|
|
|
'k=s' => \$kernelver
|
|
|
|
);
|
2009-09-24 18:51:53 +00:00
|
|
|
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";
|
|
|
|
|
|
|
|
|
2008-05-24 17:29:40 +00:00
|
|
|
#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
|
2009-09-24 18:51:53 +00:00
|
|
|
my @KVERS= <$rootimg_dir/lib/modules/*>;
|
2008-05-24 17:29:40 +00:00
|
|
|
if (scalar(@KVERS)) {
|
|
|
|
$basekernelver = basename($KVERS[0]);
|
|
|
|
}
|
|
|
|
unless ($basekernelver) {
|
|
|
|
$basekernelver = `uname -r`;
|
|
|
|
}
|
|
|
|
unless ($kernelver) {
|
|
|
|
$kernelver=$basekernelver;
|
|
|
|
}
|
|
|
|
chomp($kernelver);
|
|
|
|
unless ($osver and $profile and $netdriver and $prinic) {
|
2009-09-24 18:51:53 +00:00
|
|
|
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";
|
2008-05-24 17:29:40 +00:00
|
|
|
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";
|
2009-09-24 18:51:53 +00:00
|
|
|
print " genimage -i eth0 -ntg3 myimagename\n";
|
2008-05-24 17:29:40 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
my @ndrivers;
|
|
|
|
foreach (split /,/,$netdriver) {
|
|
|
|
unless (/\.ko$/) {
|
|
|
|
s/$/.ko/;
|
|
|
|
}
|
|
|
|
if (/^$/) {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
push @ndrivers,$_;
|
|
|
|
}
|
2008-05-26 16:11:24 +00:00
|
|
|
unless (grep /af_packet/,@ndrivers) {
|
|
|
|
unshift(@ndrivers,"af_packet.ko");
|
|
|
|
}
|
2008-05-24 17:29:40 +00:00
|
|
|
|
2009-02-18 13:43:11 +00:00
|
|
|
my $osver_host;
|
|
|
|
if(`grep VERSION /etc/SuSE-release` =~ /VERSION = (\d+)/) {
|
|
|
|
$osver_host=$1;
|
|
|
|
} else {
|
|
|
|
$osver_host=11;
|
|
|
|
}
|
|
|
|
|
2008-09-09 23:52:04 +00:00
|
|
|
|
2009-09-24 18:51:53 +00:00
|
|
|
unless ($onlyinitrd) {
|
2009-10-06 20:21:11 +00:00
|
|
|
my %extra_hash=get_extra_package_names();
|
2008-09-09 23:52:04 +00:00
|
|
|
|
|
|
|
|
2009-09-24 18:51:53 +00:00
|
|
|
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");
|
2008-05-24 17:29:40 +00:00
|
|
|
print $fd "#Dummy fstab for rpm postscripts to see\n";
|
|
|
|
close($fd);
|
2009-02-18 13:43:11 +00:00
|
|
|
if($osver_host == 11) {#zypper in SLES11 is different
|
2009-02-12 12:04:51 +00:00
|
|
|
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 {
|
2009-09-24 18:51:53 +00:00
|
|
|
system("zypper -R $rootimg_dir sa file:$srcdir");
|
2009-02-12 12:04:51 +00:00
|
|
|
}
|
2008-09-09 23:52:04 +00:00
|
|
|
|
2009-07-02 20:24:27 +00:00
|
|
|
#remove the old repository for extra packages
|
2009-10-06 20:21:11 +00:00
|
|
|
my $result=`zypper -R $rootimg_dir sl |grep otherpkg|cut -f2 -d '|'|tr "\n" " "`;
|
2009-07-02 20:24:27 +00:00
|
|
|
if ($result =~ /\S/) {
|
2009-09-24 18:51:53 +00:00
|
|
|
system("zypper -R $rootimg_dir sd $result");
|
2009-07-02 20:24:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#add the new repository for extra packages
|
|
|
|
my $extrapkgnames;
|
|
|
|
if($osver_host == 11) { #SLES11
|
2009-09-24 18:51:53 +00:00
|
|
|
if(-e "$rootimg_dir/etc/zypp/repos.d/otherpkg.repo") {
|
|
|
|
system("rm -rf $rootimg_dir/etc/zypp/repos.d/otherpkg.repo");
|
2009-07-02 20:24:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
my $index=1;
|
|
|
|
foreach (keys(%extra_hash)) {
|
2009-10-06 20:21:11 +00:00
|
|
|
if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE")) { next;}
|
2009-09-24 18:51:53 +00:00
|
|
|
my $whole_path="$srcdir_otherpkgs/$_";
|
2009-07-02 20:24:27 +00:00
|
|
|
if (-r "$srcdir_otherpkgs/$_/repodata/repomd.xml") {
|
|
|
|
if($osver_host == 11) {
|
2009-09-24 18:51:53 +00:00
|
|
|
system("zypper -R $rootimg_dir ar file:$srcdir_otherpkgs/$_ otherpkg$index");
|
2009-07-02 20:24:27 +00:00
|
|
|
}else {
|
2009-09-24 18:51:53 +00:00
|
|
|
system("zypper -R $rootimg_dir sa file:$srcdir_otherpkgs/$_");
|
2009-07-02 20:24:27 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if($osver_host == 11) {
|
2009-09-24 18:51:53 +00:00
|
|
|
system("zypper -R $rootimg_dir ar -t Plaindir file:$srcdir_otherpkgs/$_ otherpkg$index");
|
2009-07-02 20:24:27 +00:00
|
|
|
}else {
|
2009-09-24 18:51:53 +00:00
|
|
|
system("zypper -R $rootimg_dir sa -t Plaindir file:$srcdir_otherpkgs/$_");
|
2009-07-02 20:24:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$index++;
|
|
|
|
|
|
|
|
my $pa=$extra_hash{$_};
|
|
|
|
$extrapkgnames .= " " . join(' ', @$pa);
|
2008-09-09 23:52:04 +00:00
|
|
|
}
|
|
|
|
|
2009-09-24 18:51:53 +00:00
|
|
|
#-- 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;
|
2009-04-08 07:37:35 +00:00
|
|
|
if ( -r "$pathtofiles/$profile.$osver.$arch.repolist") {
|
|
|
|
$repolist = "$pathtofiles/$profile.$osver.$arch.repolist";
|
|
|
|
}elsif ( -r "$pathtofiles/$profile.$osver.repolist") {
|
|
|
|
$repolist = "$pathtofiles/$profile.$osver.repolist";
|
|
|
|
}elsif ( -r "$pathtofiles/$profile.repolist") {
|
|
|
|
$repolist = "$pathtofiles/$profile.repolist";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( -r "$repolist") {
|
2008-09-10 14:38:27 +00:00
|
|
|
print "Reading custom repositories\n";
|
|
|
|
open($repoconfig,"<","$repolist");
|
|
|
|
while (<$repoconfig>) {
|
|
|
|
chomp;
|
|
|
|
next if /^\s*#/;
|
2009-09-24 18:51:53 +00:00
|
|
|
my ($repotype,$repourl,$repoalias) = split m/\|/;
|
|
|
|
system("zypper -R $rootimg_dir ar $repourl $repoalias");
|
2008-09-10 14:38:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-24 18:51:53 +00:00
|
|
|
#my $yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir --disablerepo=* ";
|
2008-05-24 17:29:40 +00:00
|
|
|
#$yumcmd .= "install ";
|
2009-09-24 18:51:53 +00:00
|
|
|
#mkpath("$rootimg_dir/var/lib/yum");
|
2009-02-12 12:04:51 +00:00
|
|
|
my $yumcmd;
|
2009-02-18 13:43:11 +00:00
|
|
|
if($osver =~ /sles11/ && $osver_host == 11) {
|
2009-09-24 18:51:53 +00:00
|
|
|
$yumcmd = "zypper -R $rootimg_dir install -l "; #add -l for SLES11
|
2009-02-12 12:04:51 +00:00
|
|
|
}else {
|
2009-09-24 18:51:53 +00:00
|
|
|
$yumcmd = "zypper -R $rootimg_dir install ";
|
|
|
|
}
|
|
|
|
if (!$imagename) {
|
|
|
|
$pkglist= get_pkglist_file_name($customdir);
|
|
|
|
if (!$pkglist) {
|
|
|
|
$pkglist= get_pkglist_file_name($pathtofiles);
|
|
|
|
}
|
2009-02-12 12:04:51 +00:00
|
|
|
}
|
2008-09-11 22:03:01 +00:00
|
|
|
#print "pkglist=$pkglist\n";
|
|
|
|
|
|
|
|
if (!$pkglist) {
|
2008-05-24 17:29:40 +00:00
|
|
|
print "Unable to find package list for $profile!";
|
2009-02-16 22:12:03 +00:00
|
|
|
exit 1;
|
2008-05-24 17:29:40 +00:00
|
|
|
}
|
2008-09-11 22:03:01 +00:00
|
|
|
|
2009-04-23 19:12:33 +00:00
|
|
|
my $pkgnames;
|
2008-05-24 17:29:40 +00:00
|
|
|
open($yumconfig,"<","$pkglist");
|
|
|
|
while (<$yumconfig>) {
|
2008-09-10 14:16:15 +00:00
|
|
|
chomp;
|
|
|
|
s/\s*#.*//; #-- remove comments
|
|
|
|
next if /^\s*$/; #-- skip empty lines
|
2009-04-23 19:12:33 +00:00
|
|
|
$pkgnames .= $_ . " ";
|
2008-05-24 17:29:40 +00:00
|
|
|
}
|
2008-09-09 21:08:48 +00:00
|
|
|
close($yumconfig);
|
2009-04-23 19:12:33 +00:00
|
|
|
|
2008-09-09 21:08:48 +00:00
|
|
|
|
2009-04-23 19:12:33 +00:00
|
|
|
#$yumcmd =~ s/ $/\n/;
|
|
|
|
#print "$yumcmd $pkgnames\n";
|
|
|
|
my $rc = system("$yumcmd $pkgnames");
|
2008-05-24 17:29:40 +00:00
|
|
|
if ($rc) {
|
|
|
|
print "zypper invocation failed\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
2009-04-23 19:12:33 +00:00
|
|
|
|
2009-10-06 20:21:11 +00:00
|
|
|
#remove the packages that are specified in the otherpkgs.list files with leading '-'
|
|
|
|
my $yumcmd_remove= "zypper -R $rootimg_dir remove ";
|
|
|
|
if ((%extra_hash) && (exists ($extra_hash{'PRE_REMOVE'}))) {
|
|
|
|
my $pa=$extra_hash{'PRE_REMOVE'};
|
|
|
|
my $rm_packges= join(' ', @$pa);
|
|
|
|
if ($rm_packges) {
|
|
|
|
$rc = system("$yumcmd_remove $rm_packges");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-23 19:12:33 +00:00
|
|
|
#add extra packages in the list
|
|
|
|
if ($extrapkgnames) {
|
|
|
|
#print "$yumcmd $extrapkgnames\n";
|
|
|
|
$rc = system("$yumcmd $extrapkgnames");
|
|
|
|
if ($rc) {
|
|
|
|
print "zypper invocation failed\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-06 20:21:11 +00:00
|
|
|
#remove the packages that are specified in the otherpkgs.list files with leading '--'
|
|
|
|
if ((%extra_hash) && (exists ($extra_hash{'POST_REMOVE'}))) {
|
|
|
|
my $pa=$extra_hash{'POST_REMOVE'};
|
|
|
|
my $rm_packges= join(' ', @$pa);
|
|
|
|
if ($rm_packges) {
|
|
|
|
$rc = system("$yumcmd_remove $rm_packges");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-24 17:29:40 +00:00
|
|
|
postscripts(); #run 'postscripts'
|
|
|
|
}
|
|
|
|
unlink "/tmp/genimage.$$.yum.conf";
|
2008-09-10 14:32:35 +00:00
|
|
|
|
|
|
|
#-- run postinstall script
|
2009-09-24 18:51:53 +00:00
|
|
|
if (!$imagename) {
|
|
|
|
$postinstall_filename= get_postinstall_file_name($customdir);
|
|
|
|
if (!$postinstall_filename) {
|
|
|
|
$postinstall_filename= get_postinstall_file_name($pathtofiles);
|
|
|
|
}
|
2009-04-23 14:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (($postinstall_filename) && (-x $postinstall_filename)) {
|
2009-09-24 18:51:53 +00:00
|
|
|
my $rc = system($postinstall_filename, $rootimg_dir,$osver,$arch,$profile);
|
2009-02-18 13:43:11 +00:00
|
|
|
if($rc) {
|
|
|
|
print "postinstall script failed\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
}
|
2009-04-23 14:13:56 +00:00
|
|
|
|
2009-04-23 19:12:33 +00:00
|
|
|
#some rpms mounts the imageroot/proc on the /proc, need to release it,
|
|
|
|
#otherwise got kernal panic when installing
|
2009-08-13 08:36:38 +00:00
|
|
|
#sometimes, the proc fs is not mounted, so one warning/error message will display,
|
|
|
|
#and I add one check point here.
|
|
|
|
my $MTABFD;
|
|
|
|
open MTABFD, "/etc/mtab";
|
|
|
|
my @lines = <MTABFD>;
|
|
|
|
close MTABFD;
|
|
|
|
|
2009-09-24 18:51:53 +00:00
|
|
|
my $ret = grep m{$rootimg_dir/proc}, @lines;
|
2009-08-13 08:36:38 +00:00
|
|
|
if($ret > 0) {
|
2009-09-24 18:51:53 +00:00
|
|
|
system("umount $rootimg_dir/proc");
|
2009-08-13 08:36:38 +00:00
|
|
|
}
|
2008-09-10 14:32:35 +00:00
|
|
|
|
2008-05-24 17:29:40 +00:00
|
|
|
mkinitrd();
|
|
|
|
|
2009-04-23 19:12:33 +00:00
|
|
|
|
2008-05-24 17:29:40 +00:00
|
|
|
sub getlibs {
|
|
|
|
my $file = shift;
|
2009-09-24 18:51:53 +00:00
|
|
|
my $liblist = `chroot $rootimg_dir ldd $file`;
|
2008-05-24 17:29:40 +00:00
|
|
|
my @libs = split/\n/,$liblist;
|
|
|
|
my @return;
|
|
|
|
foreach (@libs) {
|
|
|
|
unless (/=>/) {
|
|
|
|
(my $wjnk, my $lib,my $jnk) = split /\s+/,$_,3;
|
|
|
|
$lib =~ s/^\///;
|
|
|
|
$libhash{$lib}=1;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
(my $temp1,my $temp2) = split />/,$_,2;
|
|
|
|
(my $whitespace,$temp1,$temp2) = split /\s+/,$temp2,4;
|
|
|
|
unless ($temp1 =~ /\//) {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
$temp1 =~ s/^\///;
|
|
|
|
$libhash{$temp1}=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub mkinitrd {
|
|
|
|
mkpath("/tmp/xcatinitrd.$$/bin");
|
|
|
|
if($basekernelver eq $kernelver) {
|
2009-09-24 18:51:53 +00:00
|
|
|
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");
|
2009-02-16 22:12:03 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-24 17:29:40 +00:00
|
|
|
else {
|
2009-09-24 18:51:53 +00:00
|
|
|
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");
|
2009-02-18 13:43:11 +00:00
|
|
|
} elsif(-r "/boot/vmlinuz-$kernelver") {
|
2009-09-24 18:51:53 +00:00
|
|
|
copy("/boot/vmlinuz-$kernelver","$destdir/kernel");
|
2009-02-16 22:12:03 +00:00
|
|
|
} elsif(-r "/boot/vmlinux-$kernelver") {#for SLES10,11
|
2009-09-24 18:51:53 +00:00
|
|
|
copy("/boot/vmlinux-$kernelver","$destdir/kernel");
|
2009-02-16 22:12:03 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-02-18 13:43:11 +00:00
|
|
|
xdie("Cannot read /boot/vmlinuz-$kernelver");
|
2009-02-16 22:12:03 +00:00
|
|
|
}
|
2008-05-24 17:29:40 +00:00
|
|
|
}
|
|
|
|
symlink("bin","/tmp/xcatinitrd.$$/sbin");
|
|
|
|
mkpath("/tmp/xcatinitrd.$$/usr/bin");
|
|
|
|
mkpath("/tmp/xcatinitrd.$$/usr/sbin");
|
|
|
|
mkpath("/tmp/xcatinitrd.$$/usr/lib");
|
|
|
|
mkpath("/tmp/xcatinitrd.$$/usr/lib64");
|
|
|
|
mkpath("/tmp/xcatinitrd.$$/lib/firmware");
|
2008-05-27 20:20:15 +00:00
|
|
|
mkpath("/tmp/xcatinitrd.$$/tmp");
|
|
|
|
mkpath("/tmp/xcatinitrd.$$/var/run");
|
2008-05-24 17:29:40 +00:00
|
|
|
mkpath("/tmp/xcatinitrd.$$/lib64/firmware");
|
2009-02-18 13:43:11 +00:00
|
|
|
if($osver =~ /sles/ && $arch eq "ppc64") {#SLES for Power6
|
2009-02-16 22:12:03 +00:00
|
|
|
mkpath("/tmp/xcatinitrd.$$/lib64/power6");
|
2009-02-12 12:04:51 +00:00
|
|
|
}
|
|
|
|
mkpath("/tmp/xcatinitrd.$$/lib/power6");#SLES10
|
2008-05-26 16:11:24 +00:00
|
|
|
mkpath("/tmp/xcatinitrd.$$/lib/mkinitrd/bin");
|
2008-05-24 17:29:40 +00:00
|
|
|
mkpath("/tmp/xcatinitrd.$$/proc");
|
|
|
|
mkpath("/tmp/xcatinitrd.$$/sys");
|
|
|
|
mkpath("/tmp/xcatinitrd.$$/dev/mapper");
|
|
|
|
mkpath("/tmp/xcatinitrd.$$/sysroot");
|
|
|
|
mkpath("/tmp/xcatinitrd.$$/etc/ld.so.conf.d");
|
2008-05-27 18:21:23 +00:00
|
|
|
mkpath("/tmp/xcatinitrd.$$/var/lib/dhcpcd");
|
2008-05-24 17:29:40 +00:00
|
|
|
my $inifile;
|
|
|
|
open($inifile,">","/tmp/xcatinitrd.$$/init");
|
2009-02-12 12:04:51 +00:00
|
|
|
print $inifile "#!/bin/bash -x\n";
|
2008-05-26 16:11:24 +00:00
|
|
|
print $inifile "mount -t proc /proc /proc\n";
|
2008-05-24 17:29:40 +00:00
|
|
|
print $inifile "mount -t sysfs /sys /sys\n";
|
|
|
|
print $inifile "mount -o mode=0755 -t tmpfs /dev /dev\n";
|
|
|
|
print $inifile "mkdir /dev/pts\n";
|
|
|
|
print $inifile "mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts\n";
|
|
|
|
print $inifile "mkdir /dev/shm\n";
|
|
|
|
print $inifile "mkdir /dev/mapper\n";
|
2009-08-17 06:40:04 +00:00
|
|
|
|
|
|
|
print $inifile "mknod /dev/random c 1 8\n";
|
|
|
|
print $inifile "mknod /dev/urandom c 1 9\n";
|
2008-05-24 17:29:40 +00:00
|
|
|
print $inifile "mknod /dev/null c 1 3\n";
|
|
|
|
print $inifile "mknod /dev/zero c 1 5\n";
|
|
|
|
print $inifile "mknod /dev/systty c 4 0\n";
|
|
|
|
print $inifile "mknod /dev/tty c 5 0\n";
|
|
|
|
print $inifile "mknod /dev/console c 5 1\n";
|
|
|
|
print $inifile "mknod /dev/ptmx c 5 2\n";
|
|
|
|
print $inifile "mknod /dev/rtc c 10 135\n";
|
|
|
|
print $inifile "mknod /dev/tty0 c 4 0\n";
|
|
|
|
print $inifile "mknod /dev/tty1 c 4 1\n";
|
|
|
|
print $inifile "mknod /dev/tty2 c 4 2\n";
|
|
|
|
print $inifile "mknod /dev/tty3 c 4 3\n";
|
|
|
|
print $inifile "mknod /dev/tty4 c 4 4\n";
|
|
|
|
print $inifile "mknod /dev/tty5 c 4 5\n";
|
|
|
|
print $inifile "mknod /dev/tty6 c 4 6\n";
|
|
|
|
print $inifile "mknod /dev/tty7 c 4 7\n";
|
|
|
|
print $inifile "mknod /dev/tty8 c 4 8\n";
|
|
|
|
print $inifile "mknod /dev/tty9 c 4 9\n";
|
|
|
|
print $inifile "mknod /dev/tty10 c 4 10\n";
|
|
|
|
print $inifile "mknod /dev/tty11 c 4 11\n";
|
|
|
|
print $inifile "mknod /dev/tty12 c 4 12\n";
|
|
|
|
print $inifile "mknod /dev/ttyS0 c 4 64\n";
|
|
|
|
print $inifile "mknod /dev/ttyS1 c 4 65\n";
|
|
|
|
print $inifile "mknod /dev/ttyS2 c 4 66\n";
|
|
|
|
print $inifile "mknod /dev/ttyS3 c 4 67\n";
|
|
|
|
foreach (@ndrivers) {
|
|
|
|
print $inifile "insmod /lib/$_\n";
|
|
|
|
}
|
|
|
|
print $inifile <<EOMS;
|
|
|
|
netstart
|
2008-05-26 16:11:24 +00:00
|
|
|
ip addr add dev lo 127.0.0.1/8
|
|
|
|
ip link set lo up
|
2008-05-24 17:29:40 +00:00
|
|
|
cd /
|
|
|
|
for i in `cat /proc/cmdline`; do
|
|
|
|
KEY=`echo \$i |awk -F= '{print \$1}'`
|
|
|
|
if [ "\$KEY" == 'imgurl' ]; then
|
|
|
|
VALUE=`echo \$i |awk -F= '{print \$2}'`
|
|
|
|
if [ "http" == "`echo \$VALUE|awk -F: '{print \$1}'`" ]; then
|
|
|
|
#NOTE needs FT retry code to scale
|
|
|
|
#NOTE: should prob have max count
|
|
|
|
FILENAME=`echo \$VALUE|awk -F/ '{print \$NF}'`
|
|
|
|
while [ ! -r "\$FILENAME" ]; do
|
|
|
|
echo Getting \$VALUE...
|
|
|
|
if ! wget \$VALUE; then
|
|
|
|
sleep 5 #should be random, exponential for scale
|
|
|
|
rm -f \$FILENAME
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
NFS=0
|
|
|
|
fi
|
|
|
|
if [ "nfs" == "`echo \$VALUE|awk -F: '{print \$1}'`" ]; then
|
|
|
|
NFS=1
|
|
|
|
SERVER=`echo \$VALUE|awk -F/ '{print \$3}'`
|
|
|
|
ROOTDIR=`echo \$VALUE|awk -F/ '{for(i=4;i<=NF;i++) printf "/%s",\$i}'`
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ "\$NFS" = "1" ]; then
|
|
|
|
echo Setting up nfs with ram overlay.
|
|
|
|
mknod /dev/loop0 b 7 0
|
|
|
|
mkdir -p /ro
|
|
|
|
mkdir -p /rw
|
|
|
|
#NOTE: should prob have max count
|
|
|
|
while [ ! -d /ro/bin ]; do
|
|
|
|
echo mounting \$SERVER:\$ROOTDIR on /ro
|
2008-05-26 16:11:24 +00:00
|
|
|
mount \$SERVER:\$ROOTDIR /ro -r -n -o nolock,rsize=32768,udp,nfsvers=3,timeo=14
|
2008-05-24 17:29:40 +00:00
|
|
|
sleep 5 #should be random, exponential for scale
|
|
|
|
done
|
|
|
|
mount -t tmpfs rw /rw
|
|
|
|
mkdir -p /rw/etc
|
2008-05-27 18:21:23 +00:00
|
|
|
mkdir -p /rw/var/lib/dhcpcd
|
2008-05-24 17:29:40 +00:00
|
|
|
mount -t aufs -o dirs=/rw:/ro mergedroot /sysroot
|
|
|
|
mkdir -p /sysroot/ro
|
|
|
|
mkdir -p /sysroot/rw
|
|
|
|
mount --move /ro /sysroot/ro
|
|
|
|
mount --move /rw /sysroot/rw
|
|
|
|
elif [ -r /rootimg.sfs ]; then
|
|
|
|
echo Setting up squashfs with ram overlay.
|
|
|
|
mknod /dev/loop0 b 7 0
|
|
|
|
mkdir -p /ro
|
|
|
|
mkdir -p /rw
|
|
|
|
mount -t squashfs /rootimg.sfs /ro
|
|
|
|
mount -t tmpfs rw /rw
|
|
|
|
mount -t aufs -o dirs=/rw:/ro mergedroot /sysroot
|
|
|
|
mkdir -p /sysroot/ro
|
|
|
|
mkdir -p /sysroot/rw
|
|
|
|
mount --move /ro /sysroot/ro
|
|
|
|
mount --move /rw /sysroot/rw
|
|
|
|
EOMS
|
|
|
|
print $inifile "elif [ -r /rootimg.gz ]; then\n";
|
|
|
|
print $inifile "echo Setting up RAM-root tmpfs.\n";
|
|
|
|
if ($rootlimit) {
|
|
|
|
print $inifile " mount -o size=$rootlimit -t tmpfs rootfs /sysroot\n";
|
|
|
|
} else {
|
|
|
|
print $inifile " mount -t tmpfs rootfs /sysroot\n";
|
|
|
|
}
|
|
|
|
print $inifile " cd /sysroot\n";
|
|
|
|
print $inifile " echo -n \"Extracting root filesystem:\"\n";
|
|
|
|
print $inifile " if [ -x /bin/cpio ]; then\n";
|
|
|
|
print $inifile " zcat /rootimg.gz |/bin/cpio -idum\n";
|
|
|
|
print $inifile " else\n";
|
|
|
|
print $inifile " zcat /rootimg.gz |cpio -idum\n";
|
|
|
|
print $inifile " fi\n";
|
|
|
|
print $inifile " echo Done\n";
|
|
|
|
print $inifile "else\n";
|
|
|
|
print $inifile " echo -n Failed to download image, panicing in 5...\n";
|
|
|
|
print $inifile " for i in 4 3 2 1 0; do\n";
|
|
|
|
print $inifile " /bin/sleep 1\n";
|
|
|
|
print $inifile " echo -n \$i...\n";
|
|
|
|
print $inifile " done\n";
|
|
|
|
print $inifile " echo\n";
|
|
|
|
print $inifile <<EOMS;
|
|
|
|
echo "You're dead. rpower nodename reset to play again.
|
|
|
|
|
|
|
|
* Did you packimage with -m cpio, -m squashfs, or -m nfs?
|
|
|
|
* If using -m squashfs did you include aufs.ko with geninitrd?
|
|
|
|
e.g.: -n tg3,squashfs,aufs,loop
|
|
|
|
* If using -m nfs did you export NFS and sync rootimg? And
|
|
|
|
did you include the aufs and nfs modules in the proper order:
|
|
|
|
e.g.: -n tg3,aufs,loop,sunrpc,lockd,nfs_acl,nfs
|
|
|
|
|
|
|
|
"
|
|
|
|
sleep 5
|
|
|
|
EOMS
|
|
|
|
print $inifile " exit\n";
|
|
|
|
print $inifile "fi\n";
|
|
|
|
print $inifile "cd /\n";
|
2009-02-12 12:04:51 +00:00
|
|
|
print $inifile "mkdir /sysroot/var/lib/dhcpcd/\n"; #neccessary for SLES11, not sure for SLES10
|
2008-05-27 18:21:23 +00:00
|
|
|
print $inifile "cp /var/lib/dhcpcd/* /sysroot/var/lib/dhcpcd/\n";
|
|
|
|
print $inifile "cp /etc/resolv.conf /sysroot/etc/\n";
|
2008-05-27 20:20:15 +00:00
|
|
|
print $inifile "cp /etc/HOSTNAME /sysroot/etc/\n";
|
2008-05-24 17:29:40 +00:00
|
|
|
print $inifile "mknod /sysroot/dev/console c 5 1\n";
|
2008-05-26 16:11:24 +00:00
|
|
|
print $inifile "exec /lib/mkinitrd/bin/run-init -c /dev/console /sysroot /sbin/init\n";
|
2008-05-24 17:29:40 +00:00
|
|
|
close($inifile);
|
|
|
|
open($inifile,">"."/tmp/xcatinitrd.$$/bin/netstart");
|
2008-05-26 16:11:24 +00:00
|
|
|
print $inifile "#!/bin/bash\n";
|
|
|
|
print $inifile "dhcpcd $prinic\n";
|
Allows diskless nodes to boot via other interfaces aside of primary boot interface, ie. provides ethernet failover.
1) In initrd, bring up aside from main interface (genimage -i option) also other interfaces (-r option).
2) /etc/resolv.conf creation needed to be rewritten, othewise it gets confused by several dhcpcd records.
3) Fill database with MAC addresses for all interfaces. Since it't not possible to have several stanzas of the same name in dhcpd.conf, we need to define unique "alias" for every interface. For example, for host "host1" we will add '00:1A:64:5D:1B:84!host1e0|00:1A:64:5D:1B:86!host1e1' to macs table. Of course, this aliases have to be defined in DNS, otherwise makedhcp command will not use this aliases:
/etc/hosts:
10.217.249.232 host1 host1e0 host1e1
Since this are aliases (need not be nessesary), both interfaces get the same IP address during initrd, but this doesn't break anything.
a) blades - changed getmacs function to gather all MAC addresses. Which interfaces we are interested in are defined in noderes.installnic or noderes.primarynic as "eth0|eth1".
b) all other - TODO. We have only 8 non-blade nodes, so we fill database manually.
Backwards compatible:
- if there is only one interface in noderes.installnic, getmacs function gathers only this one MAC address
- if we run genimage without -r option, only one interface is brought up
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@2124 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
2008-09-10 15:04:32 +00:00
|
|
|
|
|
|
|
#-- Bring other NICs up in /bin/netstart in initrd for NIC failover
|
|
|
|
foreach (split /,/,$othernics) {
|
|
|
|
if (/^$/) { next; }
|
|
|
|
print $inifile "dhcpcd $_\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
print $inifile <<END;
|
|
|
|
cat /var/lib/dhcpcd/*info | grep DOMAIN | uniq | awk -F= '{print \"search\",\$2}' | sed \"s/'//g\" >> /etc/resolv.conf
|
|
|
|
cat /var/lib/dhcpcd/*info | grep HOSTNAME | uniq | awk -F= '{print \$2}'| sed \"s/'//g\" >> /etc/HOSTNAME
|
|
|
|
for names in \$(cat /var/lib/dhcpcd/*info | grep DNS | uniq | awk -F= '{print \$2}' | sed 's/,/\\n/'); do
|
|
|
|
echo nameserver \$names >> /etc/resolv.conf
|
|
|
|
done
|
|
|
|
END
|
2008-05-27 20:20:15 +00:00
|
|
|
|
2008-05-24 17:29:40 +00:00
|
|
|
close($inifile);
|
|
|
|
chmod(0755,"/tmp/xcatinitrd.$$/init");
|
|
|
|
chmod(0755,"/tmp/xcatinitrd.$$/bin/netstart");
|
|
|
|
@filestoadd=();
|
|
|
|
foreach (@ndrivers) {
|
2008-09-11 22:03:01 +00:00
|
|
|
if (-f "$customdir/$_") {
|
2008-05-24 17:29:40 +00:00
|
|
|
push @filestoadd,[$_,"lib/$_"];
|
2008-09-11 22:03:01 +00:00
|
|
|
} elsif (-f "$pathtofiles/$_") {
|
|
|
|
push @filestoadd,[$_,"lib/$_"];
|
|
|
|
}
|
2008-05-24 17:29:40 +00:00
|
|
|
}
|
2009-02-12 12:04:51 +00:00
|
|
|
foreach ("usr/bin/grep","bin/cpio","bin/sleep","bin/mount","sbin/dhcpcd","bin/bash","sbin/insmod","bin/mkdir","bin/mknod","sbin/ip","bin/cat","usr/bin/awk","usr/bin/wget","bin/cp","usr/bin/cpio","usr/bin/zcat","usr/bin/gzip","lib/mkinitrd/bin/run-init","usr/bin/uniq","usr/bin/sed") {
|
|
|
|
getlibs($_); #there's one small bug for getlibs
|
2008-05-24 17:29:40 +00:00
|
|
|
push @filestoadd,$_;
|
|
|
|
}
|
|
|
|
if ($arch =~ /x86_64/) {
|
|
|
|
push @filestoadd,"lib64/libnss_dns.so.2";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push @filestoadd,"lib/libnss_dns.so.2";
|
|
|
|
}
|
|
|
|
push @filestoadd,keys %libhash;
|
|
|
|
if($basekernelver ne $kernelver) {
|
2009-09-24 18:51:53 +00:00
|
|
|
system("rm -rf $rootimg_dir/lib/modules/$basekernelver");
|
|
|
|
unless (-d "$rootimg_dir/lib/modules/$kernelver") {
|
2008-05-24 17:29:40 +00:00
|
|
|
if(-d "/lib/modules/$kernelver") {
|
2009-09-24 18:51:53 +00:00
|
|
|
system("cd /lib/modules;cp -r $kernelver $rootimg_dir/lib/modules/");
|
2008-05-24 17:29:40 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
xdie("Cannot read /lib/modules/$kernelver");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-24 18:51:53 +00:00
|
|
|
find(\&isnetdriver, <$rootimg_dir/lib/modules/$kernelver/*>);
|
2008-05-24 17:29:40 +00:00
|
|
|
foreach (@filestoadd) {
|
|
|
|
if (ref($_)) {
|
2008-09-11 22:03:01 +00:00
|
|
|
#print "$_->[0], $_->[1]\n";
|
2009-10-06 20:21:11 +00:00
|
|
|
my $srcpath = "$rootimg_dir/".$_->[0];
|
2008-09-11 22:03:01 +00:00
|
|
|
if (-f "$customdir/".$_->[0]) {
|
|
|
|
$srcpath="$customdir/".$_->[0];
|
|
|
|
} elsif (-f "$pathtofiles/".$_->[0]) {
|
2008-05-24 17:29:40 +00:00
|
|
|
$srcpath="$pathtofiles/".$_->[0];
|
|
|
|
}
|
|
|
|
copy($srcpath,"/tmp/xcatinitrd.$$/".$_->[1]);
|
|
|
|
chmod 0755,"/tmp/xcatinitrd.$$/".$_->[1];
|
|
|
|
} else {
|
2008-09-11 22:03:01 +00:00
|
|
|
#print "$_\n";
|
2009-09-24 18:51:53 +00:00
|
|
|
my $srcpath = "$rootimg_dir/$_";
|
2008-09-11 22:03:01 +00:00
|
|
|
if (-f "$customdir/$_") {
|
|
|
|
$srcpath = "$customdir/$_";
|
|
|
|
} elsif (-f "$pathtofiles/$_") {
|
2008-09-09 23:52:04 +00:00
|
|
|
$srcpath = "$pathtofiles/$_";
|
2008-05-24 17:29:40 +00:00
|
|
|
}
|
|
|
|
copy("$srcpath","/tmp/xcatinitrd.$$/$_");
|
|
|
|
chmod 0755,"/tmp/xcatinitrd.$$/".$_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-24 18:51:53 +00:00
|
|
|
#copy("$rootimg_dir/lib/modules/*d","/tmp/xcatinitrd.$$/$_");
|
2009-02-12 12:04:51 +00:00
|
|
|
system("cd /tmp/xcatinitrd.$$/bin/; ln -sf bash sh"); #neccessary for SLES11
|
2009-09-24 18:51:53 +00:00
|
|
|
system("cd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|gzip -9 -c - > $destdir/initrd.gz");
|
2008-05-24 17:29:40 +00:00
|
|
|
system("rm -rf /tmp/xcatinitrd.$$");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sub isyumdir {
|
|
|
|
if ($File::Find::name =~ /\/repodata$/) {
|
|
|
|
my $location = $File::Find::name;
|
|
|
|
$location =~ s/\/repodata$//;
|
|
|
|
push @yumdirs,$location;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub isnetdriver {
|
|
|
|
foreach (@ndrivers) {
|
|
|
|
if ($File::Find::name =~ /\/$_/) {
|
|
|
|
my $filetoadd = $File::Find::name;
|
2009-09-24 18:51:53 +00:00
|
|
|
$filetoadd =~ s!$rootimg_dir!!;
|
2008-05-24 17:29:40 +00:00
|
|
|
push @filestoadd,[$filetoadd,"lib/$_"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub postscripts { # TODO: customized postscripts
|
|
|
|
generic_post();
|
|
|
|
if (-d "$installroot/postscripts/hostkeys") {
|
|
|
|
for my $key (<$installroot/postscripts/hostkeys/*key>) {
|
2009-09-24 18:51:53 +00:00
|
|
|
copy ($key,"$rootimg_dir/etc/ssh/");
|
2008-05-24 17:29:40 +00:00
|
|
|
}
|
2009-09-24 18:51:53 +00:00
|
|
|
chmod 0600,<$rootimg_dir/etc/ssh/*key>;
|
2008-05-24 17:29:40 +00:00
|
|
|
}
|
|
|
|
if (-d "/$installroot/postscripts/.ssh") {
|
2009-09-24 18:51:53 +00:00
|
|
|
mkpath("$rootimg_dir/root/.ssh");
|
|
|
|
chmod(0700,"$rootimg_dir/root/.ssh/");
|
2008-05-24 17:29:40 +00:00
|
|
|
for my $file (</$installroot/postscripts/.ssh/*>) {
|
2009-09-24 18:51:53 +00:00
|
|
|
copy ($file,"$rootimg_dir/root/.ssh/");
|
2008-05-24 17:29:40 +00:00
|
|
|
}
|
2009-09-24 18:51:53 +00:00
|
|
|
chmod(0600,<$rootimg_dir/root/.ssh/*>);
|
2008-05-24 17:29:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sub generic_post { #This function is meant to leave the image in a state approximating a normal install
|
|
|
|
my $cfgfile;
|
2009-09-24 18:51:53 +00:00
|
|
|
unlink("$rootimg_dir/dev/null");
|
|
|
|
system("mknod $rootimg_dir/dev/null c 1 3");
|
|
|
|
open($cfgfile,">","$rootimg_dir/etc/fstab");
|
2008-05-24 17:29:40 +00:00
|
|
|
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";
|
|
|
|
print $cfgfile "sysfs /sys sysfs defaults 0 0\n";
|
|
|
|
if ($tmplimit) {
|
|
|
|
print $cfgfile "tmpfs /tmp tmpfs defaults 0 0\n";
|
|
|
|
print $cfgfile "tmpfs /var/tmp tmpfs defaults 0 0\n";
|
|
|
|
}
|
|
|
|
close($cfgfile);
|
2009-09-24 18:51:53 +00:00
|
|
|
open($cfgfile,">","$rootimg_dir/etc/sysconfig/network");
|
2008-05-24 17:29:40 +00:00
|
|
|
print $cfgfile "NETWORKING=yes\n";
|
|
|
|
close($cfgfile);
|
2009-09-24 18:51:53 +00:00
|
|
|
open($cfgfile,">","$rootimg_dir/etc/resolv.conf");
|
2008-05-24 17:29:40 +00:00
|
|
|
print $cfgfile "#Dummy resolv.conf to make boot cleaner";
|
|
|
|
close($cfgfile);
|
2009-09-24 18:51:53 +00:00
|
|
|
open($cfgfile,">","$rootimg_dir/etc/sysconfig/network-scripts/ifcfg-$prinic");
|
2008-05-24 17:29:40 +00:00
|
|
|
print $cfgfile "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=$prinic\n";
|
|
|
|
close($cfgfile);
|
|
|
|
foreach (split /,/,$othernics) {
|
|
|
|
if (/^$/) { next; }
|
2009-09-24 18:51:53 +00:00
|
|
|
open($cfgfile,">","$rootimg_dir/etc/sysconfig/network-scripts/ifcfg-$_");
|
2008-05-24 17:29:40 +00:00
|
|
|
print $cfgfile "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=$_\n";
|
|
|
|
close($cfgfile);
|
|
|
|
}
|
2009-09-24 18:51:53 +00:00
|
|
|
open($cfgfile,">>","$rootimg_dir/etc/securetty");
|
2008-05-24 17:29:40 +00:00
|
|
|
print $cfgfile "ttyS0\n";
|
|
|
|
print $cfgfile "ttyS1\n";
|
2009-02-16 22:12:03 +00:00
|
|
|
print $cfgfile "console\n";
|
2008-05-24 17:29:40 +00:00
|
|
|
close($cfgfile);
|
|
|
|
my @passwd;
|
2009-09-24 18:51:53 +00:00
|
|
|
open($cfgfile,"<","$rootimg_dir/etc/passwd");
|
2008-05-24 17:29:40 +00:00
|
|
|
@passwd = <$cfgfile>;
|
|
|
|
close($cfgfile);
|
2009-09-24 18:51:53 +00:00
|
|
|
open($cfgfile,">","$rootimg_dir/etc/passwd");
|
2008-05-24 17:29:40 +00:00
|
|
|
foreach (@passwd) {
|
|
|
|
if (/^root:/) {
|
|
|
|
s/^root:\*/root:x/
|
|
|
|
}
|
|
|
|
print $cfgfile $_;
|
|
|
|
}
|
|
|
|
close($cfgfile);
|
2009-09-24 18:51:53 +00:00
|
|
|
foreach (<$rootimg_dir/etc/skel/.*>) {
|
2008-05-24 17:29:40 +00:00
|
|
|
if (basename($_) eq '.' or basename($_) eq '..') {
|
|
|
|
next;
|
|
|
|
}
|
2009-09-24 18:51:53 +00:00
|
|
|
copy $_,"$rootimg_dir/root/";
|
2008-05-24 17:29:40 +00:00
|
|
|
}
|
2009-09-24 18:51:53 +00:00
|
|
|
open($cfgfile,">","$rootimg_dir/etc/init.d/gettyset");
|
2008-05-24 17:29:40 +00:00
|
|
|
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";
|
2009-09-21 16:00:57 +00:00
|
|
|
print $cfgfile " if [ \"\$KEY\" == \"console\" -a \"\$i\" != \"console=tty0\" ]; then\n";
|
2008-05-24 17:29:40 +00:00
|
|
|
print $cfgfile " VALUE=`echo \$i | cut -d= -f 2`\n";
|
|
|
|
print $cfgfile " COTTY=`echo \$VALUE|cut -d, -f 1`\n";
|
|
|
|
print $cfgfile " COSPEED=`echo \$VALUE|cut -d, -f 2|cut -dn -f 1`\n";
|
|
|
|
print $cfgfile " if echo \$VALUE | grep n8r; then\n";
|
|
|
|
print $cfgfile " FLOWFLAG=\"-h\"\n";
|
|
|
|
print $cfgfile " fi\n";
|
2009-09-21 15:49:18 +00:00
|
|
|
print $cfgfile " echo xco:2345:respawn:/sbin/agetty \$FLOWFLAG \$COTTY \$COSPEED xterm >> /etc/inittab\n";
|
2008-05-24 17:29:40 +00:00
|
|
|
print $cfgfile " init q\n";
|
|
|
|
print $cfgfile " fi\n";
|
|
|
|
print $cfgfile "done\n";
|
2008-05-27 21:11:56 +00:00
|
|
|
print $cfgfile "/etc/init.d/boot.localnet start\n";
|
|
|
|
print $cfgfile "/opt/xcat/xcatdsklspost\n";
|
2008-05-24 17:29:40 +00:00
|
|
|
close($cfgfile);
|
2009-09-24 18:51:53 +00:00
|
|
|
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");
|
2008-05-26 16:11:24 +00:00
|
|
|
if ($rc) {
|
2009-09-24 18:51:53 +00:00
|
|
|
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");
|
2008-05-26 16:11:24 +00:00
|
|
|
}
|
2009-09-24 18:51:53 +00:00
|
|
|
my $rc = system("grep gettyset $rootimg_dir/etc/init.d/.depend.start");
|
2008-05-26 16:11:24 +00:00
|
|
|
if ($rc) {
|
2009-09-24 18:51:53 +00:00
|
|
|
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");
|
2008-05-26 16:11:24 +00:00
|
|
|
}
|
2009-02-16 22:12:03 +00:00
|
|
|
if(($osver =~ /sles11/) || ($osver =~ /sles10/)) {#for sles11,sles10
|
2009-09-24 18:51:53 +00:00
|
|
|
rename(<$rootimg_dir/boot/vmlinux*>,"$destdir/kernel");
|
2009-02-12 12:04:51 +00:00
|
|
|
}else {
|
2009-09-24 18:51:53 +00:00
|
|
|
rename(<$rootimg_dir/boot/vmlinuz*>,"$destdir/kernel");
|
2009-02-12 12:04:51 +00:00
|
|
|
}
|
2008-05-24 17:29:40 +00:00
|
|
|
}
|
2008-09-09 23:52:04 +00:00
|
|
|
|
|
|
|
#get th extra package name
|
|
|
|
sub get_extra_package_names {
|
2009-09-24 18:51:53 +00:00
|
|
|
if (!$imagename) {
|
|
|
|
$otherpkglist=get_extra_pkglist_file_name($customdir);
|
|
|
|
if (!$otherpkglist) { $otherpkglist=get_extra_pkglist_file_name($pathtofiles); }
|
|
|
|
}
|
2009-10-06 20:21:11 +00:00
|
|
|
|
|
|
|
#print "customdir=$customdir,pathtofiles=$pathtofiles,otherpkglist=$otherpkglist\n";
|
|
|
|
my %pkgnames=();
|
2009-07-02 20:24:27 +00:00
|
|
|
my @tmp_array=();
|
|
|
|
|
2008-09-11 22:03:01 +00:00
|
|
|
|
2008-09-09 23:52:04 +00:00
|
|
|
if ($otherpkglist) {
|
|
|
|
my $pkgfile;
|
|
|
|
open($pkgfile,"<","$otherpkglist");
|
|
|
|
while (<$pkgfile>) {
|
|
|
|
chomp;
|
2009-07-02 20:24:27 +00:00
|
|
|
s/\s+$//; #remove trailing white spaces
|
2009-05-19 18:56:27 +00:00
|
|
|
next if /^\s*$/; #-- skip empty lines
|
2009-07-02 20:24:27 +00:00
|
|
|
push(@tmp_array,$_);
|
2008-09-09 23:52:04 +00:00
|
|
|
}
|
|
|
|
close($pkgfile);
|
2009-07-02 20:24:27 +00:00
|
|
|
|
|
|
|
if ( @tmp_array > 0) {
|
|
|
|
my $pkgtext=join(',',@tmp_array);
|
|
|
|
|
|
|
|
#handle the #INLCUDE# tag recursively
|
|
|
|
my $idir = dirname($otherpkglist);
|
|
|
|
my $doneincludes=0;
|
|
|
|
while (not $doneincludes) {
|
|
|
|
$doneincludes=1;
|
|
|
|
if ($pkgtext =~ /#INCLUDE:[^#]+#/) {
|
|
|
|
$doneincludes=0;
|
|
|
|
$pkgtext =~ s/#INCLUDE:([^#]+)#/include_file($1,$idir)/eg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print "pkgtext=$pkgtext\n";
|
|
|
|
my @tmp=split(',', $pkgtext);
|
2009-10-06 20:21:11 +00:00
|
|
|
foreach (@tmp) {
|
|
|
|
my $idir;
|
|
|
|
if (/^--/) {
|
|
|
|
$idir="POST_REMOVE"; #line starts with -- means the package should be removed after otherpkgs are installed
|
|
|
|
s/^--//;
|
|
|
|
} elsif (/^-/) {
|
|
|
|
$idir="PRE_REMOVE"; #line starts with single - means the package should be removed before otherpkgs are installed
|
|
|
|
s/^-//;
|
|
|
|
} else {
|
|
|
|
$idir=dirname($_);
|
|
|
|
}
|
2009-07-02 20:24:27 +00:00
|
|
|
my $fn=basename($_);
|
|
|
|
if (exists($pkgnames{$idir})) {
|
|
|
|
my $pa=$pkgnames{$idir};
|
|
|
|
push(@$pa, $fn);
|
|
|
|
} else {
|
|
|
|
$pkgnames{$idir}=[$fn];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-09 23:52:04 +00:00
|
|
|
}
|
|
|
|
|
2009-07-02 20:24:27 +00:00
|
|
|
return %pkgnames;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub include_file
|
|
|
|
{
|
|
|
|
my $file = shift;
|
|
|
|
my $idir = shift;
|
|
|
|
my @text = ();
|
|
|
|
unless ($file =~ /^\//) {
|
|
|
|
$file = $idir."/".$file;
|
|
|
|
}
|
|
|
|
|
|
|
|
open(INCLUDE,$file) || \
|
|
|
|
return "#INCLUDEBAD:cannot open $file#";
|
|
|
|
|
|
|
|
while(<INCLUDE>) {
|
|
|
|
chomp($_);
|
|
|
|
s/\s+$//; #remove trailing spaces
|
|
|
|
next if /^\s*$/; #-- skip empty lines
|
|
|
|
push(@text, $_);
|
|
|
|
}
|
|
|
|
|
|
|
|
close(INCLUDE);
|
|
|
|
|
|
|
|
return join(',', @text);
|
2008-09-09 23:52:04 +00:00
|
|
|
}
|
2008-09-11 22:03:01 +00:00
|
|
|
|
|
|
|
sub get_extra_pkglist_file_name {
|
|
|
|
my $base=shift;
|
|
|
|
if (-r "$base/$profile.$osver.$arch.otherpkgs.pkglist") {
|
|
|
|
return "$base/$profile.$osver.$arch.otherpkgs.pkglist";
|
|
|
|
} elsif (-r "$base/$profile.$arch.otherpkgs.pkglist") {
|
|
|
|
return "$base/$profile.$arch.otherpkgs.pkglist";
|
|
|
|
} elsif (-r "$base/$profile.$osver.otherpkgs.pkglist") {
|
|
|
|
return "$base/$profile.$osver.otherpkgs.pkglist";
|
|
|
|
} elsif (-r "$base/$profile.otherpkgs.pkglist") {
|
|
|
|
return "$base/$profile.otherpkgs.pkglist";
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_pkglist_file_name {
|
|
|
|
my $base=shift;
|
|
|
|
if (-r "$base/$profile.$osver.$arch.pkglist") {
|
|
|
|
return "$base/$profile.$osver.$arch.pkglist";
|
|
|
|
} elsif (-r "$base/$profile.$arch.pkglist") {
|
|
|
|
return "$base/$profile.$arch.pkglist";
|
|
|
|
} elsif (-r "$base/$profile.$osver.pkglist") {
|
|
|
|
return "$base/$profile.$osver.pkglist";
|
|
|
|
} elsif (-r "$base/$profile.pkglist") {
|
|
|
|
return "$base/$profile.pkglist";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-23 14:13:56 +00:00
|
|
|
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 "";
|
|
|
|
}
|
|
|
|
|
2008-09-11 22:03:01 +00:00
|
|
|
|