3 # Builds custom BootCD ISO and USB images in the current
4 # directory. For backward compatibility, if an old-style static
5 # configuration is specified, that configuration file will be parsed
6 # instead of the current PLC configuration in
7 # /etc/planetlab/plc_config.
9 # Aaron Klingaman <alk@absarokasoft.com>
10 # Mark Huang <mlhuang@cs.princeton.edu>
11 # Copyright (C) 2004-2006 The Trustees of Princeton University
13 # $Id: build.sh,v 1.5 2006/03/29 17:08:45 mlhuang Exp $
17 NODE_CONFIGURATION_FILE=
21 echo "Usage: build.sh [OPTION]..."
22 echo " -c name (Deprecated) Static configuration to use (default: $CONFIGURATION)"
23 echo " -f planet.cnf Node to customize CD for (default: none)"
24 echo " -h This message"
29 while getopts "c:f:h" opt ; do
35 NODE_CONFIGURATION_FILE=$OPTARG
43 # Do not tolerate errors
46 # Change to our source directory
47 srcdir=$(cd $(dirname $0) && pwd -P)
51 isofs=$PWD/build/isofs
53 # Build reference image if it does not exist. This should only need to
54 # be executed once at build time, never at run time.
55 if [ ! -f $isofs/bootcd.img ] ; then
59 # build/version.txt written by prep.sh
60 BOOTCD_VERSION=$(cat build/version.txt)
62 if [ -f /etc/planetlab/plc_config ] ; then
63 # Source PLC configuration
64 . /etc/planetlab/plc_config
65 elif [ -d configurations/$CONFIGURATION ] ; then
66 # (Deprecated) Source static configuration
67 . configurations/$CONFIGURATION/configuration
69 if [ -n "$EXTRA_VERSION" ] ; then
70 BOOTCD_VERSION="$BOOTCD_VERSION $EXTRA_VERSION"
72 PLC_BOOT_HOST=$PRIMARY_SERVER
73 PLC_BOOT_SSL_PORT=$PRIMARY_SERVER_PORT
74 PLC_BOOT_SSL_CRT=configurations/$CONFIGURATION/$PRIMARY_SERVER_CERT
75 PLC_ROOT_GPG_KEY_PUB=configurations/$CONFIGURATION/$PRIMARY_SERVER_GPG
78 FULL_VERSION_STRING="$PLC_NAME BootCD $BOOTCD_VERSION"
80 # Root of the ISO and USB images
81 overlay=$(mktemp -d /tmp/overlay.XXXXXX)
82 install -d -m 755 $overlay
83 trap "rm -rf $overlay" ERR
85 # Create version files
86 echo "* Creating version files"
88 # Boot Manager compares pl_version in both places to make sure that
89 # the right CD is mounted. We used to boot from an initrd and mount
90 # the CD on /usr. Now we just run everything out of the initrd.
91 for file in $overlay/pl_version $overlay/usr/isolinux/pl_version ; do
92 mkdir -p $(dirname $file)
93 echo "$FULL_VERSION_STRING" >$file
96 # Install boot server configuration files
97 echo "* Installing boot server configuration files"
99 # We always intended to bring up and support backup boot servers,
100 # but never got around to it. Just install the same parameters for
102 for dir in $overlay/usr/boot $overlay/usr/boot/backup ; do
103 install -D -m 644 $PLC_BOOT_SSL_CRT $dir/cacert.pem
104 install -D -m 644 $PLC_ROOT_GPG_KEY_PUB $dir/pubring.gpg
105 echo "$PLC_BOOT_HOST" >$dir/boot_server
106 echo "$PLC_BOOT_SSL_PORT" >$dir/boot_server_port
107 echo "/boot/" >$dir/boot_server_path
110 # (Deprecated) Install old-style boot server configuration files
111 install -D -m 644 $PLC_BOOT_SSL_CRT $overlay/usr/bootme/cacert/$PLC_BOOT_HOST/cacert.pem
112 echo "$FULL_VERSION_STRING" >$overlay/usr/bootme/ID
113 echo "$PLC_BOOT_HOST" >$overlay/usr/bootme/BOOTSERVER
114 echo "$PLC_BOOT_HOST" >$overlay/usr/bootme/BOOTSERVER_IP
115 echo "$PLC_BOOT_SSL_PORT" >$overlay/usr/bootme/BOOTPORT
117 # Generate /etc/issue
118 echo "* Generating /etc/issue"
119 mkdir -p $overlay/etc
121 echo "$FULL_VERSION_STRING"
122 echo 'Kernel \r on an \m'
125 ) >$overlay/etc/issue
128 echo "* Setting root password"
130 if [ -z "$ROOT_PASSWORD" ] ; then
131 # Generate an encrypted password with crypt() if not defined
132 # in a static configuration.
133 ROOT_PASSWORD=$(python <<EOF
134 import crypt, random, string
135 salt = [random.choice(string.letters + string.digits + "./") for i in range(0,8)]
136 print crypt.crypt('$PLC_ROOT_PASSWORD', '\$1\$' + "".join(salt) + '\$')
141 # build/passwd copied out by prep.sh
142 sed -e "s@^root:[^:]*:\(.*\)@root:$ROOT_PASSWORD:\1@" build/passwd \
145 # Install node configuration file (e.g., if node has no floppy disk or USB slot)
146 if [ -f "$NODE_CONFIGURATION_FILE" ] ; then
147 echo "* Installing node configuration file"
148 install -D -m 644 $NODE_CONFIGURATION_FILE $overlay/usr/boot/plnode.txt
151 # Pack overlay files into a compressed archive
152 echo "* Compressing overlay image"
153 (cd $overlay && find . | cpio --quiet -c -o) | gzip -9 >$isofs/overlay.img
158 # Calculate ramdisk size (total uncompressed size of both archives)
159 ramdisk_size=$(gzip -l $isofs/bootcd.img $isofs/overlay.img | tail -1 | awk '{ print $2; }') # bytes
160 ramdisk_size=$(($ramdisk_size / 1024)) # kilobytes
162 # Write isolinux configuration
163 echo "$FULL_VERSION_STRING" >$isofs/pl_version
164 cat >$isofs/isolinux.cfg <<EOF
166 APPEND ramdisk_size=$ramdisk_size initrd=bootcd.img,overlay.img root=/dev/ram0 rw
172 # Change back to output directory
176 echo "* Creating ISO image"
177 iso="$PLC_NAME-BootCD-$BOOTCD_VERSION.iso"
179 -R -allow-leading-dots -J -r \
180 -b isolinux.bin -c boot.cat \
181 -no-emul-boot -boot-load-size 4 -boot-info-table \
185 echo "* Creating USB image"
186 usb="$PLC_NAME-BootCD-$BOOTCD_VERSION.usb"
188 # Leave 1 MB of free space on the VFAT filesystem
189 mkfs.vfat -C "$usb" $(($(du -sk $isofs | awk '{ print $1; }') + 1024))
192 tmp=$(mktemp -d /tmp/bootcd.XXXXXX)
193 mount -o loop "$usb" $tmp
194 trap "umount $tmp; rm -rf $tmp" ERR
197 echo "* Populating USB image"
198 (cd $isofs && find . | cpio -p -d -u $tmp/)
200 # Use syslinux instead of isolinux to make the image bootable
201 mv $tmp/isolinux.cfg $tmp/syslinux.cfg
206 echo "* Making USB image bootable"
207 $srcdir/syslinux/unix/syslinux "$usb"