Dean Troyer | a4b5877 | 2011-09-29 21:30:27 -0500 | [diff] [blame] | 1 | #!/bin/bash -e |
Dean Troyer | 9b5ebb5 | 2011-09-28 14:14:33 -0500 | [diff] [blame] | 2 | # build_pxe_boot.sh - Create a PXE boot environment |
Dean Troyer | 3f71700 | 2011-09-27 17:53:11 -0500 | [diff] [blame] | 3 | # |
Dean Troyer | f2a343b | 2011-10-26 16:05:28 -0500 | [diff] [blame] | 4 | # build_pxe_boot.sh destdir |
Dean Troyer | 3f71700 | 2011-09-27 17:53:11 -0500 | [diff] [blame] | 5 | # |
| 6 | # Assumes syslinux is installed |
Dean Troyer | 9b5ebb5 | 2011-09-28 14:14:33 -0500 | [diff] [blame] | 7 | # Only needs to run as root if the destdir permissions require it |
Dean Troyer | 3f71700 | 2011-09-27 17:53:11 -0500 | [diff] [blame] | 8 | |
Dean Troyer | 1f80bfb | 2011-09-27 22:19:32 -0500 | [diff] [blame] | 9 | DEST_DIR=${1:-/tmp}/tftpboot |
Dean Troyer | d4a3bac | 2011-10-03 21:16:27 -0500 | [diff] [blame] | 10 | PXEDIR=${PXEDIR:-/var/cache/devstack/pxe} |
Dean Troyer | 3f71700 | 2011-09-27 17:53:11 -0500 | [diff] [blame] | 11 | OPWD=`pwd` |
Dean Troyer | c945bf8 | 2011-09-29 16:15:23 -0500 | [diff] [blame] | 12 | PROGDIR=`dirname $0` |
Dean Troyer | 3f71700 | 2011-09-27 17:53:11 -0500 | [diff] [blame] | 13 | |
Dean Troyer | 1f80bfb | 2011-09-27 22:19:32 -0500 | [diff] [blame] | 14 | mkdir -p $DEST_DIR/pxelinux.cfg |
| 15 | cd $DEST_DIR |
| 16 | for i in memdisk menu.c32 pxelinux.0; do |
Dean Troyer | f2a343b | 2011-10-26 16:05:28 -0500 | [diff] [blame] | 17 | cp -pu /usr/lib/syslinux/$i $DEST_DIR |
Dean Troyer | 1f80bfb | 2011-09-27 22:19:32 -0500 | [diff] [blame] | 18 | done |
| 19 | |
Dean Troyer | dd6636b | 2011-10-11 20:28:39 -0500 | [diff] [blame] | 20 | CFG=$DEST_DIR/pxelinux.cfg/default |
| 21 | cat >$CFG <<EOF |
Dean Troyer | 3f71700 | 2011-09-27 17:53:11 -0500 | [diff] [blame] | 22 | default menu.c32 |
Dean Troyer | 3f71700 | 2011-09-27 17:53:11 -0500 | [diff] [blame] | 23 | prompt 0 |
Dean Troyer | 9b5ebb5 | 2011-09-28 14:14:33 -0500 | [diff] [blame] | 24 | timeout 0 |
Dean Troyer | 3f71700 | 2011-09-27 17:53:11 -0500 | [diff] [blame] | 25 | |
| 26 | MENU TITLE PXE Boot Menu |
| 27 | |
| 28 | EOF |
| 29 | |
Dean Troyer | c945bf8 | 2011-09-29 16:15:23 -0500 | [diff] [blame] | 30 | # Setup devstack boot |
Dean Troyer | 3f71700 | 2011-09-27 17:53:11 -0500 | [diff] [blame] | 31 | mkdir -p $DEST_DIR/ubuntu |
Dean Troyer | 3508a3a | 2011-10-03 11:43:28 -0500 | [diff] [blame] | 32 | if [ ! -d $PXEDIR ]; then |
| 33 | mkdir -p $PXEDIR |
Dean Troyer | c945bf8 | 2011-09-29 16:15:23 -0500 | [diff] [blame] | 34 | fi |
Dean Troyer | f2a343b | 2011-10-26 16:05:28 -0500 | [diff] [blame] | 35 | |
| 36 | # Get image into place |
| 37 | if [ ! -r $PXEDIR/stack-initrd.img ]; then |
Dean Troyer | c0a6739 | 2011-10-03 16:31:36 -0500 | [diff] [blame] | 38 | cd $OPWD |
Dean Troyer | f2a343b | 2011-10-26 16:05:28 -0500 | [diff] [blame] | 39 | $PROGDIR/build_ramdisk.sh $PXEDIR/stack-initrd.img |
Dean Troyer | c945bf8 | 2011-09-29 16:15:23 -0500 | [diff] [blame] | 40 | fi |
Dean Troyer | f2a343b | 2011-10-26 16:05:28 -0500 | [diff] [blame] | 41 | if [ ! -r $PXEDIR/stack-initrd.gz ]; then |
| 42 | gzip -1 -c $PXEDIR/stack-initrd.img >$PXEDIR/stack-initrd.gz |
| 43 | fi |
| 44 | cp -pu $PXEDIR/stack-initrd.gz $DEST_DIR/ubuntu |
| 45 | |
| 46 | if [ ! -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 |
| 60 | fi |
| 61 | |
| 62 | # Get generic kernel version |
| 63 | KNAME=`basename $PXEDIR/vmlinuz-*-generic` |
| 64 | KVER=${KNAME#vmlinuz-} |
| 65 | cp -pu $PXEDIR/vmlinuz-$KVER $DEST_DIR/ubuntu |
Dean Troyer | dd6636b | 2011-10-11 20:28:39 -0500 | [diff] [blame] | 66 | cat >>$CFG <<EOF |
Dean Troyer | c945bf8 | 2011-09-29 16:15:23 -0500 | [diff] [blame] | 67 | |
| 68 | LABEL devstack |
| 69 | MENU LABEL ^devstack |
| 70 | MENU DEFAULT |
Dean Troyer | 958fa3d | 2011-09-30 09:22:23 -0500 | [diff] [blame] | 71 | KERNEL ubuntu/vmlinuz-$KVER |
Dean Troyer | c945bf8 | 2011-09-29 16:15:23 -0500 | [diff] [blame] | 72 | APPEND initrd=ubuntu/stack-initrd.gz ramdisk_size=2109600 root=/dev/ram0 |
| 73 | EOF |
| 74 | |
| 75 | # Get Ubuntu |
Dean Troyer | dd6636b | 2011-10-11 20:28:39 -0500 | [diff] [blame] | 76 | if [ -d $PXEDIR -a -r $PXEDIR/natty-base-initrd.gz ]; then |
Dean Troyer | f2a343b | 2011-10-26 16:05:28 -0500 | [diff] [blame] | 77 | cp -pu $PXEDIR/natty-base-initrd.gz $DEST_DIR/ubuntu |
Dean Troyer | dd6636b | 2011-10-11 20:28:39 -0500 | [diff] [blame] | 78 | cat >>$CFG <<EOF |
Dean Troyer | 3f71700 | 2011-09-27 17:53:11 -0500 | [diff] [blame] | 79 | |
| 80 | LABEL ubuntu |
Dean Troyer | c945bf8 | 2011-09-29 16:15:23 -0500 | [diff] [blame] | 81 | MENU LABEL ^Ubuntu Natty |
Dean Troyer | 958fa3d | 2011-09-30 09:22:23 -0500 | [diff] [blame] | 82 | KERNEL ubuntu/vmlinuz-$KVER |
Dean Troyer | c945bf8 | 2011-09-29 16:15:23 -0500 | [diff] [blame] | 83 | APPEND initrd=ubuntu/natty-base-initrd.gz ramdisk_size=419600 root=/dev/ram0 |
Dean Troyer | 3f71700 | 2011-09-27 17:53:11 -0500 | [diff] [blame] | 84 | EOF |
Dean Troyer | 1f80bfb | 2011-09-27 22:19:32 -0500 | [diff] [blame] | 85 | fi |
Dean Troyer | 1f80bfb | 2011-09-27 22:19:32 -0500 | [diff] [blame] | 86 | |
| 87 | # Local disk boot |
Dean Troyer | dd6636b | 2011-10-11 20:28:39 -0500 | [diff] [blame] | 88 | cat >>$CFG <<EOF |
Dean Troyer | 1f80bfb | 2011-09-27 22:19:32 -0500 | [diff] [blame] | 89 | |
| 90 | LABEL local |
Dean Troyer | c945bf8 | 2011-09-29 16:15:23 -0500 | [diff] [blame] | 91 | MENU LABEL ^Local disk |
Dean Troyer | 1f80bfb | 2011-09-27 22:19:32 -0500 | [diff] [blame] | 92 | LOCALBOOT 0 |
| 93 | EOF |