Hi,

On 16/02/2023 18:18, Samuel Thibault wrote:
Andy Smith, le jeu. 16 févr. 2023 15:44:21 +0000, a ecrit:
   - The PV part of grub is quite old and from what I understand
     implemented in a strange way

Ah, uh :/

     that no one wants to maintain any
     more, so this part of grub is stuck without ability to
     understand the newer kernel compressions.

I've been using the attached script to get around the problem. It tries to decompress the cloud kernel and then recompress it with something that grub-xen can handle. If recompression fails, it leaves an uncompressed kernel, which also works, in place.

The script needs to be installed in /etc/kernel/postinst.d/.

--
        Aleksi Suhonen

        () ascii ribbon campaign
        /\ support plain text e-mail
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-only
# ----------------------------------------------------------------------
# kernel-recompress-hook - recompress cloud kernels for grub-xen
#               Place this script in /etc/kernel/postinst.d/
#               Requires: binutils, lz4, xz-utils
# (c) 2021-2023 Aleksi Suhonen <reportbug-2...@ssd.axu.tm>
#
# Distilled from extract-vmlinux by
# (c) 2009,2010 Dick Streefland <d...@streefland.net>
# (c) 2011      Corentin Chary <corentin.ch...@gmail.com>
#
# ----------------------------------------------------------------------

KERNEL_VERSION="$1"
KERNEL_PATH="$2"

# The KERNEL_PATH must be valid
if [ ! -f "${KERNEL_PATH}" ]; then
        echo >&2 "Kernel file '${KERNEL_PATH}' not found. Aborting"
        exit 1
fi

# Prepare temp files:
tmp=$(mktemp /boot/vmlinux-XXXXX)
trap "rm -f $tmp ${tmp}.xz" 0

# Try to find the LZ4 header and decompress from here
LZ4_HEADER="$(printf '\002!L\030')"
for pos in `fgrep -abo "$LZ4_HEADER" "$KERNEL_PATH"`
do
        # grep counts bytes from 0, while tail counts from 1...
        pos=$((1+${pos%%:*}))
        rm -f $tmp
        tail -c+$pos "$KERNEL_PATH" | lz4 -d >$tmp
        readelf -h $tmp >/dev/null 2>&1 && break
        echo "False LZ4 header at ${pos}, looking for more..."
done

if ! readelf -h $tmp > /dev/null; then
        echo >&2 "Decompression of kernel file '${KERNEL_PATH}' failed!, not a 
valid ELF image"
        exit 0
fi

echo "Decompression of kernel file '${KERNEL_PATH}' successful"

if xz --check=crc32 --x86 --lzma2=dict=32MiB $tmp; then
        echo "Recompression also successful"
        mv -fv ${tmp}.xz ${KERNEL_PATH}
        echo "Replacement of kernel file successful"
else
        echo "Recompression unsuccessful"
        mv -fv ${tmp} ${KERNEL_PATH}
        echo "Replacement of kernel file successful"
fi

exit 0
#EOF

Reply via email to