This commit was manufactured by cvs2svn to create branch
authorPlanet-Lab Support <support@planet-lab.org>
Tue, 21 Mar 2006 14:57:32 +0000 (14:57 +0000)
committerPlanet-Lab Support <support@planet-lab.org>
Tue, 21 Mar 2006 14:57:32 +0000 (14:57 +0000)
'planetlab-3_3-branch'.

bootcd.spec
build.sh
cdcustom.sh [new file with mode: 0755]
conf_files/pl_sysinit

index 45c4f84..c14816e 100644 (file)
@@ -1,6 +1,6 @@
 %define name bootcd
-%define version 3.2
-%define release 1.planetlab%{?date:.%{date}}
+%define version 3.3
+%define release 1%{?pldistro:.%{pldistro}}%{?date:.%{date}}
 # XXX Get this from /etc/planetlab
 %define configuration default
 
@@ -34,20 +34,29 @@ environment.
 %install
 install -d $RPM_BUILD_ROOT/var/www/html/download
 pushd build/%{configuration}
+rm -f $RPM_BUILD_ROOT/var/www/html/download/PlanetLab-BootCD-%{version}.md5
 bzip2 -c PlanetLab-BootCD-%{version}.iso > \
     $RPM_BUILD_ROOT/var/www/html/download/PlanetLab-BootCD-%{version}.iso.bz2
+md5sum $RPM_BUILD_ROOT/var/www/html/download/PlanetLab-BootCD-%{version}.iso.bz2 >> \
+       $RPM_BUILD_ROOT/var/www/html/download/PlanetLab-BootCD-%{version}.md5
+
 bzip2 -c PlanetLab-BootCD-%{version}.usb > \
     $RPM_BUILD_ROOT/var/www/html/download/PlanetLab-BootCD-%{version}.usb.bz2
-md5sum PlanetLab-BootCD-%{version}.{iso,usb} >> \
-    $RPM_BUILD_ROOT/var/www/html/download/PlanetLab-BootCD-%{version}.md5
-cd $RPM_BUILD_ROOT/var/www/html/download/
-md5sum PlanetLab-BootCD-%{version}.{iso,usb}.bz2 >> \
-    PlanetLab-BootCD-%{version}.md5
+md5sum $RPM_BUILD_ROOT/var/www/html/download/PlanetLab-BootCD-%{version}.usb.bz2 >> \
+       $RPM_BUILD_ROOT/var/www/html/download/PlanetLab-BootCD-%{version}.md5
+
+bzip2 -c PlanetLab-BootCD-%{version}-biginitrd.usb > \
+    $RPM_BUILD_ROOT/var/www/html/download/PlanetLab-BootCD-%{version}-biginitrd.usb.bz2
+md5sum $RPM_BUILD_ROOT/var/www/html/download/PlanetLab-BootCD-%{version}-biginitrd.usb.bz2 >> \
+       $RPM_BUILD_ROOT/var/www/html/download/PlanetLab-BootCD-%{version}.md5
 popd
     
 # If run under sudo, allow user to delete the build directory
 if [ -n "$SUDO_USER" ] ; then
     chown -R $SUDO_USER .
+    # Some temporary cdroot files like /var/empty/sshd and
+    # /usr/bin/sudo get created with non-readable permissions.
+    find . -not -perm +0600 -exec chmod u+rw {} \;
 fi
 
 %clean
@@ -69,9 +78,13 @@ EOF
 %defattr(-,root,root,-)
 /var/www/html/download/PlanetLab-BootCD-%{version}.iso.bz2
 /var/www/html/download/PlanetLab-BootCD-%{version}.usb.bz2
+/var/www/html/download/PlanetLab-BootCD-%{version}-biginitrd.usb.bz2
 /var/www/html/download/PlanetLab-BootCD-%{version}.md5
 
 %changelog
