2008-02-12 19:10:33 +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-02-12 19:10:33 +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-04-24 16:06:50 +00:00
#use strict;
2008-02-12 19:10:33 +00:00
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-02-12 19:10:33 +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-02-12 19:36:20 +00:00
my $name = basename($0);
my $onlyinitrd=0;
if ($name =~ /geninitrd/) {
$onlyinitrd=1;
}
2008-02-27 20:32:31 +00:00
my $rootlimit;
my $tmplimit;
2008-05-12 15:45:49 +00:00
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;
2009-12-04 00:53:47 +00:00
my $rwfiles; # these files are used by statelite for tmpfs rw
2010-03-05 08:05:47 +00:00
my $mode;
my $permission; # the permission works only for statelite mode currently
2008-02-12 19:36:20 +00:00
2009-12-15 20:29:50 +00:00
2008-05-20 14:12:27 +00:00
sub xdie {
system("rm -rf /tmp/xcatinitrd.$$");
die @_;
}
$SIG{INT} = $SIG{TERM} = sub { xdie "Interrupted" };
2008-02-12 19:10:33 +00:00
GetOptions(
2008-05-12 15:45:49 +00:00
'a=s' => \$arch,
2008-02-12 19:10:33 +00:00
'p=s' => \$profile,
'o=s' => \$osver,
'n=s' => \$netdriver,
'i=s' => \$prinic,
2008-02-27 20:32:31 +00:00
'r=s' => \$othernics,
'l=s' => \$rootlimit,
2008-05-09 20:09:23 +00:00
't=s' => \$tmplimit,
2009-12-04 00:53:47 +00:00
'k=s' => \$kernelver,
2010-03-05 08:05:47 +00:00
'm=s' => \$mode,
'permission=s' => \$permission
2008-02-12 19:10:33 +00:00
);
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'};
$srcdir_otherpkgs=$ref1->{'otherpkgdir'};
$otherpkglist=$ref1->{'otherpkglist'};
$postinstall_filename=$ref1->{'postinstall'};
$destdir=$ref1->{'rootimgdir'};
}
2010-03-05 08:05:47 +00:00
if ($mode eq "statelite") {
if (!$permission) {
$permission = "755";
}
}
2009-09-24 18:51:53 +00:00
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";
2009-12-04 00:53:47 +00:00
2008-02-12 19:10:33 +00:00
unless ($osver and $profile and $netdriver and $prinic) {
2010-03-05 10:09:03 +00:00
print 'Usage: genimage -i <nodebootif> -n <nodenetdrivers> [-r <otherifaces>] -o <OSVER> -p <PROFILE> -k <KERNELVER> [-m <mode> [--permission <permission>]]'."\n";
2009-09-24 18:51:53 +00:00
print ' genimage -i <nodebootif> -n <nodenetdrivers> [-r <otherifaces>] -k <KERNELVER> <imagename>'."\n";
2010-03-05 10:09:03 +00:00
print " --permission only works when '-m statelite' is set\n";
2008-02-12 19:10:33 +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-12-04 00:53:47 +00:00
print " genimage -i eth0 -n igb,e1000e,e1000,bnx2,tg3 -o centos5.4 -p nfsroot -m statelite\n";
2010-03-05 10:09:03 +00:00
print " genimage -i eth0 -n igb,e1000e,e1000,bnx2,tg3 -o centos5.4 -p nfsroot -m statelite --permission 777\n";
2009-09-24 18:51:53 +00:00
print " genimage -i eth0 -n tg3 myimage\n";
2008-02-12 19:10:33 +00:00
exit 1;
}
2009-12-04 00:53:47 +00:00
2008-02-12 19:10:33 +00:00
my @ndrivers;
foreach (split /,/,$netdriver) {
unless (/\.ko$/) {
s/$/.ko/;
}
if (/^$/) {
next;
}
push @ndrivers,$_;
}
2009-12-04 00:53:47 +00:00
if($mode eq "statelite"){
push @ndrivers,"fscache.ko";
push @ndrivers,"sunrpc.ko";
push @ndrivers,"lockd.ko";
push @ndrivers,"nfs_acl.ko";
push @ndrivers,"nfs.ko";
}
2008-02-12 19:10:33 +00:00
2010-03-30 15:49:46 +00:00
2008-03-27 13:26:20 +00:00
unless ($onlyinitrd) {
2008-03-27 13:29:39 +00:00
@yumdirs=();
find(\&isyumdir, <$installroot/$osver/$arch/>);
unless (scalar(@yumdirs)) {
#unless ( -d $srcdir."/repodata" ) {
2008-04-29 17:53:33 +00:00
print "Need $installroot/$osver/$arch/ available from a system that has ran copycds on $osver $arch\n";
2008-03-27 13:29:39 +00:00
exit 1;
}
2008-09-09 23:52:04 +00:00
2008-03-27 13:29:39 +00:00
my $yumconfig;
open($yumconfig,">","/tmp/genimage.$$.yum.conf");
my $repnum=0;
foreach $srcdir (@yumdirs) {
print $yumconfig "[$osver-$arch-$repnum]\nname=$osver-$arch-$repnum\nbaseurl=file://$srcdir\ngpgpcheck=0\n\n";
$repnum += 1;
}
$repnum-=1;
close($yumconfig);
2009-09-24 18:51:53 +00:00
mkpath "$rootimg_dir/etc";
2009-12-04 00:53:47 +00:00
2008-05-06 18:18:33 +00:00
my $fd;
2009-09-24 18:51:53 +00:00
open($fd,">>","$rootimg_dir/etc/fstab");
2008-05-06 18:18:33 +00:00
print $fd "#Dummy fstab for rpm postscripts to see\n";
close($fd);
2009-09-24 18:51:53 +00:00
my $yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
2008-03-27 13:29:39 +00:00
foreach (0..$repnum) {
2008-09-09 21:08:48 +00:00
$yumcmd .= "--enablerepo=$osver-$arch-$_ ";
2008-03-27 13:29:39 +00:00
}
2008-09-09 23:52:04 +00:00
2008-03-27 13:29:39 +00:00
$yumcmd .= "install ";
2009-09-24 18:51:53 +00:00
mkpath("$rootimg_dir/var/lib/yum");
2008-09-09 21:08:48 +00:00
2009-09-24 18:51:53 +00:00
if (!$imagename) {
2010-03-19 21:12:56 +00:00
$pkglist= get_profile_def_filename($customdir, "pkglist");
2009-09-24 18:51:53 +00:00
if (!$pkglist) {
2010-03-19 21:12:56 +00:00
$pkglist= get_profile_def_filename($pathtofiles, "pkglist");
2009-09-24 18:51:53 +00:00
}
}
2008-09-11 22:03:01 +00:00
if (!$pkglist) {
2008-03-27 13:29:39 +00:00
print "Unable to find package list for $profile!";
2009-07-02 21:41:39 +00:00
exit 1;
2008-03-27 13:29:39 +00:00
}
2008-09-11 22:03:01 +00:00
2010-03-19 21:12:56 +00:00
my %pkg_hash=get_package_names($pkglist);
my $index=1;
2010-03-25 20:37:00 +00:00
my $pass;
foreach $pass (keys(%pkg_hash)) {
my $pkgnames = "";
foreach (keys(%{$pkg_hash{$pass}})) {
if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE")) { next;}
my $pa=$pkg_hash{$pass}{$_};
$pkgnames .= " " . join(' ', @$pa);
}
print "$yumcmd $pkgnames\n";
my $rc = system("$yumcmd $pkgnames");
if ($rc) {
print "yum invocation failed\n";
exit 1;
}
2008-02-12 19:36:20 +00:00
}
2009-07-02 21:41:39 +00:00
#Now let's handle extra packages
2010-03-19 21:12:56 +00:00
if (!$imagename) {
$otherpkglist=get_profile_def_filename($customdir, "otherpkgs.pkglist");
if (!$otherpkglist) { $otherpkglist=get_profile_def_filename($pathtofiles, "otherpkgs.pkglist"); }
}
my %extra_hash=();
if ($otherpkglist) {
%extra_hash=get_package_names($otherpkglist);
}
2010-03-25 20:37:00 +00:00
my %extrapkgnames;
2009-07-02 21:41:39 +00:00
2010-03-19 21:12:56 +00:00
if (keys(%extra_hash) > 0) {
2009-07-02 21:41:39 +00:00
open($yumconfig,">>","/tmp/genimage.$$.yum.conf");
my $index=1;
2010-03-25 20:37:00 +00:00
foreach $pass (keys(%extra_hash)) {
foreach (keys(%{$extra_hash{$pass}})) {
2009-10-06 20:21:11 +00:00
if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE")) { next;}
2009-07-02 21:41:39 +00:00
print $yumconfig "[otherpkgs$index]\nname=otherpkgs$index\nbaseurl=file://$srcdir_otherpkgs/$_\ngpgpcheck=0\n\n";
$index++;
2010-03-25 20:37:00 +00:00
my $pa=$extra_hash{$pass}{$_};
$extrapkgnames{$pass} .= " " . join(' ', @$pa);
}
2009-07-02 21:41:39 +00:00
}
close($yumconfig);
$index--;
2009-09-24 18:51:53 +00:00
$yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
2009-07-02 21:41:39 +00:00
foreach (0..$repnum) {
$yumcmd .= "--enablerepo=$osver-$arch-$_ ";
}
for (1..$index) {
$yumcmd .= "--enablerepo=otherpkgs$_ ";
}
2009-10-06 20:21:11 +00:00
2010-03-25 20:37:00 +00:00
foreach $pass (keys(%extra_hash)) {
2009-10-06 20:21:11 +00:00
#remove the packages that are specified in the otherpkgs.list files with leading '-'
2010-03-25 20:37:00 +00:00
my $yumcmd_remove= "$yumcmd erase ";
if (exists ($extra_hash{$pass}{'PRE_REMOVE'})) {
my $pa=$extra_hash{$pass}{'PRE_REMOVE'};
my $rm_packges= join(' ', @$pa);
if ($rm_packges) {
print "$yumcmd_remove $rm_packges\n";
$rc = system("$yumcmd_remove $rm_packges");
}
}
#install extra packages
my $yumcmd_base = $yumcmd;
$yumcmd .= "install ";
#append extra pkg names to yum command
if ($extrapkgnames{$pass}) {
$yumcmd .= " $extrapkgnames{$pass} ";
}
$yumcmd =~ s/ $/\n/;
2009-07-02 21:41:39 +00:00
2010-03-25 20:37:00 +00:00
#debug
print "yumcmd=$yumcmd\n";
#my $repo=`cat /tmp/genimage.$$.yum.conf`;
#print "repo=$repo";
2009-07-02 21:41:39 +00:00
2010-03-25 20:37:00 +00:00
my $rc = system($yumcmd);
if ($rc) {
print "yum 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 '--'
2010-03-25 20:37:00 +00:00
if (exists ($extra_hash{$pass}{'POST_REMOVE'})) {
my $pa=$extra_hash{$pass}{'POST_REMOVE'};
my $rm_packges= join(' ', @$pa);
if ($rm_packges) {
print "$yumcmd_remove $rm_packges\n";
$rc = system("$yumcmd_remove $rm_packges");
}
}
2009-10-06 20:21:11 +00:00
}
2010-03-25 20:37:00 +00:00
}
2010-03-08 20:46:07 +00:00
2010-03-25 20:37:00 +00:00
# run yum update to update any installed rpms
# needed when running genimage again after updating software in repositories
my $yumcmd_update = $yumcmd_base . " update ";
$rc = system("$yumcmd_update");
# ignore any return code
2010-03-08 20:46:07 +00:00
2009-07-02 21:41:39 +00:00
2008-02-12 19:36:20 +00:00
postscripts(); #run 'postscripts'
2008-02-12 19:10:33 +00:00
}
2008-07-01 14:11:01 +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
2010-03-30 15:18:31 +00:00
my @KVERS= <$rootimg_dir/boot/vmlinuz-*>;
foreach (@KVERS) {
s/vmlinuz-//;
}
unless (scalar(@KVERS)) {
@KVERS= <$rootimg_dir/lib/modules/*>;
}
2008-07-01 14:11:01 +00:00
if (scalar(@KVERS)) {
2010-03-30 15:18:31 +00:00
$basekernelver = basename(pop @KVERS);
2008-07-01 14:11:01 +00:00
}
unless ($basekernelver) {
$basekernelver = `uname -r`;
}
unless ($kernelver) {
$kernelver=$basekernelver;
}
chomp($kernelver);
2010-03-30 15:49:46 +00:00
open($moddeps,"<","$rootimg_dir/lib/modules/$kernelver/modules.dep");
my @moddeps = <$moddeps>;
my @checkdeps = @ndrivers;
while (scalar @checkdeps) {
my $driver = pop @checkdeps;
my @lines = grep /\/$driver:/,@moddeps;
foreach (@lines) {
chomp;
s/.*://;
s/^\s*//;
my @deps = split /\s+/,$_;
my $dep;
foreach $dep (@deps) {
$dep =~ s/.*\///;
unless (grep { $_ eq $dep } @ndrivers) { #only add if not added
unshift (@checkdeps,$dep); #recursively check dependencies
unshift (@ndrivers,$dep);
print "Added $dep as an autodetected depedency\n";
}
}
}
}
close($moddeps);
2008-02-12 19:10:33 +00:00
unlink "/tmp/genimage.$$.yum.conf";
2009-02-19 06:25:49 +00:00
#-- run postinstall script
2009-09-24 18:51:53 +00:00
if (!$imagename) {
2010-03-19 21:12:56 +00:00
$postinstall_filename= get_profile_def_filename($customdir, "postinstall");
2009-09-24 18:51:53 +00:00
if (!$postinstall_filename) {
2010-03-19 21:12:56 +00:00
$postinstall_filename= get_profile_def_filename($pathtofiles, "postinstall");
2009-09-24 18:51:53 +00:00
}
}
if (($postinstall_filename) && (-x $postinstall_filename)) {
my $rc = system($postinstall_filename, $rootimg_dir,$osver,$arch,$profile);
2009-02-19 06:25:49 +00:00
if($rc) {
print "postinstall script failed\n";
exit 1;
}
}
2009-12-15 20:29:50 +00:00
# statelite .statelite directory added here.
# this is where tmpfs will be created.
if($mode eq "statelite"){
mkpath "$rootimg_dir/.statelite"; # create place for NFS mounts.
# this script will get the directories.
unless(-f "../add-on/statelite/rc.statelite"){
print "Can't find ../add-on/statelite/rc.statelite!\n";
exit;
}
system("cp ../add-on/statelite/rc.statelite $rootimg_dir/etc/init.d/statelite");
# also need to add this file:
# may have already been made into a symbolic link, if so ignore it
unless(-l "$rootimg_dir/var/lib/dhclient" ){
mkpath "$rootimg_dir/var/lib/dhclient/";
system("touch $rootimg_dir/var/lib/dhclient/dhclient-$prinic.leases");
}
unless(-l "$rootimg_dir/var/lib/dhcp" ){
mkpath "$rootimg_dir/var/lib/dhcp/";
system("touch $rootimg_dir/var/lib/dhcp/dhclient-$prinic.leases");
}
}
2008-02-12 19:36:20 +00:00
mkinitrd();
2008-02-12 19:10:33 +00:00
sub getlibs {
my $file = shift;
2009-09-24 18:51:53 +00:00
my $liblist = `chroot $rootimg_dir ldd $file`;
2008-02-12 19:10:33 +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 {
2008-05-09 20:09:23 +00:00
mkpath("/tmp/xcatinitrd.$$/bin");
if($basekernelver eq $kernelver) {
2010-03-30 15:18:31 +00:00
copy(<$rootimg_dir/boot/vmlinuz*>,"$destdir/kernel");
2008-05-09 20:09:23 +00:00
}
else {
2009-09-24 18:51:53 +00:00
if(-r "$rootimg_dir/boot/vmlinuz-$kernelver") {
2010-03-30 15:18:31 +00:00
copy("$rootimg_dir/boot/vmlinuz-$kernelver","$destdir/kernel");
2008-05-19 17:38:12 +00:00
} elsif(-r "/boot/vmlinuz-$kernelver") {
2009-09-24 18:51:53 +00:00
copy("/boot/vmlinuz-$kernelver","$destdir/kernel");
2008-05-09 20:09:23 +00:00
}
else {
2008-05-20 14:12:27 +00:00
xdie("Cannot read /boot/vmlinuz-$kernelver");
2008-05-09 20:09:23 +00:00
}
}
2008-02-12 19:10:33 +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");
mkpath("/tmp/xcatinitrd.$$/lib64/firmware");
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");
mkpath("/tmp/xcatinitrd.$$/var/lib/dhclient");
my $inifile;
2009-12-04 00:53:47 +00:00
# start writing to the init script.
2008-02-12 19:10:33 +00:00
open($inifile,">","/tmp/xcatinitrd.$$/init");
print $inifile "#!/sbin/busybox.anaconda sh\n";
2009-12-04 00:53:47 +00:00
# add some functions
print $inifile <<EOS1;
NEWROOT="/sysroot"
SHELL="/bin/sh"
2009-12-15 20:29:50 +00:00
RWDIR=".statelite"
2009-12-04 00:53:47 +00:00
# Define some colors
RESET="\033[0m"
RED="\033[31m"
CYAN="\033[36m"
YELLOW="\033[33m\033[1m"
GREEN="\033[32m"
PINK="\033[35m\033[1m"
MAGENTA="\033[35m"
BROWN="\033[33m"
2009-12-15 20:29:50 +00:00
NORMAL=\$RESET
2009-12-04 00:53:47 +00:00
2009-12-15 20:29:50 +00:00
# This function is used to mount files/directories from the .statelite directory
2009-12-04 00:53:47 +00:00
# over the root directory.
# This function stolen from redhat
shell() {
echo ''
echo -e "\$YELLOW Entering rescue/debug init shell."
echo -e " Exit shell to continue booting.\$RESET"
\$SHELL
}
mountfile () {
snapshotfile=\${NEWROOT}/\${RWDIR}/\${2}\${1}
dir=`dirname \$snapshotfile`
#
# Check if file already exists in snapshot directory. If not attempt to copy
# from root directory to snapshot directory.
#
if [ ! -e \$snapshotfile ]; then
mkdir -p \$dir || echo -e "\${RED}Can't make \$dir\${NORMAL}"
#echo -e "\${YELLOW} \${1} missing from client specific area.\${RESET}"
if [ -e \$NEWROOT/\${1} ] ; then
#echo "Copying \${1}"
rsync -a \$NEWROOT/\${1} \$snapshotfile
else
#echo "Creating \${1}"
touch \$snapshotfile
fi
fi
#
# Mount the snapshotfile over the root file so the client will have r/w access
#
2009-12-15 20:29:50 +00:00
mount -n -o bind \$NEWROOT/\$RWDIR/\${2}\${1} \$NEWROOT/\${1}
2009-12-04 00:53:47 +00:00
}
fancydisplay () {
clear
echo -e "\$CYAN"
2009-12-15 20:29:50 +00:00
echo '
.. :iiii,
:tLL; .,:...,.
.j;:tLt. :. .;j: ij::::;.
:tt;:::,ii:.jEEGi :tDEEG:.ti,::::;t:
.,,,,,,,,,,,tLEEEEj: tDEEEEDtj;,,,::::::
.:,,::::::,;fDEEEEEL,. .,ijDEDDDEEGt,,,,:,ijj;
.... ..:;jDDLGDEEEGGGfjjjjjjfffLGDEEDEEDLjfGDt,:..
.iftffGDLLDEEEDDDEEDDDDEDEEGLfLjjtti:
,fii;jGDGffLjifLGLjtfffffGDEDGfji
;DEEGffDDDjiii;;ii;,tGDEGjfEEEEf.
,GEGGftiGEEEDt:,;,;;LEEDGjLEEEEEEG
;DEDGjtjfitjGGjfDGj;jLLiitfGDEGjEEDj
fGjjtfLfji;itjfGDjLDfjjjji;tGGLDEEDj
fEDGffjti;ittjjjjtjjjjt:,,iiGGGGjtf.
:fGGLfLLfLGf;i;ijffj,,tjLGDDGLfjtf,
:;tLfjiiffLGDDDGLGEEEEjfGDDGGLfjfff:
.. ,;tLLLLLL,;tijfLGGGjfDEEEEDLLGGGLLLjtjLLfi,.
.jffLLLLGGLfjj;: :,;ijLGLfjGEDDEGtfGGLfjj:.,jjLGGLti;,,;fj,
,fGGGGGGLj,. ;jGGGGLLjffftjLj;.. .,tfGGGGGGGGGGi
,jGDDDj,. :tLGLGGLGDLjt, :iLGGDDDDGLif
,LDDDL, .;LDDDDGfff, ,;iGDDj;,..
;fGGGf, ,;;;;,: tf;jL,
;.:::, Powered by xCAT ,j.:;
'
2009-12-04 00:53:47 +00:00
echo -e "\$RESET"
echo -e "\$YELLOW"
echo '
_________ ________________
___ __\\_ ___ \\ / _ \\__ ___/
\\ \\/ / \\ \\/ / /_\\ \\| |
> <\\ \\____/ | \\ |
/__/\\_ \\\\______ /\\____|__ /____|
\\/ \\/ \\/
'
echo -e "\$RESET"
}
EOS1
2008-02-12 19:10:33 +00:00
print $inifile "busybox.anaconda mount -t proc /proc /proc\n";
print $inifile "busybox.anaconda --install\n";
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";
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";
}
2008-04-24 16:06:50 +00:00
print $inifile <<EOMS;
2009-12-04 00:53:47 +00:00
# check and see if debug is specified on command line
2009-12-15 20:29:50 +00:00
grep '\(debug\)' /proc/cmdline > /dev/null && export DEBUG=1
2008-04-24 16:06:50 +00:00
netstart
2008-10-23 14:28:32 +00:00
while ! ifconfig | grep inet; do
2009-12-04 00:53:47 +00:00
echo -e "\${RED}Failed to acquire address, retrying \${RESET}"
2008-10-23 14:28:32 +00:00
sleep 1
netstart
done
2008-05-14 23:16:48 +00:00
ifconfig lo 127.0.0.1
ifconfig lo up
2008-04-24 16:06:50 +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
2009-12-04 00:53:47 +00:00
ST=`expr \$RANDOM % 5`
sleep \$ST
2008-04-24 16:06:50 +00:00
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
2009-12-04 00:53:47 +00:00
# for NFS root
elif [ "\$KEY" == 'NFSROOT' ]; then
NFSROOT=1
VALUE=`echo \$i |awk -F= '{print \$2}'`
SERVER=`echo \$VALUE|awk -F: '{print \$1}'`
ROOTDIR=`echo \$VALUE|awk -F/ '{for(i=2;i<=NF;i++) printf "/%s",\$i}'`
2009-12-15 20:29:50 +00:00
elif [ "\$KEY" == 'STATEMNT' ]; then
2009-12-04 00:53:47 +00:00
NFSROOT=1
VALUE=`echo \$i |awk -F= '{print \$2}'`
SNAPSHOTSERVER=`echo \$VALUE|awk -F: '{print \$1}'`
SNAPSHOTROOT=`echo \$VALUE|awk -F/ '{for(i=2;i<=NF;i++) printf "/%s",\$i}'`
2009-12-15 20:29:50 +00:00
# may be that there is not server and just a directory.
if [ -z \$SNAPSHOTROOT ]
then
SNAPSHOTROOT=\$SNAPSHOTSERVER
SNAPSHOTSERVER=
fi
2008-04-24 16:06:50 +00:00
fi
done
2009-12-04 00:53:47 +00:00
# show xCAT logo
fancydisplay
2009-03-03 20:05:17 +00:00
echo 0 > /proc/sys/vm/zone_reclaim_mode #Avoid kernel bug
2009-12-04 00:53:47 +00:00
# NFSROOT code here:
if [ "\$NFSROOT" = "1" ]; then
2009-12-15 20:29:50 +00:00
echo Setting up Statelite
2009-12-04 00:53:47 +00:00
# for loop back mounting capability!
mknod /dev/loop0 b 7 0
mkdir -p \$NEWROOT
2009-12-15 20:29:50 +00:00
MAXTRIES=5
ITER=0
ME=`hostname`
2010-03-01 16:32:22 +00:00
while ! mount.nfs \${SERVER}:\${ROOTDIR}/rootimg \$NEWROOT -r -n -o nolock,rsize=32768,tcp,nfsvers=3,timeo=14
2009-12-04 00:53:47 +00:00
do
ITER=\$(expr \$ITER + 1)
if [ "\$ITER" == "\$MAXTRIES" ]
2009-12-15 20:29:50 +00:00
then
2009-12-04 00:53:47 +00:00
echo "You're dead. rpower \$ME boot to play again."
echo "Possible problems:
1. This initrd wasn't created for statelite node? rerun genimage with the -m statelite flag, then rerun 'nodeset \$ME statelite'
2. Is DNS set up? Maybe that's why I can't mount \${SERVER}.
3. The nfs modules aren't set right in this initfs?"
shell
exit
fi
echo -e "\${RED}Could not mount \$SERVER:\$ROOTDIR on \$NEWROOT \$RESET"
RS=`expr \$RANDOM % 30`
echo -e "Trying again in \$RS seconds"
sleep \$RS
done
# now we need to mount the rest of the system. This is the read/write portions
#echo "Mounting Snapshot directories"
if [ ! -e "\$NEWROOT/\$RWDIR" ]
then
echo ""
2009-12-15 20:29:50 +00:00
echo -e "\${RED}Hmmm... this NFS root directory doesn't have a /\$RWDIR directory for me to mount a rw filesystem. You'd better create it... \${NORMAL}"
2009-12-04 00:53:47 +00:00
echo "."
shell
fi
2009-12-15 20:29:50 +00:00
while [ ! -e "\$NEWROOT/etc/init.d/statelite" ]
do
echo ""
echo -e "\${RED}Hmmm... \$NEWROOT/etc/init.d/statelite doesn't exist. Perhaps you didn't create this image with the -m statelite mode"
echo ""
2009-12-04 00:53:47 +00:00
shell
2009-12-15 20:29:50 +00:00
done
grep '\\(shell\\)' /proc/cmdline >/dev/null && shell
2010-03-05 08:05:47 +00:00
mount -t tmpfs rw -o mode=$permission \$NEWROOT/\$RWDIR
2009-12-15 20:29:50 +00:00
mkdir -p \$NEWROOT/\$RWDIR/tmpfs
# mount the SNAPSHOT directory here for persistent use.
if [ ! -z \$SNAPSHOTSERVER ]
then
mkdir -p \$NEWROOT/\$RWDIR/persistent
MAXTRIES=5
ITER=0
2010-03-01 16:32:22 +00:00
while ! mount \$SNAPSHOTSERVER:\$SNAPSHOTROOT \$NEWROOT/\$RWDIR/persistent -o nolock,rsize=32768,tcp,nfsvers=3,timeo=14
2009-12-15 20:29:50 +00:00
do
ITER=\$(expr \$ITER + 1)
if [ "\$ITER" == "\$MAXTRIES" ]
then
echo "You're dead. rpower \$ME boot to play again."
echo "Possible problems:
1. \$SNAPSHOTSERVER is not exporting \$SNAPSHOTROOT ?
2. Is DNS set up? Maybe that's why I can't mount \$SNAPSHOTSERVER."
shell
exit
fi
echo -e "\${RED}Hmmm... Can't mount \$SNAPSHOTSERVER:\$SNAPSHOTROOT. \${NORMAL}"
RS=`expr \$RANDOM % 20`
echo -e "Trying again in \$RS seconds"
sleep \$RS
done
2009-12-04 00:53:47 +00:00
fi
2009-12-15 20:29:50 +00:00
grep '\\(shell\\)' /proc/cmdline >/dev/null && shell
2009-12-04 00:53:47 +00:00
# have to preserve the initial DHCP request. So we link it.
2009-12-15 20:29:50 +00:00
if [ ! -d \$NEWROOT/\$RWDIR/tmpfs/var/lib/dhclient ]
2009-12-04 00:53:47 +00:00
then
2009-12-15 20:29:50 +00:00
mkdir -p \$NEWROOT/\$RWDIR/tmpfs/var/lib/dhclient
2009-12-04 00:53:47 +00:00
fi
2009-12-15 20:29:50 +00:00
if [ ! -d \$NEWROOT/\$RWDIR/tmpfs/var/lib/dhcp ]
then
mkdir -p \$NEWROOT/\$RWDIR/tmpfs/var/lib/dhcp
fi
cp -fp /var/lib/dhclient/dhclient.leases \${NEWROOT}/\${RWDIR}/tmpfs/var/lib/dhclient/dhclient-$prinic.leases
cp -fp /var/lib/dhclient/dhclient.leases \${NEWROOT}/\${RWDIR}/tmpfs/var/lib/dhcp/dhclient-$prinic.leases
2009-12-04 00:53:47 +00:00
2009-12-15 20:29:50 +00:00
# dhclient
#while ! mount -n --bind \$NEWROOT/\$RWDIR/tmpfs/var/lib/dhclient/dhclient-$prinic.leases \$NEWROOT/var/lib/dhclient/dhclient-$prinic.leases
#do
# echo "Can't mount /tmpfs/var/lib/dhclient/dhclient-$prinic.leases to /var/lib/dhclient/dhclient-$prinic.leases"
# shell
#done
2009-12-04 00:53:47 +00:00
2009-12-15 20:29:50 +00:00
# dhcp
#while ! mount -n --bind \$NEWROOT/\$RWDIR/tmpfs/var/lib/dhcp/dhclient-$prinic.leases \$NEWROOT/var/lib/dhcp/dhclient-$prinic.leases
#do
# echo "Can't mount /tmpfs/var/lib/dhcp/dhclient-$prinic.leases to /var/lib/dhcp/dhclient-$prinic.leases"
# shell
#done
[ -e /etc/ntp.conf ] && mkdir -p \$NEWROOT/\$RWDIR/tmpfs/etc && cp /etc/ntp.conf \$NEWROOT/\$RWDIR/tmpfs/etc/
[ -e /etc/ntp/step-kickers ] && mkdir -p \$NEWROOT/\$RWDIR/tmpfs/etc/ntp && cp /etc/ntp/step-kickers \$NEWROOT/\$RWDIR/tmpfs/etc/ntp
[ -e /etc/resolv.conf ] && mkdir -p \$NEWROOT/\$RWDIR/tmpfs/etc && cp /etc/resolv.conf \$NEWROOT/\$RWDIR/tmpfs/etc/
# now that everything is mounted, lets do this
# hmmm, apparently I'm checking this twice... so I'd better
# be really sure the file is there.
while [ -z \$NEWROOT/etc/init.d/statelite ]
2009-12-04 00:53:47 +00:00
do
2009-12-15 20:29:50 +00:00
echo "\$NEWROOT/etc/init.d/statelite does not exist in image!"
2009-12-04 00:53:47 +00:00
shell
done
2009-12-15 20:29:50 +00:00
# do all the mounts:
\$NEWROOT/etc/init.d/statelite
# give the debug shell just before we go if specified!
grep '\(shell\)' /proc/cmdline > /dev/null && shell
2009-12-04 00:53:47 +00:00
echo 0x100 > /proc/sys/kernel/real-root-dev
export keep_old_ip=yes
export fastboot=yes
export READONLY=yes
2009-12-15 20:29:50 +00:00
grep '\\(shell\\)' /proc/cmdline >/dev/null && shell
2009-12-04 00:53:47 +00:00
mount -n --bind /dev /sysroot/dev
umount /sys
umount /proc
if ! exec /sbin/switch_root -c /dev/console \$NEWROOT /sbin/init
then
echo ""
echo -e "\${RED}Couldn't switch_root. Something must be wrong with NFS root image.\${RESET}"
2009-12-15 20:29:50 +00:00
# mount -t proc proc /proc
2009-12-04 00:53:47 +00:00
shell
fi
exit
fi
# END NFSROOT/Statelite code
# RAM root Hybrid with NFS root
2008-04-24 16:06:50 +00:00
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
2010-03-01 16:32:22 +00:00
mount.nfs \$SERVER:\$ROOTDIR /ro -r -n -o nolock,rsize=32768,tcp,nfsvers=3,timeo=14
2009-12-04 00:53:47 +00:00
ST=`expr \$RANDOM % 5`
sleep \$ST
2008-04-24 16:06:50 +00:00
done
mount -t tmpfs rw /rw
2008-05-11 14:25:45 +00:00
mkdir -p /rw/etc
mkdir -p /rw/var/lib/dhclient
cp /etc/resolv.conf /rw/etc/
2008-05-14 23:16:48 +00:00
cp /var/lib/dhclient/dhclient.leases /rw/var/lib/dhclient/dhclient-$prinic.leases
2008-04-24 16:06:50 +00:00
mount -t aufs -o dirs=/rw:/ro mergedroot /sysroot
2008-05-09 15:31:09 +00:00
mkdir -p /sysroot/ro
mkdir -p /sysroot/rw
mount --move /ro /sysroot/ro
mount --move /rw /sysroot/rw
2008-04-28 18:03:18 +00:00
cp /etc/resolv.conf /sysroot/etc/
2008-09-09 23:52:04 +00:00
echo xcatfs / aufs rw,_netdev 0 0 >> /sysroot/etc/fstab
2008-04-24 16:06:50 +00:00
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
2008-05-09 15:31:09 +00:00
mkdir -p /sysroot/ro
mkdir -p /sysroot/rw
mount --move /ro /sysroot/ro
mount --move /rw /sysroot/rw
2008-04-24 16:06:50 +00:00
EOMS
2008-02-12 19:10:33 +00:00
print $inifile "elif [ -r /rootimg.gz ]; then\n";
2008-04-24 16:06:50 +00:00
print $inifile "echo Setting up RAM-root tmpfs.\n";
2008-02-27 20:32:31 +00:00
if ($rootlimit) {
print $inifile " mount -o size=$rootlimit -t tmpfs rootfs /sysroot\n";
} else {
print $inifile " mount -t tmpfs rootfs /sysroot\n";
}
2008-02-12 19:10:33 +00:00
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";
2008-04-24 16:06:50 +00:00
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
2008-02-12 19:10:33 +00:00
print $inifile " exit\n";
print $inifile "fi\n";
print $inifile "cd /\n";
2008-02-27 14:47:07 +00:00
print $inifile "cp /var/lib/dhclient/dhclient.leases /sysroot/dev/.dhclient-$prinic.leases\n";
2008-05-14 23:16:48 +00:00
print $inifile "cp /var/lib/dhclient/dhclient.leases /sysroot/var/lib/dhclient/dhclient-$prinic.leases\n";
2008-02-12 19:10:33 +00:00
print $inifile "mknod /sysroot/dev/console c 5 1\n";
print $inifile "exec switch_root -c /dev/console /sysroot /sbin/init\n";
close($inifile);
2009-12-04 00:53:47 +00:00
2008-02-12 19:10:33 +00:00
open($inifile,">"."/tmp/xcatinitrd.$$/bin/netstart");
print $inifile "#!/sbin/nash\n";
2008-02-27 14:47:07 +00:00
print $inifile "network --device $prinic --bootproto dhcp\n";
2008-02-12 19:10:33 +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-02-12 19:10:33 +00:00
push @filestoadd,[$_,"lib/$_"];
2008-09-11 22:03:01 +00:00
} elsif (-f "$pathtofiles/$_") {
push @filestoadd,[$_,"lib/$_"];
}
2008-02-12 19:10:33 +00:00
}
2009-12-04 00:53:47 +00:00
# add rsync for statelite
foreach ("bin/cpio","sbin/nash","sbin/busybox.anaconda","sbin/rmmod","sbin/mount.nfs","/usr/bin/rsync") {
2008-02-12 19:10:33 +00:00
getlibs($_);
push @filestoadd,$_;
}
2008-05-07 20:09:23 +00:00
if ($arch =~ /x86_64/) {
push @filestoadd,"lib64/libnss_dns.so.2";
2008-06-24 13:48:35 +00:00
push @filestoadd,"lib64/libresolv.so.2";
2008-05-07 20:09:23 +00:00
}
else {
push @filestoadd,"lib/libnss_dns.so.2";
}
2008-02-12 19:10:33 +00:00
push @filestoadd,keys %libhash;
2008-05-09 20:09:23 +00:00
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-19 17:38:12 +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-19 17:38:12 +00:00
}
else {
2008-05-20 14:12:27 +00:00
xdie("Cannot read /lib/modules/$kernelver");
2008-05-19 17:38:12 +00:00
}
}
2008-05-09 20:09:23 +00:00
}
2009-09-24 18:51:53 +00:00
find(\&isnetdriver, <$rootimg_dir/lib/modules/$kernelver/*>);
2008-09-11 22:03:01 +00:00
2008-02-12 19:10:33 +00:00
foreach (@filestoadd) {
if (ref($_)) {
2008-09-11 22:03:01 +00:00
#print "$_->[0], $_->[1]\n";
2009-09-24 18:51:53 +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-02-12 19:10:33 +00:00
$srcpath="$pathtofiles/".$_->[0];
}
2008-06-02 15:41:50 +00:00
mkpath(dirname("/tmp/xcatinitrd.$$/".$_->[1]));
2008-02-12 19:10:33 +00:00
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-02-12 19:10:33 +00:00
}
2008-06-02 15:41:50 +00:00
mkpath(dirname("/tmp/xcatinitrd.$$/$_"));
2008-02-12 19:10:33 +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.$$/$_");
system("cd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|gzip -9 -c - > $destdir/initrd.gz");
2008-02-12 19:10:33 +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) {
2008-05-09 21:18:42 +00:00
if ($File::Find::name =~ /\/$_/) {
2008-02-12 19:10:33 +00:00
my $filetoadd = $File::Find::name;
2009-09-24 18:51:53 +00:00
$filetoadd =~ s!$rootimg_dir/!!;
2008-02-12 19:10:33 +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-02-12 19:10:33 +00:00
}
2009-09-24 18:51:53 +00:00
chmod 0600,</$rootimg_dir/etc/ssh/*key>;
2008-02-12 19:10:33 +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-02-12 19:10:33 +00:00
for my $file (</$installroot/postscripts/.ssh/*>) {
2009-09-24 18:51:53 +00:00
copy ($file,"/$rootimg_dir/root/.ssh/");
2008-02-12 19:10:33 +00:00
}
2009-09-24 18:51:53 +00:00
chmod(0600,</$rootimg_dir/root/.ssh/*>);
2008-02-12 19:10:33 +00:00
}
2008-04-14 12:32:20 +00:00
2008-02-12 19:10:33 +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-02-12 19:10:33 +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";
2008-02-27 20:32:31 +00:00
if ($tmplimit) {
print $cfgfile "tmpfs /tmp tmpfs defaults 0 0\n";
print $cfgfile "tmpfs /var/tmp tmpfs defaults 0 0\n";
}
2008-02-12 19:10:33 +00:00
close($cfgfile);
2009-09-24 18:51:53 +00:00
open($cfgfile,">","$rootimg_dir/etc/sysconfig/network");
2008-02-12 19:10:33 +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-07 19:20:47 +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-02-12 19:10:33 +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-02-12 19:10:33 +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-07 14:51:12 +00:00
print $cfgfile "ttyS0\n";
print $cfgfile "ttyS1\n";
close($cfgfile);
my @passwd;
2009-09-24 18:51:53 +00:00
open($cfgfile,"<","$rootimg_dir/etc/passwd");
2008-05-07 14:51:12 +00:00
@passwd = <$cfgfile>;
close($cfgfile);
2009-09-24 18:51:53 +00:00
open($cfgfile,">","$rootimg_dir/etc/passwd");
2008-05-07 14:51:12 +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-07 15:27:10 +00:00
if (basename($_) eq '.' or basename($_) eq '..') {
next;
}
2009-09-24 18:51:53 +00:00
copy $_,"$rootimg_dir/root/";
2008-05-07 15:27:10 +00:00
}
2009-09-24 18:51:53 +00:00
unless ( -r <$rootimg_dir/etc/rc3.d/S??network>) {
symlink "/etc/init.d/network","$rootimg_dir/etc/rc3.d/S10network";
2008-06-07 16:38:08 +00:00
}
2009-09-24 18:51:53 +00:00
open($cfgfile,">","$rootimg_dir/etc/rc3.d/S60gettyset");
2008-02-12 19:10:33 +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-02-12 19:10:33 +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";
2008-06-07 16:38:08 +00:00
print $cfgfile " if [ -x /sbin/initctl ]; then\n"; #Upstart style
print $cfgfile " initctl emit --no-wait fedora.serial-console-available \$COTTY \$COSPEED\n";
print $cfgfile " else\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-06-07 16:38:08 +00:00
print $cfgfile " init q\n";
print $cfgfile " fi\n";
2008-02-12 19:10:33 +00:00
print $cfgfile " fi\n";
print $cfgfile "done\n";
2009-09-24 18:51:53 +00:00
chmod(0755,"$rootimg_dir/etc/rc3.d/S60gettyset");
#link("$rootimg_dir/sbin/init","$rootimg_dir/init");
2010-02-04 16:32:15 +00:00
#add postscript support for redhat
if($mode eq "statelite") {
print $cfgfile "/opt/xcat/xcatdsklspost 4\n";
} else {
print $cfgfile "/opt/xcat/xcatdsklspost\n";
}
2010-03-01 02:18:05 +00:00
close($cfgfile);
2008-02-12 19:10:33 +00:00
2010-03-30 15:18:31 +00:00
copy(<$rootimg_dir/boot/vmlinuz*>,"$destdir/kernel"); }
2009-10-06 20:21:11 +00:00
2010-03-19 21:12:56 +00:00
sub get_package_names {
my $plist_file_name=shift;
2009-07-02 21:41:39 +00:00
my %pkgnames=();
my @tmp_array=();
2008-09-11 22:03:01 +00:00
2010-03-19 21:12:56 +00:00
if ($plist_file_name) {
2008-09-09 23:52:04 +00:00
my $pkgfile;
2010-03-19 21:12:56 +00:00
open($pkgfile,"<","$plist_file_name");
2008-09-09 23:52:04 +00:00
while (<$pkgfile>) {
chomp;
2009-07-02 21:41:39 +00:00
s/\s+$//; #remove trailing white spaces
next if /^\s*$/; #-- skip empty lines
push(@tmp_array,$_);
2008-09-09 23:52:04 +00:00
}
close($pkgfile);
2009-07-02 21:41:39 +00:00
if ( @tmp_array > 0) {
my $pkgtext=join(',',@tmp_array);
#handle the #INLCUDE# tag recursively
2010-03-19 21:12:56 +00:00
my $idir = dirname($plist_file_name);
2009-07-02 21:41:39 +00:00
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);
2010-03-25 20:37:00 +00:00
my $pass=1;
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/^-//;
2010-03-25 20:37:00 +00:00
} elsif (/^#NEW_INSTALL_LIST#/) {
$pass++;
next;
} elsif (/^#/) {
# ignore all other comment lines
next;
2009-10-06 20:21:11 +00:00
} else {
$idir=dirname($_);
}
2009-07-02 21:41:39 +00:00
my $fn=basename($_);
2010-03-25 20:37:00 +00:00
if (exists($pkgnames{$pass}{$idir})) {
my $pa=$pkgnames{$pass}{$idir};
2009-07-02 21:41:39 +00:00
push(@$pa, $fn);
} else {
2010-03-25 20:37:00 +00:00
$pkgnames{$pass}{$idir}=[$fn];
2009-07-02 21:41:39 +00:00
}
}
}
2008-09-09 23:52:04 +00:00
}
2009-07-02 21:41:39 +00:00
return %pkgnames;
2008-09-09 23:52:04 +00:00
}
2009-07-02 21:41:39 +00:00
2009-10-06 20:21:11 +00:00
2009-07-02 21:41:39 +00:00
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-11 22:03:01 +00:00
2010-03-19 21:12:56 +00:00
sub get_profile_def_filename {
2008-09-11 22:03:01 +00:00
my $base=shift;
2010-03-19 21:12:56 +00:00
my $ext=shift;
my $dotpos = rindex($osver, ".");
my $osbase = substr($osver, 0, $dotpos);
if (-r "$base/$profile.$osver.$arch.$ext") {
return "$base/$profile.$osver.$arch.$ext";
} elsif (-r "$base/$profile.$osbase.$arch.$ext") {
return "$base/$profile.$osbase.$arch.$ext";
} elsif (-r "$base/$profile.$arch.$ext") {
return "$base/$profile.$arch.$ext";
} elsif (-r "$base/$profile.$osver.$ext") {
return "$base/$profile.$osver.$ext";
} elsif (-r "$base/$profile.$osbase.$ext") {
return "$base/$profile.$osbase.$ext";
} elsif (-r "$base/$profile.$ext") {
return "$base/$profile.$ext";
2008-09-11 22:03:01 +00:00
}
return "";
}
2009-12-04 00:53:47 +00:00