Integrate netboot package generation
authorMichael Prokop <mika@grml.org>
Fri, 9 Dec 2011 16:56:48 +0000 (17:56 +0100)
committerMichael Prokop <mika@grml.org>
Fri, 9 Dec 2011 22:14:11 +0000 (23:14 +0100)
Provide script to generate netboot package without booting the ISO
(see generate_netboot_package.sh).

Also provide netboot package build step inside grml-live itself,
can be configured via $NETBOOT and skipped via -Q option.

Signed-off-by: Michael Prokop <mika@grml.org>
Acked-by: Christian Hofstaedtler <ch@grml.org>
docs/grml-live.txt
etc/grml/grml-live.conf
grml-live
scripts/generate_netboot_package.sh [new file with mode: 0755]
templates/boot/isolinux/netboot.cfg [new file with mode: 0644]

index debc706..a430a12 100644 (file)
@@ -191,6 +191,10 @@ Build the ISO without (re-)creating the squashfs compressed file using mksquashf
 This option is useful if you just want to update parts outside the chroot in the ISO.
 Consider combining this option with the build-only option '-b'.
 
+  -Q::
+
+Build the ISO without generating a netboot package.
+
   -r **RELEASENAME**::
 
 Specify name of the release.
index a5d0e50..3923936 100644 (file)
@@ -23,6 +23,8 @@
 # BUILD_OUTPUT="$OUTPUT/grml_cd"
 # Where do you want to find the final ISO?
 # ISO_OUTPUT="$OUTPUT/grml_isos"
+# Where do you want to find the netboot package?
+# NETBOOT="${OUTPUT}/netboot/"
 
 # Do you want to preserve the logfile from being cleaned after each execution
 # of grml-live? By default the logfile is cleaned so the log doesn't fill up.
index 83ef125..e43ae7e 100755 (executable)
--- a/grml-live
+++ b/grml-live
@@ -56,6 +56,7 @@ Usage: $PN [options, see as follows]
    -N                      bootstrap (build chroot) only, do not create files for ISO
    -o <output_directory>   main output directory of the build process
    -q                      skip mksquashfs
+   -Q                      skip netboot package build
    -r <release_name>       release name
    -s <suite>              Debian suite; values: etch, lenny, squeeze, sid
    -t <template_directory> place of the templates
@@ -183,6 +184,7 @@ bailout() {
     [ -n "${CHROOT_OUTPUT}"  -a -d "${CHROOT_OUTPUT}"  ] && chown -R "${CHOWN_USER}:" "${CHROOT_OUTPUT}"
     [ -n "${ISO_OUTPUT}"     -a -d "${ISO_OUTPUT}"     ] && chown -R "${CHOWN_USER}:" "${ISO_OUTPUT}"
     [ -n "${LOG_OUTPUT}"     -a -d "${LOG_OUTPUT}"     ] && chown -R "${CHOWN_USER}:" "${LOG_OUTPUT}"
+    [ -n "${NETBOOT}"        -a -d "${NETBOOT}"        ] && chown -R "${CHOWN_USER}:" "${NETBOOT}"
     [ -n "${CHROOT_ARCHIVE}" -a -f "${CHROOT_ARCHIVE}" ] && chown -R "${CHOWN_USER}:" "${CHROOT_ARCHIVE}"
     eend 0
   fi
@@ -284,7 +286,7 @@ copy_addon_file() {
 # }}}
 
 # command line parsing {{{
-while getopts "a:C:c:d:D:g:i:I:o:r:s:t:T:U:v:AbBFnNquVz" opt; do
+while getopts "a:C:c:d:D:g:i:I:o:r:s:t:T:U:v:AbBFnNqQuVz" opt; do
   case "$opt" in
     a) ARCH="$OPTARG" ;;
     A) PACK_ARTIFACTS=1 ;;
@@ -301,6 +303,7 @@ while getopts "a:C:c:d:D:g:i:I:o:r:s:t:T:U:v:AbBFnNquVz" opt; do
     N) BOOTSTRAP_ONLY=1; SKIP_MKISOFS=1; SKIP_MKSQUASHFS=1 ;;
     o) OUTPUT="$OPTARG" ;;
     q) SKIP_MKSQUASHFS=1 ;;