+* Mon Jan 29 2006 Marc E. Fiuczynski <mef@cs.princeton.edu> - 
+- added biginitrd usb image
+
 * Fri Sep  2 2005 Mark Huang <mlhuang@cotton.CS.Princeton.EDU> - 
 - Initial build.
 
index a51797c..472cd13 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -8,7 +8,7 @@ CONFIGURATIONS_DIR=configurations/
 # where built files are stored
 BUILD_DIR=build/
 
-BOOTCD_VERSION="3.2"
+BOOTCD_VERSION="3.3"
 FULL_VERSION_STRING="PlanetLab BootCD"
 OUTPUT_IMAGE_NAME='PlanetLab-BootCD'
     
@@ -110,6 +110,13 @@ EOF
    # the yum configuration. This cooperates with the PlanetLab build
    # system.
    if [ -n "$RPM_BUILD_DIR" ] ; then
+       yum-arch $(dirname $RPM_BUILD_DIR)/RPMS
+       createrepo $(dirname $RPM_BUILD_DIR)/RPMS || :
+       # If run under sudo, allow user to delete the headers/ and
+       # repodata/ directories.
+       if [ -n "$SUDO_USER" ] ; then
+          chown -R $SUDO_USER $(dirname $RPM_BUILD_DIR)/RPMS
+       fi
        cat >>yum.conf <<EOF
 [Bootstrap]
 name=Bootstrap RPMS -- $(dirname $RPM_BUILD_DIR)/RPMS/
@@ -188,11 +195,9 @@ EOF
     touch $CD_ROOT/.built
 }
 
-function build_initrd()
+function init_initrd()
 {
-    echo "building initrd"
-    rm -f $INITRD
-    rm -f $INITRD.gz
+    echo "initialize configuration files"
 
     echo "copy fstab and mtab"
     cp -f $CONF_FILES_DIR/fstab $CD_ROOT/etc/
@@ -252,7 +257,6 @@ function build_initrd()
     cp -f $CONF_FILES_DIR/lvm.conf $CD_ROOT/etc/lvm/
 
     echo "copying isolinux configuration files"
-    cp -f $CONF_FILES_DIR/isolinux.cfg $CD_ROOT/usr/isolinux/
     echo "$FULL_VERSION_STRING" > $CD_ROOT/usr/isolinux/message.txt
 
     echo "writing /etc/issue"
@@ -267,11 +271,6 @@ function build_initrd()
            $CD_ROOT/usr/boot/plnode.txt
     fi
 
-    echo "making the isolinux initrd kernel command line match rd size"
-    let INITRD_SIZE_KB=$(($RAMDISK_SIZE * 1024))
-    sed -i "s#ramdisk_size=0#ramdisk_size=$INITRD_SIZE_KB#g" \
-       $CD_ROOT/usr/isolinux/isolinux.cfg
-
     echo "building pcitable for hardware detection"
     pci_map_file=`find $CD_ROOT/lib/modules/ -name modules.pcimap | head -1`
     module_dep_file=`find $CD_ROOT/lib/modules/ -name modules.dep | head -1`
@@ -279,7 +278,33 @@ function build_initrd()
     $BOOTMANAGER_DIR/source/merge_hw_tables.py \
        $module_dep_file $pci_map_file $pci_table $CD_ROOT/etc/pl_pcitable
 
-    dd if=/dev/zero of=$INITRD bs=1M count=$RAMDISK_SIZE
+}
+
+function build_initrd()
+{
+    big=$1
+
+    echo "building initrd"
+    rm -f $INITRD
+    rm -f $INITRD.gz
+    rm -f $CD_ROOT/usr/isolinux/initrd
+    rm -f $CD_ROOT/usr/isolinux/initrd.gz
+
+    TOTAL_SIZE=$(du -ksc $CD_ROOT | awk '$2 == "total" { print $1}')
+    if [ $big -eq 1 ]; then
+       let TOTAL_SIZE=$TOTAL_SIZE-$(du -ksc $CD_ROOT/usr/isolinux | awk '$2 == "total" { print $1}')
+    else
+       let TOTAL_SIZE=$TOTAL_SIZE-$(du -ksc $CD_ROOT/usr | awk '$2 == "total" { print $1}')
+    fi
+    let INITRD_SIZE=($TOTAL_SIZE/1024)+$RAMDISK_SIZE+4
+
+    echo "making the isolinux initrd kernel command line match rd size"
+    let INITRD_SIZE_KB=$(($INITRD_SIZE * 1024))
+    cp -f $CONF_FILES_DIR/isolinux.cfg $CD_ROOT/usr/isolinux/
+    sed -i "s#ramdisk_size=0#ramdisk_size=$INITRD_SIZE_KB#g" \
+       $CD_ROOT/usr/isolinux/isolinux.cfg
+
+    dd if=/dev/zero of=$INITRD bs=1M count=$INITRD_SIZE
     /sbin/mkfs.ext2 -F -m 0 -i $INITRD_BYTES_PER_INODE $INITRD
     mkdir -p $INITRD_MOUNT
     mount -o loop,rw $INITRD $INITRD_MOUNT
@@ -290,11 +315,22 @@ function build_initrd()
     find . -path ./usr -prune -o -print | cpio -p -d -u $INITRD_MOUNT
     popd
 
+    if [ $big -eq 1 ]; then
+       echo "copy usr to ramdisk"
+       pushd .
+       cd $CD_ROOT
+       find ./usr -path ./usr/isolinux -o -print | cpio -p -d -u $INITRD_MOUNT
+       popd
+    fi
+
     umount $INITRD_MOUNT
     rmdir $INITRD_MOUNT
     
+    # INITRD_SIZE=$(`ls -sh $INITRD | awk '{print $1}'`)
+    # echo "initrd size = $INITRD_SIZE"
     echo "compressing ramdisk"
-    gzip $INITRD
+    gzip -9 $INITRD
+    mv -f $INITRD.gz $CD_ROOT/usr/isolinux
 }
 
 function build()
