From patchwork Fri Oct 25 00:21:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Santos X-Patchwork-Id: 1183669 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=busybox.net (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="IYG/6WoZ"; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46zlCw3vD1z9sPh for ; Fri, 25 Oct 2019 11:21:46 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 5F24B84353; Fri, 25 Oct 2019 00:21:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id e+kJnIMGLJbI; Fri, 25 Oct 2019 00:21:41 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 43BE487831; Fri, 25 Oct 2019 00:21:41 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id D689F1BF9CC for ; Fri, 25 Oct 2019 00:21:39 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id D0BC385BC8 for ; Fri, 25 Oct 2019 00:21:39 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id u2mmLf-OtUNL for ; Fri, 25 Oct 2019 00:21:38 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by fraxinus.osuosl.org (Postfix) with ESMTPS id B2861844B5 for ; Fri, 25 Oct 2019 00:21:38 +0000 (UTC) Received: by mail-qt1-f195.google.com with SMTP id u22so606631qtq.13 for ; Thu, 24 Oct 2019 17:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=EZVRngY/EMm9BzplW4peboi4/zw9Po6tCxFv02eC4BM=; b=IYG/6WoZF2trra+ogJx6LDL3Aap8G4hvj5z2sHSJtvSLfvT5CN4WqmPCh8QV2Gsplj PEad5CB61329v6LzQVKeDJ4955RfyUY83446rCZX5vkxos4fRL2NlJjX7eJ6u0rdoL9/ Gbzv9okgeBP0nmbrQ+UON/AaVCbZOiR7/TmlMhuG432HpnNjBj9/0u600zTvUqWyiHsc 6SEqNhJcK8ieUCki4iWJpNdQojXHcHgrx8yZAxU/hhvKnHs3wQnrBn67c7nYWqxymfGN x7zQbFbu6ME1ic3WaurvSCQsknalLzQ0aQYjYpeToGUsOexQBMfal2f2c6aVIfC+aqV1 23Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=EZVRngY/EMm9BzplW4peboi4/zw9Po6tCxFv02eC4BM=; b=LRj/b2OB4cj8UeHonb987mOquMrL8oMYkQIvDq1P5U68yDZtzwaIlxa08mvi/0i2W9 Qxd3tly0eqRtlFkvaubMzWXffUb7MBpGDY2AouuN2512TrktJxctkaNMpyK2rdPOmx4T 6BUw2OIuBX+z6LhHHoNd71JDRZ1MykhqX0yxA9iZBunVTTO/k45I71Md0uHGfiry5uX7 J2jZFE+bNGWZgD/YupqD0zfFLW2Kd49Ek4m80CNyJbW1d21ljO5ACX7eda3E0aI9XmP9 XAnfKLClOQOdNOdt1LYZlddacgL2nJoDgAPXjlNo9F712vNuLBrTq4gE9Q3WvHRNk15L Ddnw== X-Gm-Message-State: APjAAAUP5WgMi+v0uNpPdvdNHkfvmzqlU3PEO/Pqo6pGKBcIlVqGcr5Z 77E4dX6GBd6C5Lh0UC5d+eyN2c3h X-Google-Smtp-Source: APXvYqzXpS9W93EbeYlLg0otu3JEwTf8vAq+OwIvunqF3vwrnR64FbUckVjyw/wjkz6yFHAphO8bIw== X-Received: by 2002:a0c:fb0b:: with SMTP id c11mr717264qvp.88.1571962897155; Thu, 24 Oct 2019 17:21:37 -0700 (PDT) Received: from casantos.remote.csb ([177.134.42.67]) by smtp.gmail.com with ESMTPSA id r6sm174992qtp.75.2019.10.24.17.21.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 17:21:36 -0700 (PDT) From: unixmania@gmail.com To: buildroot@buildroot.org Date: Thu, 24 Oct 2019 21:21:24 -0300 Message-Id: <20191025002124.5004-1-unixmania@gmail.com> X-Mailer: git-send-email 2.18.1 Subject: [Buildroot] [PATCH] package/test-vm: a virtual machine image to test libvirt X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Carlos Santos , Matthew Weber MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Carlos Santos Builds and installs a virtual machine disk image to test libvirt. Only x86_64 is supported at the moment. Refer to package/test-vm/readme.txt for instructions. Signed-off-by: Carlos Santos --- CC: Matthew Weber --- --- package/Config.in | 1 + package/test-vm/Config.in | 4 ++ package/test-vm/grub-bios.cfg | 10 +++++ package/test-vm/post-build.sh | 11 ++++++ package/test-vm/readme.txt | 63 +++++++++++++++++++++++++++++++ package/test-vm/test-vm.mk | 25 ++++++++++++ package/test-vm/test-vm.xml | 59 +++++++++++++++++++++++++++++ package/test-vm/test_vm_defconfig | 28 ++++++++++++++ 8 files changed, 201 insertions(+) create mode 100644 package/test-vm/Config.in create mode 100644 package/test-vm/grub-bios.cfg create mode 100755 package/test-vm/post-build.sh create mode 100644 package/test-vm/readme.txt create mode 100644 package/test-vm/test-vm.mk create mode 100644 package/test-vm/test-vm.xml create mode 100644 package/test-vm/test_vm_defconfig diff --git a/package/Config.in b/package/Config.in index a3fb5af04b..d71582dafd 100644 --- a/package/Config.in +++ b/package/Config.in @@ -2290,6 +2290,7 @@ menu "System tools" source "package/systemd-bootchart/Config.in" source "package/sysvinit/Config.in" source "package/tar/Config.in" + source "package/test-vm/Config.in" source "package/tpm-tools/Config.in" source "package/tpm2-abrmd/Config.in" source "package/tpm2-tools/Config.in" diff --git a/package/test-vm/Config.in b/package/test-vm/Config.in new file mode 100644 index 0000000000..efaa475e22 --- /dev/null +++ b/package/test-vm/Config.in @@ -0,0 +1,4 @@ +config BR2_PACKAGE_TEST_VM + bool "test-vm" + help + A test VM for Libvirt. diff --git a/package/test-vm/grub-bios.cfg b/package/test-vm/grub-bios.cfg new file mode 100644 index 0000000000..e3cc13a269 --- /dev/null +++ b/package/test-vm/grub-bios.cfg @@ -0,0 +1,10 @@ +serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 +terminal_input serial +terminal_output serial + +set default="0" +set timeout="5" + +menuentry "Buildroot" { + linux /boot/bzImage root=/dev/vda1 rootwait console=ttyS0,115200n8 locale.LANG=C net.ifnames=0 +} diff --git a/package/test-vm/post-build.sh b/package/test-vm/post-build.sh new file mode 100755 index 0000000000..5e4dc88a3d --- /dev/null +++ b/package/test-vm/post-build.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# exit on any failure +set -e + +MY_DIR=$(dirname "$0") + +cp -f "$MY_DIR/grub-bios.cfg" "$TARGET_DIR/boot/grub/grub.cfg" + +# Copy grub 1st stage to binaries, required for genimage +cp -f "$HOST_DIR/lib/grub/i386-pc/boot.img" "$BINARIES_DIR" diff --git a/package/test-vm/readme.txt b/package/test-vm/readme.txt new file mode 100644 index 0000000000..ca04a749d6 --- /dev/null +++ b/package/test-vm/readme.txt @@ -0,0 +1,63 @@ +How to use this package + +1. Build an image with a defconfig containing + +BR2_x86_64=y + +BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV=y +BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y + +BR2_PACKAGE_QEMU=y +BR2_PACKAGE_QEMU_CUSTOM_TARGETS="x86_64-softmmu" +BR2_PACKAGE_QEMU_SLIRP=y + +BR2_PACKAGE_LIBVIRT=y +BR2_PACKAGE_LIBVIRT_QEMU=y +BR2_PACKAGE_TEST_VM=y + +For remote accesss you will need an SSH server + +BR2_PACKAGE_DROPBEAR=y +BR2_PACKAGE_DROPBEAR_DISABLE_REVERSEDNS=y + +Ensure that the kernel configuration has + +CONFIG_VFIO=m +CONFIG_VFIO_PCI=m +CONFIG_VFIO_MDEV=m +CONFIG_VFIO_MDEV_DEVICE=m +CONFIG_VHOST_NET=m +CONFIG_VHOST_VSOCK=y +CONFIG_TUN=m + +The rootfs size must be arount 100MB for a sysvinit/busybox init system and +200MB for a systemd system. + +Configure the OS to obtain an IP address, either statically or via DHCP. + +2. Boot and log in as root, then run + + # virsh define /etc/vm-templates/test-xm.xml + # virsh start test-vm && virsh console test-vm + +Leave the vm console by hitting ^] + +Shutdown the vm + + # virsh shutdown test-vm + +3. Access the vm remotely using virt-manager + +On a machine with virt-manager installed, open it and create a new connection. +Supposing that the host IP address is 192.168.2.2: + + File->Add Connection + + Name: QEMU/KVM on 192.168.2.2 + Libvirt URL: qemu+ssh://root@192.168.2.2/system + +Double-click on the connection and provide the root user password. A "test-vm" +item will appear (supposing that you wen through step 2, above). Double-click +on it. Use the vm window to play with it. + +Have fun! diff --git a/package/test-vm/test-vm.mk b/package/test-vm/test-vm.mk new file mode 100644 index 0000000000..cc7f5b9240 --- /dev/null +++ b/package/test-vm/test-vm.mk @@ -0,0 +1,25 @@ +################################################################################ +# +# test-vm +# +################################################################################ + +define TEST_VM_CONFIGURE_CMDS + $(MAKE) O=$(@D) \ + BR2_DEFCONFIG=$(TEST_VM_PKGDIR)/test_vm_defconfig \ + BR2_DL_DIR=$(BR2_DL_DIR) \ + defconfig +endef + +define TEST_VM_BUILD_CMDS + $(MAKE) -C $(@D) +endef + +define TEST_VM_INSTALL_TARGET_CMDS + $(INSTALL) -D -m 644 $(@D)/images/disk.img \ + $(TARGET_DIR)/var/lib/libvirt/images/test-vm.img + $(INSTALL) -D -m 644 $(TEST_VM_PKGDIR)/test-vm.xml \ + $(TARGET_DIR)/etc/vm-templates/test-xm.xml +endef + +$(eval $(generic-package)) diff --git a/package/test-vm/test-vm.xml b/package/test-vm/test-vm.xml new file mode 100644 index 0000000000..c0821f9f7d --- /dev/null +++ b/package/test-vm/test-vm.xml @@ -0,0 +1,59 @@ + + test-vm + 1048576 + 1048576 + 2 + + hvm + + + + + + + + + + + + + + + + destroy + restart + destroy + + + + + + /usr/bin/qemu-system-x86_64 + + + + +
+ + + + + +
+ + + + + + + + + + +
+ + +
+ + + diff --git a/package/test-vm/test_vm_defconfig b/package/test-vm/test_vm_defconfig new file mode 100644 index 0000000000..1c548eafd7 --- /dev/null +++ b/package/test-vm/test_vm_defconfig @@ -0,0 +1,28 @@ +BR2_x86_64=y +BR2_TOOLCHAIN_EXTERNAL=y +BR2_TOOLCHAIN_EXTERNAL_DOWNLOAD=y +BR2_TOOLCHAIN_EXTERNAL_URL="https://toolchains.bootlin.com/downloads/releases/toolchains/x86-64-core-i7/tarballs/x86-64-core-i7--glibc--bleeding-edge-2018.11-1.tar.bz2" +BR2_TOOLCHAIN_EXTERNAL_GCC_8=y +BR2_TOOLCHAIN_EXTERNAL_HEADERS_4_14=y +BR2_TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC=y +BR2_TOOLCHAIN_EXTERNAL_CXX=y +BR2_TARGET_GENERIC_HOSTNAME="test-vm" +BR2_TARGET_GENERIC_ISSUE="Welcome to test-vm" +BR2_SYSTEM_DHCP="eth0" +BR2_ROOTFS_POST_BUILD_SCRIPT="package/test-vm/post-build.sh" +BR2_ROOTFS_POST_IMAGE_SCRIPT="support/scripts/genimage.sh" +BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/pc/genimage-bios.cfg" +BR2_LINUX_KERNEL=y +BR2_LINUX_KERNEL_CUSTOM_VERSION=y +BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.19.16" +BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y +BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/x86_64/linux.config" +BR2_LINUX_KERNEL_INSTALL_TARGET=y +BR2_PACKAGE_ACPID=y +BR2_TARGET_ROOTFS_EXT2=y +BR2_TARGET_ROOTFS_EXT2_4=y +BR2_TARGET_ROOTFS_EXT2_SIZE="120M" +# BR2_TARGET_ROOTFS_TAR is not set +BR2_TARGET_GRUB2=y +BR2_TARGET_GRUB2_BUILTIN_MODULES="boot linux ext2 fat squash4 part_msdos part_gpt normal biosdisk serial" +BR2_PACKAGE_HOST_GENIMAGE=y