From 58e8a9e0a56395d39944ab63b88388c6dde092a6 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Fri, 16 Jan 2015 23:35:18 -0500 Subject: [PATCH] genimage changes to support sles12 diskless on x86_64 --- xCAT-server/lib/xcat/plugins/sles.pm | 3 + .../netboot/sles/compute.sles12.x86_64.exlist | 36 +++ .../sles/compute.sles12.x86_64.pkglist | 35 +++ .../sles/compute.sles12.x86_64.postinstall | 46 ++++ xCAT-server/share/xcat/netboot/sles/genimage | 215 +++++++++++++++--- 5 files changed, 308 insertions(+), 27 deletions(-) create mode 100755 xCAT-server/share/xcat/netboot/sles/compute.sles12.x86_64.exlist create mode 100644 xCAT-server/share/xcat/netboot/sles/compute.sles12.x86_64.pkglist create mode 100755 xCAT-server/share/xcat/netboot/sles/compute.sles12.x86_64.postinstall diff --git a/xCAT-server/lib/xcat/plugins/sles.pm b/xCAT-server/lib/xcat/plugins/sles.pm index d61d52e42..ea13dc732 100755 --- a/xCAT-server/lib/xcat/plugins/sles.pm +++ b/xCAT-server/lib/xcat/plugins/sles.pm @@ -580,6 +580,9 @@ sub mknetboot # add flow control setting $kcmdline .= "FC=$useflowcontrol "; + # add dhcp for ip + $kcmdline .= "ip=dhcp "; + # add the kernel-booting parameter: netdev=, or BOOTIF= my $netdev = ""; my $mac = xCAT::Utils->parseMacTabEntry($machash->{$node}->[0]->{mac},$node); diff --git a/xCAT-server/share/xcat/netboot/sles/compute.sles12.x86_64.exlist b/xCAT-server/share/xcat/netboot/sles/compute.sles12.x86_64.exlist new file mode 100755 index 000000000..c7678ccd7 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/sles/compute.sles12.x86_64.exlist @@ -0,0 +1,36 @@ +./boot* +./etc/bootsplash/themes/SLES/images* +./opt/sci/include* +./usr/include* +./usr/lib/locale* +./usr/lib/perl5/5.10.0/x86_64-linux-thread-multi/auto/Encode/CN* +./usr/lib/perl5/5.10.0/x86_64-linux-thread-multi/auto/Encode/JP* +./usr/lib/perl5/5.10.0/x86_64-linux-thread-multi/auto/Encode/TW* +./usr/lib/perl5/5.10.0/x86_64-linux-thread-multi/auto/Encode/KR* +./usr/lib/perl5/5.10.0/x86_64-linux-thread-multi/Encode/CN* +./usr/lib/perl5/5.10.0/x86_64-linux-thread-multi/Encode/JP* +./usr/lib/perl5/5.10.0/x86_64-linux-thread-multi/Encode/KR* +./usr/lib/perl5/5.10.0/x86_64-linux-thread-multi/Encode/TW* +./usr/lib64/gcc/x86_64-suse-linux/4.3/include* +./usr/local/include* +./usr/local/man* +./usr/x86_64-suse-linux/include* +./usr/share/X11/locale/* ++./usr/share/X11/locale/en_US.UTF-8* ++./usr/share/X11/locale/C* +./usr/share/cracklib* +./usr/share/doc* +./usr/share/doc/packages/cyrus-sasl/doc* +./usr/share/gnome* +./usr/share/i18n* +./usr/share/info* +./usr/share/locale/* ++./usr/share/locale/en_US* ++./usr/share/locale/C* +./usr/share/man* +./usr/share/omf* +./usr/share/vim/site/doc* +./usr/share/vim/vim72/doc* +./var/cache/man* +./var/cache/yum* + diff --git a/xCAT-server/share/xcat/netboot/sles/compute.sles12.x86_64.pkglist b/xCAT-server/share/xcat/netboot/sles/compute.sles12.x86_64.pkglist new file mode 100644 index 000000000..88297099a --- /dev/null +++ b/xCAT-server/share/xcat/netboot/sles/compute.sles12.x86_64.pkglist @@ -0,0 +1,35 @@ +aaa_base +bash +nfs-kernel-server +openssl +dhcp-client +kernel-default +openssh +procps +psmisc +wget +sysconfig +rsyslog +vim +rsync +timezone +bc +ntp +gzip +e2fsprogs +parted +binutils +tar +open-iscsi +curl +plymouth +btrfsprogs +cryptsetup +dmraid +mdadm +multipath-tools +gpg2 +cifs-utils +kernel-firmware +util-linux-systemd + diff --git a/xCAT-server/share/xcat/netboot/sles/compute.sles12.x86_64.postinstall b/xCAT-server/share/xcat/netboot/sles/compute.sles12.x86_64.postinstall new file mode 100755 index 000000000..c75134560 --- /dev/null +++ b/xCAT-server/share/xcat/netboot/sles/compute.sles12.x86_64.postinstall @@ -0,0 +1,46 @@ +#!/bin/sh +#-- Do not remove following line if you want to make use of CVS version tracking +#-- $Id: compute.postinstall,v 1.21 2008/09/04 12:05:45 sikorsky Exp $ +#-- jurij.sikorsky@t-systems.cz +#-- +#-- this script is run after all packages from $profile.pkglist are installed +#-- +#-- it gets these arguments: +#-- +#-- $1 = install root (chroot directory for profile) +#-- $2 = OS version +#-- $3 = architecture +#-- $4 = profile name +#-- $5 = work dir (where genimage is located) +#-- +#-- +installroot=$1 +osver=$2 +arch=$3 +profile=$4 +workdir=$5 + +#-- Example how /etc/fstab can be automatically generated during image generation: +cat <$installroot/etc/fstab +proc /proc proc rw 0 0 +sysfs /sys sysfs rw 0 0 +devpts /dev/pts devpts rw,gid=5,mode=620 0 0 +${profile}_${arch} / tmpfs rw 0 1 +none /tmp tmpfs defaults,size=10m 0 2 +none /var/tmp tmpfs defaults,size=10m 0 2 +END + +#-- Uncomment the line contains "cons" in /etc/inittab +#cons:12345:respawn:/sbin/smart_agetty -L 38400 console +TMP_inittab=`sed 's/\(#\)\(cons:12345.*\)$/\2/' $installroot/etc/inittab` +echo "$TMP_inittab" > $installroot/etc/inittab + + +#-- Example of booted image versioning +#-- We want to know, with what configuration (version of the image) each node was booted. +#-- Hence, we keep image definition files and postscripts in CVS. During image generation we create file /etc/IMGVERSION and fill it with CVS "$Id$" of files with image definition (.pkglist, .exlist, .repolist, .postinstall). Then, during boot, each "CVS enabled" postscript (see /install/postscripts/cvs_template.sh and /install/postscripts/cvs_template.pl) adds one line to /etc/IMGVERSION. Then you can determine in any time what image you are running and what postscipts in which versions were run. +#cat /dev/null > $installroot/etc/IMGVERSION +#for ext in pkglist exlist postinstall repolist; do +# [ -r $workdir/$profile.$ext ] && cat $workdir/$profile.$ext | grep -E '^[[:space:]]*#.*[[:space:]]\$Id' >> $installroot/etc/IMGVERSION +#done + diff --git a/xCAT-server/share/xcat/netboot/sles/genimage b/xCAT-server/share/xcat/netboot/sles/genimage index bba3e72fd..02ff3f6e2 100755 --- a/xCAT-server/share/xcat/netboot/sles/genimage +++ b/xCAT-server/share/xcat/netboot/sles/genimage @@ -21,6 +21,9 @@ use imgutils; Getopt::Long::Configure("bundling"); Getopt::Long::Configure("pass_through"); +my $dracutmode; #Indicate whether this is a dracut style initrd +my $dracutdir = "dracut"; # The default directory name of dracut +my $dracutver; my $prinic; #TODO be flexible on node primary nic my $othernics; #TODO be flexible on node primary nic my $netdriver; @@ -248,7 +251,7 @@ unless ($onlyinitrd) { my $non_interactive; if (!$prompt) { $non_interactive="--non-interactive --no-gpg-checks --gpg-auto-import-keys"; } - if($osver_host == 11) {#zypper in SLES11 is different + if($osver_host >= 11) {#zypper in SLES11 is different system("rm -rf $rootimg_dir/etc/zypp/repos.d/$osver-*.repo"); my @pkgdirs = split(",", $srcdir); @@ -286,7 +289,7 @@ unless ($onlyinitrd) { print "Cannot find the directory for the kernel at $kerneldir.\n"; exit 1; } - if ($osver_host == 11) { + if ($osver_host >= 11) { if (-e "$rootimg_dir/etc/zypp/repos.d/$kernelver.repo") { system("rm -rf $rootimg_dir/etc/zypp/repos.d/$kernelver.repo"); } @@ -297,7 +300,7 @@ unless ($onlyinitrd) { } #remove the old repository for extra packages - if ($osver_host == 11) { + if ($osver_host >= 11) { my $result=`zypper -R $rootimg_dir $non_interactive lr |grep otherpkg|cut -f2 -d '|'|tr "\n" " "`; if ($result =~ /\S/) { system("zypper -R $rootimg_dir $non_interactive rr $result"); @@ -311,7 +314,7 @@ unless ($onlyinitrd) { #add the new repository for extra packages my %extrapkgnames; - if($osver_host == 11) { #SLES11 + if($osver_host >= 11) { #SLES11 if(-e "$rootimg_dir/etc/zypp/repos.d/otherpkg.repo") { system("rm -rf $rootimg_dir/etc/zypp/repos.d/otherpkg.repo"); } @@ -329,13 +332,13 @@ unless ($onlyinitrd) { if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE") || ($_ eq "ENVLIST")) { next;} my $whole_path="$srcdir_otherpkgs/$_"; if (-r "$srcdir_otherpkgs/$_/repodata/repomd.xml") { - if($osver_host == 11) { + if($osver_host >= 11) { system("zypper -R $rootimg_dir $non_interactive ar file:$srcdir_otherpkgs/$_ otherpkg$index"); }else { system("zypper -R $rootimg_dir $non_interactive sa file:$srcdir_otherpkgs/$_"); } } else { - if($osver_host == 11) { + if($osver_host >= 11) { system("zypper -R $rootimg_dir $non_interactive ar -t Plaindir file:$srcdir_otherpkgs/$_ otherpkg$index"); }else { system("zypper -R $rootimg_dir $non_interactive sa -t Plaindir file:$srcdir_otherpkgs/$_"); @@ -364,7 +367,7 @@ unless ($onlyinitrd) { chomp; next if /^\s*#/; my ($repotype,$repourl,$repoalias) = split m/\|/; - if($osver_host == 11) { + if($osver_host >= 11) { system("zypper -R $rootimg_dir $non_interactive ar $repourl $repoalias"); }else { system("zypper -R $rootimg_dir $non_interactive sa $repourl $repoalias"); @@ -379,10 +382,10 @@ unless ($onlyinitrd) { #$yumcmd .= "install "; #mkpath("$rootimg_dir/var/lib/yum"); my $yumcmd; - if($osver =~ /sles11/ && $osver_host == 11) { - $yumcmd = "zypper -R $rootimg_dir $non_interactive install -l --no-recommends "; #add -l for SLES11 - }else { + if( $osver_host < 11) { $yumcmd = "zypper -R $rootimg_dir $non_interactive install "; + }else { + $yumcmd = "zypper -R $rootimg_dir $non_interactive install -l --no-recommends "; #add -l for SLES11 } #install packages from pkglist file @@ -490,7 +493,7 @@ unless ($onlyinitrd) { my $index=1; #remove the old repository for extra packages - if ($osver_host == 11) { + if ($osver_host >= 11) { my $result=`zypper -R $rootimg_dir $non_interactive lr |grep otherpkg|cut -f2 -d '|'|tr "\n" " "`; if ($result =~ /\S/) { system("zypper -R $rootimg_dir $non_interactive rr $result"); @@ -505,13 +508,13 @@ unless ($onlyinitrd) { foreach (keys(%{$extra_hash{$pass}})) { if (($_ eq "PRE_REMOVE") || ($_ eq "POST_REMOVE") || ($_ eq "ENVLIST")) { next;} if (-r "$srcdir_otherpkgs/$_/repodata/repomd.xml") { - if($osver_host == 11) { + if($osver_host >= 11) { system("zypper -R $rootimg_dir $non_interactive ar file:$srcdir_otherpkgs/$_ otherpkg$index"); } else { system("zypper -R $rootimg_dir $non_interactive sa file:$srcdir_otherpkgs/$_"); } } else { - if($osver_host == 11) { + if($osver_host >= 11) { system("zypper -R $rootimg_dir $non_interactive ar -t Plaindir file:$srcdir_otherpkgs/$_ otherpkg$index"); }else { system("zypper -R $rootimg_dir $non_interactive sa -t Plaindir file:$srcdir_otherpkgs/$_"); @@ -565,7 +568,7 @@ unless ($onlyinitrd) { # run zypper update to update any installed rpms # needed when running genimage again after updating software in repositories my $yumcmd_update; - if ($osver_host == 11) { + if ($osver_host >= 11) { $yumcmd_update = "zypper -R $rootimg_dir $non_interactive update "; } else { $yumcmd_update = "zypper -R $rootimg_dir $non_interactive update "; @@ -575,7 +578,7 @@ unless ($onlyinitrd) { } #remove the old repository for extra packages - if ($osver_host == 11) { + if ($osver_host >= 11) { my $result=`zypper -R $rootimg_dir $non_interactive lr |grep otherpkg|cut -f2 -d '|'|tr "\n" " "`; if ($result =~ /\S/) { system("zypper -R $rootimg_dir $non_interactive rr $result"); @@ -593,6 +596,22 @@ unless ($onlyinitrd) { } unlink "/tmp/genimage.$$.yum.conf"; +# added dracut mode +if ( (-d "$rootimg_dir/usr/share/dracut") or (-d "$rootimg_dir/usr/lib/dracut") ) { + $dracutmode = 1; + # get dracut version + $dracutver = `rpm --root $rootimg_dir -qi dracut | grep Version | awk -F' ' '{print \$3}' `; + chomp($dracutver); + if ($dracutver =~ /^\d\d\d$/) { + if ($dracutver >= "033") { + $dracutdir = "dracut_033"; + } else { + $dracutdir = "dracut"; # The default directory + } + } + print "Enter the dracut mode. Dracut version: $dracutver. Dracut directory: $dracutdir.\n"; +} + # 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. @@ -784,6 +803,20 @@ unless( -r "$pathtofiles/../add-on/statelite/rc.statelite") { system("cp $pathtofiles/../add-on/statelite/rc.statelite $rootimg_dir/etc/init.d/statelite"); system("cp $pathtofiles/../add-on/statelite/rc.localdisk $rootimg_dir/etc/init.d/localdisk"); +# added dracutmode +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"); + } + } + + # the dhcp client information stores in the directory "/var/lib/dhcpcd/" unless(-l "$rootimg_dir/var/lib/dhcpcd") { mkpath "$rootimg_dir/var/lib/dhcpcd/"; @@ -863,13 +896,17 @@ foreach my $dn (@ndrivers) { # before mkinitrd, run depmod to generate the modules.dep system("chroot $rootimg_dir depmod $kernelver"); -my @drivers; # backup of @ndrivers -push @drivers, @ndrivers; -mkinitrd("statelite"); -@ndrivers=(); -push @ndrivers, @drivers; -mkinitrd("stateless"); - +if ($dracutmode) { + mkinitrd_dracut("statelite"); + mkinitrd_dracut("stateless"); +} else { + my @drivers; # backup of @ndrivers + push @drivers, @ndrivers; + mkinitrd("statelite"); + @ndrivers=(); + push @ndrivers, @drivers; + mkinitrd("stateless"); +} sub getlibs { my $file = shift; @@ -896,6 +933,130 @@ sub getlibs { } } +#added dracut +sub mkinitrd_dracut { + my ($mode) = @_; # the mode is for statelite or stateless + + my $dracutmoduledir="$rootimg_dir/usr/share/dracut/modules.d/"; + if ( (! -d $dracutmoduledir) and (-d "$rootimg_dir/usr/lib/dracut/modules.d/")) + { + $dracutmoduledir="$rootimg_dir/usr/lib/dracut/modules.d/"; + } + + my $dracutmpath = $dracutmoduledir."97xcat/"; + mkpath($dracutmpath); + + my $perm = (stat("$fullpath/$dracutdir/check"))[2]; + cp("$fullpath/$dracutdir/check", $dracutmpath); + chmod($perm&07777, "$dracutmpath/check"); + + foreach (@ndrivers) { s/\.ko$//; } + # Add drivers to support local disk + push @ndrivers, "ext3"; + push @ndrivers, "ext4"; + #remove the duplicated drivers + my @fulldrivers; + foreach my $dn (@ndrivers) { + unless (grep {$_ eq $dn} @fulldrivers) { + push @fulldrivers, $dn; + } + } + @ndrivers = @fulldrivers; + + my $add_drivers = join(' ', @ndrivers); + print "Try to load drivers: $add_drivers to initrd.\n"; + my $DRACUTCONF; + + if ($mode eq "statelite") { + # for statelite + cp("$fullpath/$dracutdir/install.statelite","$dracutmpath/install"); + $perm = (stat("$fullpath/$dracutdir/install.statelite"))[2]; + chmod($perm&07777, "$dracutmpath/install"); + + cp("$fullpath/$dracutdir/xcat-updateflag",$dracutmpath); + $perm = (stat("$fullpath/$dracutdir/xcat-updateflag"))[2]; + chmod($perm&07777, "$dracutmpath/xcat-updateflag"); + + cp("$fullpath/$dracutdir/xcat-prepivot.sh",$dracutmpath); + $perm = (stat("$fullpath/$dracutdir/xcat-prepivot.sh"))[2]; + chmod($perm&07777, "$dracutmpath/xcat-prepivot.sh"); + + cp("$fullpath/$dracutdir/xcat-premount.sh",$dracutmpath); + $perm = (stat("$fullpath/$dracutdir/xcat-premount.sh"))[2]; + chmod($perm&07777, "$dracutmpath/xcat-premount.sh"); + + #update etc/dracut.conf + open($DRACUTCONF, '>', "$rootimg_dir/etc/dracut.conf"); + if (-d glob($dracutmoduledir."[0-9]*fadump")){ + print $DRACUTCONF qq{dracutmodules+="xcat nfs base network kernel-modules fadump"\n}; + } + else{ + print $DRACUTCONF qq{dracutmodules+="xcat nfs base network kernel-modules"\n}; + } + print $DRACUTCONF qq{add_drivers+="$add_drivers"\n}; + print $DRACUTCONF qq{filesystems+="nfs"\n}; + close $DRACUTCONF; + } elsif ($mode eq "stateless") { + cp("$fullpath/$dracutdir/install.netboot","$dracutmpath/install"); + $perm = (stat("$fullpath/$dracutdir/install.netboot"))[2]; + chmod($perm&07777, "$dracutmpath/install"); + + cp("$fullpath/$dracutdir/xcat-cmdline.sh","$dracutmpath/"); + $perm = (stat("$fullpath/$dracutdir/xcat-cmdline.sh"))[2]; + chmod($perm&07777, "$dracutmpath/xcat-cmdline.sh"); + + cp("$fullpath/$dracutdir/xcat-updateflag",$dracutmpath); + $perm = (stat("$fullpath/$dracutdir/xcat-updateflag"))[2]; + chmod($perm&07777, "$dracutmpath/xcat-updateflag"); + if ($prinic) { + my $optspec; + open($optspec,'>>',"$dracutmpath/xcat-cmdline.sh"); + print $optspec "PRINIC=$prinic\n"; + close $optspec; + } + + cp("$fullpath/$dracutdir/xcatroot","$dracutmpath/"); + $perm = (stat("$fullpath/$dracutdir/xcatroot"))[2]; + chmod($perm&07777, "$dracutmpath/xcatroot"); + + cp("$fullpath/$dracutdir/installkernel", "$dracutmpath/"); + $perm = (stat("$fullpath/$dracutdir/installkernel"))[2]; + chmod($perm&07777, "$dracutmpath/installkernel"); + + # update etc/dracut.conf + open($DRACUTCONF, '>', "$rootimg_dir/etc/dracut.conf"); + if (-d glob($dracutmoduledir."[0-9]*fadump")){ + print $DRACUTCONF qq{dracutmodules+="xcat nfs base network kernel-modules fadump"\n}; + } + else{ + print $DRACUTCONF qq{dracutmodules+="xcat nfs 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"; + } + + my $additional_options=undef; + if($rootlimit) + { + open(my $ETC_CMDLINE,">","$rootimg_dir/tmp/cmdline"); + print $ETC_CMDLINE qq{rootlimit=$rootlimit\n}; + close $ETC_CMDLINE; + $additional_options= qq{--include /tmp/cmdline /etc/cmdline}; + } + + # force the dracut run in non-hostonly mode for dracut higher than version 033 + if ($dracutver > "033") { + $additional_options .= " -N"; + } + + system("chroot $rootimg_dir dracut $additional_options -f /tmp/initrd.$$.gz $kernelver"); + print "the initial ramdisk for $mode is generated successfully.\n"; + move("$rootimg_dir/tmp/initrd.$$.gz", "$destdir/initrd-$mode.gz"); +} + + sub mkinitrd { my ($mode) = @_; # statelite or stateless @@ -1518,7 +1679,7 @@ EOMS getlibs($_); push @filestoadd,$_; } - if($osver_host == 11) { + if($osver_host >= 11) { foreach ("sbin/mount.nfs", "sbin/umount.nfs", "sbin/udevadm") { getlibs($_); push @filestoadd,$_; @@ -1530,7 +1691,7 @@ EOMS getlibs($_); push @filestoadd,$_; } - if($osver_host == 11) { + if($osver_host >= 11) { getlibs("sbin/udevadm"); push @filestoadd,"sbin/udevadm"; } @@ -1589,7 +1750,7 @@ EOMS rmtree($pathonrootimage); #copy conf files needed by nfs mount in sles11.2 - if($osver_host == 11) + if($osver_host >= 11) { system("cp -r $rootimg_dir/etc/protocols /tmp/xcatinitrd.$$/etc/"); system("cp -r $rootimg_dir/etc/netconfig /tmp/xcatinitrd.$$/etc/"); @@ -1676,13 +1837,13 @@ sub generic_post { # This function is meant to leave the image in a state approx #modify /etc/sysconfig/clock in the image:HWCLOCK="--local", TIMEZONE=site:timezone if ($timezone) { - if (-e $rootimg_dir/etc/sysconfig/clock) { + if (-e "$rootimg_dir/etc/sysconfig/clock") { system("sed -i '".'s!\(TIMEZONE=\).*!\1'."\"$timezone\"!"."' $rootimg_dir/etc/sysconfig/clock"); } system("chroot $rootimg_dir zic -l $timezone"); } - if (-e $rootimg_dir/etc/sysconfig/clock) { + if (-e "$rootimg_dir/etc/sysconfig/clock") { system("sed -i 's!\\(HWCLOCK=\\).*!\\1\"--localtime\"!' $rootimg_dir/etc/sysconfig/clock"); }