rollback the Schema.pm, xcatroot and genimage to r7384

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@7392 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
mxi1 2010-09-09 08:54:48 +00:00
parent 0e7331553d
commit 18ba59ac23
3 changed files with 297 additions and 379 deletions

View File

@ -586,7 +586,7 @@ osimage => {
},
},
linuximage => {
cols => [qw(imagename template pkglist pkgdir otherpkglist otherpkgdir exlist postinstall rootimgdir nodebootif otherifce netdrivers kernelver permission comments disable)],
cols => [qw(imagename template pkglist pkgdir otherpkglist otherpkgdir exlist postinstall rootimgdir netdrivers kernelver comments disable)],
keys => [qw(imagename)],
table_desc => 'Information about a Linux operating system image that can be used to deploy cluster nodes.',
descriptions => {
@ -599,11 +599,8 @@ linuximage => {
exlist => 'The fully qualified name of the file that stores the file names and directory names that will be excluded from the image during packimage command. It is used for diskless image only.',
postinstall => 'The fully qualified name of the script file that will be run at the end of the packimage command. It is used for diskless image only.',
rootimgdir => 'The directory name where the image is stored. It is used for diskless image only.',
nodebootif => 'The network interface the stateless/statelite node will boot over (e.g. eth0)',
otherifce => 'Other network interfaces (e.g. eth1) in the image that should be configured via DHCP',
netdrivers => 'the ethernet device drivers of the nodes which will use this linux image, at least the device driver for the nodes\' installnic should be included',
kernelver => 'the version of linux kernel used in the linux image. If the kernel version is not set, the default kernel in rootimgdir will be used',
permission => 'the mount permission of /.statelite directory is used, its default value is 755',
comments => 'Any user-written notes.',
disable => "Set to 'yes' or '1' to comment out this row.",
},
@ -1817,16 +1814,6 @@ push(@{$defspec{node}->{'attrs'}}, @nodeattrs);
tabentry => 'linuximage.rootimgdir',
access_tabentry => 'linuximage.imagename=attr:imagename',
},
{attr_name => 'nodebootif',
only_if => 'imagetype=linux',
tabentry => 'linuximage.nodebootif',
access_tabentry => 'linuximage.imagename=attr:imagename',
},
{attr_name => 'otherifce',
only_if => 'imagetype=linux',
tabentry => 'linuximage.otherifce',
access_tabentry => 'linuximage.imagename=attr:imagename',
},
{attr_name => 'netdrivers',
only_if => 'imagetype=linux',
tabentry => 'linuximage.netdrivers',
@ -1837,11 +1824,6 @@ push(@{$defspec{node}->{'attrs'}}, @nodeattrs);
tabentry => 'linuximage.kernelver',
access_tabentry => 'linuximage.imagename=attr:imagename',
},
{attr_name => 'permission',
only_if => 'imagetype=linux',
tabentry => 'linuximage.permission',
access_tabentry => 'linuximage.imagename=attr:imagename',
},
####################
# nimimage table#
####################

View File

@ -24,7 +24,32 @@ if [ ! -z "$imgurl" ]; then
fi
#echo 0 > /proc/sys/vm/zone_reclaim_mode #Avoid kernel bug
if [ -r /rootimg.sfs ]; then
# RAM root Hybrid with NFS root
if [ "$NFS" = "1" ]; then
echo Setting up nfs with ram overlay.
modprobe nfs
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
mount.nfs $SERVER:$ROOTDIR /ro -r -n -o nolock,rsize=32768,tcp,nfsvers=3,timeo=14
ST=`expr $RANDOM % 5`
sleep $ST
done
mount -t tmpfs rw /rw
mkdir -p /rw/etc
mkdir -p /rw/var/lib/dhclient
cp /etc/resolv.conf /rw/etc/
mount -t aufs -o dirs=/rw:/ro mergedroot $NEWROOT
mkdir -p $NEWROOT/ro
mkdir -p $NEWROOT/rw
mount --move /ro $NEWROOT/ro
mount --move /rw $NEWROOT/rw
cp /etc/resolv.conf $NEWROOT/etc/
echo xcatfs / aufs rw,_netdev 0 0 >> $NEWROOT/etc/fstab
elif [ -r /rootimg.sfs ]; then
echo Setting up squashfs with ram overlay.
mknod /dev/loop0 b 7 0
mkdir -p /ro
@ -37,14 +62,14 @@ if [ -r /rootimg.sfs ]; then
mount --move /ro $NEWROOT/ro
mount --move /rw $NEWROOT/rw
elif [ -r /rootimg.gz ]; then
echo Setting up RAM-root tmpfs.
echo Setting up RAM-root tmpfs.
mount -t tmpfs rootfs $NEWROOT
cd $NEWROOT
echo -n "Extracting root filesystem:"
if [ -x /bin/cpio ]; then
gzip -cd /rootimg.gz |/bin/cpio -idum
gzip -cd /rootimg.gz |/bin/cpio -idum
else
gzip -cd /rootimg.gz |cpio -idum
gzip -cd /rootimg.gz |cpio -idum
fi
echo Done
else

View File

@ -53,6 +53,7 @@ my $srcdir_otherpkgs;
my $otherpkglist;
my $postinstall_filename;
my $rootimg_dir;
my $mode;
my $permission; # the permission works only for statelite mode currently
@ -72,152 +73,98 @@ GetOptions(
'l=s' => \$rootlimit,
't=s' => \$tmplimit,
'k=s' => \$kernelver,
'm=s' => \$mode,
'permission=s' => \$permission
);
# if "Table.pm" can be found here, the attributes in linuximage and osimage will be updated
my $needUpdateTable = 0;
my %keyhash = ();
my %updates_os = (); # the hash for updating osimage table
my %updates = (); # the hash for updating linuximage table
my $osimagetab;
my $linuximagetab;
my $ref_linuximage_tab;
my $ref_osimage_tab;
# load the module in memory
eval { require("$::XCATROOT/lib/perl/xCAT/Table.pm") };
unless ($@) {
# Table.pm is there, we can update the xCAT tables
$needUpdateTable = 1;
# get the info from the osimage and linux
$osimagetab = xCAT::Table->new('osimage', -create=>1);
unless ($osimagetab) {
print "The osimage table cannot be opened.\n";
exit 1;
}
$linuximagetab = xCAT::Table->new('linuximage', -create=>1);
unless ($linuximagetab) {
print "The linuximage table cannot be opened.\n";
exit 1;
}
}
if (@ARGV > 0 and $needUpdateTable eq 1) {
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";
print "-o, -p and -a options are not allowed when a image name is specified.\n";
exit 1;
}
($ref_osimage_tab) = $osimagetab->getAttribs({imagename => $imagename}, 'osvers', 'osarch', 'profile', 'provmethod');
unless ($ref_osimage_tab) {
print "Cannot find image \'$imagename\' from the osimage table.\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;
}
($ref_linuximage_tab) = $linuximagetab->getAttribs({imagename => $imagename}, 'pkglist', 'pkgdir', 'otherpkglist', 'otherpkgdir', 'postinstall', 'rootimgdir', 'nodebootif', 'otherifce', 'kernelver', 'netdrivers', 'permission');
unless ($ref_linuximage_tab) {
print "Cannot find $imagename from the linuximage table\n";
exit 1;
}
$osver = $ref_osimage_tab->{'osvers'};
$arch = $ref_osimage_tab->{'osarch'};
$profile = $ref_osimage_tab->{'profile'};
my $provmethod = $ref_osimage_tab->{'provmethod'}; # TODO: not necessary; and need to update both statelite and stateless modes
$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;
print"osimage.osvers, osimage.osarch, osimage.profile and osimage.provmethod must be specified for the image $imagename in the database.\n";
exit 1;
}
unless ($provmethod eq 'netboot' || $provmethod eq 'statelite') {
print "\'$imagename\' cannot be used to build diskless image. Make sure osimage.provmethod is 'netboot'.";
exit 1;
if ($provmethod ne 'netboot') {
print "\'$imagename\' cannot be used to build diskless image. Make sure osimage.provmethod is 'netboot'.";
exit 1;
}
unless ( $ref_linuximage_tab->{'pkglist'} ) {
print"A .pkglist file must be specified for image \'$imagename\' in the linuximage table.\n";
if (! $ref1->{'pkglist'}) {
print"A .pkglist file must be specified for image \'$imagename\' in the linuximage table.\n";
exit 0;
}
$pkglist = $ref_linuximage_tab->{'pkglist'};
$pkglist =$ref1->{'pkglist'};
$srcdir= $ref_linuximage_tab->{'pkgdir'};
$srcdir_otherpkgs = $ref_linuximage_tab->{'otherpkgdir'};
$otherpkglist = $ref_linuximage_tab->{'otherpkglist'};
$postinstall_filename = $ref_linuximage_tab->{'postinstall'};
$destdir = $ref_linuximage_tab->{'rootimgdir'};
# TODO: how can we do if the user specifies one wrong value to the following attributes?
# currently, one message is output to indicate the users there will be some updates
if ($prinic) {
if ($prinic ne $ref_linuximage_tab->{'nodebootif'}) {
print "The primary nic is different from the value in linuximage table, will update it\n";
$updates{'nodebootif'} = $prinic;
}
} else {
$prinic = $ref_linuximage_tab->{'nodebootif'};
}
if ($othernics) {
if ($othernics ne $ref_linuximage_tab->{'otherifce'}) {
print "The other ifces are different from the value in linuximage table, will update it\n";
$updates{'otherifce'} = $othernics;
}
} else {
$othernics = $ref_linuximage_tab->{'otherifce'};
}
if ($kernelver) {
if ($kernelver ne $ref_linuximage_tab->{'kernelver'}) {
print "The kernelver is different from the value in linuximage table, will update it\n";
$updates{'kernelver'} = $kernelver;
}
} else {
$kernelver = $ref_linuximage_tab->{'kernelver'};
}
if ($ndrivers) {
if ($ndrivers ne $ref_linuximage_tab->{'netdrivers'}) {
print "The netdrivers are different from the value in linuximage table, will update it\n";
$updates{'netdrivers'} = $ndrivers;
}
} else {
$ndrivers = $ref_linuximage_tab->{'netdrivers'};
}
if ($permission) {
if ($permission ne $ref_linuximage_tab->{'permission'}) {
print "The permission value is different from the value in linuximage table, will update it\n";
$updates{'permission'} = $permission;
}
} else {
$permission = $ref_linuximage_tab->{'permission'};
}
# TODO: update the Attributes, put it later
#$linuximagetab->setAttribs(\%keyhash, \%updates);
#$linuximagetab->commit;
$srcdir=$ref1->{'pkgdir'};
$srcdir_otherpkgs=$ref1->{'otherpkgdir'};
$otherpkglist=$ref1->{'otherpkglist'};
$postinstall_filename=$ref1->{'postinstall'};
$destdir=$ref1->{'rootimgdir'};
}
$permission = "755" unless ($permission);
$updates{'permission'} = $permission if ( $needUpdateTable );
if ($mode eq "statelite") {
if (!$permission) {
$permission = "755";
}
}
unless ($arch) {
if (!$arch) {
$arch = `uname -m`;
chomp($arch);
$arch = "x86" if ($arch =~ /i.86$/);
if ($arch =~ /i.86$/) {
$arch = "x86";
}
}
$srcdir="$installroot/$osver/$arch" unless ($srcdir);
$updates{'srcdir'} = $srcdir if ($needUpdateTable);
if (!$srcdir) {
$srcdir="$installroot/$osver/$arch";
}
$srcdir_otherpkgs = "$installroot/post/otherpkgs/$osver/$arch" unless ($srcdir_otherpkgs);
$updates{'otherpkgdir'} = $srcdir_otherpkgs if ($needUpdateTable);
$destdir="$installroot/netboot/$osver/$arch/$profile" unless ($destdir);
$updates{'rootimgdir'} = $destdir if ($needUpdateTable);
if (!$srcdir_otherpkgs) {
$srcdir_otherpkgs = "$installroot/post/otherpkgs/$osver/$arch";
}
if (!$destdir)
{
$destdir="$installroot/netboot/$osver/$arch/$profile";
}
$rootimg_dir="$destdir/rootimg";
# Get the subchannels of the given interface
@ -247,37 +194,46 @@ if ($arch eq "s390x") {
}
unless ($osver and $profile) {
print 'Usage: genimage [ -i <nodebootif> ] [ -n <nodenetdrivers> ] [-r <otherifaces>] -o <OSVER> -p <PROFILE> -k <KERNELVER> [--permission <permission>]'."\n";
print 'Usage: genimage [ -i <nodebootif> ] [ -n <nodenetdrivers> ] [-r <otherifaces>] -o <OSVER> -p <PROFILE> -k <KERNELVER> [-m <mode> [--permission <permission>]]'."\n";
print ' genimage [ -i <nodebootif> ] [ -n <nodenetdrivers> ] [-r <otherifaces>] -k <KERNELVER> <imagename>'."\n";
print " --permission only works with statelite mode\n";
print " --permission only works when '-m statelite' is set\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 igb,e1000e,e1000,bnx2,tg3 -o centos5.4 -p nfsroot\n";
print " genimage -i eth0 -n igb,e1000e,e1000,bnx2,tg3 -o centos5.4 -p nfsroot --permission 777\n";
print " genimage -i eth0 -n igb,e1000e,e1000,bnx2,tg3 -o centos5.4 -p nfsroot -m statelite\n";
print " genimage -i eth0 -n igb,e1000e,e1000,bnx2,tg3 -o centos5.4 -p nfsroot -m statelite --permission 777\n";
print " genimage -i eth0 -n tg3 myimage\n";
exit 1;
}
my @ndrivers;
if ($netdriver) {
if ( ($updates{'netdrivers'} ne $netdriver) and ($needUpdateTable) ) {
$updates{'netdrivers'} = $netdriver;
}
} else {
if ($arch eq 'x86' or $arch eq 'x86_64') {
@ndrivers = qw/tg3 bnx2 bnx2x e1000 e1000e igb mlx_en/;
} elsif ($arch eq 'ppc64') {
@ndrivers = qw/e1000 e1000e igb ibmveth ehea/;
}
# TODO: need to set the default network drivers for s390x ?
unless ($netdriver) {
@ndrivers = qw/tg3 bnx2 bnx2x e1000 e1000e igb mlx_en/;
}
foreach (split /,/,$netdriver) {
unless (/\.ko$/) {
s/$/.ko/;
}
next if (/^$/);
push @ndrivers, $_;
if (/^$/) {
next;
}
push @ndrivers,$_;
}
unless (-d "$rootimg_dir/usr/share/dracut") { # dracut will handle the nfs-related kernel modules
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";
# Additional modules needed on s390x
if ($arch eq "s390x") {
# The network drivers need to be loaded in this order
unshift @ndrivers,"ccwgroup.ko";
unshift @ndrivers,"qdio.ko";
}
}
}
unless ($onlyinitrd) {
@ -312,18 +268,16 @@ unless ($onlyinitrd) {
$yumcmd .= "install ";
mkpath("$rootimg_dir/var/lib/yum");
unless ($imagename) {
if (!$imagename) {
$pkglist= imgutils::get_profile_def_filename($osver, $profile, $arch, $customdir, "pkglist");
unless ($pkglist) {
$pkglist= imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "pkglist");
if (!$pkglist) {
$pkglist= imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "pkglist");
}
}
if ($pkglist) {
$updates{'pkglist'} = $pkglist if ($needUpdateTable);
} else {
print "Unable to find package list for $profile!";
exit 1;
if (!$pkglist) {
print "Unable to find package list for $profile!";
exit 1;
}
my %pkg_hash=imgutils::get_package_names($pkglist);
@ -346,14 +300,13 @@ unless ($onlyinitrd) {
}
#Now let's handle extra packages
unless ($imagename) {
$otherpkglist = imgutils::get_profile_def_filename($osver, $profile, $arch, $customdir, "otherpkgs.pkglist");
unless ($otherpkglist) { $otherpkglist=imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "otherpkgs.pkglist"); }
if (!$imagename) {
$otherpkglist=imgutils::get_profile_def_filename($osver, $profile, $arch, $customdir, "otherpkgs.pkglist");
if (!$otherpkglist) { $otherpkglist=imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "otherpkgs.pkglist"); }
}
my %extra_hash=();
if ($otherpkglist) {
$updates{'otherpkglist'} = $otherpkglist if ($needUpdateTable);
%extra_hash = imgutils::get_package_names($otherpkglist);
%extra_hash=imgutils::get_package_names($otherpkglist);
}
my %extrapkgnames;
@ -362,64 +315,64 @@ unless ($onlyinitrd) {
my $index=1;
foreach $pass (sort (keys(%extra_hash))) {
foreach (keys(%{$extra_hash{$pass}})) {
if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE")) { next;}
print $yumconfig "[otherpkgs$index]\nname=otherpkgs$index\nbaseurl=file://$srcdir_otherpkgs/$_\ngpgpcheck=0\n\n";
$index++;
my $pa=$extra_hash{$pass}{$_};
$extrapkgnames{$pass} .= " " . join(' ', @$pa);
if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE")) { next;}
print $yumconfig "[otherpkgs$index]\nname=otherpkgs$index\nbaseurl=file://$srcdir_otherpkgs/$_\ngpgpcheck=0\n\n";
$index++;
my $pa=$extra_hash{$pass}{$_};
$extrapkgnames{$pass} .= " " . join(' ', @$pa);
}
}
close($yumconfig);
$index--;
$yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$rootimg_dir/ --disablerepo=* ";
foreach (0..$repnum) {
$yumcmd .= "--enablerepo=$osver-$arch-$_ ";
$yumcmd .= "--enablerepo=$osver-$arch-$_ ";
}
for (1..$index) {
$yumcmd .= "--enablerepo=otherpkgs$_ ";
$yumcmd .= "--enablerepo=otherpkgs$_ ";
}
foreach $pass (sort (keys(%extra_hash))) {
# remove the packages that are specified in the otherpkgs.list files with leading '-'
#remove the packages that are specified in the otherpkgs.list files with leading '-'
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) {
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");
}
$rc = system("$yumcmd_remove $rm_packges");
}
}
# install extra packages
#install extra packages
my $yumcmd_base = $yumcmd;
$yumcmd .= "install ";
# append extra pkg names to yum command
#append extra pkg names to yum command
if ($extrapkgnames{$pass}) {
$yumcmd .= " $extrapkgnames{$pass} ";
$yumcmd .= " $extrapkgnames{$pass} ";
}
$yumcmd =~ s/ $/\n/;
# debug
#print "yumcmd=$yumcmd\n";
#debug
print "yumcmd=$yumcmd\n";
#my $repo=`cat /tmp/genimage.$$.yum.conf`;
#print "repo=$repo";
my $rc = system($yumcmd);
if ($rc) {
print "yum invocation failed\n";
exit 1;
print "yum invocation failed\n";
exit 1;
}
# remove the packages that are specified in the otherpkgs.list files with leading '--'
#remove the packages that are specified in the otherpkgs.list files with leading '--'
if (exists ($extra_hash{$pass}{'POST_REMOVE'})) {
my $pa=$extra_hash{$pass}{'POST_REMOVE'};
my $rm_packges= join(' ', @$pa);
if ($rm_packges) {
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");
}
$rc = system("$yumcmd_remove $rm_packges");
}
}
}
}
@ -442,17 +395,20 @@ unless ($onlyinitrd) {
s/vmlinuz-//;
}
@KVERS= <$rootimg_dir/lib/modules/*> unless (scalar(@KVERS));
$basekernelver = basename(pop @KVERS) if (scalar(@KVERS));
$basekernelver = `uname -r` unless ($basekernelver);
$kernelver = $basekernelver unless ($kernelver);
unless (scalar(@KVERS)) {
@KVERS= <$rootimg_dir/lib/modules/*>;
}
if (scalar(@KVERS)) {
$basekernelver = basename(pop @KVERS);
}
unless ($basekernelver) {
$basekernelver = `uname -r`;
}
unless ($kernelver) {
$kernelver=$basekernelver;
}
chomp($kernelver);
$updates{'kernelver'} = $kernelver if ($needUpdateTable);
if ($kernelver ne $basekernelver) {
# the kernelver is specified by "-k",
# the kernel file should be in /boot
@ -517,21 +473,18 @@ while (scalar @checkdeps) {
close($moddeps);
unlink "/tmp/genimage.$$.yum.conf";
if (-d "$rootimg_dir/usr/share/dracut") {
$dracutmode = 1;
$dracutmode=1;
}
#-- run postinstall script
unless ($imagename) {
if (!$imagename) {
$postinstall_filename= imgutils::get_profile_def_filename($osver, $profile, $arch, $customdir, "postinstall");
unless ($postinstall_filename) {
$postinstall_filename= imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "postinstall");
if (!$postinstall_filename) {
$postinstall_filename= imgutils::get_profile_def_filename($osver, $profile, $arch, $pathtofiles, "postinstall");
}
}
if (($postinstall_filename) && (-x $postinstall_filename)) {
$updates{'postinstall'} = $postinstall_filename if ($needUpdateTable);
my $rc = system($postinstall_filename, $rootimg_dir,$osver,$arch,$profile);
if($rc) {
print "postinstall script failed\n";
@ -539,113 +492,63 @@ if (($postinstall_filename) && (-x $postinstall_filename)) {
}
}
if ($needUpdateTable) {
# all the attributes have been gathered
# now, update the linuximage and osimage tables
# TODO: do statelite and stateless share the same attributes?
if ($imagename) {
$keyhash{'imagename'} = $imagename;
$linuximagetab->setAttribs(\%keyhash, \%updates);
$linuximagetab->commit;
} else {
# update the imagename for diskless
$keyhash{'imagename'} = "$osver-$arch-netboot-$profile";
$updates_os{'profile'} = $profile;
$updates_os{'imagetype'} = 'linux';
$updates_os{'provmethod'} = 'netboot';
$updates_os{'osname'} = 'Linux';
$updates_os{'osvers'} = $osver;
$updates_os{'osdistro'} = 'rh'; # it is not used currently
$updates_os{'osarch'} = $arch;
$osimagetab->setAttribs(\%keyhash, \%updates_os);
$osimagetab->commit;
$linuximagetab->setAttribs(\%keyhash, \%updates);
$linuximagetab->commit;
# update the imagename for netboot
$keyhash{'imagename'} = "$osver-$arch-statelite-$profile";
$updates_os{'provmethod'} = 'statelite';
$osimagetab->setAttribs(\%keyhash, \%updates_os);
$osimagetab->commit;
$linuximagetab->setAttribs(\%keyhash, \%updates);
$linuximagetab->commit;
}
}
# 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
mkpath "$rootimg_dir/.statelite"; # create place for NFS mounts.
# this script will get the directories.
# TODO: the file is re-copied in liteimg.pm
unless (-f "../add-on/statelite/rc.statelite") {
print "Can't find ../add-on/statelite/rc.statelite!\n";
exit 1;
}
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 ($dracutmode) { #in dracut mode, we delegate all this activity
unless (-l "$rootimg_dir/var/lib/dhclient" ) {
mkpath "$rootimg_dir/var/lib/dhclient/";
system("touch $rootimg_dir/var/lib/dhclient/dhclient-$prinic.leases");
}
unless ($dracutmode) { #in dracut mode, we delegate all this activity
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");
unless(-l "$rootimg_dir/var/lib/dhcp" ){
mkpath "$rootimg_dir/var/lib/dhcp/";
system("touch $rootimg_dir/var/lib/dhcp/dhclient-$prinic.leases");
}
}
}
# modify etc/rc.sysinit, prevent remounting
my $SYSINITFILE;
my $TMPSYSINITFILE;
if (-f "$rootimg_dir/etc/rc.sysinit") {
open($SYSINITFILE, "$rootimg_dir/etc/rc.sysinit");
open($TMPSYSINITFILE, '>', "/tmp/rc.sysinit.tmp");
# find the following lines,
# if remount_needed ; then
# action $"Remounting root filesystem in read-write mode: " mount -n -o remount,rw /
# fi
# and change "if remount_needed ; then" to "if false; then"
while(<$SYSINITFILE>) {
if ($_ eq "if remount_needed ; then\n") {
$_ = "if false; then\n";
}
# modify etc/rc.sysinit, prevent remounting
my $SYSINITFILE;
my $TMPSYSINITFILE;
if (-f "$rootimg_dir/etc/rc.sysinit") {
open($SYSINITFILE, "$rootimg_dir/etc/rc.sysinit");
open($TMPSYSINITFILE, '>', "/tmp/rc.sysinit.tmp");
# find the following lines,
# if remount_needed ; then
# action $"Remounting root filesystem in read-write mode: " mount -n -o remount,rw /
# fi
# and change "if remount_needed ; then" to "if false; then"
while(<$SYSINITFILE>) {
if ($_ eq "if remount_needed ; then\n") {
$_ = "if false; then\n";
}
print $TMPSYSINITFILE $_;
}
close($SYSINITFILE);
close($TMPSYSINITFILE);
cp("/tmp/rc.sysinit.tmp", "$rootimg_dir/etc/rc.sysinit");
}
close($SYSINITFILE);
close($TMPSYSINITFILE);
cp("/tmp/rc.sysinit.tmp", "$rootimg_dir/etc/rc.sysinit");
}
}
# before mkinitrd, run depmod to generate modules.dep
system("chroot $rootimg_dir depmod $kernelver");
# TODO: for the genimage-enchement, need to create two initial ramdisks,
# one is for stateless
# the other one is for statelite
# move the load_dd() and @ndrivers-related code here
if ($dracutmode) {
mkinitrd_dracut("statelite");
mkinitrd_dracut("stateless");
mkinitrd_dracut();
} else {
mkinitrd("statelite");
mkinitrd("stateless");
mkinitrd();
}
sub getlibs {
@ -666,12 +569,11 @@ sub getlibs {
next;
}
$temp1 =~ s/^\///;
$libhash{$temp1}=1;
$libhash{$temp1}=1;
}
}
sub mkinitrd_dracut {
my ($mode) = @_; # the mode is for statelite or stateless
my $dracutmpath = "$rootimg_dir/usr/share/dracut/modules.d/97xcat";
mkpath($dracutmpath);
@ -700,7 +602,8 @@ sub mkinitrd_dracut {
print $DRACUTCONF qq{add_drivers+="$add_drivers"\n};
print $DRACUTCONF qq{filesystems+="nfs"\n};
close $DRACUTCONF;
} elsif ($mode eq "stateless") {
} else {
# for diskless
cp("$fullpath/dracut/install.netboot","$dracutmpath/install");
$perm = (stat("$fullpath/dracut/install.netboot"))[2];
chmod($perm&07777, "$dracutmpath/install");
@ -729,33 +632,13 @@ sub mkinitrd_dracut {
print $DRACUTCONF qq{dracutmodules+="xcat base network kernel-modules"\n};
print $DRACUTCONF qq{add_drivers+="$add_drivers"\n};
close $DRACUTCONF;
} else {
xdie "the mode: $mode is not supported by genimage";
}
system("chroot $rootimg_dir dracut -f /tmp/initrd.$$.gz $kernelver");
system("chroot '$rootimg_dir' dracut -f /tmp/initrd.$$.gz $kernelver");
print "the initial ramdisk is generated successfully.\n";
move("$rootimg_dir/tmp/initrd.$$.gz", "$destdir/initrd-$mode.gz");
move("$rootimg_dir/tmp/initrd.$$.gz", "$destdir/initrd.gz");
}
sub mkinitrd {
my ($mode) = @_; # statelite or stateless
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";
# Additional modules needed on s390x
if ($arch eq "s390x") {
# The network drivers need to be loaded in this order
unshift @ndrivers, "ccwgroup.ko";
unshift @ndrivers, "qdio.ko";
}
}
mkpath("/tmp/xcatinitrd.$$/bin");
symlink("bin","/tmp/xcatinitrd.$$/sbin");
@ -797,7 +680,7 @@ NORMAL=\$RESET
# This function is used to mount files/directories from the .statelite directory
# over the root directory.
# This function is stolen from redhat
# This function stolen from redhat
shell() {
echo ''
echo -e "\$YELLOW Entering rescue/debug init shell."
@ -849,9 +732,9 @@ echo '
EOS1
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 "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";
@ -881,7 +764,6 @@ EOS1
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";
}
@ -920,7 +802,6 @@ EOMS
# check and see if debug is specified on command line
grep '\(debug\)' /proc/cmdline > /dev/null && export DEBUG=1
# TODO: need to change its policy
IFACE=$prinic
if [ -z "\$IFACE" ]; then
for i in `cat /proc/cmdline`; do
@ -941,7 +822,7 @@ export IFACE=\$IFACE
netstart
while ! ifconfig | grep inet; do
echo -e "\${RED}Failed to acquire address, retrying \${RESET}"
sleep 5
sleep 1
netstart
done
ifconfig lo 127.0.0.1
@ -1039,7 +920,7 @@ if [ "\$NFSROOT" = "1" ]; then
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 run liteimg for the current osimage"
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 ""
shell
done
@ -1105,7 +986,6 @@ if [ "\$NFSROOT" = "1" ]; then
do
echo "\$NEWROOT/etc/init.d/statelite does not exist in image!"
shell
exit
done
# do all the mounts:
@ -1134,7 +1014,32 @@ if [ "\$NFSROOT" = "1" ]; then
fi
# END NFSROOT/Statelite code
if [ -r /rootimg.sfs ]; then
# RAM root Hybrid with NFS root
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
mount.nfs \$SERVER:\$ROOTDIR /ro -r -n -o nolock,rsize=32768,tcp,nfsvers=3,timeo=14
ST=`expr \$RANDOM % 5`
sleep \$ST
done
mount -t tmpfs rw /rw
mkdir -p /rw/etc
mkdir -p /rw/var/lib/dhclient
cp /etc/resolv.conf /rw/etc/
cp /var/lib/dhclient/dhclient.leases /rw/var/lib/dhclient/dhclient-\$IFACE.leases
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
cp /etc/resolv.conf /sysroot/etc/
echo xcatfs / aufs rw,_netdev 0 0 >> /sysroot/etc/fstab
elif [ -r /rootimg.sfs ]; then
echo Setting up squashfs with ram overlay.
mknod /dev/loop0 b 7 0
mkdir -p /ro
@ -1165,7 +1070,7 @@ EOMS
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 5\n";
print $inifile " /bin/sleep 1\n";
print $inifile " echo -n \$i...\n";
print $inifile " done\n";
print $inifile " echo\n";
@ -1191,18 +1096,22 @@ EOMS
print $inifile "exec switch_root -c /dev/console /sysroot /sbin/init\n";
close($inifile);
open($inifile,">"."/tmp/xcatinitrd.$$/bin/netstart");
print $inifile "#!/sbin/nash\n";
print $inifile "network --device \$IFACE --bootproto dhcp\n";
close($inifile);
chmod(0755,"/tmp/xcatinitrd.$$/init");
chmod(0755,"/tmp/xcatinitrd.$$/bin/netstart");
chmod(0755,"/tmp/xcatinitrd.$$/init");
chmod(0755,"/tmp/xcatinitrd.$$/bin/netstart");
@filestoadd=();
foreach (@ndrivers) {
if (-f "$customdir/$_") {
push @filestoadd,[$_,"lib/$_"];
if (-f "$customdir/$_") {
push @filestoadd,[$_,"lib/$_"];
} elsif (-f "$pathtofiles/$_") {
push @filestoadd,[$_,"lib/$_"];
push @filestoadd,[$_,"lib/$_"];
}
}
# add rsync for statelite
@ -1211,32 +1120,34 @@ EOMS
push @filestoadd,$_;
}
# Additional binaries needed for udev on s390x
if ($arch eq "s390x") {
foreach ("sbin/udevsettle", "sbin/udevtrigger", "sbin/udevd", "sbin/depmod") {
getlibs($_);
push @filestoadd,$_;
}
}
# Additional binaries needed for udev on s390x
if ($arch eq "s390x") {
foreach ("sbin/udevsettle", "sbin/udevtrigger", "sbin/udevd", "sbin/depmod") {
getlibs($_);
push @filestoadd,$_;
}
}
if ($arch =~ /x86_64/) {
push @filestoadd,"lib64/libnss_dns.so.2";
push @filestoadd,"lib64/libresolv.so.2";
} else {
}
else {
push @filestoadd,"lib/libnss_dns.so.2";
}
push @filestoadd,keys %libhash;
if($basekernelver ne $kernelver) {
system("rm -rf $rootimg_dir/lib/modules/$basekernelver");
if($basekernelver ne $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 $rootimg_dir/lib/modules/");
} else {
xdie("Cannot read /lib/modules/$kernelver");
}
if(-d "/lib/modules/$kernelver") {
system("cd /lib/modules;cp -r $kernelver $rootimg_dir/lib/modules/");
}
else {
xdie("Cannot read /lib/modules/$kernelver");
}
}
}
}
find(\&isnetdriver, <$rootimg_dir/lib/modules/$kernelver/*>);
foreach (@filestoadd) {
@ -1290,7 +1201,7 @@ EOMS
}
#copy("$rootimg_dir/lib/modules/*d","/tmp/xcatinitrd.$$/$_");
system("cd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|gzip -9 -c - > $destdir/initrd-$mode.gz");
system("cd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|gzip -9 -c - > $destdir/initrd.gz");
system("rm -rf /tmp/xcatinitrd.$$");
}
@ -1322,11 +1233,13 @@ sub isnetdriver {
sub postscripts { # TODO: customized postscripts
generic_post();
if( ! -d "$rootimg_dir/opt/xcat/") {
mkdir "$rootimg_dir/opt/xcat/";
}
copy ("$installroot/postscripts/xcatdsklspost", "$rootimg_dir/opt/xcat/");
chmod '0755', "$rootimg_dir/opt/xcat/xcatdsklspost";
if ($mode eq "statelite") {
if( ! -d "$rootimg_dir/opt/xcat/") {
mkdir "$rootimg_dir/opt/xcat/";
}
copy ("$installroot/postscripts/xcatdsklspost", "$rootimg_dir/opt/xcat/");
chmod '0755', "$rootimg_dir/opt/xcat/xcatdsklspost";
}
}
sub generic_post { #This function is meant to leave the image in a state approximating a normal install
@ -1338,18 +1251,16 @@ sub generic_post { #This function is meant to leave the image in a state approxi
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,size=$tmplimit 0 2\n";
print $cfgfile "tmpfs /var/tmp tmpfs defaults,size=$tmplimit 0 2\n";
} else {
print $cfgfile "tmpfs /tmp tmpfs defaults,size=10m 0 2\n";
print $cfgfile "tmpfs /var/tmp tmpfs defaults,size=10m 0 2\n";
}
my $rootfs_name=$profile."_".$arch;
print $cfgfile "$rootfs_name / tmpfs rw 0 1\n";
print $cfgfile "sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0\n";
if ($mode ne "statelite") {
my $rootfs_name=$profile."_".$arch;
print $cfgfile "$rootfs_name / tmpfs rw 0 1\n";
} else {
print $cfgfile "sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0\n";
}
close($cfgfile);
open($cfgfile,">","$rootimg_dir/etc/sysconfig/network");