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