blob: da8bbcc3481b26c4c0fbea5c088a827149c409d0 [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 Troyerf2a343b2011-10-26 16:05:28 -05004# build_pxe_boot.sh 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 Troyer1f80bfb2011-09-27 22:19:32 -05009DEST_DIR=${1:-/tmp}/tftpboot
Dean Troyerd4a3bac2011-10-03 21:16:27 -050010PXEDIR=${PXEDIR:-/var/cache/devstack/pxe}
Dean Troyer3f717002011-09-27 17:53:11 -050011OPWD=`pwd`
Dean Troyerc945bf82011-09-29 16:15:23 -050012PROGDIR=`dirname $0`
Dean Troyer3f717002011-09-27 17:53:11 -050013
Dean Troyer1f80bfb2011-09-27 22:19:32 -050014mkdir -p $DEST_DIR/pxelinux.cfg
15cd $DEST_DIR
16for i in memdisk menu.c32 pxelinux.0; do
Dean Troyerf2a343b2011-10-26 16:05:28 -050017 cp -pu /usr/lib/syslinux/$i $DEST_DIR
Dean Troyer1f80bfb2011-09-27 22:19:32 -050018done
19
Dean Troyerdd6636b2011-10-11 20:28:39 -050020CFG=$DEST_DIR/pxelinux.cfg/default
21cat >$CFG <<EOF
Dean Troyer3f717002011-09-27 17:53:11 -050022default menu.c32
Dean Troyer3f717002011-09-27 17:53:11 -050023prompt 0
Dean Troyer9b5ebb52011-09-28 14:14:33 -050024timeout 0
Dean Troyer3f717002011-09-27 17:53:11 -050025
26MENU TITLE PXE Boot Menu
27
28EOF
29
Dean Troyerc945bf82011-09-29 16:15:23 -050030# Setup devstack boot
Dean Troyer3f717002011-09-27 17:53:11 -050031mkdir -p $DEST_DIR/ubuntu
Dean Troyer3508a3a2011-10-03 11:43:28 -050032if [ ! -d $PXEDIR ]; then
33 mkdir -p $PXEDIR
Dean Troyerc945bf82011-09-29 16:15:23 -050034fi
Dean Troyerf2a343b2011-10-26 16:05:28 -050035
36# Get image into place
37if [ ! -r $PXEDIR/stack-initrd.img ]; then
Dean Troyerc0a67392011-10-03 16:31:36 -050038 cd $OPWD
Dean Troyerf2a343b2011-10-26 16:05:28 -050039 $PROGDIR/build_ramdisk.sh $PXEDIR/stack-initrd.img
Dean Troyerc945bf82011-09-29 16:15:23 -050040fi
Dean Troyerf2a343b2011-10-26 16:05:28 -050041if [ ! -r $PXEDIR/stack-initrd.gz ]; then
42 gzip -1 -c $PXEDIR/stack-initrd.img >$PXEDIR/stack-initrd.gz
43fi
44cp -pu $PXEDIR/stack-initrd.gz $DEST_DIR/ubuntu
45
46if [ ! -r $PXEDIR/vmlinuz-*-generic ]; then
47 MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
48 mount -t ext4 -o loop $PXEDIR/stack-initrd.img $MNTDIR
49
50 if [ ! -r $MNTDIR/boot/vmlinuz-*-generic ]; then
51 echo "No kernel found"
52 umount $MNTDIR
53 rmdir $MNTDIR
54 exit 1
55 else
56 cp -pu $MNTDIR/boot/vmlinuz-*-generic $PXEDIR
57 fi
58 umount $MNTDIR
59 rmdir $MNTDIR
60fi
61
62# Get generic kernel version
63KNAME=`basename $PXEDIR/vmlinuz-*-generic`
64KVER=${KNAME#vmlinuz-}
65cp -pu $PXEDIR/vmlinuz-$KVER $DEST_DIR/ubuntu
Dean Troyerdd6636b2011-10-11 20:28:39 -050066cat >>$CFG <<EOF
Dean Troyerc945bf82011-09-29 16:15:23 -050067
68LABEL devstack
69 MENU LABEL ^devstack
70 MENU DEFAULT
Dean Troyer958fa3d2011-09-30 09:22:23 -050071 KERNEL ubuntu/vmlinuz-$KVER
Dean Troyerc945bf82011-09-29 16:15:23 -050072 APPEND initrd=ubuntu/stack-initrd.gz ramdisk_size=2109600 root=/dev/ram0
73EOF
74
75# Get Ubuntu
Dean Troyerdd6636b2011-10-11 20:28:39 -050076if [ -d $PXEDIR -a -r $PXEDIR/natty-base-initrd.gz ]; then
Dean Troyerf2a343b2011-10-26 16:05:28 -050077 cp -pu $PXEDIR/natty-base-initrd.gz $DEST_DIR/ubuntu
Dean Troyerdd6636b2011-10-11 20:28:39 -050078 cat >>$CFG <<EOF
Dean Troyer3f717002011-09-27 17:53:11 -050079
80LABEL ubuntu
Dean Troyerc945bf82011-09-29 16:15:23 -050081 MENU LABEL ^Ubuntu Natty
Dean Troyer958fa3d2011-09-30 09:22:23 -050082 KERNEL ubuntu/vmlinuz-$KVER
Dean Troyerc945bf82011-09-29 16:15:23 -050083 APPEND initrd=ubuntu/natty-base-initrd.gz ramdisk_size=419600 root=/dev/ram0
Dean Troyer3f717002011-09-27 17:53:11 -050084EOF
Dean Troyer1f80bfb2011-09-27 22:19:32 -050085fi
Dean Troyer1f80bfb2011-09-27 22:19:32 -050086
87# Local disk boot
Dean Troyerdd6636b2011-10-11 20:28:39 -050088cat >>$CFG <<EOF
Dean Troyer1f80bfb2011-09-27 22:19:32 -050089
90LABEL local
Dean Troyerc945bf82011-09-29 16:15:23 -050091 MENU LABEL ^Local disk
Dean Troyer1f80bfb2011-09-27 22:19:32 -050092 LOCALBOOT 0
93EOF