3 # Builds custom BootCD ISO and USB images in the current
6 # Mark Huang <mlhuang@cs.princeton.edu>
7 # Copyright (C) 2004-2006 The Trustees of Princeton University
12 PATH=/sbin:/bin:/usr/sbin:/usr/bin
16 if [ -f /etc/planetlab/plc_config ] ; then
17 # Source PLC configuration
18 . /etc/planetlab/plc_config
20 echo "Could not find /etc/planetlab/plc_config."
21 echo "This file defines the configuration of your PlanetLab installation."
25 # This support for backwards compatibility can be taken out in the
26 # future. RC1 based MyPLCs set $PLC_BOOT_SSL_CRT in the plc_config
27 # file, but >=RC2 based bootcd assumes that $PLC_BOOT_CA_SSL_CRT is
29 if [ -z "$PLC_BOOT_CA_SSL_CRT" -a ! -z "$PLC_BOOT_SSL_CRT" ] ; then
30 PLC_BOOT_CA_SSL_CRT=$PLC_BOOT_SSL_CRT
31 PLC_API_CA_SSL_CRT=$PLC_API_SSL_CRT
34 output="$PLC_NAME-BootCD-$BOOTCD_VERSION.iso"
38 echo "Usage: build.sh [OPTION]..."
39 eceho " -o file Output file (default: $output)"
40 echo " -h This message"
45 while getopts "o:h" opt ; do
56 FULL_VERSION_STRING="$PLC_NAME BootCD $BOOTCD_VERSION"
57 echo "* Building image for $FULL_VERSION_STRING"
59 # Do not tolerate errors
62 # Change to our source directory
63 srcdir=$(cd $(dirname $0) && pwd -P)
64 pushd $srcdir >/dev/null
70 misc=$(mktemp -d /tmp/misc.XXXXXX)
71 trap "rm -rf $misc" ERR INT
73 # initramfs requires that /init be present
74 ln -sf /sbin/init $misc/init
77 echo "$FULL_VERSION_STRING" >$misc/.bootcd
79 # Install GPG, boot, and API server public keys and certificates
80 install -D -m 644 $PLC_ROOT_GPG_KEY_PUB $misc/$PLC_ROOT_GPG_KEY_PUB
81 install -D -m 644 $PLC_BOOT_CA_SSL_CRT $misc/$PLC_BOOT_CA_SSL_CRT
82 install -D -m 644 $PLC_API_CA_SSL_CRT $misc/$PLC_API_CA_SSL_CRT
84 cat > $misc/etc/planetlab/plc_config <<EOF
85 PLC_ROOT_GPG_KEY_PUB='$PLC_ROOT_GPG_KEY_PUB'
87 PLC_BOOT_HOST='$PLC_BOOT_HOST'
88 PLC_BOOT_IP='$PLC_BOOT_IP'
89 PLC_BOOT_PORT=$PLC_BOOT_PORT
90 PLC_BOOT_SSL_PORT=$PLC_BOOT_SSL_PORT
91 PLC_BOOT_CA_SSL_CRT='$PLC_BOOT_CA_SSL_CRT'
93 PLC_API_HOST='$PLC_API_HOST'
94 PLC_API_IP='$PLC_API_IP'
95 PLC_API_PORT=$PLC_API_PORT
96 PLC_API_PATH='$PLC_API_PATH'
97 PLC_API_CA_SSL_CRT='$PLC_API_CA_SSL_CRT'
100 # Generate /etc/issue
101 if [ "$PLC_WWW_PORT" = "443" ] ; then
102 PLC_WWW_URL="https://$PLC_WWW_HOST/"
103 elif [ "$PLC_WWW_PORT" != "80" ] ; then
104 PLC_WWW_URL="http://$PLC_WWW_HOST:$PLC_WWW_PORT/"
106 PLC_WWW_URL="http://$PLC_WWW_HOST/"
110 cat >$misc/etc/issue <<EOF
116 This machine is a node in the $PLC_NAME distributed network. It has
117 not fully booted yet. If you have cancelled the boot process at the
118 request of $PLC_NAME Support, please follow the instructions provided
119 to you. Otherwise, please contact $PLC_MAIL_SUPPORT_ADDRESS.
121 Console login at this point is restricted to root. Provide the root
122 password of the default $PLC_NAME Central administrator account at the
123 time that this CD was created.
127 # Pack miscellaneous files into a compressed archive
128 echo "* Compressing miscellaneous files image"
129 (cd $misc && find . | cpio --quiet -H newc -o) | \
130 python ../filesystem/cpiochown.py --owner root:root - | \
131 gzip -9 >$isofs/misc.img
136 # Calculate ramdisk size (total uncompressed size of all initrds)
137 ramdisk_size=$(gzip -l $isofs/*.img | tail -1 | awk '{ print $2; }') # bytes
138 ramdisk_size=$((($ramdisk_size + 1023) / 1024)) # kilobytes
140 # Write isolinux configuration
141 echo "$FULL_VERSION_STRING" >$isofs/version
142 cat >$isofs/isolinux.cfg <<EOF
144 APPEND ramdisk_size=$ramdisk_size initrd=base.img,bootcd.img,misc.img root=/dev/ram0 rw console=tty0
153 echo "* Creating ISO image"
154 mkisofs -o "$output" \
155 -R -allow-leading-dots -J -r \
156 -b isolinux.bin -c boot.cat \
157 -no-emul-boot -boot-load-size 4 -boot-info-table \
160 # XXX Create USB image