blob: d01dad0d071f25a6812b805e3053080aff2b8876 [file] [log] [blame]
Dean Troyera4b58772011-09-29 21:30:27 -05001#!/bin/bash -e
Jesse Andrewsec74eef2011-11-11 13:51:55 -08002# build_pxe_env.sh - Create a PXE boot environment
Dean Troyer3f717002011-09-27 17:53:11 -05003#
Jesse Andrewsec74eef2011-11-11 13:51:55 -08004# build_pxe_env.sh destdir
Dean Troyer3f717002011-09-27 17:53:11 -05005#
Jesse Andrewsec74eef2011-11-11 13:51:55 -08006# Requires Ubuntu Oneiric
7#
Dean Troyer9b5ebb52011-09-28 14:14:33 -05008# Only needs to run as root if the destdir permissions require it
Dean Troyer3f717002011-09-27 17:53:11 -05009
Jesse Andrewsec74eef2011-11-11 13:51:55 -080010dpkg -l syslinux || apt-get install -y syslinux
11
Dean Troyer1f80bfb2011-09-27 22:19:32 -050012DEST_DIR=${1:-/tmp}/tftpboot
Jesse Andrewsd7326d22011-11-20 10:02:26 -080013PXEDIR=${PXEDIR:-/opt/ramstack/pxe}
Dean Troyerc945bf82011-09-29 16:15:23 -050014PROGDIR=`dirname $0`
Dean Troyer3f717002011-09-27 17:53:11 -050015
Dean Troyer55c02732011-11-01 17:44:03 -050016# Clean up any resources that may be in use
17cleanup() {
18 set +o errexit
19
20 # Mop up temporary files
21 if [ -n "$MNTDIR" -a -d "$MNTDIR" ]; then
22 umount $MNTDIR
23 rmdir $MNTDIR
24 fi
25
26 # Kill ourselves to signal any calling process
27 trap 2; kill -2 $$
28}
29
Jesse Andrewsd7326d22011-11-20 10:02:26 -080030trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT EXIT
31
32# Keep track of the current directory
33TOOLS_DIR=$(cd $(dirname "$0") && pwd)
34TOP_DIR=`cd $TOOLS_DIR/..; pwd`
Dean Troyer55c02732011-11-01 17:44:03 -050035
Dean Troyer1f80bfb2011-09-27 22:19:32 -050036mkdir -p $DEST_DIR/pxelinux.cfg
37cd $DEST_DIR
38for i in memdisk menu.c32 pxelinux.0; do
Dean Troyerf2a343b2011-10-26 16:05:28 -050039 cp -pu /usr/lib/syslinux/$i $DEST_DIR
Dean Troyer1f80bfb2011-09-27 22:19:32 -050040done
41
Dean Troyerdd6636b2011-10-11 20:28:39 -050042CFG=$DEST_DIR/pxelinux.cfg/default
43cat >$CFG <<EOF
Dean Troyer3f717002011-09-27 17:53:11 -050044default menu.c32
Dean Troyer3f717002011-09-27 17:53:11 -050045prompt 0
Dean Troyer9b5ebb52011-09-28 14:14:33 -050046timeout 0
Dean Troyer3f717002011-09-27 17:53:11 -050047
Jesse Andrewsd7326d22011-11-20 10:02:26 -080048MENU TITLE devstack PXE Boot Menu
Dean Troyer3f717002011-09-27 17:53:11 -050049
50EOF
51
Dean Troyerc945bf82011-09-29 16:15:23 -050052# Setup devstack boot
Dean Troyer3f717002011-09-27 17:53:11 -050053mkdir -p $DEST_DIR/ubuntu
Dean Troyer3508a3a2011-10-03 11:43:28 -050054if [ ! -d $PXEDIR ]; then
55 mkdir -p $PXEDIR
Dean Troyerc945bf82011-09-29 16:15:23 -050056fi
Dean Troyerf2a343b2011-10-26 16:05:28 -050057
58# Get image into place
59if [ ! -r $PXEDIR/stack-initrd.img ]; then
Jesse Andrewsd7326d22011-11-20 10:02:26 -080060 cd $TOP_DIR
Dean Troyerf2a343b2011-10-26 16:05:28 -050061 $PROGDIR/build_ramdisk.sh $PXEDIR/stack-initrd.img
Dean Troyerc945bf82011-09-29 16:15:23 -050062fi
Dean Troyerf2a343b2011-10-26 16:05:28 -050063if [ ! -r $PXEDIR/stack-initrd.gz ]; then
64 gzip -1 -c $PXEDIR/stack-initrd.img >$PXEDIR/stack-initrd.gz
65fi
66cp -pu $PXEDIR/stack-initrd.gz $DEST_DIR/ubuntu
67
68if [ ! -r $PXEDIR/vmlinuz-*-generic ]; then
69 MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
70 mount -t ext4 -o loop $PXEDIR/stack-initrd.img $MNTDIR
71
72 if [ ! -r $MNTDIR/boot/vmlinuz-*-generic ]; then
73 echo "No kernel found"
74 umount $MNTDIR
75 rmdir $MNTDIR
76 exit 1
77 else
78 cp -pu $MNTDIR/boot/vmlinuz-*-generic $PXEDIR
79 fi
80 umount $MNTDIR
81 rmdir $MNTDIR
82fi
83
84# Get generic kernel version
85KNAME=`basename $PXEDIR/vmlinuz-*-generic`
86KVER=${KNAME#vmlinuz-}
87cp -pu $PXEDIR/vmlinuz-$KVER $DEST_DIR/ubuntu
Dean Troyerdd6636b2011-10-11 20:28:39 -050088cat >>$CFG <<EOF
Dean Troyerc945bf82011-09-29 16:15:23 -050089
90LABEL devstack
91 MENU LABEL ^devstack
92 MENU DEFAULT
Dean Troyer958fa3d2011-09-30 09:22:23 -050093 KERNEL ubuntu/vmlinuz-$KVER
Dean Troyerc945bf82011-09-29 16:15:23 -050094 APPEND initrd=ubuntu/stack-initrd.gz ramdisk_size=2109600 root=/dev/ram0
95EOF
96
97# Get Ubuntu
Dean Troyerdd6636b2011-10-11 20:28:39 -050098if [ -d $PXEDIR -a -r $PXEDIR/natty-base-initrd.gz ]; then
Dean Troyerf2a343b2011-10-26 16:05:28 -050099 cp -pu $PXEDIR/natty-base-initrd.gz $DEST_DIR/ubuntu
Dean Troyerdd6636b2011-10-11 20:28:39 -0500100 cat >>$CFG <<EOF
Dean Troyer3f717002011-09-27 17:53:11 -0500101
102LABEL ubuntu
Dean Troyerc945bf82011-09-29 16:15:23 -0500103 MENU LABEL ^Ubuntu Natty
Dean Troyer958fa3d2011-09-30 09:22:23 -0500104 KERNEL ubuntu/vmlinuz-$KVER
Dean Troyerc945bf82011-09-29 16:15:23 -0500105 APPEND initrd=ubuntu/natty-base-initrd.gz ramdisk_size=419600 root=/dev/ram0
Dean Troyer3f717002011-09-27 17:53:11 -0500106EOF
Dean Troyer1f80bfb2011-09-27 22:19:32 -0500107fi
Dean Troyer1f80bfb2011-09-27 22:19:32 -0500108
109# Local disk boot
Dean Troyerdd6636b2011-10-11 20:28:39 -0500110cat >>$CFG <<EOF
Dean Troyer1f80bfb2011-09-27 22:19:32 -0500111
112LABEL local
Dean Troyerc945bf82011-09-29 16:15:23 -0500113 MENU LABEL ^Local disk
Dean Troyer1f80bfb2011-09-27 22:19:32 -0500114 LOCALBOOT 0
115EOF
Jesse Andrewsd7326d22011-11-20 10:02:26 -0800116
117trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT EXIT