From 447d4cb4b661f93c91eff4fa1600de412c14ab54 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Mon, 26 Nov 2007 03:39:25 +0000 Subject: [PATCH] Use mtools to build USB images, no more loop-mounts here, woohoo! Add an option to specify which image(s) to build. Some cleanup. --- bootcd.spec | 2 +- build.sh | 559 +++++++++++++++++++++++++--------------------------- 2 files changed, 271 insertions(+), 290 deletions(-) diff --git a/bootcd.spec b/bootcd.spec index 78d2cbb..05279bb 100644 --- a/bootcd.spec +++ b/bootcd.spec @@ -16,7 +16,7 @@ Group: System Environment/Base Source0: %{name}-%{version}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root -Requires: dosfstools, mkisofs, gzip +Requires: dosfstools, mkisofs, gzip, mtools AutoReqProv: no %define debug_package %{nil} diff --git a/build.sh b/build.sh index a85a41e..faf52e7 100755 --- a/build.sh +++ b/build.sh @@ -8,7 +8,7 @@ # # Aaron Klingaman # Mark Huang -# Copyright (C) 2004-2006 The Trustees of Princeton University +# Copyright (C) 2004-2007 The Trustees of Princeton University # # $Id$ # @@ -17,35 +17,46 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin CONFIGURATION=default NODE_CONFIGURATION_FILE= -ALL=0 +TYPES="usb iso usb_serial iso_serial" # Leave 4 MB of free space FREE_SPACE=4096 +CUSTOM_DIR= +OUTPUT_BASE= +MKISOFS_OPTS="-R -J -r -f -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table" usage() { echo "Usage: build.sh [OPTION]..." - echo " -c name (Deprecated) Static configuration to use (default: $CONFIGURATION)" - echo " -f planet.cnf Node to customize CD for (default: none)" - echo " -a Build all images (default: only base images)" - echo " -h This message" + echo " -c name (Deprecated) Static configuration to use (default: $CONFIGURATION)" + echo " -f planet.cnf Node to customize CD for (default: none)" + echo " -t 'types' Build the specified images (default: $TYPES)" + echo " -C custom-dir Custom directory" + echo " -O output-base The basename of the generated files (default: PLC_NAME-BootCD-VERSION)" + echo " -h This message" exit 1 } # Get options -while getopts "c:f:ah" opt ; do +while getopts "O:c:f:t:C:h" opt ; do case $opt in - c) - CONFIGURATION=$OPTARG - ;; - f) - NODE_CONFIGURATION_FILE=$OPTARG - ;; - a) - ALL=1 - ;; - h|*) - usage - ;; + c) + CONFIGURATION=$OPTARG + ;; + f) + NODE_CONFIGURATION_FILE=$OPTARG + ;; + t) + TYPES="$OPTARG" + ;; + C) + CUSTOM_DIR="$OPTARG" + ;; + O) + OUTPUT_BASE="$OPTARG" + ;; + h|*) + usage + ;; esac done @@ -63,7 +74,7 @@ isofs=$PWD/build/isofs # we disable the initial logic that called prep.sh if that was not the case # this is because prep.sh needs to know pldistro if [ ! -f $isofs/bootcd.img -o ! -f build/version.txt ] ; then - echo "you have to run prep.sh prior to calling $0 - exiting" + echo "You have to run prep.sh prior to calling $0 - exiting" exit 1 fi @@ -92,7 +103,7 @@ if [ -z "$PLC_BOOT_CA_SSL_CRT" -a -d configurations/$CONFIGURATION ] ; then PLC_WWW_HOST="www.planet-lab.org" PLC_WWW_PORT=80 if [ -n "$EXTRA_VERSION" ] ; then - BOOTCD_VERSION="$BOOTCD_VERSION $EXTRA_VERSION" + BOOTCD_VERSION="$BOOTCD_VERSION $EXTRA_VERSION" fi PLC_BOOT_HOST=$PRIMARY_SERVER PLC_BOOT_SSL_PORT=$PRIMARY_SERVER_PORT @@ -111,18 +122,45 @@ echo "* Building images for $FULL_VERSION_STRING" # is available. BUILDTMP=/usr/tmp if [ -d /data ] ; then - isreadonly=$(mktemp /data/isreadonly.XXXXXX || /bin/true) - if [ -n "$isreadonly" ] ; then - rm -f "$isreadonly" - BUILDTMP=/data - fi + isreadonly=$(mktemp /data/isreadonly.XXXXXX || /bin/true) + if [ -n "$isreadonly" ] ; then + rm -f "$isreadonly" + BUILDTMP=/data + fi fi +declare -a _CLEANUPS=() +function do_cleanup() +{ + cd / + for i in "${_CLEANUPS[@]}"; do + $i + done +} +function push_cleanup() +{ + _CLEANUPS=( "${_CLEANUPS[@]}" "$*" ) +} +function pop_cleanup() +{ + unset _CLEANUPS[$((${#_CLEANUPS[@]} - 1))] +} + +trap "do_cleanup" ERR INT EXIT + +BUILDTMP=$(mktemp -d ${BUILDTMP}/bootcd.XXXXXX) +push_cleanup rm -fr "${BUILDTMP}" +mkdir "${BUILDTMP}/isofs" +for i in "$isofs"/{bootcd.img,kernel,isolinux.bin}; do + ln -s "$i" "${BUILDTMP}/isofs" +done +isofs="${BUILDTMP}/isofs" + # Root of the ISO and USB images echo "* Populating root filesystem..." -overlay=$(mktemp -d ${BUILDTMP}/overlay.XXXXXX) +overlay="${BUILDTMP}/overlay" install -d -m 755 $overlay -trap "rm -rf $overlay" ERR INT +push_cleanup rm -fr $overlay # Create version files echo "* Creating version files" @@ -142,11 +180,11 @@ echo "* Installing boot server configuration files" # but never got around to it. Just install the same parameters for # both for now. for dir in $overlay/usr/boot $overlay/usr/boot/backup ; do - install -D -m 644 $PLC_BOOT_CA_SSL_CRT $dir/cacert.pem - install -D -m 644 $PLC_ROOT_GPG_KEY_PUB $dir/pubring.gpg - echo "$PLC_BOOT_HOST" >$dir/boot_server - echo "$PLC_BOOT_SSL_PORT" >$dir/boot_server_port - echo "/boot/" >$dir/boot_server_path + install -D -m 644 $PLC_BOOT_CA_SSL_CRT $dir/cacert.pem + install -D -m 644 $PLC_ROOT_GPG_KEY_PUB $dir/pubring.gpg + echo "$PLC_BOOT_HOST" >$dir/boot_server + echo "$PLC_BOOT_SSL_PORT" >$dir/boot_server_port + echo "/boot/" >$dir/boot_server_path done # (Deprecated) Install old-style boot server configuration files @@ -214,192 +252,161 @@ echo "* Compressing overlay image" (cd $overlay && find . | cpio --quiet -c -o) | gzip -9 >$isofs/overlay.img rm -rf $overlay -trap - ERR INT +pop_cleanup + +if [ -n "$CUSTOM_DIR" ]; then + echo "* Compressing custom image" + (cd "$CUSTOM_DIR" && find . | cpio --quiet -c -o) | gzip -9 >$isofs/custom.img +fi # Calculate ramdisk size (total uncompressed size of both archives) -ramdisk_size=$(gzip -l $isofs/bootcd.img $isofs/overlay.img | tail -1 | awk '{ print $2; }') # bytes +ramdisk_size=$(gzip -l $isofs/bootcd.img $isofs/overlay.img ${CUSTOM_DIR:+$isofs/custom.img} | tail -1 | awk '{ print $2; }') # bytes ramdisk_size=$((($ramdisk_size + 1023) / 1024)) # kilobytes -# Write isolinux configuration echo "$FULL_VERSION_STRING" >$isofs/pl_version -cat >$isofs/isolinux.cfg <$isofs/isolinux.cfg <$tmp/syslinux.cfg <$isofs/isolinux.cfg <$tmp/syslinux.cfg <$tmp </dev/null || : + mcopy -i "$usb" "$tmp" ::/syslinux.cfg + rm -f "$tmp" -umount $tmp -rmdir $tmp -trap - ERR INT - -echo "making USB image with serial line support bootable." -$srcdir/syslinux/unix/syslinux "$usb" + echo "making USB image bootable." + $srcdir/syslinux/unix/syslinux "$usb" +} -[ $ALL -eq 0 ] && exit 0 # Setup CRAMFS related support -echo "* Setting up CRAMFS-based images" -tmp=$(mktemp -d ${BUILDTMP}/bootcd.XXXXXX) -cramfs=$(mktemp ${BUILDTMP}/cramfs.XXXXXX) -trap "$tmp; rm -rf $tmp $cramfs" ERR INT -pushd $tmp -gzip -d -c $isofs/bootcd.img | cpio -diu -gzip -d -c $isofs/overlay.img | cpio -diu - -# clean out unnecessary rpm lib -echo "* clearing var/lib/rpm/*" -rm -f var/lib/rpm/* - -# bootcd requires this directory -mkdir -p mnt/confdevice - -# relocate various directory to /tmp -rm -rf root -ln -fs /tmp/root root -ln -fs /sbin/init linuxrc -ln -fs /tmp/resolv.conf etc/resolv.conf -ln -fs /tmp/etc/mtab etc/mtab - -# have pl_rsysinit copy over appropriate etc & var directories into /tmp/etc/ -# make /tmp/etc -echo "* renaming dirs in ./etc" -pushd etc -for dir in `find * -type d -prune | grep -v rc.d`; do mv ${dir} ${dir}_o; ln -fs /tmp/etc/${dir} ${dir} ; done -popd - -echo "* renaming dirs in ./var" -# rename all top-level directories and put in a symlink to /tmp/var -pushd var -for dir in `find * -type d -prune`; do mv ${dir} ${dir}_o; ln -fs /tmp/var/${dir} ${dir} ; done -popd - -#overwrite fstab to mount / as cramfs and /tmp as tmpfs -echo "* Overwriting etc/fstab to use cramfs and tmpfs" -rm -f ./etc/fstab -cat >./etc/fstab <./etc/fstab <> etc/inittab -# and let root log in -echo "ttyS0" >> etc/securetty + # modify inittab to have a serial console + echo "T0:23:respawn:/sbin/agetty -L ttyS0 9600 vt100" >> etc/inittab + # and let root log in + echo "ttyS0" >> etc/securetty -#calculate the size of /tmp based on the size of /etc & /var + 8MB slack -etcsize=$(du -s ./etc | awk '{ print $1 }') -varsize=$(du -s ./var | awk '{ print $1 }') -let msize=($varsize+$etcsize+8192)/1024 + # calculate the size of /tmp based on the size of /etc & /var + 8MB slack + etcsize=$(du -s ./etc | awk '{ print $1 }') + varsize=$(du -s ./var | awk '{ print $1 }') + let msize=($varsize+$etcsize+8192)/1024 -# generate pl_rsysinit -cat > etc/rc.d/init.d/pl_rsysinit < etc/rc.d/init.d/pl_rsysinit <$tmp/isolinux.cfg <$tmp/isolinux.cfg <$tmp/isolinux.cfg <$tmp/syslinux.cfg <$tmp <$tmp/syslinux.cfg <