From 162daf0c978ab67131f18856c816d3dbd5ed819f Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 26 Jun 2015 16:55:54 +0200 Subject: [PATCH] Use the uncompressed kernel file on arm and aarch to detect kernel version This is due to file cannot read out the kernel version on these. Many thanks to Alexander Graf finding this in old SUSE mkinitrd code. Converted by Thomas Renninger. Signed-off-by: Thomas Renninger https://bugzilla.suse.com/show_bug.cgi?id=908454 Signed-off-by: Thomas Renninger --- mkinitrd-suse.sh | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/mkinitrd-suse.sh b/mkinitrd-suse.sh index c2b314f..0f2b3c4 100755 --- a/mkinitrd-suse.sh +++ b/mkinitrd-suse.sh @@ -145,6 +145,33 @@ is_xen_kernel() { return } +# kernel_image_gz_from_image() and kernel_version_from_image() are helpers +# for arm* kernels which produce zImage files which cannot be read from +# get_kernel_version -> get rid of this workaround if possible +kernel_image_gz_from_image() { + local arch=$(uname -i) + local r=${1}.gz + + # uImage kernels can't be extracted directly. Use the vmlinux.gz instead + r=${r//uImage/vmlinux} + + # on ARM a zImage can't be extracted directly. Other platforms define it + # as a gzipped vmlinux file, but not ARM. So only on ARM, use vmlinux.gz. + if [[ $arch =~ arm ]] || [[ $arch =~ aarch ]]; then + r=${r//zImage/vmlinux} + fi + + echo $r +} + +kernel_version_from_image() { + local kernel_image="$1" kernel_image_gz=$(kernel_image_gz_from_image "$1") + + if get_kernel_version "$kernel_image" 2>/dev/null; then + return + fi + get_kernel_version "$kernel_image_gz" 2>/dev/null +} # Taken over from SUSE mkinitrd default_kernel_images() { @@ -183,7 +210,8 @@ default_kernel_images() { [ -L "$boot_dir/$kernel_image" ] && continue [ "${kernel_image%%.gz}" != "$kernel_image" ] && continue - kernel_version=$(/usr/bin/get_kernel_version \ + + kernel_version=$(kernel_version_from_image \ $boot_dir/$kernel_image 2> /dev/null) initrd_image=$(echo $kernel_image | sed -e "s|${regex}|initrd|") if [ "$kernel_image" != "$initrd_image" -a \