diff --git a/xCAT-server/share/xcat/netboot/sles/genimage b/xCAT-server/share/xcat/netboot/sles/genimage index 9e06470a8..084de8e7f 100755 --- a/xCAT-server/share/xcat/netboot/sles/genimage +++ b/xCAT-server/share/xcat/netboot/sles/genimage @@ -46,6 +46,8 @@ my $srcdir_otherpkgs; my $otherpkglist; my $postinstall_filename; my $rootimg_dir; +my $rwfiles; #these files are used by statelite for tmpfs rw +my $mode; sub xdie { system("rm -rf /tmp/xcatinitrd.$$"); @@ -77,7 +79,8 @@ GetOptions( 'r=s' => \$othernics, 'l=s' => \$rootlimit, 't=s' => \$tmplimit, - 'k=s' => \$kernelver + 'k=s' => \$kernelver, + 'm=s' => \$mode #provide options for the mode of "genimage" ); if (@ARGV > 0) { $imagename=$ARGV[0]; @@ -183,11 +186,12 @@ unless ($kernelver) { } chomp($kernelver); unless ($osver and $profile and $netdriver and $prinic) { - print 'Usage: genimage -i -n [-r ] -k -o -p -a '."\n"; + print 'Usage: genimage -i -n [-r ] -k -o -p -a -m '."\n"; print ' genimage -i -n [-r ] -k '."\n"; print "Examples:\n"; print " genimage -i eth0 -n tg3 -o centos5.1 -p compute\n"; print " genimage -i eth0 -r eth1,eth2 -n tg3,bnx2 -o centos5.1 -p compute\n"; + print " genimage -i eth0 -n tg3,bnx2 -o centos5.1 -p compute -p nfsroot -m statelite\n"; print " genimage -i eth0 -ntg3 myimagename\n"; exit 1; } @@ -205,6 +209,16 @@ unless (grep /af_packet/,@ndrivers) { unshift(@ndrivers,"af_packet.ko"); } +if($mode eq "statelite") { + push @ndrivers, "sunrpc.ko"; + push @ndrivers, "lockd.ko"; + push @ndrivers, "nfs_acl.ko"; + push @ndrivers, "auth_rpcgss.ko"; + push @ndrivers, "exportfs.ko"; + push @ndrivers, "nfsd.ko"; + push @ndrivers, "nfs.ko"; +} + my $osver_host; if(`grep VERSION /etc/SuSE-release` =~ /VERSION = (\d+)/) { $osver_host=$1; @@ -220,8 +234,12 @@ unless ($onlyinitrd) { mkpath "$rootimg_dir/etc"; mkpath "$rootimg_dir/dev"; #system "mount -o bind /dev $rootimg_dir/dev"; - system "mknod $rootimg_dir/dev/zero c 1 5"; - system "mknod $rootimg_dir/dev/null c 1 3"; #that's neccessary for SLES11 + if( ! -e "$rootimg_dir/dev/zero") { + system "mknod $rootimg_dir/dev/zero c 1 5"; + } + if( ! -e "$rootimg_dir/dev/null") { + system "mknod $rootimg_dir/dev/null c 1 3"; #that's neccessary for SLES11 + } open($fd,">>","$rootimg_dir/etc/fstab"); print $fd "#Dummy fstab for rpm postscripts to see\n"; close($fd); @@ -384,6 +402,23 @@ if (($postinstall_filename) && (-x $postinstall_filename)) { } } + +if($mode eq "statelite") { + mkpath "$rootimg_dir/.statelite"; # create place for NFS mounts; + # this script will get the directories; + unless( -r "../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"); + # the dhcp client information stores in the directory "/var/lib/dhcpcd/" + unless(-l "$rootimg_dir/var/lib/dhcpcd") { + mkpath "$rootimg_dir/var/lib/dhcpcd/"; + system("touch $rootimg_dir/var/lib/dhcpcd/dhcpcd-$prinic.info"); + } + # which is different from the Redhat family +} + #some rpms mounts the imageroot/proc on the /proc, need to release it, #otherwise got kernal panic when installing #sometimes, the proc fs is not mounted, so one warning/error message will display, @@ -468,7 +503,102 @@ sub mkinitrd { mkpath("/tmp/xcatinitrd.$$/var/lib/dhcpcd"); my $inifile; open($inifile,">","/tmp/xcatinitrd.$$/init"); - print $inifile "#!/bin/bash -x\n"; + print $inifile "#!/bin/bash\n"; + +# copied from genimage for rh +# add some functions + print $inifile < <\\ \\____/ | \\ | + /__/\\_ \\\\______ /\\____|__ /____| + \\/ \\/ \\/ +' + echo -e "\$RESET" +} + + +EOS1 + print $inifile "mount -t proc /proc /proc\n"; print $inifile "mount -t sysfs /sys /sys\n"; print $inifile "mount -o mode=0755 -t tmpfs /dev /dev\n"; @@ -503,11 +633,22 @@ sub mkinitrd { 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"; } +if($mode eq "statelite") { + print $inifile "echo debug: before netstart\n"; + print $inifile "# check and see if debug is specified on command line\n"; + print $inifile "grep '\(debug\)' /proc/cmdline > /dev/null && export DEBUG=1\n"; +} print $inifile </dev/null && shell + mount -t tmpfs rw \$NEWROOT/\$RWDIR + 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 + while ! mount \$SNAPSHOTSERVER:\$SNAPSHOTROOT \$NEWROOT/\$RWDIR/persistent + 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 + fi + + grep '\\(shell\\)' /proc/cmdline >/dev/null && shell + + # have to preserve the initial DHCP request. So we link it. + # SLES uses different file to store DHCP info + if [ ! -d \$NEWROOT/\$RWDIR/tmpfs/var/lib/dhcpcd ] + then + mkdir -p \$NEWROOT/\$RWDIR/tmpfs/var/lib/dhcpcd + fi + cp -fp /var/lib/dhcpcd/dhcpcd-$prinic.info \${NEWROOT}/\${RWDIR}/tmpfs/var/lib/dhcpcd/dhcpcd-$prinic.info + + [ -e /etc/ntp.conf ] && mkdir -p \$NEWROOT/\$RWDIR/tmpfs/etc && cp /etc/ntp.conf \$NEWROOT/\$RWDIR/tmpfs/etc/ + + [ -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 ] + do + echo "\$NEWROOT/etc/init.d/statelite does not exist in image!" + shell + done + + # 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 + + echo 0x100 > /proc/sys/kernel/real-root-dev + export keep_old_ip=yes + export fastboot=yes + export READONLY=yes + grep '\\(shell\\)' /proc/cmdline >/dev/null && shell + mount -n --bind /dev /sysroot/dev + umount /sys + umount /proc + + # sles use the standard utility to chroot + if ! exec /usr/bin/chroot \$NEWROOT /sbin/init + then + echo "" + echo -e "\${RED}Couldn't chroot. Something must be wrong with NFS root image.\${RESET}" + shell + fi + exit +fi +# end NFSROOT/Statelite code + if [ "\$NFS" = "1" ]; then echo Setting up nfs with ram overlay. mknod /dev/loop0 b 7 0 @@ -544,7 +818,8 @@ if [ "\$NFS" = "1" ]; then while [ ! -d /ro/bin ]; do echo mounting \$SERVER:\$ROOTDIR on /ro mount \$SERVER:\$ROOTDIR /ro -r -n -o nolock,rsize=32768,udp,nfsvers=3,timeo=14 - sleep 5 #should be random, exponential for scale + ST=`expr \$RANDOM % 5` + sleep \$ST done mount -t tmpfs rw /rw mkdir -p /rw/etc @@ -637,10 +912,17 @@ END push @filestoadd,[$_,"lib/$_"]; } } - foreach ("usr/bin/grep","bin/cpio","bin/sleep","bin/mount","sbin/dhcpcd","bin/bash","sbin/insmod","bin/mkdir","bin/mknod","sbin/ip","bin/cat","usr/bin/awk","usr/bin/wget","bin/cp","usr/bin/cpio","usr/bin/zcat","usr/bin/gzip","lib/mkinitrd/bin/run-init","usr/bin/uniq","usr/bin/sed") { - getlibs($_); #there's one small bug for getlibs - push @filestoadd,$_; - } + if($mode eq "statelite") { + foreach ("sbin/ifconfig", "usr/bin/clear", "sbin/mount.nfs","sbin/umount.nfs","bin/hostname","usr/bin/egrep","bin/ln","bin/ls","usr/bin/dirname","usr/bin/expr","usr/bin/chroot","usr/bin/grep","bin/cpio","bin/sleep","bin/mount","bin/umount","sbin/dhcpcd","bin/bash","sbin/insmod","bin/mkdir","bin/mknod","sbin/ip","bin/cat","usr/bin/awk","usr/bin/wget","bin/cp","usr/bin/cpio","usr/bin/zcat","usr/bin/gzip","lib/mkinitrd/bin/run-init","usr/bin/uniq","usr/bin/sed") { + getlibs($_); + push @filestoadd,$_; + } + }else { + foreach ("sbin/ifconfig","usr/bin/clear", "usr/bin/grep","bin/cpio","bin/sleep","bin/mount","sbin/dhcpcd","bin/bash","sbin/insmod","bin/mkdir","bin/mknod","sbin/ip","bin/cat","usr/bin/awk","usr/bin/wget","bin/cp","usr/bin/cpio","usr/bin/zcat","usr/bin/gzip","lib/mkinitrd/bin/run-init","usr/bin/uniq","usr/bin/sed") { + getlibs($_); #there's one small bug for getlibs + push @filestoadd,$_; + } + } if ($arch =~ /x86_64/) { push @filestoadd,"lib64/libnss_dns.so.2"; } @@ -717,6 +999,15 @@ sub isnetdriver { sub postscripts { # TODO: customized postscripts generic_post(); + 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"; + system("$XCATROOT/share/xcat/netboot/add-on/statelite/add_passwd $rootimg_dir"); + system("$XCATROOT/share/xcat/netboot/add-on/statelite/add_ssh $rootimg_dir"); + } if (-d "$installroot/postscripts/hostkeys") { for my $key (<$installroot/postscripts/hostkeys/*key>) { copy ($key,"$rootimg_dir/etc/ssh/"); @@ -736,18 +1027,20 @@ sub postscripts { # TODO: customized postscripts sub generic_post { #This function is meant to leave the image in a state approximating a normal install my $cfgfile; - unlink("$rootimg_dir/dev/null"); - system("mknod $rootimg_dir/dev/null c 1 3"); - open($cfgfile,">","$rootimg_dir/etc/fstab"); - print $cfgfile "devpts /dev/pts devpts gid=5,mode=620 0 0\n"; - print $cfgfile "tmpfs /dev/shm tmpfs defaults 0 0\n"; - print $cfgfile "proc /proc proc defaults 0 0\n"; - 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); + if($mode ne "statelite") { + unlink("$rootimg_dir/dev/null"); + system("mknod $rootimg_dir/dev/null c 1 3"); + open($cfgfile,">","$rootimg_dir/etc/fstab"); + print $cfgfile "devpts /dev/pts devpts gid=5,mode=620 0 0\n"; + print $cfgfile "tmpfs /dev/shm tmpfs defaults 0 0\n"; + print $cfgfile "proc /proc proc defaults 0 0\n"; + 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,">","$rootimg_dir/etc/sysconfig/network"); print $cfgfile "NETWORKING=yes\n"; close($cfgfile); @@ -802,7 +1095,11 @@ sub generic_post { #This function is meant to leave the image in a state approxi print $cfgfile " fi\n"; print $cfgfile "done\n"; print $cfgfile "/etc/init.d/boot.localnet start\n"; - print $cfgfile "/opt/xcat/xcatdsklspost\n"; + if($mode eq "statelite") { + print $cfgfile "/opt/xcat/xcatdsklspost 4\n"; + } else { + print $cfgfile "/opt/xcat/xcatdsklspost\n"; + } close($cfgfile); chmod(0755,"$rootimg_dir/etc/init.d/gettyset"); #link("$rootimg_dir/sbin/init","$rootimg_dir/init"); @@ -976,4 +1273,22 @@ sub get_postinstall_file_name { return ""; } - +sub get_rwfiles_file_name { + my $base = shift; + my $dotpos = rindex($osver, "."); + my $osbase = substr($osver, 0, $dotpos); + if( -r "$base/$profile.$osver.$arch.rwfiles") { + return "$base/$profile.$osver.$arch.rwfiles"; + } elsif (-r "$base/$profile.$osbase.$arch.rwfiles") { + return "$base/$profile.$osbase.$arch.rwfiles"; + } elsif (-r "$base/$profile.$arch.rwfiles") { + return "$base/$profile.$arch.rwfiles"; + } elsif (-r "$base/$profile.$osver.rwfiles") { + return "$base/$profile.$osver.rwfiles"; + } elsif (-r "$base/$profile.$osbase.rwfiles") { + return "$base/$profile.$osbase.rwfiles"; + } elsif( -r "$base/$profile.rwfiles") { + return "$base/$profile.rwfiles"; + } + return ""; +}