From e2910708b330aa5b38b1578a56d3c006e7fc1b29 Mon Sep 17 00:00:00 2001 From: "John P. Davis" Date: Wed, 6 Oct 2004 01:34:29 +0000 Subject: [PATCH] initial import of netboot code git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/catalyst/trunk@448 d1e1f19c-881f-0410-ab34-b69fee027534 --- ChangeLog | 10 +- modules/catalyst_support.py | 4 +- modules/generic_stage_target.py | 6 +- modules/netboot.py | 112 +++++++++++++++++++++++ targets/netboot/netboot-busybox.sh | 35 +++++++ targets/netboot/netboot-image.sh | 137 ++++++++++++++++++++++++++++ targets/netboot/netboot-kernel.sh | 48 ++++++++++ targets/netboot/netboot-packages.sh | 47 ++++++++++ targets/netboot/netboot.sh | 78 ++++++++++++++++ 9 files changed, 473 insertions(+), 4 deletions(-) create mode 100644 modules/netboot.py create mode 100644 targets/netboot/netboot-busybox.sh create mode 100644 targets/netboot/netboot-image.sh create mode 100644 targets/netboot/netboot-kernel.sh create mode 100644 targets/netboot/netboot-packages.sh create mode 100644 targets/netboot/netboot.sh diff --git a/ChangeLog b/ChangeLog index 32a03b14..e03855db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,14 @@ # ChangeLog for gentoo/src/catalyst # Copyright 2002-2004 Gentoo Technologies, Inc.; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo/src/catalyst/ChangeLog,v 1.88 2004/10/05 13:22:06 zhen Exp $ +# $Header: /var/cvsroot/gentoo/src/catalyst/ChangeLog,v 1.89 2004/10/06 01:34:29 zhen Exp $ + + 05 Oct 2004; John Davis modules/catalyst_support.py, + modules/generic_stage_target.py, +modules/netboot.py, + +targets/netboot/netboot-busybox.sh, +targets/netboot/netboot-image.sh, + +targets/netboot/netboot-kernel.sh, +targets/netboot/netboot-packages.sh, + +targets/netboot/netboot.sh: + initial import of the netboot code. thanks to Guy Martin + for writing them! 05 Oct 2004; John Davis modules/generic_stage_target.py, targets/embedded/embedded-chroot.sh, targets/grp/grp-chroot.sh, diff --git a/modules/catalyst_support.py b/modules/catalyst_support.py index 474b0871..33907963 100644 --- a/modules/catalyst_support.py +++ b/modules/catalyst_support.py @@ -1,6 +1,6 @@ # Distributed under the GNU General Public License version 2 # Copyright 2003-2004 Gentoo Technologies, Inc. -# $Header: /var/cvsroot/gentoo/src/catalyst/modules/catalyst_support.py,v 1.27 2004/09/16 05:53:50 zhen Exp $ +# $Header: /var/cvsroot/gentoo/src/catalyst/modules/catalyst_support.py,v 1.28 2004/10/06 01:34:29 zhen Exp $ import sys,string,os,types,re @@ -10,7 +10,7 @@ required_build_targets=["generic_target","generic_stage_target"] # new build types should be added here valid_build_targets=["stage1_target","stage2_target","stage3_target","grp_target", "livecd_stage1_target","livecd_stage2_target","embedded_target", - "tinderbox_target","snapshot_target"] + "tinderbox_target","snapshot_target","netboot"] required_config_file_values=["storedir","sharedir","distdir","portdir"] valid_config_file_values=required_config_file_values[:] diff --git a/modules/generic_stage_target.py b/modules/generic_stage_target.py index b2ed52b3..588ae973 100644 --- a/modules/generic_stage_target.py +++ b/modules/generic_stage_target.py @@ -1,6 +1,6 @@ # Distributed under the GNU General Public License version 2 # Copyright 2003-2004 Gentoo Technologies, Inc. -# $Header: /var/cvsroot/gentoo/src/catalyst/modules/generic_stage_target.py,v 1.14 2004/10/05 13:22:06 zhen Exp $ +# $Header: /var/cvsroot/gentoo/src/catalyst/modules/generic_stage_target.py,v 1.15 2004/10/06 01:34:29 zhen Exp $ """ This class does all of the chroot setup, copying of files, etc. It is @@ -112,6 +112,10 @@ class generic_stage_target(generic_target): elif self.settings["target"] == "livecd-stage2": self.settings["source_path"]=st+"/tmp/"+self.settings["source_subpath"] self.settings["cdroot_path"]=st+"/builds/"+self.settings["target_subpath"] + + elif self.settings["target"] == "netboot": + self.settings["target_path"]=st+"/builds/"+self.settings["target_subpath"] + self.settings["source_path"]=st+"/builds/"+self.settings["source_subpath"]+".tar.bz2" else: self.settings["target_path"]=st+"/builds/"+self.settings["target_subpath"]+".tar.bz2" diff --git a/modules/netboot.py b/modules/netboot.py new file mode 100644 index 00000000..5d4a0e57 --- /dev/null +++ b/modules/netboot.py @@ -0,0 +1,112 @@ +# Distributed under the GNU General Public License version 2 +# Copyright 2003-2004 Gentoo Technologies, Inc. +# $Header: /var/cvsroot/gentoo/src/catalyst/modules/Attic/netboot.py,v 1.1 2004/10/06 01:34:29 zhen Exp $ + +""" +Builder class for a netboot build. +""" + +import os,string,types +from catalyst_support import * +from generic_stage_target import * + +class netboot_target(generic_stage_target): + def __init__(self,spec,addlargs): + self.required_values=["netboot/kernel/sources",\ + "netboot/kernel/config","netboot/busybox_config"] + + self.valid_values=["netboot/extra_files"] + if not addlargs.has_key("netboot/packages"): + raise CatalystError, "Required value netboot/packages not specified." + + if type(addlargs["netboot/packages"]) == types.StringType: + loopy=[addlargs["netboot/packages"]] + + else: + loopy=addlargs["netboot/packages"] + + for x in loopy: + self.required_values.append("netboot/packages/"+x+"/files") + + self.valid_values.extend(self.required_values) + + generic_stage_target.__init__(self,spec,addlargs) + + file_locate(self.settings, ["netboot/busybox_config"]) + file_locate(self.settings, ["netboot/kernel/config"]) + file_locate(self.settings, ["netboot/base_tarball"]) + + def run_local(self): + # Build packages + mypack=list_bashify(self.settings["netboot/packages"]) + try: + cmd("/bin/bash "+self.settings["sharedir"]+\ + "/targets/netboot/netboot.sh packages "+mypack) + + except CatalystError: + self.unbind() + raise CatalystError,"netboot build aborting due to error." + + # Build busybox + try: + cmd("/bin/bash "+self.settings["sharedir"]+\ + "/targets/netboot/netboot.sh busybox "+ self.settings["netboot/busybox_config"]) + + except CatalystError: + self.unbind() + raise CatalystError,"netboot build aborting due to error." + + # Build kernel + try: + cmd("/bin/bash "+self.settings["sharedir"]+\ + "/targets/netboot/netboot.sh kernel "+ self.settings["netboot/kernel/sources"] + " " +\ + self.settings["netboot/kernel/config"]) + + except CatalystError: + self.unbind() + raise CatalystError,"netboot build aborting due to error." + + # Create image + myfiles=[] + if type(self.settings["netboot/packages"]) == types.StringType: + loopy=[self.settings["netboot/packages"]] + + else: + loopy=self.settings["netboot/packages"] + + for x in loopy: + print x, self.settings["netboot/packages/"+x+"/files"] + if type(self.settings["netboot/packages/"+x+"/files"]) == types.ListType: + myfiles.extend(self.settings["netboot/packages/"+x+"/files"]) + else: + myfiles.append(self.settings["netboot/packages/"+x+"/files"]) + + if type(self.settings["netboot/extra_files"]) == types.ListType: + myfiles.extend(self.settings["netboot/extra_files"]) + else: + myfiles.append(self.settings["netboot/extra_files"]) + + try: + cmd("/bin/bash "+self.settings["sharedir"]+\ + "/targets/netboot/netboot.sh image "+ self.settings["netboot/base_tarball"] + " " + list_bashify(myfiles)) + + except CatalystError: + self.unbind() + raise CatalystError,"netboot build aborting due to error." + + # Copying images in the target_path + try: + cmd("/bin/bash "+self.settings["sharedir"]+\ + "/targets/netboot/netboot.sh finish") + + except CatalystError: + self.unbind() + raise CatalystError,"netboot build aborting due to error." + + # End + print "netboot: build finished !" + + +def register(foo): + foo.update({"netboot":netboot_target}) + return foo diff --git a/targets/netboot/netboot-busybox.sh b/targets/netboot/netboot-busybox.sh new file mode 100644 index 00000000..381554c5 --- /dev/null +++ b/targets/netboot/netboot-busybox.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# Copyright 1999-2003 Gentoo Technologies, Inc. +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo/src/catalyst/targets/netboot/Attic/netboot-busybox.sh,v 1.1 2004/10/06 01:34:29 zhen Exp $ + +/usr/sbin/env-update +source /etc/profile + +[ -f /tmp/envscript ] && source /tmp/envscript + +if [ -n "${clst_DISTCC}" ] +then + export clst_myfeatures="${clst_myfeatures} distcc" + export DISTCC_HOSTS="${clst_distcc_hosts}" + + USE="-gnome -gtk" emerge --oneshot --nodeps -b -k distcc || exit 1 +fi + +## setup the environment +export FEATURES="${clst_myfeatures}" +export CONFIG_PROTECT="-*" + +## START BUILD +export USE_ORDER="env:conf:defaults" + +# Use the catalyst config +export USE="savedconfig make-busybox-symlinks" +mkdir -pv ${IMAGE_PATH} +ROOT=${IMAGE_PATH} emerge --nodeps ${clst_emergeopts} busybox || exit 1 + +# Remove portage's unneeded files +rm -R ${IMAGE_PATH}/etc +rm -R ${IMAGE_PATH}/tmp +rm -R ${IMAGE_PATH}/usr +rm -R ${IMAGE_PATH}/var diff --git a/targets/netboot/netboot-image.sh b/targets/netboot/netboot-image.sh new file mode 100644 index 00000000..e6544ef5 --- /dev/null +++ b/targets/netboot/netboot-image.sh @@ -0,0 +1,137 @@ +#!/bin/bash +# Copyright 1999-2003 Gentoo Technologies, Inc. +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo/src/catalyst/targets/netboot/netboot-image.sh,v 1.1 2004/10/06 01:34:29 zhen Exp $ + +/usr/sbin/env-update +source /etc/profile + +[ -f /tmp/envscript ] && source /tmp/envscript + +IMAGE_PATH=$1 +shift +TARBALL=$1 +shift + +if [ -z "${IMAGE_PATH}" ] +then + echo "IMAGE_PATH not specified !" + exit 1 +fi + +# Required directories +mkdir -vp ${IMAGE_PATH}/bin +mkdir -vp ${IMAGE_PATH}/dev +mkdir -vp ${IMAGE_PATH}/etc +mkdir -vp ${IMAGE_PATH}/mnt/gentoo +mkdir -vp ${IMAGE_PATH}/proc +mkdir -vp ${IMAGE_PATH}/var/log + +# Copy libs of a executable in the chroot +function copy_libs() { + + # Check if it's a dynamix exec + ldd ${1} > /dev/null 2>&1 || return + + for lib in `ldd ${1} | awk '{ print $3 }'` + do + if [ -e ${lib} ] + then + if [ ! -e ${IMAGE_PATH}/${lib} ] + then + copy_file ${lib} + [ -e "${IMAGE_PATH}/${lib}" ] && strip -R .comment -R .note ${IMAGE_PATH}/${lib} || echo "WARNING : Cannot strip lib ${IMAGE_PATH}/${lib} !" + fi + else + echo "WARNING : Some library was not found for ${lib} !" + fi + done + +} + +function copy_symlink() { + + STACK=${2} + [ "${STACK}" = "" ] && STACK=16 || STACK=$((${STACK} - 1 )) + + if [ ${STACK} -le 0 ] + then + echo "WARNING : ${TARGET} : too many levels of symbolic links !" + return + fi + + [ ! -e ${IMAGE_PATH}/`dirname ${1}` ] && mkdir -p ${IMAGE_PATH}/`dirname ${1}` + [ ! -e ${IMAGE_PATH}/${1} ] && cp -vfdp ${1} ${IMAGE_PATH}/${1} + + TARGET=`readlink -f ${1}` + if [ -h ${TARGET} ] + then + copy_symlink ${TARGET} ${STACK} + else + copy_file ${TARGET} + fi + +} + +function copy_file() { + + f="${1}" + + if [ ! -e "${f}" ] + then + echo "WARNING : File not found : ${f}" + continue + fi + + [ ! -e ${IMAGE_PATH}/`dirname ${f}` ] && mkdir -p ${IMAGE_PATH}/`dirname ${f}` + [ ! -e ${IMAGE_PATH}/${f} ] && cp -vfdp ${f} ${IMAGE_PATH}/${f} + if [ -x ${f} -a ! -h ${f} ] + then + copy_libs ${f} + strip -R .comment -R .note ${IMAGE_PATH}/${f} > /dev/null 2>&1 + elif [ -h ${f} ] + then + copy_symlink ${f} + fi +} + + +# Copy the files needed in the chroot + +copy_libs ${IMAGE_PATH}/bin/busybox + +FILES="${@}" +for f in ${FILES} +do + copy_file ${f} +done + + +# Copy the kernel modules + +[ ! -e ${IMAGE_PATH}/lib ] && mkdir -p ${IMAGE_PATH}/lib +cp -Rv /lib/modules ${IMAGE_PATH}/lib +#find ${IMAGE_PATH}/lib -name \*.o -o -name \*.ko | xargs strip -R .comment -R .note + +# Extract the base tarball + +tar xjvf ${TARBALL} -C ${IMAGE_PATH}/ + +# Unpack the kernel + +tar xjvf ${GK_BINARIES}/kernel.tar.bz2 -C / +mv -f /kernel-2.* /kernel + +# Create the ramdisk + +IMAGE_SIZE=`du -s ${IMAGE_PATH} | awk '{ print $1 }'` + +dd if=/dev/zero of=/ramdisk bs=1k count=$((IMAGE_SIZE + 500)) + +yes | mke2fs /ramdisk + +mkdir /ramdisk-loop +mount -o loop ramdisk ramdisk-loop +cp -R ${IMAGE_PATH}/* /ramdisk-loop +umount /ramdisk-loop +rmdir /ramdisk-loop diff --git a/targets/netboot/netboot-kernel.sh b/targets/netboot/netboot-kernel.sh new file mode 100644 index 00000000..0d90d8c7 --- /dev/null +++ b/targets/netboot/netboot-kernel.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# Copyright 1999-2003 Gentoo Technologies, Inc. +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo/src/catalyst/targets/netboot/Attic/netboot-kernel.sh,v 1.1 2004/10/06 01:34:29 zhen Exp $ + +/usr/sbin/env-update +source /etc/profile + +[ -f /tmp/envscript ] && source /tmp/envscript + +if [ -n "${clst_DISTCC}" ] +then + export clst_myfeatures="${clst_myfeatures} distcc" + export DISTCC_HOSTS="${clst_distcc_hosts}" + + USE="-gnome -gtk" emerge --oneshot --nodeps -b -k distcc || exit 1 +fi + +if [ -n "${clst_PKGCACHE}" ] +then + clst_emergeopts="--usepkg --buildpkg" +else + clst_emergeopts="" +fi + +KERNEL_SOURCES=$1 +shift + +## setup the environment +export FEATURES="${clst_myfeatures}" +export CONFIG_PROTECT="-*" + +## START BUILD +export USE_ORDER="env:conf:defaults" + +emerge ${clst_emergeopts} genkernel || exit 1 + +# Fix dumb genkernel bug (#64514) (remove this when genkernel 3.0.2g goes stable) +sed -e "/BUILD_INITRD/{s/&&/& (/ +s/$/ )/ }" -i /usr/share/genkernel/gen_package.sh + +USE="${@}" emerge ${KERNEL_SOURCES} || exit 1 + +mkdir -p ${GK_BINARIES} + +genkernel --kerneldir=/usr/src/linux --kernel-config=/var/tmp/kernel.config \ + --minkernpackage=${GK_BINARIES}/kernel.tar.bz2 \ + kernel || exit 1 diff --git a/targets/netboot/netboot-packages.sh b/targets/netboot/netboot-packages.sh new file mode 100644 index 00000000..7fa11f98 --- /dev/null +++ b/targets/netboot/netboot-packages.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# Copyright 1999-2003 Gentoo Technologies, Inc. +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo/src/catalyst/targets/netboot/Attic/netboot-packages.sh,v 1.1 2004/10/06 01:34:29 zhen Exp $ + +/usr/sbin/env-update +source /etc/profile + +[ -f /tmp/envscript ] && source /tmp/envscript + +if [ -n "${clst_CCACHE}" ] +then + export clst_myfeatures="${clst_myfeatures} ccache" + emerge --oneshot --nodeps -b -k ccache || exit 1 +fi + +if [ -n "${clst_DISTCC}" ] +then + export clst_myfeatures="${clst_myfeatures} distcc" + export DISTCC_HOSTS="${clst_distcc_hosts}" + + USE="-gnome -gtk" emerge --oneshot --nodeps -b -k distcc || exit 1 +fi + +if [ -n "${clst_PKGCACHE}" ] +then + clst_emergeopts="--usepkg --buildpkg" +else + clst_emergeopts="" +fi + +## setup the environment +export FEATURES="${clst_myfeatures}" +export CONFIG_PROTECT="-*" + +## START BUILD +USE="build" emerge portage +#turn off auto-use: +export USE_ORDER="env:conf:defaults" + +if [ "${clst_VERBOSE}" ] +then + emerge ${clst_emergeopts} -vp ${clst_packages} + sleep 15 +fi + +emerge ${clst_emergeopts} ${clst_packages} diff --git a/targets/netboot/netboot.sh b/targets/netboot/netboot.sh new file mode 100644 index 00000000..ad91b1b2 --- /dev/null +++ b/targets/netboot/netboot.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# Copyright 1999-2003 Gentoo Technologies, Inc. +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo/src/catalyst/targets/netboot/Attic/netboot.sh,v 1.1 2004/10/06 01:34:29 zhen Exp $ + +export GK_BINARIES=/usr/portage/packages/gk_binaries +export IMAGE_PATH=/image + +# Force usage of -Os for smaller size +export CFLAGS="-Os -pipe" +export CXXFLAGS="-Os -pipe" + +case $1 in + enter) + ${clst_CHROOT} ${clst_chroot_path} + ;; + packages) + shift + + cp ${clst_sharedir}/targets/netboot/netboot-packages.sh ${clst_chroot_path}/tmp + clst_packages="$*" ${clst_CHROOT} ${clst_chroot_path} /tmp/netboot-packages.sh || exit 1 + rm -f ${clst_chroot_path}/tmp/netboot-packages.sh + ;; + busybox) + shift + + cp ${clst_sharedir}/targets/netboot/netboot-busybox.sh ${clst_chroot_path}/tmp + mkdir -p ${clst_chroot_path}/etc/busybox/${clst_CHOST}/ + # Seems busybox doesn't have a CCHOST set when emerging + CCHOST= + cp ${1} ${clst_chroot_path}/etc/busybox/${CCHOST}/busybox.config + ${clst_CHROOT} ${clst_chroot_path} /tmp/netboot-busybox.sh || exit 1 + rm -f ${clst_chroot_path}/tmp/netboot-busybox.sh + ;; + + kernel) + shift + SOURCES=${1} + shift + CONFIG=${1} + shift + + cp ${clst_sharedir}/targets/netboot/netboot-kernel.sh ${clst_chroot_path}/tmp + cp ${CONFIG} ${clst_chroot_path}/var/tmp/kernel.config + ${clst_CHROOT} ${clst_chroot_path} /tmp/netboot-kernel.sh ${SOURCES} ${clst_netboot_kernel_use} || exit 1 + rm -f ${clst_chroot_path}/tmp/netboot-kernel.sh + ;; + + image) + shift + TARBALL=${1} + shift + + cp ${clst_sharedir}/targets/netboot/netboot-image.sh ${clst_chroot_path}/tmp + cp ${TARBALL} ${clst_chroot_path}/netboot-base.tar.bz2 + ${clst_CHROOT} ${clst_chroot_path} /tmp/netboot-image.sh ${IMAGE_PATH} /netboot-base.tar.bz2 ${@} || exit 1 + rm -f ${clst_chroot_path}/tmp/netboot-image.sh + exit 0 + + ;; + finish) + [ ! -e ${clst_target_path} ] && mkdir -p ${clst_target_path} + cp ${clst_chroot_path}/ramdisk ${clst_chroot_path}/kernel ${clst_target_path} + strip ${clst_target_path}/kernel > /dev/null 2>&1 + gzip -9f ${clst_target_path}/ramdisk + exit 0 + ;; + + clean) + exit 0 + ;; + + *) + exit 1 + ;; + +esac +exit 0 -- 2.26.2