+    Q) SKIP_NETBOOT=1 ;;
     r) RELEASENAME="$OPTARG" ;;
     s) SUITE="$OPTARG" ;;
     t) TEMPLATE_DIRECTORY="$OPTARG";;
@@ -371,6 +374,7 @@ fi
 [ -n "$ISO_OUTPUT" ]       || ISO_OUTPUT="$OUTPUT/grml_isos"
 [ -n "$LOG_OUTPUT" ]       || LOG_OUTPUT="$OUTPUT/grml_logs"
 [ -n "$REPORTS" ]          || REPORTS="${LOG_OUTPUT}/reports/"
+[ -n "$NETBOOT" ]          || NETBOOT="${OUTPUT}/netboot/"
 # }}}
 
 # some misc checks before executing FAI {{{
@@ -436,6 +440,7 @@ if [ -z "$FORCE" ] ; then
      echo "  Bootstrapping only and not building (files for) ISO."
    else
      [ -n "$SKIP_MKSQUASHFS" ]     && echo "  Skipping creation of SQUASHFS file."
+     [ -n "$SKIP_NETBOOT" ]        && echo "  Skipping creation of NETBOOT package."
      [ -n "$SKIP_MKISOFS" ]        && echo "  Skipping creation of ISO file."
      [ -n "$BUILD_ONLY" ]          && echo "  Executing BUILD_ONLY instead of fresh installation or UPDATE."
      [ -n "$BUILD_DIRTY" ]         && echo "  Executing BUILD_DIRTY to leave chroot untouched."
@@ -457,6 +462,7 @@ if [ -n "${PACK_ARTIFACTS}" ]; then
   [ -n "${BUILD_OUTPUT}"   -a -d "${BUILD_OUTPUT}"   ] && rm -r "${BUILD_OUTPUT}"
   [ -n "${ISO_OUTPUT}"     -a -d "${ISO_OUTPUT}"     ] && rm -r "${ISO_OUTPUT}"
   [ -n "${LOG_OUTPUT}"     -a -d "${LOG_OUTPUT}"     ] && rm -r "${LOG_OUTPUT}"
+  [ -n "${NETBOOT}"        -a -d "${NETBOOT}"        ] && rm -r "${NETBOOT}"
 fi
 # }}}
 
@@ -1339,6 +1345,61 @@ else
 fi
 # }}}
 
+# netboot package {{{
+create_netbootpackage() {
+  local OUTPUT_FILE="${NETBOOT}/grml_netboot_package_${GRML_NAME}_${VERSION}.tar.bz2"
+
+  if [ -f "${OUTPUT_FILE}" -a -z "$UPDATE" -a -z "$BUILD_ONLY" -a -z "$BUILD_DIRTY" ] ; then
+    log   "Skipping stage 'netboot' as $OUTPUT_FILE exists already."
+    ewarn "Skipping stage 'netboot' as $OUTPUT_FILE exists already." ; eend 0
+    return 0
+  elif [ -n "$SKIP_NETBOOT" ] ; then
+    log   "Skipping stage 'netboot' as requested via option -Q"
+    ewarn "Skipping stage 'netboot' as requested via option -Q" ; eend 0
+    return 0
+  fi
+
+  mkdir -p "$NETBOOT"
+
+  if ! [ -r "${CHROOT}/usr/lib/syslinux/pxelinux.0" ] ; then
+    ewarn "File /usr/lib/syslinux/pxelinux.0 not found in build chroot." ; eend 0
+    eindent
+    einfo "Install syslinux[-common] package in chroot to get a netboot package."
+    eoutdent
+    return 0
+  fi
+
+  local OUTPUTDIR="${NETBOOT}/build_tmp"
+  local WORKING_DIR="${OUTPUTDIR}/grml_netboot_package_${GRML_NAME}_${VERSION}/tftpboot/"
+
+  mkdir -p "$WORKING_DIR"
+
+  cp "${CHROOT_OUTPUT}"/boot/vmlinuz-*    "$WORKING_DIR"/linux26
+  cp "${CHROOT_OUTPUT}"/boot/initrd.img-* "$WORKING_DIR"/initrd.img
+  cp "${CHROOT_OUTPUT}"/usr/lib/syslinux/pxelinux.0 "${WORKING_DIR}/pxelinux.0"
+
+  if [ -r "${BUILD_OUTPUT}/boot/isolinux/netboot.cfg" ] ; then
+    mkdir -p "${WORKING_DIR}/pxelinux.cfg/default"
+    cp "${BUILD_OUTPUT}/boot/isolinux/netboot.cfg" "${WORKING_DIR}/pxelinux.cfg/default"
+  else
+    ewarn "File ${BUILD_OUTPUT}/boot/isolinux/netboot.cfg not found." ; eend 0
+  fi
+
+  mkdir -p "${WORKING_DIR}/pxelinux.cfg"
+
+  if tar -C "$OUTPUTDIR" -jcf "${OUTPUT_FILE}" "grml_netboot_package_${GRML_NAME}_${VERSION}" ; then
+    einfo "Generated netboot package ${OUTPUT_FILE}" ; eend 0
+    rm -rf "${OUTPUTDIR}"
+  else
+    rm -rf "${OUTPUTDIR}"
+    eerror "Could not generate netboot package ${OUTPUT_FILE}" ; eend 1
+    bailout 21
+  fi
+}
+
+create_netbootpackage
+# }}}
+
 # pack artifacts {{{
 if [ -n "$PACK_ARTIFACTS" ]; then
   log "Packing artifcats"
