-Beginning of SLES stateless implementation (not yet working)

-SLES iSCSI template/scripts
-Patch SLES10.2 media on copycds to allow for unattended iSCSI installation


git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@1487 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jbjohnso 2008-05-24 17:29:40 +00:00
parent ed472c70b3
commit 1da75068dd
10 changed files with 897 additions and 0 deletions

View File

@ -2,6 +2,7 @@
package xCAT_plugin::sles;
use Storable qw(dclone);
use Sys::Syslog;
use File::Temp qw/tempdir/;
use xCAT::Table;
use xCAT::Utils;
use xCAT::MsgUtils;
@ -294,6 +295,8 @@ sub copycd
my $request = shift;
my $callback = shift;
my $doreq = shift;
my $distname = "";
my $detdistname = "";
my $installroot;
$installroot = "/install";
my $sitetab = xCAT::Table->new('site');
@ -370,6 +373,7 @@ sub copycd
{
my @parts = split /\s+/, $prod;
my @subparts = split /-/, $parts[2];
$detdistname = "sles" . $subparts[0];
unless ($distname) { $distname = "sles" . $subparts[0] };
}
}
@ -440,6 +444,41 @@ sub copycd
# );
chmod 0755, "$installroot/$distname/$arch";
chmod 0755, "$installroot/$distname/$arch/$discnumber";
if ($detdistname eq "sles10.2" and $discnumber eq "1") { #Go and correct inst_startup.ycp in the install root
my $tmnt = tempdir("xcat-sles.$$.XXXXXX",TMPDIR=>1);
my $tdir = tempdir("xcat-slesd.$$.XXXXXX",TMPDIR=>1);
my $startupfile;
my $ycparch = $arch;
if ($arch eq "x86") {
$ycparch = "i386";
}
system("mount -o loop $installroot/$distname/$arch/$discnumber/boot/$ycparch/root $tmnt");
system("cd $tmnt;find . |cpio -dump $tdir");
system("umount $tmnt;rm $installroot/$distname/$arch/$discnumber/boot/$ycparch/root");
open($startupfile,"<","$tdir/usr/share/YaST2/clients/inst_startup.ycp");
my @ycpcontents = <$startupfile>;
my @newcontents;
my $writecont=1;
close($startupfile);
foreach (@ycpcontents) {
if (/No hard disks/) {
$writecont=0;
} elsif (/\}/) {
$writecont=1;
}
s/cancel/next/;
if ($writecont) {
push @newcontents, $_;
}
}
open($startupfile,">","$tdir/usr/share/YaST2/clients/inst_startup.ycp");
foreach (@newcontents) {
print $startupfile $_;
}
close($startupfile);
system("cd $tdir;mkfs.cramfs . $installroot/$distname/$arch/$discnumber/boot/$ycparch/root");
system("rm -rf $tmnt $tdir");
}
if ($rc != 0)
{

View File

@ -0,0 +1,112 @@
<chroot-scripts config:type="list">
<script>
<filename>boot.sh</filename>
<interpreter>shell</interpreter>
<chrooted config:type="boolean">true</chrooted>
<source>
<![CDATA[
#!/bin/sh
AWK=`find / -name awk | head -1`
#old awk /mounts/instsys/bin/awk -f
cat >/tmp/locktftpdir.awk <<EOF
#!$AWK -f
BEGIN {
xcatdport = #TABLE:site:key=xcatiport:value#
xcatdhost = "#XCATVAR:XCATMASTER#"
ns = "/inet/tcp/0/" xcatdhost "/" xcatdport
while(1) {
if((ns |& getline) > 0)
print \$0 | "logger -t xcat"
if(\$0 == "ready")
print "locktftpdir" |& ns
if(\$0 == "done")
break
}
close(ns)
exit 0
}
EOF
cat >/tmp/setiscsiparms.awk <<EOF
#!$AWK -f
BEGIN {
xcatdhost = ARGV[1]
xcatdport = ARGV[2]
kernel = ARGV[3]
initrd = ARGV[4]
kcmd = ARGV[5]
ns = "/inet/tcp/0/" ARGV[1] "/" xcatdport
while(1) {
if((ns |& getline) > 0)
print \$0 | "logger -t xcat"
if(\$0 == "ready")
print "setiscsiparms "kernel" "initrd" "kcmd |& ns
if(\$0 == "done")
break
}
close(ns)
exit 0
}
EOF
cat >/tmp/unlocktftpdir.awk <<EOF
#!$AWK -f
BEGIN {
xcatdport = #TABLE:site:key=xcatiport:value#
xcatdhost = "#XCATVAR:XCATMASTER#"
ns = "/inet/tcp/0/" xcatdhost "/" xcatdport
while(1) {
if((ns |& getline) > 0)
print \$0 | "logger -t xcat"
if(\$0 == "ready")
print "unlocktftpdir" |& ns
if(\$0 == "done")
break
}
close(ns)
exit 0
}
EOF
chmod 755 /tmp/unlocktftpdir.awk
chmod 755 /tmp/locktftpdir.awk
chmod 755 /tmp/setiscsiparms.awk
if [ -r /boot/etc/yaboot.conf ]; then
KNAME=`grep ^image /boot/etc/yaboot.conf|head -n 1|cut -d= -f 2|sed -e 's!^/!!'`
KERNEL=/boot/$KNAME
KERNEL=`echo $KERNEL|sed -e 's!//!/!g'`
INAME=`grep initrd /boot/etc/yaboot.conf|head -n 1|cut -d= -f 2|sed -e 's!^/!!'`
INITRD=/boot/$INAME
INITRD=`echo $INITRD|sed -e 's!//!/!g'`
KCMDLINE=`grep append= /boot/etc/yaboot.conf|head -n 1|cut -d= -f 2-`
KCMDLINE=`echo $KCMDLINE|sed -e 's! rhgb!!'|sed -e 's!"!!g'`
elif [ -r /boot/grub/menu.lst ]; then
KNAME=`grep -v ^# /boot/grub/menu.lst|grep -v title|grep kernel|awk '{print $2}'|sed -e 's!/boot/!!'|head -n 1`
KERNEL=/boot/$KNAME
KCMDLINE=`grep -v ^# /boot/grub/menu.lst|grep -v title|grep kernel|sed -e 's!^.*kernel[[:space:]]\+[[:graph:]]\+[[:space:]]\+!!'|head -n 1`
INAME=`grep -v ^# /boot/grub/menu.lst|grep -v title|grep initrd|awk '{print $2}'|sed -e 's!/boot/!!'|head -n 1`
INITRD=/boot/$INAME
INITRD=`echo $INITRD|sed -e 's!//!/!g'`
fi
/tmp/unlocktftpdir.awk #XCATVAR:XCATMASTER# 3002
curl -T $KERNEL tftp://#XCATVAR:XCATMASTER#/xcat/#TABLE:nodelist:$NODE:node#/$KNAME
curl -T $INITRD tftp://#XCATVAR:XCATMASTER#/xcat/#TABLE:nodelist:$NODE:node#/$INAME
/tmp/locktftpdir.awk #XCATVAR:XCATMASTER# 3002
/tmp/setiscsiparms.awk #XCATVAR:XCATMASTER# 3002 $KNAME $INAME "$KCMDLINE"
]]>
</source>
</script>
</chroot-scripts>

View File

@ -0,0 +1,95 @@
<post-scripts config:type="list">
<script>
<filename>xcat.sh</filename>
<interpreter>shell</interpreter>
<source>
<![CDATA[
#!/bin/sh
RAND=$(perl -e 'print int(rand(50)). "\n"')
sleep $RAND
jsi=0
while [ $(hostname) == 'linux' ]
do
if [ $jsi -gt 10 ]; then
logger "Slept too long!"
exit
fi
let jsi=jsi+1
sleep 1
done
echo "Slept $jsi seconds before hostname made sense."
HOSTNAME=$(hostname -s)
echo $HOSTNAME
/sbin/portmap
export MASTER_IP=#XCATVAR:XCATMASTER#
export MASTER_IPS=#XCATVAR:XCATMASTER#
export MASTER="#XCATVAR:XCATMASTER#"
#
# This script has not yet been updated to work with service nodes
#
for i in $(seq 1 20)
do
GOTIT=0
for i in $MASTER_IPS
do
#mount -r $i:/install/postscripts /xcatpost
wget -l inf -N -r --waitretry=10 --random-wait --retry-connrefused -t 0 -T 60 ftp://$i/postscripts
if [ "$?" = "0" ]
then
mkdir -p /var/stunnel
if [ -x /usr/sbin/stunnel ]; then #Stop if no stunnel to help the next bit
echo client=yes > /etc/stunnel/stunnel.conf
echo foreground=no >> /etc/stunnel/stunnel.conf
echo output=/dev/null >> /etc/stunnel/stunnel.conf
echo verify=0 >> /etc/stunnel/stunnel.conf
echo '[xcatd]' >> /etc/stunnel/stunnel.conf
echo accept=400 >> /etc/stunnel/stunnel.conf
echo connect=$i:3001 >> /etc/stunnel/stunnel.conf
stunnel
STUN_PID=$!
sleep 1
fi
mv $i/postscripts /xcatpost
rm -rf $i
chmod +x /xcatpost/*
/xcatpost/getpostscript.awk |sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' > /tmp/mypostscript
MYCONT=`cat /tmp/mypostscript`
while [ -z "$MYCONT" ]; do
let SLI=$RANDOM%10+10
sleep $SLI
/xcatpost/getpostscript.awk |sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' > /tmp/mypostscript
MYCONT=`cat /tmp/mypostscript`
done
chmod +x /tmp/mypostscript
GOTIT=1
break
fi
done
if [ "$GOTIT" = "1" ]
then
break
fi
RAND=$(perl -e 'print int(rand(5)). "\n"')
sleep $RAND
done
PATH=/xcatpost:$PATH
export PATH
/tmp/mypostscript
updateflag.awk $MASTER 3002
cd /
/xcatpost/#TABLE:nodelist:$NODE:node#
rm -Rf /xcatpost
rm -f /tmp/mypostscript
rm -f /etc/stunnel/stunnel.conf
rmdir /xcatpost
]]>
</source>
</script>
</post-scripts>

View File

@ -0,0 +1,99 @@
<?xml version="1.0"?>
<!DOCTYPE profile SYSTEM "/usr/share/YaST2/include/autoinstall/profile.dtd">
<profile xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns">
<install>
<bootloader>
<write_bootloader config:type="boolean">true</write_bootloader>
<activate config:type="boolean">true</activate>
<kernel_parameters></kernel_parameters>
<lba_support config:type="boolean">false</lba_support>
<linear config:type="boolean">false</linear>
<location>mbr</location>
</bootloader>
<iscsi-client>
<initiatorname>#TABLE:nodelist:$NODE:node#</initiatorname>
<targets config:type="list">
<listentry>
<authmethod>None</authmethod>
<portal>#TABLE:iscsi:$NODE:server#:3260,1</portal>
<startup>onboot</startup>
<target>#TABLE:iscsi:$NODE:target#</target>
</listentry>
</targets>
<version>1.0</version>
</iscsi-client>
<general>
<clock>
<hwclock>GMT</hwclock>
<timezone>#TABLE:site:key=timezone:value#</timezone>
</clock>
<keyboard>
<keymap>english-us</keymap>
</keyboard>
<language>en_US</language>
<mode>
<confirm config:type="boolean">false</confirm>
<forceboot config:type="boolean">false</forceboot>
<interactive_boot config:type="boolean">false</interactive_boot>
<reboot config:type="boolean">true</reboot>
</mode>
<mouse>
<id>non</id>
</mouse>
</general>
<partitioning config:type="list">
<drive>
<device>/dev/sda</device>
<initialize config:type="boolean">true</initialize>
<use>all</use>
</drive>
</partitioning>
<software>
<patterns config:type="list">
<pattern>base</pattern>
<pattern>x11</pattern>
</patterns>
<packages config:type="list">
<package>stunnel</package>
<package>xntp</package>
<package>rsync</package>
<package>open-iscsi</package>
</packages>
</software>
</install>
<configure>
<users config:type="list">
<user>
<username>root</username>
<user_password>#CRYPT:passwd:key=system,username=root:password#</user_password>
<encrypted config:type="boolean">true</encrypted>
<forename/>
<surname/>
</user>
</users>
<networking>
<dns>
<dhcp_hostname config:type="boolean">true</dhcp_hostname>
<dhcp_resolv config:type="boolean">true</dhcp_resolv>
<domain>#TABLE:site:key=domain:value#</domain>
<hostname>#TABLE:nodelist:$NODE:node#</hostname>
</dns>
<interfaces config:type="list">
<interface>
<bootproto>dhcp</bootproto>
<device>eth0</device>
<startmode>nfsroot</startmode>
</interface>
</interfaces>
<routing>
<ip_forward config:type="boolean">false</ip_forward>
<routes config:type="list"/>
</routing>
</networking>
<scripts>
#INCLUDE:../scripts/pre.sles#
#INCLUDE:../scripts/chroot.sles.iscsi#
#INCLUDE:../scripts/post.sles.iscsi#
</scripts>
</configure>
</profile>

View File

@ -0,0 +1,13 @@
./usr/share/man*
./usr/share/locale*
./usr/share/i18n*
./var/cache/yum*
./usr/share/doc*
./usr/share/gnome*
./usr/share/zoneinfo*
./usr/share/cracklib*
./usr/share/info*
./usr/share/omf*
./usr/lib/locale*
./usr/lib/perl5*
./boot*

View File

@ -0,0 +1,8 @@
bash
nfs-utils
stunnel
dhcpcd
kernel-smp
openssh
busybox
wget

View File

@ -0,0 +1,498 @@
#!/usr/bin/env perl
use File::Basename;
use File::Path;
use File::Copy;
use File::Find;
use Getopt::Long;
#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;
my $arch = `uname -m`;
chomp($arch);
if ($arch =~ /i.86$/) {
$arch = x86;
}
my %libhash;
my @filestoadd;
my $profile;
my $osver;
my $pathtofiles=dirname($0);
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;
sub xdie {
system("rm -rf /tmp/xcatinitrd.$$");
die @_;
}
$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
);
#Default to the first kernel found in the install image if nothing specified explicitly.
#A more accurate guess than whatever the image build server happens to be running
#If specified, that takes precedence.
#if image has one, that is used
#if all else fails, resort to uname -r like this script did before
my @KVERS= <$installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/*>;
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) {
print 'Usage: genimage -i <nodebootif> -n <nodenetdrivers> [-r <otherifaces>] -o <OSVER> -p <PROFILE> -k <KERNELVER>'."\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";
exit 1;
}
my @ndrivers;
foreach (split /,/,$netdriver) {
unless (/\.ko$/) {
s/$/.ko/;
}
if (/^$/) {
next;
}
push @ndrivers,$_;
}
unless ($onlyinitrd) {
my $srcdir = "$installroot/$osver/$arch/1";
mkpath "$installroot/netboot/$osver/$arch/$profile/rootimg/etc";
mkpath "$installroot/netboot/$osver/$arch/$profile/rootimg/dev";
#system "mount -o bind /dev $installroot/netboot/$osver/$arch/$profile/rootimg/dev";
system "mknod $installroot/netboot/$osver/$arch/$profile/rootimg/dev/zero c 1 5";
open($fd,">>","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/fstab");
print $fd "#Dummy fstab for rpm postscripts to see\n";
close($fd);
system("zypper -R $installroot/netboot/$osver/$arch/$profile/rootimg/ sa file:$srcdir");
#my $yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$installroot/netboot/$osver/$arch/$profile/rootimg/ --disablerepo=* ";
#$yumcmd .= "install ";
#mkpath("$installroot/netboot/$osver/$arch/$profile/rootimg/var/lib/yum");
my $yumcmd = "zypper -R $installroot/netboot/$osver/$arch/$profile/rootimg/ install -y ";
my $pkglist;
if (-r "$pathtofiles/$profile.$osver.$arch.pkglist") {
$pkglist = "$pathtofiles/$profile.$osver.$arch.pkglist";
} elsif (-r "$pathtofiles/$profile.$arch.pkglist") {
$pkglist = "$pathtofiles/$profile.$arch.pkglist";
} elsif (-r "$pathtofiles/$profile.$osver.pkglist") {
$pkglist = "$pathtofiles/$profile.$osver.pkglist";
} elsif (-r "$pathtofiles/$profile.pkglist") {
$pkglist = "$pathtofiles/$profile.pkglist";
} else {
print "Unable to find package list for $profile!";
return 1;
}
open($yumconfig,"<","$pkglist");
while (<$yumconfig>) {
chomp;
$yumcmd .= $_ . " ";
}
$yumcmd =~ s/ $/\n/;
my $rc = system($yumcmd);
if ($rc) {
print "zypper invocation failed\n";
exit 1;
}
postscripts(); #run 'postscripts'
}
unlink "/tmp/genimage.$$.yum.conf";
mkinitrd();
sub getlibs {
my $file = shift;
my $liblist = `chroot $installroot/netboot/$osver/$arch/$profile/rootimg ldd $file`;
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) {
rename(<$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinuz*>,"$installroot/netboot/$osver/$arch/$profile/kernel");
}
else {
if(-r "$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinuz-$kernelver") {
rename("$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinuz-$kernelver","$installroot/netboot/$osver/$arch/$profile/kernel");
} elsif(-r "/boot/vmlinuz-$kernelver") {
copy("/boot/vmlinuz-$kernelver","$installroot/netboot/$osver/$arch/$profile/kernel");
}
else {
xdie("Cannot read /boot/vmlinuz-$kernelver");
}
}
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;
open($inifile,">","/tmp/xcatinitrd.$$/init");
print $inifile "#!/sbin/busybox.anaconda sh\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";
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";
}
print $inifile <<EOMS;
netstart
ifconfig lo 127.0.0.1
ifconfig lo up
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
mount.nfs \$SERVER:\$ROOTDIR /ro -r -n -o nolock,rsize=32768,udp,nfsvers=3,timeo=14
sleep 5 #should be random, exponential for scale
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-$prinic.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/
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";
print $inifile "cp /var/lib/dhclient/dhclient.leases /sysroot/dev/.dhclient-$prinic.leases\n";
print $inifile "cp /var/lib/dhclient/dhclient.leases /sysroot/var/lib/dhclient/dhclient-$prinic.leases\n";
print $inifile "mknod /sysroot/dev/console c 5 1\n";
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 $prinic --bootproto dhcp\n";
close($inifile);
chmod(0755,"/tmp/xcatinitrd.$$/init");
chmod(0755,"/tmp/xcatinitrd.$$/bin/netstart");
@filestoadd=();
foreach (@ndrivers) {
if (-f "$pathtofiles/$_") {
push @filestoadd,[$_,"lib/$_"];
}
}
foreach ("bin/cpio","sbin/nash","sbin/busybox.anaconda","sbin/rmmod","sbin/mount.nfs") {
getlibs($_);
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) {
system("rm -rf $installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/$basekernelver");
unless (-d "$installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/$kernelver") {
if(-d "/lib/modules/$kernelver") {
system("cd /lib/modules;cp -r $kernelver $installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/");
}
else {
xdie("Cannot read /lib/modules/$kernelver");
}
}
}
find(\&isnetdriver, <$installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/$kernelver/*>);
foreach (@filestoadd) {
if (ref($_)) {
my $srcpath = "$installroot/netboot/$osver/$arch/$profile/rootimg/".$_->[0];
if (-f "$pathtofiles/".$_->[0]) {
$srcpath="$pathtofiles/".$_->[0];
}
copy($srcpath,"/tmp/xcatinitrd.$$/".$_->[1]);
chmod 0755,"/tmp/xcatinitrd.$$/".$_->[1];
} else {
my $srcpath = "$installroot/netboot/$osver/$arch/$profile/rootimg/$_";
if (-f "$pathtofiles/$_") {
$srcpatch = "$pathtofiles/$_";
}
copy("$srcpath","/tmp/xcatinitrd.$$/$_");
chmod 0755,"/tmp/xcatinitrd.$$/".$_;
}
}
#copy("$installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/*d","/tmp/xcatinitrd.$$/$_");
system("cd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|gzip -9 -c - > $installroot/netboot/$osver/$arch/$profile/initrd.gz");
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;
$filetoadd =~ s!$installroot/netboot/$osver/$arch/$profile/rootimg/!!;
push @filestoadd,[$filetoadd,"lib/$_"];
}
}
}
sub postscripts { # TODO: customized postscripts
generic_post();
if (-d "$installroot/postscripts/hostkeys") {
for my $key (<$installroot/postscripts/hostkeys/*key>) {
copy ($key,"$installroot/netboot/$osver/$arch/$profile/rootimg/etc/ssh/");
}
chmod 0600,</$installroot/netboot/$osver/$arch/$profile/rootimg/etc/ssh/*key>;
}
if (-d "/$installroot/postscripts/.ssh") {
mkpath("/$installroot/netboot/$osver/$arch/$profile/rootimg/root/.ssh");
chmod(0700,"/$installroot/netboot/$osver/$arch/$profile/rootimg/root/.ssh/");
for my $file (</$installroot/postscripts/.ssh/*>) {
copy ($file,"/$installroot/netboot/$osver/$arch/$profile/rootimg/root/.ssh/");
}
chmod(0600,</$installroot/netboot/$osver/$arch/$profile/rootimg/root/.ssh/*>);
}
}
sub generic_post { #This function is meant to leave the image in a state approximating a normal install
my $cfgfile;
unlink("$installroot/netboot/$osver/$arch/$profile/rootimg/dev/null");
system("mknod $installroot/netboot/$osver/$arch/$profile/rootimg/dev/null c 1 3");
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/fstab");
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);
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/sysconfig/network");
print $cfgfile "NETWORKING=yes\n";
close($cfgfile);
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/resolv.conf");
print $cfgfile "#Dummy resolv.conf to make boot cleaner";
close($cfgfile);
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/sysconfig/network-scripts/ifcfg-$prinic");
print $cfgfile "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=$prinic\n";
close($cfgfile);
foreach (split /,/,$othernics) {
if (/^$/) { next; }
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/sysconfig/network-scripts/ifcfg-$_");
print $cfgfile "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=$_\n";
close($cfgfile);
}
open($cfgfile,">>","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/securetty");
print $cfgfile "ttyS0\n";
print $cfgfile "ttyS1\n";
close($cfgfile);
my @passwd;
open($cfgfile,"<","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/passwd");
@passwd = <$cfgfile>;
close($cfgfile);
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/passwd");
foreach (@passwd) {
if (/^root:/) {
s/^root:\*/root:x/
}
print $cfgfile $_;
}
close($cfgfile);
foreach (<$installroot/netboot/$osver/$arch/$profile/rootimg/etc/skel/.*>) {
if (basename($_) eq '.' or basename($_) eq '..') {
next;
}
copy $_,"$installroot/netboot/$osver/$arch/$profile/rootimg/root/";
}
open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/rc3.d/S60gettyset");
print $cfgfile "#!/bin/bash\n";
print $cfgfile "for i in `cat /proc/cmdline`; do\n";
print $cfgfile ' KEY=`echo $i|cut -d= -f 1`'."\n";
print $cfgfile " if [ \"\$KEY\" == \"console\" ]; then\n";
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";
print $cfgfile " echo xco:2345:respawn:/sbin/agetty \$FLOWFLAG \$COTTY \$COSPEED xterm >> /etc/inittab\n";
print $cfgfile " init q\n";
print $cfgfile " fi\n";
print $cfgfile "done\n";
close($cfgfile);
chmod(0755,"$installroot/netboot/$osver/$arch/$profile/rootimg/etc/rc3.d/S60gettyset");
#link("$installroot/netboot/$osver/$arch/$profile/rootimg/sbin/init","$installroot/netboot/$osver/$arch/$profile/rootimg/init");
rename(<$installroot/netboot/$osver/$arch/$profile/rootimg/boot/vmlinuz*>,"$installroot/netboot/$osver/$arch/$profile/kernel");
}

View File

@ -0,0 +1 @@
genimage

View File

@ -0,0 +1,12 @@
./usr/share/man*
./usr/share/locale*
./usr/share/i18n*
./var/cache/yum*
./usr/share/doc*
./usr/share/gnome*
./usr/share/zoneinfo*
./usr/share/cracklib*
./usr/share/info*
./usr/share/omf*
./usr/lib/locale*
./boot*

View File

@ -0,0 +1,20 @@
bash
stunnel
dhclient
kernel
openssh-server
openssh-clients
busybox-anaconda
vi
rpm
bind
bind-utils
atftp
ksh
nfs-utils
dhcp
bzip2
rootfiles
vixie-cron
wget
vsftpd