@@ -303,7 +339,11 @@ function build()
     build_cdroot
 
     # always build/rebuild initrd
-    build_initrd
+    init_initrd
+
+    ####################################################################################
+    # build small initrd for small iso and usb image
+    build_initrd 0
 
     # build iso image
     rm -f $ISO
@@ -320,7 +360,7 @@ function build()
     mkdir -p $INITRD_MOUNT
     mount -o loop,rw $USB_IMAGE $INITRD_MOUNT
 
-    # populate the root of the image with the iso, pl_version, and the syslinux files
+    # populate the root of the image with pl_version, and the syslinux files
     cp -a $ISO $INITRD_MOUNT
     cp -a $CD_ROOT/usr/isolinux/{initrd.gz,kernel,message.txt,pl_version} $INITRD_MOUNT
     cp -a $CD_ROOT/usr/isolinux/isolinux.cfg $INITRD_MOUNT/syslinux.cfg
@@ -330,6 +370,29 @@ function build()
 
     # make it bootable
     syslinux $USB_IMAGE
+
+    ####################################################################################
+    # build small initrd for small iso and usb image
+    build_initrd 1
+    
+    # build usb image and make it bootable with syslinux (instead of isolinux)
+    USB_IMAGE=${ISO%*.iso}-biginitrd.usb
+    # leave 1 MB of free space on the filesystem
+    USB_KB=$(du -kc $CD_ROOT/usr/isolinux | awk '$2 == "total" { print $1 + 1024 }')
+    /sbin/mkfs.vfat -C $USB_IMAGE $USB_KB
+
+    mkdir -p $INITRD_MOUNT
+    mount -o loop,rw $USB_IMAGE $INITRD_MOUNT
+
+    # populate the root of the image with pl_version, and the syslinux files
+    cp -a $CD_ROOT/usr/isolinux/{initrd.gz,kernel,message.txt,pl_version} $INITRD_MOUNT
+    cp -a $CD_ROOT/usr/isolinux/isolinux.cfg $INITRD_MOUNT/syslinux.cfg
+
+    umount $INITRD_MOUNT
+    rmdir $INITRD_MOUNT
+
+    # make it bootable
+    syslinux $USB_IMAGE
 }
 
 function burn()
