From 2b7ea39ce245073dd818bd7f7858d3adbeede861 Mon Sep 17 00:00:00 2001 From: Jeremi Piotrowski Date: Thu, 11 Apr 2024 13:40:23 +0000 Subject: [PATCH 1/5] coreos-base/oem-xen: Introduce xen configs Simple stuff, setting console to hvc0 and enabling autologin. Signed-off-by: Jeremi Piotrowski --- build_library/vm_image_util.sh | 1 + .../coreos-base/oem-xen/files/grub.cfg | 3 ++ .../coreos-base/oem-xen/files/oem-release | 4 +++ .../coreos-base/oem-xen/metadata.xml | 4 +++ .../coreos-base/oem-xen/oem-xen-0.0.1.ebuild | 28 +++++++++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 sdk_container/src/third_party/coreos-overlay/coreos-base/oem-xen/files/grub.cfg create mode 100644 sdk_container/src/third_party/coreos-overlay/coreos-base/oem-xen/files/oem-release create mode 100644 sdk_container/src/third_party/coreos-overlay/coreos-base/oem-xen/metadata.xml create mode 100644 sdk_container/src/third_party/coreos-overlay/coreos-base/oem-xen/oem-xen-0.0.1.ebuild diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index 48f98188866..60b93706dd1 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -133,6 +133,7 @@ IMG_qemu_uefi_OEM_SYSEXT=oem-qemu ## xen IMG_xen_CONF_FORMAT=xl +IMG_xen_OEM_PACKAGE=oem-xen ## virtualbox IMG_virtualbox_DISK_FORMAT=vmdk_ide diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-xen/files/grub.cfg b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-xen/files/grub.cfg new file mode 100644 index 00000000000..2ac83f956ae --- /dev/null +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-xen/files/grub.cfg @@ -0,0 +1,3 @@ +# Flatcar GRUB settings +set linux_console="console=hvc0" +set linux_append="flatcar.autologin" diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-xen/files/oem-release b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-xen/files/oem-release new file mode 100644 index 00000000000..0e5b0140c26 --- /dev/null +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-xen/files/oem-release @@ -0,0 +1,4 @@ +ID=xen +VERSION_ID=@@OEM_VERSION_ID@@ +NAME="Xen" +BUG_REPORT_URL="https://issues.flatcar.org" diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-xen/metadata.xml b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-xen/metadata.xml new file mode 100644 index 00000000000..097975e3adc --- /dev/null +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-xen/metadata.xml @@ -0,0 +1,4 @@ + + + + diff --git a/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-xen/oem-xen-0.0.1.ebuild b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-xen/oem-xen-0.0.1.ebuild new file mode 100644 index 00000000000..3c33f1a56a7 --- /dev/null +++ b/sdk_container/src/third_party/coreos-overlay/coreos-base/oem-xen/oem-xen-0.0.1.ebuild @@ -0,0 +1,28 @@ +# Copyright (c) 2013 CoreOS, Inc.. All rights reserved. +# Distributed under the terms of the GNU General Public License v2 + +EAPI=7 + +DESCRIPTION="OEM suite for Xen" +HOMEPAGE="" +SRC_URI="" + +LICENSE="Apache-2.0" +SLOT="0" +KEYWORDS="amd64" +IUSE="" + +# no source directory +S="${WORKDIR}" + +src_prepare() { + default + sed -e "s\\@@OEM_VERSION_ID@@\\${PVR}\\g" \ + "${FILESDIR}/oem-release" > "${T}/oem-release" || die +} + +src_install() { + insinto "/oem" + doins "${FILESDIR}/grub.cfg" + doins "${T}/oem-release" +} From 21f4a50dfd00cafa8cf2d56961d95ef32e1cb5d7 Mon Sep 17 00:00:00 2001 From: Jeremi Piotrowski Date: Thu, 11 Apr 2024 13:44:50 +0000 Subject: [PATCH 2/5] Switch to xen-pvh grub implementation Our Xen configs don't currently work because xen grub uses a special code path in grub that does not support zstd compressed kernels. We switched kernel compression to zstd two years ago. The only grub xen config that supports this is xen-pvh. Switch our grub xen to the pvh and adapt configs to run domU in PVH mode. With this change the pygrub config works. Signed-off-by: Jeremi Piotrowski --- build_library/build_image_util.sh | 2 +- build_library/grub_install.sh | 5 +++-- build_library/vm_image_util.sh | 4 ++-- .../coreos-overlay/profiles/coreos/amd64/make.defaults | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/build_library/build_image_util.sh b/build_library/build_image_util.sh index c2863b7bd1e..9616420e492 100755 --- a/build_library/build_image_util.sh +++ b/build_library/build_image_util.sh @@ -857,7 +857,7 @@ EOF # This script must mount the ESP partition differently, so run it after unmount if [[ "${install_grub}" -eq 1 ]]; then local target - local target_list="i386-pc x86_64-efi x86_64-xen" + local target_list="i386-pc x86_64-efi i386-xen_pvh" if [[ ${BOARD} == "arm64-usr" ]]; then target_list="arm64-efi" fi diff --git a/build_library/grub_install.sh b/build_library/grub_install.sh index db83d614a1a..53c3ba129ff 100755 --- a/build_library/grub_install.sh +++ b/build_library/grub_install.sh @@ -64,7 +64,7 @@ case "${FLAGS_target}" in CORE_NAME="core.efi" SBAT_ARG=( --sbat "${BOARD_ROOT}/usr/share/grub/sbat.csv" ) ;; - x86_64-xen) + i386-xen_pvh) CORE_NAME="core.elf" ;; arm64-efi) @@ -234,9 +234,10 @@ case "${FLAGS_target}" in "${FLAGS_copy_shim}" fi ;; - x86_64-xen) + i386-xen_pvh) info "Installing default x86_64 Xen bootloader." sudo mkdir -p "${ESP_DIR}/xen" "${ESP_DIR}/boot/grub" + # keep the pvboot name for chainloading? sudo cp "${ESP_DIR}/${GRUB_DIR}/${CORE_NAME}" \ "${ESP_DIR}/xen/pvboot-x86_64.elf" sudo cp "${BUILD_LIBRARY_DIR}/menu.lst" \ diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index 60b93706dd1..7e37c088b5f 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -1004,9 +1004,9 @@ _write_xl_conf() { echo 'extra = "(hd0,0)/boot/grub/menu.lst"' >> "${pvgrub}" # The rest is the same - tee -a "${pygrub}" >> "${pvgrub}" </dev/null < Date: Thu, 11 Apr 2024 13:48:47 +0000 Subject: [PATCH 3/5] build_library: Switch pvgrub xen config to use our grub In PVH mode grub can't be chainloaded from grub, so we either need to use pygrub or the host provided grub needs to support Flatcar specifics. Publish our xen-pvh grub along with the image and use it from the pvgrub config. Signed-off-by: Jeremi Piotrowski --- build_library/build_image_util.sh | 3 +++ build_library/grub_install.sh | 6 ++++++ build_library/vm_image_util.sh | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/build_library/build_image_util.sh b/build_library/build_image_util.sh index 9616420e492..ec095006eee 100755 --- a/build_library/build_image_util.sh +++ b/build_library/build_image_util.sh @@ -874,6 +874,9 @@ EOF ) fi for target in ${target_list}; do + if [[ "${target}" = "i386-xen_pvh" ]]; then + grub_args+=(--copy_xen_grub="${BUILD_DIR}/${image_grub%.grub}-grub-xen_pvh.bin") + fi ${BUILD_LIBRARY_DIR}/grub_install.sh \ --board="${BOARD}" \ --target="${target}" \ diff --git a/build_library/grub_install.sh b/build_library/grub_install.sh index 53c3ba129ff..28cdeb95e40 100755 --- a/build_library/grub_install.sh +++ b/build_library/grub_install.sh @@ -26,6 +26,8 @@ DEFINE_string copy_efi_grub "" \ "Copy the EFI GRUB image to the specified path." DEFINE_string copy_shim "" \ "Copy the shim image to the specified path." +DEFINE_string copy_xen_grub "" \ + "Copy Xen PVH grub to the specified path." # Parse flags FLAGS "$@" || exit 1 @@ -242,6 +244,10 @@ case "${FLAGS_target}" in "${ESP_DIR}/xen/pvboot-x86_64.elf" sudo cp "${BUILD_LIBRARY_DIR}/menu.lst" \ "${ESP_DIR}/boot/grub/menu.lst" + if [[ -n "${FLAGS_copy_xen_grub}" ]]; then + cp --no-preserve=mode "${ESP_DIR}/xen/pvboot-x86_64.elf" \ + "${FLAGS_copy_xen_grub}" + fi ;; arm64-efi) info "Installing default arm64 UEFI bootloader." diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index 7e37c088b5f..a00bd8e3a8b 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -991,6 +991,7 @@ _write_xl_conf() { local src_name=$(basename "$VM_SRC_IMG") local dst_name=$(basename "$VM_DST_IMG") local dst_dir=$(dirname "$VM_DST_IMG") + local grub_name="flatcar_production_image-grub-xen_pvh.bin" local pygrub="${dst_dir}/$(_src_to_dst_name "${src_name}" "_pygrub.cfg")" local pvgrub="${dst_dir}/$(_src_to_dst_name "${src_name}" "_pvgrub.cfg")" local disk_format=$(_get_vm_opt DISK_FORMAT) @@ -1000,8 +1001,7 @@ _write_xl_conf() { echo 'bootloader = "pygrub"' >> "${pygrub}" echo '# Xen PV config using pvgrub' > "${pvgrub}" - echo 'kernel = "/usr/lib/xen/boot/pv-grub-x86_64.gz"' >> "${pvgrub}" - echo 'extra = "(hd0,0)/boot/grub/menu.lst"' >> "${pvgrub}" + echo "kernel = \"${grub_name}\"" >> "${pvgrub}" # The rest is the same tee -a "${pygrub}" "${pvgrub}" >/dev/null < Date: Thu, 11 Apr 2024 13:50:57 +0000 Subject: [PATCH 4/5] build_library: Add xen hvm config For completeness. Signed-off-by: Jeremi Piotrowski --- build_library/vm_image_util.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index a00bd8e3a8b..58d1aebbc96 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -994,6 +994,7 @@ _write_xl_conf() { local grub_name="flatcar_production_image-grub-xen_pvh.bin" local pygrub="${dst_dir}/$(_src_to_dst_name "${src_name}" "_pygrub.cfg")" local pvgrub="${dst_dir}/$(_src_to_dst_name "${src_name}" "_pvgrub.cfg")" + local hvm="${dst_dir}/$(_src_to_dst_name "${src_name}" "_hvm.cfg")" local disk_format=$(_get_vm_opt DISK_FORMAT) # Set up the few differences between pygrub and pvgrub @@ -1003,9 +1004,14 @@ _write_xl_conf() { echo '# Xen PV config using pvgrub' > "${pvgrub}" echo "kernel = \"${grub_name}\"" >> "${pvgrub}" + echo 'type = "hvm"'> "${hvm}" # The rest is the same tee -a "${pygrub}" "${pvgrub}" >/dev/null </dev/null < Date: Thu, 11 Apr 2024 13:59:10 +0000 Subject: [PATCH 5/5] changelog: Add entry for xen bugfixes Signed-off-by: Jeremi Piotrowski --- changelog/bugfixes/2024-04-11-xen.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelog/bugfixes/2024-04-11-xen.md diff --git a/changelog/bugfixes/2024-04-11-xen.md b/changelog/bugfixes/2024-04-11-xen.md new file mode 100644 index 00000000000..b03cbcad9d0 --- /dev/null +++ b/changelog/bugfixes/2024-04-11-xen.md @@ -0,0 +1,2 @@ +- Fixes for running Flatcar as xen domU in PV(H) mode. This required switching + to xen-pvh so only PVH and HVM modes are supported.