Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch xen to PVH mode #1879

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion build_library/build_image_util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}" \
Expand Down
11 changes: 9 additions & 2 deletions build_library/grub_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -64,7 +66,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)
Expand Down Expand Up @@ -234,13 +236,18 @@ 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" \
"${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."
Expand Down
20 changes: 15 additions & 5 deletions build_library/vm_image_util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -990,22 +991,28 @@ _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 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
echo '# Xen PV config using pygrub' > "${pygrub}"
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}"

echo 'type = "hvm"'> "${hvm}"
# The rest is the same
tee -a "${pygrub}" >> "${pvgrub}" <<EOF
tee -a "${pygrub}" "${pvgrub}" >/dev/null <<EOF
type = "pvh"
EOF

# The rest is the same
tee -a "${pygrub}" "${hvm}" "${pvgrub}" >/dev/null <<EOF

builder = "generic"
name = "${VM_NAME}"

memory = "${vm_mem}"
Expand All @@ -1023,13 +1030,16 @@ xl create -c "${pygrub##*/}"
Or with pvgrub instead:
xl create -c "${pvgrub##*/}"

For HVM:
xl create -c "${hvm##*/}"

Detach from the console with ^] and reattach with:
xl console ${VM_NAME}

Kill the vm with:
xl destroy ${VM_NAME}
EOF
VM_GENERATED_FILES+=( "${pygrub}" "${pvgrub}" "${VM_README}" )
VM_GENERATED_FILES+=( "${pygrub}" "${pvgrub}" "${hvm}" "${VM_README}" )
}

_write_ovf_virtualbox_conf() {
Expand Down
2 changes: 2 additions & 0 deletions changelog/bugfixes/2024-04-11-xen.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Flatcar GRUB settings
set linux_console="console=hvc0"
set linux_append="flatcar.autologin"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ID=xen
VERSION_ID=@@OEM_VERSION_ID@@
NAME="Xen"
BUG_REPORT_URL="https://issues.flatcar.org"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
</pkgmetadata>
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ BOOTSTRAP_USE="${BOOTSTRAP_USE} -pax_kernel -xtpax"
USE="-pax_kernel -urandom -xtpax"

# Enable our assorted Grub targets
GRUB_PLATFORMS="efi-64 pc xen"
GRUB_PLATFORMS="efi-64 pc xen-pvh"
Loading