blob: c5ef276678a857a8fc6a17021c74049cdd28188f [file] [log] [blame]
Dean Troyer3f717002011-09-27 17:53:11 -05001#!/bin/bash
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 Troyerc945bf82011-09-29 16:15:23 -05007# Assumes devstack files are in `pwd`/pxe
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
10UBUNTU_MIRROR=http://archive.ubuntu.com/ubuntu/dists/natty/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64
11
Dean Troyer1f80bfb2011-09-27 22:19:32 -050012MEMTEST_VER=4.10
13MEMTEST_BIN=memtest86+-${MEMTEST_VER}.bin
14MEMTEST_URL=http://www.memtest.org/download/${MEMTEST_VER}/
15
Dean Troyerc945bf82011-09-29 16:15:23 -050016KVER=`uname -r`
17if [ "$1" = "-k" ]; then
18 KVER=$2
19 shift;shift
20fi
21
Dean Troyer1f80bfb2011-09-27 22:19:32 -050022DEST_DIR=${1:-/tmp}/tftpboot
Dean Troyer3f717002011-09-27 17:53:11 -050023OPWD=`pwd`
Dean Troyerc945bf82011-09-29 16:15:23 -050024PROGDIR=`dirname $0`
Dean Troyer3f717002011-09-27 17:53:11 -050025
Dean Troyer1f80bfb2011-09-27 22:19:32 -050026mkdir -p $DEST_DIR/pxelinux.cfg
27cd $DEST_DIR
28for i in memdisk menu.c32 pxelinux.0; do
29 cp -p /usr/lib/syslinux/$i $DEST_DIR
30done
31
Dean Troyer3f717002011-09-27 17:53:11 -050032DEFAULT=$DEST_DIR/pxelinux.cfg/default
33cat >$DEFAULT <<EOF
34default menu.c32
Dean Troyer3f717002011-09-27 17:53:11 -050035prompt 0
Dean Troyer9b5ebb52011-09-28 14:14:33 -050036timeout 0
Dean Troyer3f717002011-09-27 17:53:11 -050037
38MENU TITLE PXE Boot Menu
39
40EOF
41
Dean Troyerc945bf82011-09-29 16:15:23 -050042# Setup devstack boot
Dean Troyer3f717002011-09-27 17:53:11 -050043mkdir -p $DEST_DIR/ubuntu
Dean Troyerc945bf82011-09-29 16:15:23 -050044if [ ! -d $OPWD/pxe ]; then
45 mkdir -p $OPWD/pxe
46fi
47if [ ! -r $OPWD/pxe/vmlinuz-${KVER}-generic ]; then
48 if [ ! -r /boot/vmlinuz-${KVER}-generic ]; then
49 echo "No kernel found"
50 else
51 cp -p /boot/vmlinuz-${KVER}-generic $OPWD/pxe
52 fi
53fi
54cp -p $OPWD/pxe/vmlinuz-${KVER}-generic $DEST_DIR/ubuntu
55if [ ! -r $OPWD/pxe/stack-initrd.gz ]; then
56 $PROGDIR/build_pxe_ramdisk.sh $OPWD/pxe/stack-initrd.gz
57fi
58cp -p $OPWD/pxe/stack-initrd.gz $DEST_DIR/ubuntu
59cat >>$DEFAULT <<EOF
60
61LABEL devstack
62 MENU LABEL ^devstack
63 MENU DEFAULT
64 KERNEL ubuntu/vmlinuz-$KVER-generic
65 APPEND initrd=ubuntu/stack-initrd.gz ramdisk_size=2109600 root=/dev/ram0
66EOF
67
68# Get Ubuntu
69if [ -d $OPWD/pxe ]; then
70 cp -p $OPWD/pxe/natty-min-initrd.gz $DEST_DIR/ubuntu
71fi
Dean Troyer3f717002011-09-27 17:53:11 -050072cat >>$DEFAULT <<EOF
73
74LABEL ubuntu
Dean Troyerc945bf82011-09-29 16:15:23 -050075 MENU LABEL ^Ubuntu Natty
76 KERNEL ubuntu/vmlinuz-$KVER-generic
77 APPEND initrd=ubuntu/natty-base-initrd.gz ramdisk_size=419600 root=/dev/ram0
Dean Troyer3f717002011-09-27 17:53:11 -050078EOF
Dean Troyer3f717002011-09-27 17:53:11 -050079
Dean Troyer1f80bfb2011-09-27 22:19:32 -050080# Get Memtest
81cd $DEST_DIR
82if [ ! -r $MEMTEST_BIN ]; then
83 wget -N --quiet ${MEMTEST_URL}/${MEMTEST_BIN}.gz
84 gunzip $MEMTEST_BIN
85fi
86cat >>$DEFAULT <<EOF
87
88LABEL memtest
Dean Troyerc945bf82011-09-29 16:15:23 -050089 MENU LABEL ^Memtest86+
Dean Troyer1f80bfb2011-09-27 22:19:32 -050090 KERNEL $MEMTEST_BIN
91EOF
Dean Troyer1f80bfb2011-09-27 22:19:32 -050092
Dean Troyer3f717002011-09-27 17:53:11 -050093# Get FreeDOS
94mkdir -p $DEST_DIR/freedos
95cd $DEST_DIR/freedos
96wget -N --quiet http://www.fdos.org/bootdisks/autogen/FDSTD.288.gz
97gunzip -f FDSTD.288.gz
98cat >>$DEFAULT <<EOF
99
100LABEL freedos
101 MENU LABEL ^FreeDOS bootdisk
102 KERNEL memdisk
103 APPEND initrd=freedos/FDSTD.288
104EOF
Dean Troyer1f80bfb2011-09-27 22:19:32 -0500105
106# Local disk boot
107cat >>$DEFAULT <<EOF
108
109LABEL local
Dean Troyerc945bf82011-09-29 16:15:23 -0500110 MENU LABEL ^Local disk
Dean Troyer1f80bfb2011-09-27 22:19:32 -0500111 MENU DEFAULT
112 LOCALBOOT 0
113EOF