diff --git a/xCAT-server/share/xcat/netboot/rh/dracut/install b/xCAT-server/share/xcat/netboot/rh/dracut/install.netboot similarity index 51% rename from xCAT-server/share/xcat/netboot/rh/dracut/install rename to xCAT-server/share/xcat/netboot/rh/dracut/install.netboot index bae06f172..294be8e87 100755 --- a/xCAT-server/share/xcat/netboot/rh/dracut/install +++ b/xCAT-server/share/xcat/netboot/rh/dracut/install.netboot @@ -1,6 +1,6 @@ #!/bin/sh echo $drivers -dracut_install wget cpio gzip -dracut_install grep ifconfig hostname awk egrep grep dash +dracut_install wget cpio gzip dash modprobe +dracut_install grep ifconfig hostname awk egrep grep dirname inst "$moddir/xcatroot" "/sbin/xcatroot" inst_hook cmdline 10 "$moddir/xcat-cmdline.sh" diff --git a/xCAT-server/share/xcat/netboot/rh/dracut/install.statelite b/xCAT-server/share/xcat/netboot/rh/dracut/install.statelite new file mode 100755 index 000000000..9168603fb --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/dracut/install.statelite @@ -0,0 +1,5 @@ +#!/bin/sh +echo $drivers +dracut_install wget cpio gzip dash modprobe +dracut_install grep ifconfig hostname awk egrep grep dirname +inst_hook pre-pivot 10 "$moddir/xcat-prepivot.sh" diff --git a/xCAT-server/share/xcat/netboot/rh/dracut/xcat-prepivot.sh b/xCAT-server/share/xcat/netboot/rh/dracut/xcat-prepivot.sh new file mode 100755 index 000000000..6ee5b641f --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/dracut/xcat-prepivot.sh @@ -0,0 +1,83 @@ +#!/bin/sh +NEWROOT=/sysroot +SERVER=${SERVER%%/*} +SERVER=${SERVER%:} +RWDIR=.statelite +if [ ! -z $statemnt ]; then #btw, uri style might have left future options other than nfs open, will u se // to detect uri in the future I guess + SNAPSHOTSERVER=${statemnt%:*} + SNAPSHOTROOT=${statemnt#*/} + # may be that there is not server and just a directory. + if [ -z $SNAPSHOTROOT ]; then + SNAPSHOTROOT=$SNAPSHOTSERVER + SNAPSHOTSERVER= + fi +fi + +echo Setting up Statelite +mkdir -p $NEWROOT + +# now we need to mount the rest of the system. This is the read/write portions +# echo Mounting snapshot directories + +MAXTRIES=7 +ITER=0 +if [ ! -e "$NEWROOT/$RWDIR" ]; then + echo "" + echo "This NFS root directory doesn't have a /$RWDIR directory for me to mount a rw filesystem. You'd better create it... " + echo "" + /bin/sh +fi + +if [ ! -e "$NEWROOT/etc/init.d/statelite" ]; then + echo "" + echo "$NEWROOT/etc/init.d/statelite doesn't exist. Perhaps you didn't create this image with th e -m statelite mode" + echo "" + /bin/sh +fi + +mount -t tmpfs rw $NEWROOT/$RWDIR +mkdir -p $NEWROOT/$RWDIR/tmpfs +ME=`hostname` + +# 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 -o nolock,rsize=32768,tc p,nfsvers=3,timeo=14; do + ITER=$((ITER +1 )) + if [ "$ITER" == "$MAXTRIES" ]; then + echo "Your are 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." + /bin/sh + exit + fi + RS= $(( $RANDOM % 20 )) + echo "Trying again in $RS seconds..." + sleep $RS + done +fi + +# TODO: handle the dhclient/resolv.conf/ntp, etc +echo "TODO: handle the dhclient/resolv/ntp, etc" +$NEWROOT/etc/init.d/statelite +READONLY=yes +export READONLY +fastboot=yes +export fastboot +keep_old_ip=yes +export keep_old_ip +mount -n --bind /dev $NREWROOT/dev +mount -n --bind /proc $NEWROOT/proc +mount -n --bind /sys $NEWROOT/sys + +if [ -d "$NEWROOT/etc/sysconfig" -a ! -e "$NEWROOT/etc/sysconfig/selinux" ]; then + echo "SELINUX=disabled" >> "$NEWROOT/etc/sysconfig/selinux" +fi + +# inject new exit_if_exists +echo 'settle_exit_if_exists="--exit-if-exists=/dev/root"; rm "$job"' > /initqueue/xcat.sh +# force udevsettle to break +> /initqueue/work diff --git a/xCAT-server/share/xcat/netboot/rh/dracut/xcatroot b/xCAT-server/share/xcat/netboot/rh/dracut/xcatroot index c76dcfcf7..df339f36e 100755 --- a/xCAT-server/share/xcat/netboot/rh/dracut/xcatroot +++ b/xCAT-server/share/xcat/netboot/rh/dracut/xcatroot @@ -21,155 +21,12 @@ if [ ! -z "$imgurl" ]; then SERVER=${SERVER%:} ROOTDIR=/${ROOTDIR#*/} fi -elif [ ! -z "$nfsroot" ]; then #fyi, done this way to tolerate nfs:// - NFSROOT=1 - SERVER=${nfsroot} - ROOTDIR=$SERVER - SERVER=${SERVER%%/*} - SERVER=${SERVER%:} - ROOTDIR=/${ROOTDIR#*/} -elif [ ! -z $statemnt ]; then #btw, uri style might have left future options other than nfs open, will use // to detect uri in the future I guess - NFSROOT=1 - SNAPSHOTSERVER=${statemnt%:*} - SNAPSHOTROOT=${statemnt#*/} - # may be that there is not server and just a directory. - if [ -z $SNAPSHOTROOT ] - then - SNAPSHOTROOT=$SNAPSHOTSERVER - SNAPSHOTSERVER= - fi -fi - #echo 0 > /proc/sys/vm/zone_reclaim_mode #Avoid kernel bug -if [ "$NFSROOT" = "1" ]; then - echo Setting up Statelite - mkdir -p $NEWROOT - MAXTRIES=7 - ITER=0 - #ME=`hostname` - while ! mount.nfs ${SERVER}:${ROOTDIR}/rootimg $NEWROOT -r -n -o nolock,rsize=32768,tcp,nfsvers=3,timeo=14 - do - ITER=$(expr $ITER + 1) - if [ "$ITER" == "$MAXTRIES" ] - then - echo "Failed mounting nfs" - 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?" - - /bin/dash - exit - fi - echo "Could not mount $SERVER:$ROOTDIR on $NEWROOT $RESET" - RS=30 #`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 "" - echo "This NFS root directory doesn't have a /$RWDIR directory for me to mount a rw filesystem. You'd better create it... ${NORMAL}" - echo "." - /bin/dash - fi - - while [ ! -e "$NEWROOT/etc/init.d/statelite" ] - do - echo "" - echo "$NEWROOT/etc/init.d/statelite doesn't exist. Perhaps you didn't create this image with the -m statelite mode" - echo "" - /bin/dash - done - grep '\(shell\)' /proc/cmdline >/dev/null && /bin/dash - mount -t tmpfs rw -o mode= $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 -o nolock,rsize=32768,tcp,nfsvers=3,timeo=14 - 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 "Can't mount $SNAPSHOTSERVER:$SNAPSHOTROOT. ${NORMAL}" - RS=45 #`expr $RANDOM % 20` - echo "Trying again in $RS seconds" - sleep $RS - done - fi - - grep '\(shell\)' /proc/cmdline >/dev/null && /bin/dash - - # have to preserve the initial DHCP request. So we link it. - - if [ ! -d $NEWROOT/$RWDIR/tmpfs/var/lib/dhclient ] - then - mkdir -p $NEWROOT/$RWDIR/tmpfs/var/lib/dhclient - fi - if [ ! -d $NEWROOT/$RWDIR/tmpfs/var/lib/dhcp ] - then - mkdir -p $NEWROOT/$RWDIR/tmpfs/var/lib/dhcp - fi - - [ -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 ] - do - echo "$NEWROOT/etc/init.d/statelite does not exist in image!" - /bin/dash - 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 && dash - - echo 0x100 > /proc/sys/kernel/real-root-dev - keep_old_ip=yes - export keep_old_ip - fastboot=yes - export fastboot - READONLY=yes - export READONLY - grep '\(shell\)' /proc/cmdline >/dev/null && /bin/dash - mount -n --bind /dev $NEWROOT/dev - umount /sys - umount /proc - -fi -# END NFSROOT/Statelite code - # 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 diff --git a/xCAT-server/share/xcat/netboot/rh/genimage b/xCAT-server/share/xcat/netboot/rh/genimage index d8e88a682..073911747 100755 --- a/xCAT-server/share/xcat/netboot/rh/genimage +++ b/xCAT-server/share/xcat/netboot/rh/genimage @@ -189,22 +189,23 @@ foreach (split /,/,$netdriver) { } push @ndrivers,$_; } -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"; +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"; - } + # 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) { @yumdirs=(); find(\&isyumdir, <$installroot/$osver/$arch/>); @@ -483,21 +484,81 @@ sub getlibs { } sub mkinitrd_dracut { - mkpath("$rootimg_dir/usr/share/dracut/modules.d/97xcat"); - foreach (<$fullpath/dracut/*>) { - my $perm = (stat($_))[2]; - cp($_,"$rootimg_dir/usr/share/dracut/modules.d/97xcat"); - chmod($perm&07777,"$rootimg_dir/usr/share/dracut/modules.d/97xcat/".basename($_)); + my $dracutmpath = "$rootimg_dir/usr/share/dracut/modules.d/97xcat"; + mkpath($dracutmpath); + + my $perm = (stat("$fullpath/dracut/check"))[2]; + cp("$fullpath/dracut/check", $dracutmpath); + chmod($perm&07777, "$dracutmpath/check"); + + my $add_drivers = join(' ', @ndrivers); + my $DRACUTCONF; + + if ($mode eq "statelite") { + # for statelite + cp("$fullpath/dracut/install.statelite","$dracutmpath/install"); + $perm = (stat("$fullpath/dracut/install.statelite"))[2]; + chmod($perm&07777, "$dracutmpath/install"); + + cp("$fullpath/dracut/xcat-prepivot.sh",$dracutmpath); + $perm = (stat("$fullpath/dracut/xcat-prepivot.sh"))[2]; + chmod($perm&07777, "$dracutmpath/xcat-prepivot.sh"); + + # update etc/dracut.conf + open($DRACUTCONF, '>', "$rootimg_dir/etc/dracut.conf"); + print $DRACUTCONF qq{dracutmodules+="xcat nfs base network"\n}; + print $DRACUTCONF qq{add_drivers+="$add_drivers"\n}; + print $DRACUTCONF qq{filesystems+="nfs"\n}; + close $DRACUTCONF; + # TODO: modify etc/rc.sysinit, prevent remounting + my $SYSINITFILE; + my $TMPSYSINITFILE; + 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"); + } else { + # for diskless + cp("$fullpath/dracut/install.netboot","$dracutmpath/install"); + $perm = (stat("$fullpath/dracut/xcat-cmdline.sh"))[2]; + chmod($perm&07777, "$dracutmpath/install"); + + if ($prinic) { + my $optspec; + open($optspec,'>>',"$dracutmpath/xcat-cmdline.sh"); + print $optspec "IFACE=$prinic\n"; + close $optspec; + } + + cp("$fullpath/dracut/xcatroot","$dracutmpath/"); + $perm = (stat("$fullpath/dracut/xcatroot"))[2]; + chmod($perm&07777, "$dracutmpath/xcatroot"); + + cp("$fullpath/dracut/installkernel", "$dracutmpath/"); + $perm = (stat("$fullpath/dracut/installkernel"))[2]; + chmod($perm&07777, "$dracutmpath/installkernel"); + + # update etc/dracut.conf + open($DRACUTCONF, '>', "$rootimg_dir/etc/dracut.conf"); + print $DRACUTCONF qq{dracutmodules+="xcat base network"\n}; + print $DRACUTCONF qq{add_drivers+="$add_drivers"\n}; + close $DRACUTCONF; } - if ($prinic) { - my $optspec; - open($optspec,'>>',"$rootimg_dir/usr/share/dracut/modules.d/97xcat/xcat-cmdline.sh"); - print $optspec "IFACE=$prinic\n"; - close($optspec); - } - foreach (@ndrivers) { s/\.ko$//; } - system("chroot '$rootimg_dir' dracut -d '".join(' ',@ndrivers)."' -m 'xcat base' /tmp/initrd.$$.gz $kernelver"); - move("$rootimg_dir/tmp/initrd.$$.gz","$destdir/initrd.gz"); + 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.gz"); } sub mkinitrd {