带有 lz4 压缩内核的 Xen pvgrub

带有 lz4 压缩内核的 Xen pvgrub

我正在使用 pvgrub 在 xen 4.11 上运行 PV guest 虚拟机。最近发布的 ubuntu (>19.04) 似乎已切换到 lz4 压缩内核。这些内核在直接启动时工作正常,但在 pvgrub 和 pvgrub2 下它们似乎无法启动。

最新版本的 ubuntu focus 20.04。来宾内核 5.4.0-28。

error: not xen image.                [ vmlinuz-5.4.0-28-gen  10B  0%  0.17B/s ]
error: you need to load the kernel first.

Press any key to continue...

相同的设置适用于较旧的内核(例如 4.19)

我注意到 xen 本身存在一个问题,有人让这些内核与 pvgrub 一起工作吗?

答案1

感谢 Andy 在 xen-users 邮件列表上的一些建议,我有了一个临时的解决办法。听起来 lz4 还不支持。

针对 Ubuntu PV 来宾,我编写了以下内容作为 apt hook,使用 extract-vmlinux 在安装过程中解压缩内核。 https://raw.githubusercontent.com/torvalds/linux/master/scripts/extract-vmlinux

该钩子需要在某处extract-linux(我使用/usr/local/bin)并进入/etc/kernel/postinst.d/

#!/bin/bash

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

# extract-vmlinux is in /usr/local/bin
PATH="${PATH}:/usr/local/bin"

# Ensure we have the extract-linux tool
if ! command -v extract-vmlinux > /dev/null; then
        echo >&2 "Command 'extract-vmlinux' is not available (https://raw.githubusercontent.com/torvalds/linux/master/scripts/extract-vmlinux),  Aborting"
        exit 1
fi

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

# Create a temp file
TEMP_FILE=$(mktemp /tmp/decompress-kernel-XXXXX)
trap "rm -f ${TEMP_FILE}" 0

# If the given kernel file is still a bzimage see if its needs decompression
if echo "$(file -b "${KERNEL_PATH}")" | grep -q "^Linux kernel x86 boot executable bzImage"; then

        # Kernel is probably lz4 if there are lz4 headers in it
        LZ4_HEADER="$(printf '\002!L\030')"
        if ! grep -aqo "${LZ4_HEADER}" ${KERNEL_PATH}; then
                echo "No lz4 compression headers found, skipping..."
                exit 0
        fi

        echo "Decompressing '${KERNEL_PATH}'..."
        # Extract the kernel and replace existing if successful
        if extract-vmlinux ${KERNEL_PATH} > ${TEMP_FILE}; then

                # Double check the kernel is a valid ELF image
                if ! readelf -h ${TEMP_FILE} > /dev/null; then
                        echo >&2 "Decompression of kernel file '${KERNEL_PATH}' failed!, not a valid ELF image"
                        exit 1
                fi

                echo "Decompression of kernel file '${KERNEL_PATH}' successful"
                cp -v ${TEMP_FILE} ${KERNEL_PATH}

        else
                echo >&2 "Decompression of kernel file '${KERNEL_PATH}' failed!"
                exit 1
        fi

# Perhaps its already been decompressed
elif echo "$(file -b "${KERNEL_PATH}")" | grep -q "^ELF 64-bit LSB executable"; then
        echo "Kernel file '${KERNEL_PATH}' appears to be decompressed already. skipping"

else
        echo >&2 "Unable to determine the state of kernel file '${KERNEL_PATH}'"
        exit 1
fi

相关内容