@@ -382,10 +445,15 @@ if [[ "$1" == "clean" || "$1" == "burn" || "$1" == "build" ]]; then
     mkdir -p $CD_ROOT
 
     # location of the uncompressed ramdisk image
-    INITRD=$CD_ROOT/usr/isolinux/initrd
+    INITRD=`pwd`/$BUILD_DIR/initrd
 
     # temporary mount point for rd
-    INITRD_MOUNT=`pwd`/$BUILD_DIR/rd
+    MYPWD=`pwd`
+    INITRD_MOUNT=`mktemp -q -p $MYPWD/$BUILD_DIR -d -t rd.XXXXXXXX`
+    if [ $? -ne 0 ]; then
+       echo "failed to create tempory mount point for initrd"
+       exit 1
+    fi
 
 
     case $action in 
diff --git a/cdcustom.sh b/cdcustom.sh
new file mode 100755 (executable)
index 0000000..67a6b69
--- /dev/null
@@ -0,0 +1,133 @@
+#!/bin/bash
+
+# purpose : create a node-specific CD ISO image
+
+# given a CD ISO image, and a node-specific config file, this command
+# creates a new almost identical ISO image with the config file
+# embedded as boot/plnode.txt 
+
+set -e 
+COMMAND=$(basename $0)
+
+function usage () {
+
+   echo "Usage: $0 generic-iso node-config [node-configs]"
+   echo "Creates a node-specific ISO image"
+   echo "with the node-specific config file embedded as /boot/plnode.txt"
+   exit 1
+}
+
+### read config file in a subshell and echoes host_name
+function host_name () {
+  export CONFIG=$1; shift
+  ( . $CONFIG ; echo $HOST_NAME )
+}
+
+function cleanup () {
+   echo "Unmounting"
+   umount $ISOINROOT
+   echo "Cleaning mount-point"
+   rmdir $ISOINROOT
+   if [ -f $NODECONFPLAIN ] ; then
+     echo Cleaning $NODECONFPLAIN
+     rm -f $NODECONFPLAIN
+   fi
+}
+
+function abort () {
+   echo "Cleaning $ISOOUT"
+   rm -f $ISOOUT
+   cleanup
+}
+
+function main () {
+
+   [[ -n "$TRACE" ]] && set -x
+
+   [[ -z "$@" ]] && usage
+   ISOIN=$1; shift
+   [[ -z "$@" ]] && usage
+
+   for NODECONF in "$@" ; do
+
+     NODENAME=$(host_name $NODECONF)
+     if [ -z "$NODENAME" ] ; then
+       echo "HOST_NAME not found in $NODECONF - exiting"
+       exit 1
+     fi
+   
+     ISODIR=$(dirname "$ISOIN")
+     ISOOUT=$ISODIR/$NODENAME.iso
+     ISOLOG=$ISODIR/$NODENAME.log
+
+
+     ### temporary mount point
+     ISOINROOT=$(basename $ISOIN .iso)
+     
+     ### checking
+     if [ ! -f $ISOIN ] ; then
+       echo "Could not find template ISO image - exiting" ; exit 1
+     fi
+     if [ ! -f $NODECONF ] ; then
+       echo "Could not find node-specifig config - exiting" ; exit 1
+     fi
+     if [ -e "$ISOINROOT" ] ; then
+       echo "Temporary mount point $ISOINROOT exists, please clean up first - exiting" ; exit 1
+     fi
+     if [ -e  "$ISOOUT" ] ; then
+       echo "$ISOOUT exists, please remove first - exiting" ; exit 1
+     fi
+     
+     ### in case the NODECONF is a symlink
+     NODECONFPLAIN=/tmp/$$
+     cp $NODECONF $NODECONFPLAIN
+     
+     ### summary
+     echo -e "Generic ISO image:\r\t\t\t$ISOIN"
+     echo -e "Node-specific config:\r\t\t\t$NODECONF"
+     echo -e "Node-specific ISO:\r\t\t\t$ISOOUT"
+     echo -e "Temporary mount-point:\r\t\t\t$ISOINROOT"
+     
+     echo -ne "OK ? "
+     read answer
+     
+     echo -n "Creating mount-point "
+     mkdir -p $ISOINROOT
+     echo Done
+
+     echo -n "Mounting generic image "
+     mount -o ro,loop $ISOIN $ISOINROOT 
+     echo Done
+
+     ### mkisofs needs to have write access on the boot image passed with -b
+     ### and we cannot use the same name as isolinux.bin either, so we change it to isolinux
+     ### the good news is that this way we can check we start from a fresh image
+     
+     if [ -e $ISOINROOT/isolinux/isolinux ] ; then
+       echo "$ISOIN already contains isolinux/isolinux"
+       echo "It looks like this is not a first-hand image - exiting"
+       cleanup
+       exit 1
+     fi
+
+     echo -n "Copying isolinux.bin in /tmp/isolinux "
+     cp $ISOINROOT/isolinux/isolinux.bin /tmp/isolinux
+     echo Done
+     
+     echo -n "Writing custom image ... "
+     trap abort int hup quit err
+     mkisofs -o $ISOOUT -R -allow-leading-dots -J -r -b isolinux/isolinux \
+     -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table \
+     --graft-points $ISOINROOT isolinux/isolinux=/tmp/isolinux boot/plnode.txt=$NODECONFPLAIN > $ISOLOG 2>&1
+     trap - int hup quit 
+     echo Done
+   
+     cleanup
+
+     echo "CD ISO image for $NODENAME in $ISOOUT"
+   done
+
+}
+
+####################
+main "$@"
index fa5810e..b5499b2 100755 (executable)
@@ -8,67 +8,95 @@ echo "pl_sysinit: mounting file systems"
 echo "pl_sysinit: invoking hardware initialization script"
 /etc/init.d/pl_hwinit
 
