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.32 2006/04/03 19:33:56 mlhuang Exp $
16 PATH=/sbin:/bin:/usr/sbin:/usr/bin
19 NODE_CONFIGURATION_FILE=
23 echo "Usage: build.sh [OPTION]..."
24 echo " -c name (Deprecated) Static configuration to use (default: $CONFIGURATION)"
25 echo " -f planet.cnf Node to customize CD for (default: none)"
26 echo " -h This message"
31 while getopts "c:f:h" opt ; do
37 NODE_CONFIGURATION_FILE=$OPTARG
45 # Do not tolerate errors
48 # Change to our source directory
49 srcdir=$(cd $(dirname $0) && pwd -P)
53 isofs=$PWD/build/isofs
55 # Build reference image if it does not exist. This should only need to
56 # be executed once at build time, never at run time.
57 if [ ! -f $isofs/bootcd.img ] ; then
61 # build/version.txt written by prep.sh
62 BOOTCD_VERSION=$(cat build/version.txt)
64 if [ -f /etc/planetlab/plc_config ] ; then
65 # Source PLC configuration
66 . /etc/planetlab/plc_config
67 elif [ -d configurations/$CONFIGURATION ] ; then
68 # (Deprecated) Source static configuration
69 . configurations/$CONFIGURATION/configuration
71 if [ -n "$EXTRA_VERSION" ] ; then
72 BOOTCD_VERSION="$BOOTCD_VERSION $EXTRA_VERSION"
74 PLC_BOOT_HOST=$PRIMARY_SERVER
75 PLC_BOOT_SSL_PORT=$PRIMARY_SERVER_PORT
76 PLC_BOOT_SSL_CRT=configurations/$CONFIGURATION/$PRIMARY_SERVER_CERT
77 PLC_ROOT_GPG_KEY_PUB=configurations/$CONFIGURATION/$PRIMARY_SERVER_GPG
80 FULL_VERSION_STRING="$PLC_NAME BootCD $BOOTCD_VERSION"
82 # Root of the ISO and USB images
83 overlay=$(mktemp -d /tmp/overlay.XXXXXX)
84 install -d -m 755 $overlay
85 trap "rm -rf $overlay" ERR
87 # Create version files
88 echo "* Creating version files"
90 # Boot Manager compares pl_version in both places to make sure that
91 # the right CD is mounted. We used to boot from an initrd and mount
92 # the CD on /usr. Now we just run everything out of the initrd.
93 for file in $overlay/pl_version $overlay/usr/isolinux/pl_version ; do
94 mkdir -p $(dirname $file)
95 echo "$FULL_VERSION_STRING" >$file
98 # Install boot server configuration files
99 echo "* Installing boot server configuration files"
101 # We always intended to bring up and support backup boot servers,
102 # but never got around to it. Just install the same parameters for
104 for dir in $overlay/usr/boot $overlay/usr/boot/backup ; do
105 install -D -m 644 $PLC_BOOT_SSL_CRT $dir/cacert.pem
106 install -D -m 644 $PLC_ROOT_GPG_KEY_PUB $dir/pubring.gpg
107 echo "$PLC_BOOT_HOST" >$dir/boot_server
108 echo "$PLC_BOOT_SSL_PORT" >$dir/boot_server_port
109 echo "/boot/" >$dir/boot_server_path
112 # (Deprecated) Install old-style boot server configuration files
113 install -D -m 644 $PLC_BOOT_SSL_CRT $overlay/usr/bootme/cacert/$PLC_BOOT_HOST/cacert.pem
114 echo "$FULL_VERSION_STRING" >$overlay/usr/bootme/ID
115 echo "$PLC_BOOT_HOST" >$overlay/usr/bootme/BOOTSERVER
116 echo "$PLC_BOOT_HOST" >$overlay/usr/bootme/BOOTSERVER_IP
117 echo "$PLC_BOOT_SSL_PORT" >$overlay/usr/bootme/BOOTPORT
119 # Generate /etc/issue
120 echo "* Generating /etc/issue"
121 mkdir -p $overlay/etc
123 echo "$FULL_VERSION_STRING"
124 echo 'Kernel \r on an \m'
127 ) >$overlay/etc/issue
130 echo "* Setting root password"
132 if [ -z "$ROOT_PASSWORD" ] ; then
133 # Generate an encrypted password with crypt() if not defined
134 # in a static configuration.
135 ROOT_PASSWORD=$(python <<EOF
136 import crypt, random, string
137 salt = [random.choice(string.letters + string.digits + "./") for i in range(0,8)]
138 print crypt.crypt('$PLC_ROOT_PASSWORD', '\$1\$' + "".join(salt) + '\$')
143 # build/passwd copied out by prep.sh
144 sed -e "s@^root:[^:]*:\(.*\)@root:$ROOT_PASSWORD:\1@" build/passwd \
147 # Install node configuration file (e.g., if node has no floppy disk or USB slot)
148 if [ -f "$NODE_CONFIGURATION_FILE" ] ; then
149 echo "* Installing node configuration file"
150 install -D -m 644 $NODE_CONFIGURATION_FILE $overlay/usr/boot/plnode.txt
153 # Pack overlay files into a compressed archive
154 echo "* Compressing overlay image"
155 (cd $overlay && find . | cpio --quiet -c -o) | gzip -9 >$isofs/overlay.img
160 # Calculate ramdisk size (total uncompressed size of both archives)
161 ramdisk_size=$(gzip -l $isofs/bootcd.img $isofs/overlay.img | tail -1 | awk '{ print $2; }') # bytes
162 ramdisk_size=$(($ramdisk_size / 1024)) # kilobytes
164 # Write isolinux configuration
165 echo "$FULL_VERSION_STRING" >$isofs/pl_version
166 cat >$isofs/isolinux.cfg <<EOF
168 APPEND ramdisk_size=$ramdisk_size initrd=bootcd.img,overlay.img root=/dev/ram0 rw
174 # Change back to output directory
178 echo "* Creating ISO image"
179 iso="$PLC_NAME-BootCD-$BOOTCD_VERSION.iso"
181 -R -allow-leading-dots -J -r \
182 -b isolinux.bin -c boot.cat \
183 -no-emul-boot -boot-load-size 4 -boot-info-table \
187 echo "* Creating USB image"
188 usb="$PLC_NAME-BootCD-$BOOTCD_VERSION.usb"
190 # Leave 1 MB of free space on the VFAT filesystem
191 mkfs.vfat -C "$usb" $(($(du -sk $isofs | awk '{ print $1; }') + 1024))
194 tmp=$(mktemp -d /tmp/bootcd.XXXXXX)
195 mount -o loop "$usb" $tmp
196 trap "umount $tmp; rm -rf $tmp" ERR
199 echo "* Populating USB image"
200 (cd $isofs && find . | cpio -p -d -u $tmp/)
202 # Use syslinux instead of isolinux to make the image bootable
203 mv $tmp/isolinux.cfg $tmp/syslinux.cfg
208 echo "* Making USB image bootable"
209 $srcdir/syslinux/unix/syslinux "$usb"