From dabaa628a8bbe1f57f652ef7695174cd2d978df5 Mon Sep 17 00:00:00 2001 From: Christian Stewart Date: Wed, 1 Mar 2023 23:28:24 -0800 Subject: [PATCH] virt/qemu: fix mounting, arch, kernel opts, execute script Fixes #275 Signed-off-by: Christian Stewart --- configs/virt/qemu/buildroot/tools | 1 - configs/virt/qemu/kernel/qemu | 5 +++ configs/virt/qemu/resources/qemu-genimage.cfg | 17 -------- .../virt/qemu/root_overlay/etc/skiff-swap.env | 2 +- .../etc/systemd/system/ninfod.service | 1 + .../etc/systemd/system/rdisc.service | 1 + .../01-virt-qemu-startup-timeout.conf | 3 ++ .../01-virt-qemu-journal-flush.conf | 6 +++ .../systemd/system/systemd-sysupdate.service | 1 + .../scripts/mount-all.pre.d/01-qemu-mounts.sh | 16 +++++-- configs/virt/qemu/scripts/execute_qemu.sh | 43 ++++--------------- configs/virt/virtualbox/kernel/vbox | 3 +- 12 files changed, 42 insertions(+), 57 deletions(-) delete mode 100644 configs/virt/qemu/resources/qemu-genimage.cfg create mode 120000 configs/virt/qemu/root_overlay/etc/systemd/system/ninfod.service create mode 120000 configs/virt/qemu/root_overlay/etc/systemd/system/rdisc.service create mode 100644 configs/virt/qemu/root_overlay/etc/systemd/system/sshd.service.d/01-virt-qemu-startup-timeout.conf create mode 100644 configs/virt/qemu/root_overlay/etc/systemd/system/systemd-journal-flush.service.d/01-virt-qemu-journal-flush.conf create mode 120000 configs/virt/qemu/root_overlay/etc/systemd/system/systemd-sysupdate.service diff --git a/configs/virt/qemu/buildroot/tools b/configs/virt/qemu/buildroot/tools index 85180c586..bc9724156 100644 --- a/configs/virt/qemu/buildroot/tools +++ b/configs/virt/qemu/buildroot/tools @@ -3,4 +3,3 @@ BR2_PACKAGE_HOST_QEMU_SYSTEM_MODE=y BR2_PACKAGE_HOST_QEMU_VIRTFS=y BR2_PACKAGE_HOST_E2FSPROGS=y BR2_PACKAGE_HOST_GENEXT2FS=y -BR2_PACKAGE_HOST_GENIMAGE=y diff --git a/configs/virt/qemu/kernel/qemu b/configs/virt/qemu/kernel/qemu index 8c6b46ea3..1b1982159 100644 --- a/configs/virt/qemu/kernel/qemu +++ b/configs/virt/qemu/kernel/qemu @@ -17,6 +17,11 @@ CONFIG_DRM_VIRTIO_GPU=y CONFIG_EXT4_FS=y CONFIG_HW_RANDOM_VIRTIO=y CONFIG_HYPERVISOR_GUEST=y +CONFIG_VIRTUALIZATION=y +CONFIG_MEMORY_HOTPLUG=y +CONFIG_MEMORY_HOTREMOVE=y +CONFIG_VIRTIO_MEM=m +CONFIG_VIRTIO_PCI=m CONFIG_INET=y CONFIG_INPUT_EVDEV=y CONFIG_MODULES=y diff --git a/configs/virt/qemu/resources/qemu-genimage.cfg b/configs/virt/qemu/resources/qemu-genimage.cfg deleted file mode 100644 index e39a0da24..000000000 --- a/configs/virt/qemu/resources/qemu-genimage.cfg +++ /dev/null @@ -1,17 +0,0 @@ -image qemu-persist.ext4 { - ext4 { - label = "persist" - } - size = 100M -} - -image qemu-image.img { - hdimage { - } - - partition persist { - partition-type = 0x83 - image = "qemu-persist.ext4" - size = 100M - } -} diff --git a/configs/virt/qemu/root_overlay/etc/skiff-swap.env b/configs/virt/qemu/root_overlay/etc/skiff-swap.env index f21c9bd15..216f703b2 100644 --- a/configs/virt/qemu/root_overlay/etc/skiff-swap.env +++ b/configs/virt/qemu/root_overlay/etc/skiff-swap.env @@ -1 +1 @@ -SWAPFILE_SIZE=20 +DISABLE_SWAPFILE=true diff --git a/configs/virt/qemu/root_overlay/etc/systemd/system/ninfod.service b/configs/virt/qemu/root_overlay/etc/systemd/system/ninfod.service new file mode 120000 index 000000000..dc1dc0cde --- /dev/null +++ b/configs/virt/qemu/root_overlay/etc/systemd/system/ninfod.service @@ -0,0 +1 @@ +/dev/null \ No newline at end of file diff --git a/configs/virt/qemu/root_overlay/etc/systemd/system/rdisc.service b/configs/virt/qemu/root_overlay/etc/systemd/system/rdisc.service new file mode 120000 index 000000000..dc1dc0cde --- /dev/null +++ b/configs/virt/qemu/root_overlay/etc/systemd/system/rdisc.service @@ -0,0 +1 @@ +/dev/null \ No newline at end of file diff --git a/configs/virt/qemu/root_overlay/etc/systemd/system/sshd.service.d/01-virt-qemu-startup-timeout.conf b/configs/virt/qemu/root_overlay/etc/systemd/system/sshd.service.d/01-virt-qemu-startup-timeout.conf new file mode 100644 index 000000000..4dd544c31 --- /dev/null +++ b/configs/virt/qemu/root_overlay/etc/systemd/system/sshd.service.d/01-virt-qemu-startup-timeout.conf @@ -0,0 +1,3 @@ +[Service] +# Give longer for ssh-keygen to work. +TimeoutStartSec=600 diff --git a/configs/virt/qemu/root_overlay/etc/systemd/system/systemd-journal-flush.service.d/01-virt-qemu-journal-flush.conf b/configs/virt/qemu/root_overlay/etc/systemd/system/systemd-journal-flush.service.d/01-virt-qemu-journal-flush.conf new file mode 100644 index 000000000..0ffacb409 --- /dev/null +++ b/configs/virt/qemu/root_overlay/etc/systemd/system/systemd-journal-flush.service.d/01-virt-qemu-journal-flush.conf @@ -0,0 +1,6 @@ +[Unit] +# Delay flushing till system is done booting. +Before= + +[Service] +TimeoutSec=0 diff --git a/configs/virt/qemu/root_overlay/etc/systemd/system/systemd-sysupdate.service b/configs/virt/qemu/root_overlay/etc/systemd/system/systemd-sysupdate.service new file mode 120000 index 000000000..dc1dc0cde --- /dev/null +++ b/configs/virt/qemu/root_overlay/etc/systemd/system/systemd-sysupdate.service @@ -0,0 +1 @@ +/dev/null \ No newline at end of file diff --git a/configs/virt/qemu/root_overlay/opt/skiff/scripts/mount-all.pre.d/01-qemu-mounts.sh b/configs/virt/qemu/root_overlay/opt/skiff/scripts/mount-all.pre.d/01-qemu-mounts.sh index a0806b0d2..ddce2f2d5 100755 --- a/configs/virt/qemu/root_overlay/opt/skiff/scripts/mount-all.pre.d/01-qemu-mounts.sh +++ b/configs/virt/qemu/root_overlay/opt/skiff/scripts/mount-all.pre.d/01-qemu-mounts.sh @@ -1,14 +1,24 @@ export QEMU_PERSIST_DEVICE="/dev/vda" +attempts=0 +while [ ! -b ${QEMU_PERSIST_DEVICE} ]; do + attempts=$((attempts + 1)) + echo "Waiting for ${QEMU_PERSIST_DEVICE} to exist (attempt ${attempts})..." + if [ $attempts -gt 60 ]; then + echo "Waited too long for ${QEMU_PERSIST_DEVICE}, continuing without." + break + fi + sleep 1 +done + export PERSIST_DEVICE="${QEMU_PERSIST_DEVICE}1" -if [ ! -b ${QEMU_PERSIST_DEVICE} ]; then - echo "${QEMU_PERSIST_DEVICE} not found: expected persist device" -elif [ ! -b ${PERSIST_DEVICE} ]; then +if [ -b ${QEMU_PERSIST_DEVICE} ] && [ ! -b ${PERSIST_DEVICE} ]; then echo "${PERSIST_DEVICE} not found: creating partition layout" parted ${QEMU_PERSIST_DEVICE} mklabel msdos partprobe ${QEMU_PERSIST_DEVICE} || true parted -a optimal ${QEMU_PERSIST_DEVICE} -- mkpart primary ext4 2MiB "100%" partprobe ${QEMU_PERSIST_DEVICE} || true mkfs.ext4 -F -L "persist" ${PERSIST_DEVICE} + partprobe ${QEMU_PERSIST_DEVICE} || true fi export DISABLE_RESIZE_PERSIST="true" diff --git a/configs/virt/qemu/scripts/execute_qemu.sh b/configs/virt/qemu/scripts/execute_qemu.sh index 58f50c562..23a71be6c 100755 --- a/configs/virt/qemu/scripts/execute_qemu.sh +++ b/configs/virt/qemu/scripts/execute_qemu.sh @@ -3,42 +3,19 @@ set -eo pipefail IMAGES_DIR=$BUILDROOT_DIR/images QEMU_DIR=${BUILDROOT_DIR}/qemu-exec -ROOTFS_IMAGE=${QEMU_DIR}/qemu-image.img ROOTFS_DISK=${QEMU_DIR}/qemu-persist.qcow2 SHARED_DIR=${QEMU_DIR}/qemu-shared -GENIMAGE_CFG=${SKIFF_CURRENT_CONF_DIR}/resources/qemu-genimage.cfg -GENIMAGE_TMP=${QEMU_DIR}/genimage.tmp -# Sparse rootfs file -# however: embiggen-disk can be quite slow +# sparse rootfs file if [ -z "${ROOTFS_MAX_SIZE}" ]; then ROOTFS_MAX_SIZE="32G" fi mkdir -p ${QEMU_DIR} cd ${IMAGES_DIR} -if [ ! -f ${ROOTFS_IMAGE} ]; then - echo "Building qemu root image..." - mkdir -p ${QEMU_DIR}/fakeroot - # Format the image - genimage \ - --tmppath "${GENIMAGE_TMP}" \ - --rootpath "${QEMU_DIR}/fakeroot" \ - --inputpath "${IMAGES_DIR}" \ - --outputpath "${QEMU_DIR}" \ - --config "${GENIMAGE_CFG}" - rm -rf \ - ${QEMU_DIR}/fakeroot \ - ${QEMU_DIR}/qemu-resources.ext4 \ - ${QEMU_DIR}/qemu-persist.ext4 -fi if [ ! -f ${ROOTFS_DISK} ]; then # Sparse/dynamically allocated image qemu-img create -f qcow2 ${ROOTFS_DISK} ${ROOTFS_MAX_SIZE} - - # Convert existing image to sparse image & resize - # qemu-img convert -f raw -O qcow2 ${ROOTFS_IMAGE} ${ROOTFS_DISK} - # qemu-img resize ${ROOTFS_DISK} ${ROOTFS_MAX_SIZE} fi KERNEL_IMAGE=Image @@ -67,16 +44,14 @@ fi # Faster networking, but needs root: -nic tap mkdir -p ${SHARED_DIR} ${BUILDROOT_DIR}/host/bin/qemu-system \ - -bios default \ - -machine virt \ - -netdev user,id=vmnic \ -smp ${QEMU_CPUS} \ -m "size=${QEMU_MEMORY}" \ - -device virtio-net,netdev=vmnic \ - -device virtio-rng-pci \ -nographic -serial mon:stdio \ - -kernel ${KERNEL_IMAGE} \ - -initrd rootfs.cpio.lz4 \ - -append "console=ttyS0 console=tty root=/dev/ram0 crashkernel=256M" \ - -drive file=${ROOTFS_DISK},if=virtio \ - -virtfs local,path=${SHARED_DIR},mount_tag=host0,security_model=mapped,id=host0 + -device virtio-rng-pci \ + -device virtio-net,netdev=vmnic \ + -netdev user,id=vmnic \ + -kernel ${KERNEL_IMAGE} \ + -initrd rootfs.cpio.lz4 \ + -append "console=ttyS0 root=/dev/ram0" \ + -drive file=${ROOTFS_DISK},if=virtio \ + -virtfs local,path=${SHARED_DIR},mount_tag=host0,security_model=mapped,id=host0 diff --git a/configs/virt/virtualbox/kernel/vbox b/configs/virt/virtualbox/kernel/vbox index 59afe9396..df8246bbf 100644 --- a/configs/virt/virtualbox/kernel/vbox +++ b/configs/virt/virtualbox/kernel/vbox @@ -18,4 +18,5 @@ CONFIG_SATA_ACHI=y CONFIG_SND_INTEL8X0=y CONFIG_VIRTIO_PCI=m CONFIG_X86_SYSFB=y - +CONFIG_HYPERVISOR_GUEST=y +CONFIG_VIRTUALIZATION=y