blob: b4205b73057eeb250ce232bcbaa0fff059ae0542 [file] [log] [blame]
Dean Troyer274ec102011-10-11 20:32:07 -05001#!/bin/bash -e
2# build_usb_boot.sh - Create a syslinux boot environment
3#
4# build_usb_boot.sh [-k kernel-version] destdev
5#
6# Assumes syslinux is installed
7# Assumes devstack files are in `pwd`/pxe
8# Needs to run as root
9
10KVER=`uname -r`
11if [ "$1" = "-k" ]; then
12 KVER=$2
13 shift;shift
14fi
15
16DEST_DIR=${1:-/tmp/syslinux-boot}
17PXEDIR=${PXEDIR:-/var/cache/devstack/pxe}
18OPWD=`pwd`
19PROGDIR=`dirname $0`
20
21if [ -b $DEST_DIR ]; then
22 # We have a block device, install syslinux and mount it
23 DEST_DEV=$DEST_DIR
24 DEST_DIR=`mktemp -d mntXXXXXX`
25
26 # Install syslinux on the device
27 syslinux --install --directory syslinux $DEST_DEV
28
29 mount $DEST_DEV $DEST_DIR
30else
31 # We have a directory (for sanity checking output)
32 DEST_DEV=""
33 if [ ! -d $DEST_DIR/syslinux ]; then
34 mkdir -p $DEST_DIR/syslinux
35 fi
36fi
37
38# Get some more stuff from syslinux
39for i in memdisk menu.c32; do
40 cp -p /usr/lib/syslinux/$i $DEST_DIR/syslinux
41done
42
43CFG=$DEST_DIR/syslinux/syslinux.cfg
44cat >$CFG <<EOF
45default /syslinux/menu.c32
46prompt 0
47timeout 0
48
49MENU TITLE Boot Menu
50
51EOF
52
53# Setup devstack boot
54mkdir -p $DEST_DIR/ubuntu
55if [ ! -d $PXEDIR ]; then
56 mkdir -p $PXEDIR
57fi
58if [ ! -r $PXEDIR/vmlinuz-${KVER} ]; then
59 sudo chmod 644 /boot/vmlinuz-${KVER}
60 if [ ! -r /boot/vmlinuz-${KVER} ]; then
61 echo "No kernel found"
62 else
63 cp -p /boot/vmlinuz-${KVER} $PXEDIR
64 fi
65fi
66cp -p $PXEDIR/vmlinuz-${KVER} $DEST_DIR/ubuntu
67if [ ! -r $PXEDIR/stack-initrd.gz ]; then
68 cd $OPWD
69 sudo $PROGDIR/build_ramdisk.sh $PXEDIR/stack-initrd.gz
70fi
71cp -p $PXEDIR/stack-initrd.gz $DEST_DIR/ubuntu
72cat >>$CFG <<EOF
73
74LABEL devstack
75 MENU LABEL ^devstack
76 MENU DEFAULT
77 KERNEL /ubuntu/vmlinuz-$KVER
78 APPEND initrd=/ubuntu/stack-initrd.gz ramdisk_size=2109600 root=/dev/ram0
79EOF
80
81# Get Ubuntu
82if [ -d $PXEDIR -a -r $PXEDIR/natty-base-initrd.gz ]; then
83 cp -p $PXEDIR/natty-base-initrd.gz $DEST_DIR/ubuntu
84 cat >>$CFG <<EOF
85
86LABEL ubuntu
87 MENU LABEL ^Ubuntu Natty
88 KERNEL /ubuntu/vmlinuz-$KVER
89 APPEND initrd=/ubuntu/natty-base-initrd.gz ramdisk_size=419600 root=/dev/ram0
90EOF
91fi
92
93# Local disk boot
94cat >>$CFG <<EOF
95
96LABEL local
97 MENU LABEL ^Local disk
98 MENU DEFAULT
99 LOCALBOOT 0
100EOF
101
102if [ -n "$DEST_DEV" ]; then
103 umount $DEST_DIR
104 rmdir $DEST_DIR
105fi