diff --git a/xCAT-server-2.0/lib/xcat/plugins/fedora.pm b/xCAT-server-2.0/lib/xcat/plugins/fedora.pm index 074cbb8d1..51b4cf5f1 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/fedora.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/fedora.pm @@ -105,13 +105,15 @@ sub mknetboot { my $osver = $ent->{os}; my $arch = $ent->{arch}; my $profile = $ent->{profile}; - unless (-r "/$installroot/netboot/$osver/$arch/$profile/kernel" and -r "$installroot/netboot/$osver/$arch/$profile/rootimg.gz") { - makenetboot($osver,$arch,$profile,$installroot,$callback); - mkpath("/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); - copy("/$installroot/netboot/$osver/$arch/$profile/kernel","/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); - copy("/$installroot/netboot/$osver/$arch/$profile/rootimg.gz","/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); - } - unless (-r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/kernel" and -r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/rootimg.gz") { + unless (-r "/$installroot/netboot/$osver/$arch/$profile/kernel") { + $callback->({error=>["No imageroot found, run genimage.pl -o $osver -p $profile on a system of type $arch"],errorcode=>[1]}); + next; + } + packimage($osver,$arch,$profile,$installroot,$callback); + mkpath("/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); + copy("/$installroot/netboot/$osver/$arch/$profile/kernel","/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); + copy("/$installroot/netboot/$osver/$arch/$profile/rootimg.gz","/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); + unless (-r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/kernel" and -r "/$tftpdir/xcat/netboot/$osver/$arch/$profile/rootimg.gz") { mkpath("/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); copy("/$installroot/netboot/$osver/$arch/$profile/kernel","/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); copy("/$installroot/netboot/$osver/$arch/$profile/rootimg.gz","/$tftpdir/xcat/netboot/$osver/$arch/$profile/"); @@ -142,7 +144,7 @@ sub mknetboot { }); } } -sub makenetboot { +sub packimage { my $osver = shift; my $arch = shift; my $profile = shift; @@ -152,51 +154,32 @@ sub makenetboot { $callback->({error=>["No installdir defined in site table"],errorcode=>[1]}); return; } - my $srcdir = "/$installroot/$osver/$arch/Server"; - unless ( -d $srcdir."/repodata" ) { - $callback->({error=>["copycds has not been run for $osver/$arch (/$installroot/$osver/$arch/Server/repodata not found"],errorcode=>[1]}); - return; - } - my $yumconf; - open($yumconf,">","/tmp/mknetboot.$$.yum.conf"); - print $yumconf "[$osver-$arch]\nname=$osver-$arch\nbaseurl=file:///$srcdir\ngpgcheck=0\n"; - close($yumconf); - system("yum -y -c /tmp/mknetboot.$$.yum.conf --installroot=$installroot/netboot/$osver/$arch/$profile/rootimg/ --disablerepo=* --enablerepo=$osver-$arch install bash dhclient kernel openssh-server openssh-clients dhcpv6_client vim-minimal"); - my $cfgfile; - 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"; - 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/sysconfig/network-scripts/ifcfg-eth0"); - print $cfgfile "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=eth0\n"; - close($cfgfile); - open ($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/sysconfig/network-scripts/ifcfg-eth1"); - print $cfgfile "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=eth1\n"; - close($cfgfile); - 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"); - if (-d "$installroot/postscripts/hostkeys") { - for my $key (<$installroot/postscripts/hostkeys/*key>) { - copy ($key,"$installroot/netboot/$osver/$arch/$profile/rootimg/etc/ssh/"); - } - chmod 0600,; - } - 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 () { - copy ($file,"/$installroot/netboot/$osver/$arch/$profile/rootimg/root/.ssh/"); - } - chmod(0600,); - } my $oldpath=cwd; + my $exlistloc; + if (-r "$::XCATROOT/share/xcat/netboot/fedora/$profile.$osver.$arch.exlist") { + $exlistloc = "$::XCATROOT/share/xcat/netboot/fedora/$profile.$osver.$arch.exlist"; + } elsif (-r "$::XCATROOT/share/xcat/netboot/fedora/$profile.$arch.exlist") { + $exlistloc = "$::XCATROOT/share/xcat/netboot/fedora/$profile.$arch.exlist"; + } elsif (-r "$::XCATROOT/share/xcat/netboot/fedora/$profile.$osver.exlist") { + $exlistloc = "$::XCATROOT/share/xcat/netboot/fedora/$profile.$osver.exlist"; + } elsif (-r "$::XCATROOT/share/xcat/netboot/fedora/$profile.exlist") { + $exlistloc = "$::XCATROOT/share/xcat/netboot/fedora/$profile.exlist"; + } else { + $callback->({error=>["Unable to finde file exclusion list under $::XCATROOT/share/xcat/netboot/fedora/ for $profile/$arch/$osver"],errorcode=>[1]}); + next; + } + my $exlist; + open($exlist,"<",$exlistloc); + my $excludestr = "find . "; + while (<$exlist>) { + chomp $_; + $excludestr .= "'!' -wholename '".$_."' -a "; + } + close($exlist); + $excludestr =~ s!-a \z!|cpio -H newc -o | gzip -c - > ../rootimg.gz!; chdir("$installroot/netboot/$osver/$arch/$profile/rootimg"); - system("find . '!' -wholename './usr/share/man*' -a '!' -wholename './usr/share/locale*' -a '!' -wholename './usr/share/i18n*' -a '!' -wholename './var/cache/yum*' -a '!' -wholename './usr/share/doc*' -a '!' -wholename './usr/lib/locale*' -a '!' -wholename './boot*' |cpio -H newc -o | gzip -c - > ../rootimg.gz"); + system($excludestr); + print $excludestr. " ". $oldpath."\n"; chdir($oldpath); } sub mkinstall { diff --git a/xCAT-server-2.0/share/xcat/netboot/fedora/compute.exlist b/xCAT-server-2.0/share/xcat/netboot/fedora/compute.exlist new file mode 100644 index 000000000..23963520f --- /dev/null +++ b/xCAT-server-2.0/share/xcat/netboot/fedora/compute.exlist @@ -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* diff --git a/xCAT-server-2.0/share/xcat/netboot/fedora/compute.pkglist b/xCAT-server-2.0/share/xcat/netboot/fedora/compute.pkglist new file mode 100644 index 000000000..9ed087d25 --- /dev/null +++ b/xCAT-server-2.0/share/xcat/netboot/fedora/compute.pkglist @@ -0,0 +1,6 @@ +bash +dhclient +kernel +openssh-server +openssh-clients + diff --git a/xCAT-server-2.0/share/xcat/netboot/fedora/genimage.pl b/xCAT-server-2.0/share/xcat/netboot/fedora/genimage.pl new file mode 100755 index 000000000..76437a400 --- /dev/null +++ b/xCAT-server-2.0/share/xcat/netboot/fedora/genimage.pl @@ -0,0 +1,93 @@ +#!/usr/bin/env perl +use File::Basename; +use File::Path; +use File::Copy; +use Getopt::Long; +Getopt::Long::Configure("bundling"); +Getopt::Long::Configure("pass_through"); + +my $prinic = 'eth0'; #TODO be flexible on node primary nic +my $secnic = 'eth1'; #TODO be flexible on node primary nic +my $arch = `uname -m`; +chomp($arch); +my $profile; +my $osver; +GetOptions( + #'a=s' => \$architecture, + 'p=s' => \$profile, + 'o=s' => \$osver, +); +unless ($osver and $profile) { + print 'Usage: genimage -o $OSVER -p $PROFILE'."\n"; + exit 1; +} + +my $installroot = "/install"; +my $srcdir = "$installroot/$osver/$arch"; +unless ( -d $srcdir."/repodata" ) { + print "Need $installroot/$osver/$arch/repodata available from a system that has ran copycds on $osver $arch"; + exit 1; +} +my $pathtofiles=dirname($0); +my $yumconfig; +open($yumconfig,">","/tmp/genimage.$$.yum.conf"); +print $yumconfig "[$osver-$arch]\nname=$osver-$arch\nbaseurl=file://$srcdir\ngpgpcheck=0\n"; +close($yumconfig); +my $yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$installroot/netboot/$osver/$arch/$profile/rootimg/ --disablerepo=* --enablerepo=$osver-$arch install "; +open($yumconfig,"<","$pathtofiles/$profile.pkglist"); +while (<$yumconfig>) { + chomp; + $yumcmd .= $_ . " "; +} +$yumcmd =~ s/ $/\n/; +my $rc = system($yumcmd); +if ($rc) { + print "yum invocation failed\n"; + exit 1; +} +postscripts(); #run 'postscripts' +unlink "/tmp/genimage.$$.yum.conf"; + + + +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,; + } + 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 () { + copy ($file,"/$installroot/netboot/$osver/$arch/$profile/rootimg/root/.ssh/"); + } + chmod(0600,); + } +} + +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"; + 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/sysconfig/network-scripts/ifcfg-$prinic"); + print ("$installroot/netboot/$osver/$arch/$profile/rootimg/etc/sysconfig/network-scripts/ifcfg-$prinic"); + print $cfgfile "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=$prinic\n"; + close($cfgfile); + open($cfgfile,">","$installroot/netboot/$osver/$arch/$profile/rootimg/etc/sysconfig/network-scripts/ifcfg-$secnic"); + print $cfgfile "ONBOOT=no\nBOOTPROTO=dhcp\nDEVICE=$secnic\n"; + close($cfgfile); + 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"); +} diff --git a/xCAT-server-2.0/xCAT-server.spec b/xCAT-server-2.0/xCAT-server.spec index 96abff101..c45079965 100644 --- a/xCAT-server-2.0/xCAT-server.spec +++ b/xCAT-server-2.0/xCAT-server.spec @@ -33,6 +33,7 @@ xCAT-server provides the core server and configuration management components of rm -rf $RPM_BUILD_ROOT mkdir -p $RPM_BUILD_ROOT/%{prefix}/sbin mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/xcat/install +mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/xcat/netboot mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/xcat/ca mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/xcat/scripts mkdir -p $RPM_BUILD_ROOT/%{prefix}/share/xcat/cons @@ -43,8 +44,10 @@ mkdir -p $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT_monitoring/samples %ifos linux cp -a share/xcat/install/* $RPM_BUILD_ROOT/%{prefix}/share/xcat/install/ +cp -a share/xcat/netboot/* $RPM_BUILD_ROOT/%{prefix}/share/xcat/netboot/ %else cp -hpR share/xcat/install/* $RPM_BUILD_ROOT/%{prefix}/share/xcat/install/ +cp -hpR share/xcat/netboot/* $RPM_BUILD_ROOT/%{prefix}/share/xcat/netboot/ %endif cp sbin/* $RPM_BUILD_ROOT/%{prefix}/sbin