From e33c5f6327ac54083452f6a22f2d7fc4d37ab45f Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Wed, 26 Oct 2011 15:13:00 -0500 Subject: [PATCH] Extract boot kernel from ramdisk image --- tools/build_usb_boot.sh | 55 ++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/tools/build_usb_boot.sh b/tools/build_usb_boot.sh index 332c869..c79cf2b 100755 --- a/tools/build_usb_boot.sh +++ b/tools/build_usb_boot.sh @@ -1,17 +1,11 @@ #!/bin/bash -e # build_usb_boot.sh - Create a syslinux boot environment # -# build_usb_boot.sh [-k kernel-version] destdev +# build_usb_boot.sh destdev # # Assumes syslinux is installed # Needs to run as root -KVER=`uname -r` -if [ "$1" = "-k" ]; then - KVER=$2 - shift;shift -fi - DEST_DIR=${1:-/tmp/syslinux-boot} PXEDIR=${PXEDIR:-/var/cache/devstack/pxe} OPWD=`pwd` @@ -20,7 +14,7 @@ PROGDIR=`dirname $0` if [ -b $DEST_DIR ]; then # We have a block device, install syslinux and mount it DEST_DEV=$DEST_DIR - DEST_DIR=`mktemp -d mntXXXXXX` + DEST_DIR=`mktemp -d --tmpdir mntXXXXXX` mount $DEST_DEV $DEST_DIR if [ ! -d $DEST_DIR/syslinux ]; then @@ -57,20 +51,41 @@ mkdir -p $DEST_DIR/ubuntu if [ ! -d $PXEDIR ]; then mkdir -p $PXEDIR fi -if [ ! -r $PXEDIR/vmlinuz-${KVER} ]; then - sudo chmod 644 /boot/vmlinuz-${KVER} - if [ ! -r /boot/vmlinuz-${KVER} ]; then - echo "No kernel found" - else - cp -p /boot/vmlinuz-${KVER} $PXEDIR - fi -fi -cp -p $PXEDIR/vmlinuz-${KVER} $DEST_DIR/ubuntu -if [ ! -r $PXEDIR/stack-initrd.gz ]; then + +# Get image into place +if [ ! -r $PXEDIR/stack-initrd.img ]; then cd $OPWD - sudo $PROGDIR/build_ramdisk.sh $PXEDIR/stack-initrd.gz + $PROGDIR/build_ramdisk.sh $PXEDIR/stack-initrd.img fi -cp -p $PXEDIR/stack-initrd.gz $DEST_DIR/ubuntu +if [ ! -r $PXEDIR/stack-initrd.gz ]; then + gzip -1 -c $PXEDIR/stack-initrd.img >$PXEDIR/stack-initrd.gz +fi +#cp -p $PXEDIR/stack-initrd.gz $DEST_DIR/ubuntu + +if [ ! -r $PXEDIR/vmlinuz-*-generic ]; then + MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX` + mount -t ext4 -o loop $PXEDIR/stack-initrd.img $MNTDIR + + if [ ! -r $MNTDIR/boot/vmlinuz-*-generic ]; then + echo "No kernel found" + umount $MNTDIR + rmdir $MNTDIR + if [ -n "$DEST_DEV" ]; then + umount $DEST_DIR + rmdir $DEST_DIR + fi + exit 1 + else + cp -p $MNTDIR/boot/vmlinuz-*-generic $PXEDIR + fi + umount $MNTDIR + rmdir $MNTDIR +fi + +# Get generic kernel version +KNAME=`basename $PXEDIR/vmlinuz-*-generic` +KVER=${KNAME#vmlinuz-} +cp -p $PXEDIR/vmlinuz-$KVER $DEST_DIR/ubuntu cat >>$CFG <