diff --git a/scripts/generate_netboot_package.sh b/scripts/generate_netboot_package.sh
new file mode 100755 (executable)
index 0000000..5eae60a
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/bash
+################################################################################
+# Purpose: hackish script to generate netboot package without booting the system
+################################################################################
+
+if [ $# -lt 2 ] ; then
+  echo "Usage: $0 <chroot> <output_file>" >&2
+  exit 1
+fi
+
+set -u
+set -e
+
+CHROOT="${1}"
+OUTPUT_FILE="${2}"
+
+if ! [ -f "${CHROOT}/etc/grml_version" ] ; then
+  echo "Error: could not read ${CHROOT}/etc/grml_version" >&2
+  exit 1
+fi
+
+GRML_VERSION="$(awk '{print $1"_"$2}' ${CHROOT}/etc/grml_version)"
+
+if ! [ -r "${CHROOT}/usr/lib/syslinux/pxelinux.0" ] ; then
+  echo "Error: /usr/lib/syslinux/pxelinux.0 not found. Please install syslinux[-common." >&2
+  exit 1
+fi
+
+OUTPUTDIR="$(mktemp -d)" || exit 1
+WORKING_DIR="${OUTPUTDIR}/grml_netboot_package_${GRML_VERSION}/tftpboot/"
+mkdir -p "$WORKING_DIR" || exit 2
+
+cp "$CHROOT"/boot/vmlinuz-*    "$WORKING_DIR"/linux26
+cp "$CHROOT"/boot/initrd.img-* "$WORKING_DIR"/initrd.img
+cp "$CHROOT"/usr/lib/syslinux/pxelinux.0 "${WORKING_DIR}/pxelinux.0"
+
+mkdir -p "${WORKING_DIR}/pxelinux.cfg"
+cat > "${WORKING_DIR}/pxelinux.cfg/default" << EOF
+default grml
+label grml
+  kernel linux26
+  append initrd=initrd.img root=/dev/nfs rw nfsroot=192.168.0.1:/live/image boot=live apm=power-off quiet nomce noprompt noeject vga=791 
+EOF
+
+if tar -C "$OUTPUTDIR" -acf "${OUTPUT_FILE}" "grml_netboot_package_${GRML_VERSION}" ; then
+  rm -rf "${OUTPUTDIR}"
+  echo "Generated ${OUTPUT_FILE}"
+fi
+
+## END OF FILE #################################################################
diff --git a/templates/boot/isolinux/netboot.cfg b/templates/boot/isolinux/netboot.cfg
new file mode 100644 (file)
index 0000000..ecfb0b5
--- /dev/null
@@ -0,0 +1,15 @@
+default grml
+label grml
+  menu DEFAULT
+  menu label %GRML_NAME% ^Standard (%VERSION%, %ARCH%)
+  kernel linux26
+  append initrd=initrd.img root=/dev/nfs rw nfsroot=192.168.0.1:/live/image boot=live bootid=%BOOTID% apm=power-off quiet nomce noprompt noeject vga=791 
+
+  text help
+                                        Grml is a Debian based Linux live
+                                        system for system administrators
+                                        and users of text tools.
+
+                                                         http://grml.org/
+  endtext
+