-echo "pl_sysinit: finding cd to mount on /usr"
-mounted=0
-initrd_version=$(/bin/cat /pl_version)
-mkdir /usr
-
-# so that * expands to empty string if there are no block
-# devices
-shopt -s nullglob
-
-for device in /sys/block/*; do
-    device=$(/bin/basename $device)
-
-    # skipping any devices that start with md or ra (ram) or lo (loop) or
-    # fd (floppy)
-    start_device=${device:0:2}
-    if [ "$start_device" == "ra" ] || [ "$start_device" == "md" ] ||
-       [ "$start_device" == "lo" ] || [ "$start_device" == "fd" ]; then
-       continue
+check_initrd()
+{
+    _mounted=0
+    if [ -f /usr/isolinux/pl_version ] ; then
+        # it mounted, but we should probably make sure its our boot cd
+        # this can be done by making sure the /pl_version file (on initrd)
+        # matches /usr/isolinux/pl_version
+       initrd_version=$(/bin/cat /pl_version)
+       cd_version=$(/bin/cat /usr/isolinux/pl_version)
+       if [ "$initrd_version" == "$cd_version" ]; then
+           _mounted=1 
+       fi
     fi
+    return $_mounted
+}
+
+check_block_devices()
+{
+    _mounted=0
+    # so that * expands to empty string if there are no block devices
+    shopt -s nullglob
 
-    # If this is a removable (e.g., USB flash) device, then try to
-    # look for an ISO image on each of its partitions.
-    if [ "$(cat /sys/block/$device/removable)" = "1" ] ; then
-       partitions=$(/bin/awk "\$4 ~ /${device}[0-9]*/ { print \$4 }" /proc/partitions)
-       for partition in $partitions ; do
-           echo "pl_sysinit: checking $partition for iso image"
-           mkdir -p /tmp/$partition
-           if /bin/mount -o ro -t msdos,ext2 /dev/$partition /tmp/$partition 2>&1 > /dev/null ; then
+    for device in /sys/block/*; do
+       device=$(/bin/basename $device)
+
+        # skipping any devices that start with md or ra (ram) or lo
+       # (loop) or fd (floppy)
+
+       start_device=${device:0:2}
+       if [ "$start_device" == "ra" ] || [ "$start_device" == "md" ] ||
+           [ "$start_device" == "lo" ] || [ "$start_device" == "fd" ]; then
+           continue
+       fi
+
+        # If this is a removable (e.g., USB flash) device, then try to
+        # look for an ISO image on each of its partitions.
+       if [ "$(cat /sys/block/$device/removable)" = "1" ] ; then
+           partitions=$(/bin/awk "\$4 ~ /${device}[0-9]*/ { print \$4 }" /proc/partitions)
+           for partition in $partitions ; do
+               echo "pl_sysinit: checking $partition for iso image"
+               mkdir -p /tmp/$partition
+               if /bin/mount -o ro -t msdos,ext2 /dev/$partition /tmp/$partition 2>&1 > /dev/null ; then
                # Look for the first ISO image
