diff --git a/bin/disk-image-get-kernel b/bin/disk-image-get-kernel index 933979c67..7d7eac0f3 100755 --- a/bin/disk-image-get-kernel +++ b/bin/disk-image-get-kernel @@ -42,7 +42,6 @@ function show_options () { } TEMP=`getopt -o hd:i:o:x -n $SCRIPTNAME -- "$@"` -echo "XXX $TEMP" if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi # Note the quotes around `$TEMP': they are essential! @@ -73,7 +72,7 @@ source $_LIB/img-defaults source $_LIB/common-functions source $_LIB/img-functions -echo "Extracting kernel + ramdisk from $IMAGE_FILE and writing them to $OUT_DIR" +echo "Extracting kernel + ramdisk from $IMAGE_FILE to $OUT_PFX-vmlinuz and $OUT_PFX-initrd in $OUT_DIR" ensure_nbd @@ -87,15 +86,16 @@ RAMDISK= if [ -f $WORK_DIR/etc/redhat-release ]; then # Prioritize PAE if present - KERNEL=$(basename `ls -1rv $BOOTDIR/vmlinuz* | grep PAE | grep -v debug | head -1` || /bin/true) + KERNEL=$(ls -1rv $BOOTDIR/vmlinuz* | grep PAE | grep -v debug | head -1) if [ ! $KERNEL ]; then - KERNEL=$(basename `ls -1rv $BOOTDIR/vmlinuz* | grep -v debug | head -1` || /bin/true) + KERNEL=$(ls -1rv $BOOTDIR/vmlinuz* | grep -v debug | head -1) if [ ! $KERNEL ]; then echo "No suitable kernel found." exit 1 fi fi + KERNEL=$(basename $KERNEL) KERNEL_VERSION=`echo $KERNEL | sed 's/vmlinuz-//g'` RAMDISK=$(basename `ls $BOOTDIR/initramfs-$KERNEL_VERSION.img`) @@ -118,5 +118,3 @@ sudo chmod a+r $OUT_DIR/$OUT_PFX-vmlinuz sudo chmod a+r $OUT_DIR/$OUT_PFX-initrd unmount_qcow_image - -echo "$OUT_PFX-vmlinuz,$OUT_PFX-initrd" diff --git a/lib/common-functions b/lib/common-functions index f00e06ec6..f3afe39e2 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -131,7 +131,7 @@ function eval_run_d () { # Usage: map_nbd $image # Returns nbd device path function map_nbd { - (lsmod | grep '^nbd ') || sudo modprobe nbd max_part=16 + (lsmod | grep '^nbd ' >/dev/null) || sudo modprobe nbd max_part=16 if [[ $(qemu-nbd --help | grep cache) == *writeback* ]] ; then CACHE="--cache=writeback" @@ -161,7 +161,7 @@ function map_nbd { # Delete and unmount the working dir used in extracting kernel/initrd function unmount_qcow_image () { sudo umount $WORK_DIR || true - sudo qemu-nbd -d $NBD_DEV || true + sudo qemu-nbd -d $NBD_DEV >/dev/null || true sudo rm -rf $WORK_DIR trap - SIGHUP SIGINT SIGTERM EXIT diff --git a/lib/img-functions b/lib/img-functions index 7d0f51e91..055204400 100644 --- a/lib/img-functions +++ b/lib/img-functions @@ -45,7 +45,7 @@ function ensure_nbd () { exit 1 fi # prep nbd for mounting - (lsmod | grep '^nbd ') || sudo modprobe nbd max_part=16 + (lsmod | grep '^nbd ' >/dev/null) || sudo modprobe nbd max_part=16 } function ensure_sudo () {