blob: 7fd964bda6356c13c78ab588cb7b8c71faf98622 [file] [log] [blame]
Dean Troyera4b58772011-09-29 21:30:27 -05001#!/bin/bash -e
Dean Troyer9b5ebb52011-09-28 14:14:33 -05002# build_pxe_boot.sh - Create a PXE boot environment
Dean Troyer3f717002011-09-27 17:53:11 -05003#
Dean Troyerc945bf82011-09-29 16:15:23 -05004# build_pxe_boot.sh [-k kernel-version] destdir
Dean Troyer3f717002011-09-27 17:53:11 -05005#
6# Assumes syslinux is installed
Dean Troyer9b5ebb52011-09-28 14:14:33 -05007# Only needs to run as root if the destdir permissions require it
Dean Troyer3f717002011-09-27 17:53:11 -05008
Dean Troyerc945bf82011-09-29 16:15:23 -05009KVER=`uname -r`
10if [ "$1" = "-k" ]; then
11 KVER=$2
12 shift;shift
13fi
14
Dean Troyer1f80bfb2011-09-27 22:19:32 -050015DEST_DIR=${1:-/tmp}/tftpboot
Dean Troyerd4a3bac2011-10-03 21:16:27 -050016PXEDIR=${PXEDIR:-/var/cache/devstack/pxe}
Dean Troyer3f717002011-09-27 17:53:11 -050017OPWD=`pwd`
Dean Troyerc945bf82011-09-29 16:15:23 -050018PROGDIR=`dirname $0`
Dean Troyer3f717002011-09-27 17:53:11 -050019
Dean Troyer1f80bfb2011-09-27 22:19:32 -050020mkdir -p $DEST_DIR/pxelinux.cfg
21cd $DEST_DIR
22for i in memdisk menu.c32 pxelinux.0; do
Vishvananda Ishaya9b353672011-10-20 10:07:10 -070023 cp -p /usr/lib/syslinux/$i $DEST_DIR
Dean Troyer1f80bfb2011-09-27 22:19:32 -050024done
25
Dean Troyerdd6636b2011-10-11 20:28:39 -050026CFG=$DEST_DIR/pxelinux.cfg/default
27cat >$CFG <<EOF
Dean Troyer3f717002011-09-27 17:53:11 -050028default menu.c32
Dean Troyer3f717002011-09-27 17:53:11 -050029prompt 0
Dean Troyer9b5ebb52011-09-28 14:14:33 -050030timeout 0
Dean Troyer3f717002011-09-27 17:53:11 -050031
32MENU TITLE PXE Boot Menu
33
34EOF
35
Dean Troyerc945bf82011-09-29 16:15:23 -050036# Setup devstack boot
Dean Troyer3f717002011-09-27 17:53:11 -050037mkdir -p $DEST_DIR/ubuntu
Dean Troyer3508a3a2011-10-03 11:43:28 -050038if [ ! -d $PXEDIR ]; then
39 mkdir -p $PXEDIR
Dean Troyerc945bf82011-09-29 16:15:23 -050040fi
Dean Troyer3508a3a2011-10-03 11:43:28 -050041if [ ! -r $PXEDIR/vmlinuz-${KVER} ]; then
Dean Troyer783cc772011-09-29 18:43:44 -050042 sudo chmod 644 /boot/vmlinuz-${KVER}
43 if [ ! -r /boot/vmlinuz-${KVER} ]; then
Dean Troyerc945bf82011-09-29 16:15:23 -050044 echo "No kernel found"
45 else
Dean Troyer3508a3a2011-10-03 11:43:28 -050046 cp -p /boot/vmlinuz-${KVER} $PXEDIR
Dean Troyerc945bf82011-09-29 16:15:23 -050047 fi
48fi
Dean Troyer3508a3a2011-10-03 11:43:28 -050049cp -p $PXEDIR/vmlinuz-${KVER} $DEST_DIR/ubuntu
50if [ ! -r $PXEDIR/stack-initrd.gz ]; then
Dean Troyerc0a67392011-10-03 16:31:36 -050051 cd $OPWD
Dean Troyer56119512011-10-11 19:39:34 -050052 sudo $PROGDIR/build_ramdisk.sh $PXEDIR/stack-initrd.gz
Dean Troyerc945bf82011-09-29 16:15:23 -050053fi
Dean Troyer3508a3a2011-10-03 11:43:28 -050054cp -p $PXEDIR/stack-initrd.gz $DEST_DIR/ubuntu
Dean Troyerdd6636b2011-10-11 20:28:39 -050055cat >>$CFG <<EOF
Dean Troyerc945bf82011-09-29 16:15:23 -050056
57LABEL devstack
58 MENU LABEL ^devstack
59 MENU DEFAULT
Dean Troyer958fa3d2011-09-30 09:22:23 -050060 KERNEL ubuntu/vmlinuz-$KVER
Dean Troyerc945bf82011-09-29 16:15:23 -050061 APPEND initrd=ubuntu/stack-initrd.gz ramdisk_size=2109600 root=/dev/ram0
62EOF
63
64# Get Ubuntu
Dean Troyerdd6636b2011-10-11 20:28:39 -050065if [ -d $PXEDIR -a -r $PXEDIR/natty-base-initrd.gz ]; then
Dean Troyer3508a3a2011-10-03 11:43:28 -050066 cp -p $PXEDIR/natty-base-initrd.gz $DEST_DIR/ubuntu
Dean Troyerdd6636b2011-10-11 20:28:39 -050067 cat >>$CFG <<EOF
Dean Troyer3f717002011-09-27 17:53:11 -050068
69LABEL ubuntu
Dean Troyerc945bf82011-09-29 16:15:23 -050070 MENU LABEL ^Ubuntu Natty
Dean Troyer958fa3d2011-09-30 09:22:23 -050071 KERNEL ubuntu/vmlinuz-$KVER
Dean Troyerc945bf82011-09-29 16:15:23 -050072 APPEND initrd=ubuntu/natty-base-initrd.gz ramdisk_size=419600 root=/dev/ram0
Dean Troyer3f717002011-09-27 17:53:11 -050073EOF
Dean Troyer1f80bfb2011-09-27 22:19:32 -050074fi
Dean Troyer1f80bfb2011-09-27 22:19:32 -050075
76# Local disk boot
Dean Troyerdd6636b2011-10-11 20:28:39 -050077cat >>$CFG <<EOF
Dean Troyer1f80bfb2011-09-27 22:19:32 -050078
79LABEL local
Dean Troyerc945bf82011-09-29 16:15:23 -050080 MENU LABEL ^Local disk
Dean Troyer1f80bfb2011-09-27 22:19:32 -050081 LOCALBOOT 0
82EOF