-               for iso in /tmp/$partition/*.iso ; do
-                   if /sbin/losetup /dev/loop0 $iso ; then
-                       echo "pl_sysinit: using $(basename $iso) on $partition"
-                       device="loop0"
-                       break
+                   for iso in /tmp/$partition/*.iso ; do
+                       if /sbin/losetup /dev/loop0 $iso ; then
+                           echo "pl_sysinit: using $(basename $iso) on $partition"
+                           device="loop0"
+                           break
+                       fi
+                   done
+                   if [ "$device" != "loop0" ] ; then
+                       /bin/umount /tmp/$partition 2>&1 > /dev/null
                    fi
-               done
-               if [ "$device" != "loop0" ] ; then
-                   /bin/umount /tmp/$partition 2>&1 > /dev/null
                fi
-           fi
-       done
-    fi
-    
-    echo "pl_sysinit: checking $device for /usr contents"
-    /bin/mount -o ro -t iso9660 /dev/$device /usr 2>&1 > /dev/null
-    if [ $? -eq 0 ]; then
+           done
+       fi
+       
+       echo "pl_sysinit: checking $device for /usr contents"
+       /bin/mount -o ro -t iso9660 /dev/$device /usr 2>&1 > /dev/null
+       if [ $? -eq 0 ]; then
        # it mounted, but we should probably make sure its our boot cd
        # this can be done by making sure the /pl_version file (on initrd)
        # matches /usr/isolinux/pl_version
-       cd_version=$(/bin/cat /usr/isolinux/pl_version)
+           initrd_version=$(/bin/cat /pl_version)
+           cd_version=$(/bin/cat /usr/isolinux/pl_version)
 
-       if [ "$initrd_version" != "$cd_version" ]; then
+           if [ "$initrd_version" != "$cd_version" ]; then
            # eh, wrong cd, keep trying
-           /bin/umount /usr 2>&1 /dev/null
-       else
-           echo "pl_sysinit: found cd and mounted on /usr"
-           mounted=1
-           break
+               /bin/umount /usr 2>&1 /dev/null
+           else
+               echo "pl_sysinit: found cd and mounted on /usr"
+               _mounted=1
+               break
+           fi
        fi
-    fi
-done
+    done
+    return $_mounted
+}
+
+echo "pl_sysinit: finding cd to mount on /usr"
+mounted=0
+check_initrd
+if [ $? -eq 1 ]; then
+    mounted=1
+else
+    [ ! -d /usr ] && mkdir /usr
+    check_block_devices
+    [ $? -eq 1 ] && mounted=1
+fi
 
 if [ $mounted -eq 0 ]; then
     echo "pl_sysinit: unable to find boot cdrom, cannot continue."