[PATCH] supermin: Die with an error if no kernels found (RHBZ#539746).
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://et.redhat.com/~rjones/libguestfs/ See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html
Richard W.M. Jones wrote:
Subject: [PATCH] supermin: Die with an error if no kernels found (RHBZ#539746).
--- appliance/libguestfs-supermin-helper.in | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/appliance/libguestfs-supermin-helper.in b/appliance/libguestfs-supermin-helper.in index 69f22e4..3e4a260 100755 --- a/appliance/libguestfs-supermin-helper.in +++ b/appliance/libguestfs-supermin-helper.in @@ -39,6 +39,12 @@ initrd="$3"
arch=$(echo "@host_cpu@" | sed 's/^i.86$/i?86/') kernels=$(ls -1vr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen; ls -1vr /boot/vmlinuz-* 2>/dev/null | grep -v xen) + +if [ -z "$kernels" ]; then + echo "$0: failed to find a suitable kernel" >&2 + exit 1 +fi + for f in $kernels; do b=$(basename "$f") b=$(echo "$b" | sed 's,vmlinuz-,,')
Hi Rich, That change looks fine. However, the context can be improved slightly. First, on this kernels-assigning line, kernels=$(ls -1vr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen; ls -1vr /boot/vmlinuz-* 2>/dev/null | grep -v xen) if you add ls' -d option, that will prevent a false-positive match if /boot/vmlinuz-* ever matches a directory containing something whose name includes "xen". Also, you can avoid duplicating the "2>/dev/null | grep -v xen" part by using a single invocatin of ls, and then I noticed that the expansion of the second glob, /boot/vmlinuz-*, would include anything matched by the first one, so this is adequate: kernels=$(ls -1dvr /boot/vmlinuz-* 2>/dev/null | grep -v xen) diff --git a/appliance/libguestfs-supermin-helper.in b/appliance/libguestfs-supermin-helper.in index 69f22e4..a24d905 100755 --- a/appliance/libguestfs-supermin-helper.in +++ b/appliance/libguestfs-supermin-helper.in @@ -38,7 +38,8 @@ initrd="$3" # without arch second. arch=$(echo "@host_cpu@" | sed 's/^i.86$/i?86/') -kernels=$(ls -1vr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen; ls -1vr /boot/vmlinuz-* 2>/dev/null | grep -v xen) +kernels=$(ls -1dvr /boot/vmlinuz-* 2>/dev/null | grep -v xen) + for f in $kernels; do b=$(basename "$f") b=$(echo "$b" | sed 's,vmlinuz-,,')
On Wed, Nov 25, 2009 at 09:25:37AM +0100, Jim Meyering wrote:
kernels=$(ls -1vr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen; ls -1vr /boot/vmlinuz-* 2>/dev/null | grep -v xen)
if you add ls' -d option, that will prevent a false-positive match if /boot/vmlinuz-* ever matches a directory containing something whose name includes "xen".
Also, you can avoid duplicating the "2>/dev/null | grep -v xen" part by using a single invocatin of ls, and then I noticed that the expansion of the second glob, /boot/vmlinuz-*, would include anything matched by the first one, so this is adequate:
kernels=$(ls -1dvr /boot/vmlinuz-* 2>/dev/null | grep -v xen)
diff --git a/appliance/libguestfs-supermin-helper.in b/appliance/libguestfs-supermin-helper.in index 69f22e4..a24d905 100755 --- a/appliance/libguestfs-supermin-helper.in +++ b/appliance/libguestfs-supermin-helper.in @@ -38,7 +38,8 @@ initrd="$3" # without arch second.
arch=$(echo "@host_cpu@" | sed 's/^i.86$/i?86/') -kernels=$(ls -1vr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen; ls -1vr /boot/vmlinuz-* 2>/dev/null | grep -v xen) +kernels=$(ls -1dvr /boot/vmlinuz-* 2>/dev/null | grep -v xen)
OK - but we need to keep $arch in there otherwise it would select the wrong arch kernel ... Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v
On Wed, Nov 25, 2009 at 09:25:37AM +0100, Jim Meyering wrote:
First, on this kernels-assigning line,
kernels=$(ls -1vr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen; ls -1vr /boot/vmlinuz-* 2>/dev/null | grep -v xen)
if you add ls' -d option, that will prevent a false-positive match if /boot/vmlinuz-* ever matches a directory containing something whose name includes "xen".
Also, you can avoid duplicating the "2>/dev/null | grep -v xen" part by using a single invocatin of ls, and then I noticed that the expansion of the second glob, /boot/vmlinuz-*, would include anything matched by the first one, so this is adequate:
kernels=$(ls -1dvr /boot/vmlinuz-* 2>/dev/null | grep -v xen)
On rereading this, I understand the mistake. The order that the kernels is presented in is significant, which is why we first search for $arch-specific kernels, and secondly for general kernels (in both cases avoiding Xen PV kernels). However adding -d is an improvement. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/
Richard W.M. Jones wrote:
On Wed, Nov 25, 2009 at 09:25:37AM +0100, Jim Meyering wrote:
First, on this kernels-assigning line,
kernels=$(ls -1vr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen; ls -1vr /boot/vmlinuz-* 2>/dev/null | grep -v xen)
if you add ls' -d option, that will prevent a false-positive match if /boot/vmlinuz-* ever matches a directory containing something whose name includes "xen".
Also, you can avoid duplicating the "2>/dev/null | grep -v xen" part by using a single invocatin of ls, and then I noticed that the expansion of the second glob, /boot/vmlinuz-*, would include anything matched by the first one, so this is adequate:
kernels=$(ls -1dvr /boot/vmlinuz-* 2>/dev/null | grep -v xen)
On rereading this, I understand the mistake.
The order that the kernels is presented in is significant, which is why we first search for $arch-specific kernels, and secondly for general kernels (in both cases avoiding Xen PV kernels).
Ahh.. good point. I hadn't looked at how $kernels was used. Keeping the two globs, you can still use only one ls invocation, (adding ls's -U (don't sort) option): kernels=$(ls -1duvr /boot/vmlinuz-*.$arch* /boot/vmlinuz-* 2>/dev/null \ | grep -v xen) Does it matter that ls's -v (version sort) option is relatively new? It was added in coreutils-7.0 (2008-10-05).
On Wed, Nov 25, 2009 at 12:02:55PM +0100, Jim Meyering wrote:
Does it matter that ls's -v (version sort) option is relatively new? It was added in coreutils-7.0 (2008-10-05).
It exists in RHEL 5.4, which is all I care about :-) Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/
participants (2)
-
Jim Meyering -
Richard W.M. Jones