From af8b7f05a14cdf742354c14102212ab4ce3d4659 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Mon, 9 Dec 2013 12:58:25 +0000 Subject: [PATCH] Quieten disk-image-get-kernel disk-image-get-kernel is pretty noisy and you see e.g.: $> load-image overcloud-compute.qcow2 XXX -d '/tmp/image.lWGCgPoj' -o 'tmp' -i '/home/stack/overcloud-compute.qcow2' -- Extracting kernel + ramdisk from /home/stack/overcloud-compute.qcow2 and writing them to /tmp/image.lWGCgPoj nbd 17554 0 nbd 17554 0 basename: missing operand Try 'basename --help' for more information. /dev/nbd0 disconnected tmp-vmlinuz,tmp-initrd Clean all this up so we just get: $> load-image overcloud-compute.qcow2 Extracting kernel + ramdisk from /home/stack/overcloud-compute.qcow2 to tmp-vmlinuz and tmp-initrd in /tmp/image.g6b0lG88 Change-Id: I8971ec0bbcd87157b07fc17254c56bb9f9f2a597 --- bin/disk-image-get-kernel | 10 ++++------ lib/common-functions | 4 ++-- lib/img-functions | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/bin/disk-image-get-kernel b/bin/disk-image-get-kernel index 933979c6..7d7eac0f 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 f00e06ec..f3afe39e 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 7d0f51e9..05520440 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 () {