Skip to content

Instantly share code, notes, and snippets.

@mcastelino
Forked from sameo/nemu-local-test.md
Created August 6, 2018 23:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcastelino/f37bd4b9e5d0460fac9d9da464ee2aa1 to your computer and use it in GitHub Desktop.
Save mcastelino/f37bd4b9e5d0460fac9d9da464ee2aa1 to your computer and use it in GitHub Desktop.

NEMU build

Configure script: configure.sh

git clone https://github.com/intel/nemu
cd nemu
git checkout -b topic/virt-x86 origin/topic/virt-x86
mkdir build-x86-64
cd build-x86-64
./configure.sh
make -j `nproc` 

Testing

We can test the NEMU virt machine type through either direct kernel boot (a.k.a. nofw) or through a regular cloud or server image as long as it supports EFI boot.

Direct kernel boot

Kernel

I use the v4.9.34-75 branch from the Clear Containers kernel with a custom .config

Initramfs image

See the busybox initramfs build instructions, and then configure the above kernel build to point to your local rootfs.

Command line

#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh


sudo /home/samuel/devlp/hypervisor/nemu/build-x86-64/x86_64-softmmu/qemu-system-x86_64 \
     -nographic \
     -nodefaults \
     -L . \
     -net none \
     -machine virt,accel=kvm,kernel_irqchip,nofw \
     -smp sockets=1,cpus=4,cores=2,maxcpus=8 -cpu host \
     -m 1G,slots=3,maxmem=4G \
     -kernel /home/samuel/devlp/kernels/nfc/arch/x86/boot/compressed/vmlinux.bin -append 'console=hvc0 single iommu=false root=/dev/ram0' \
     -device virtio-serial-pci,id=virtio-serial0 -device virtconsole,chardev=charconsole0,id=console0 -chardev stdio,id=charconsole0 \
     -monitor telnet:127.0.0.1:55555,server,nowait

Cloud image

Warning Most cloud or server images kernels do not have HW reduced ACPI enabled so they won't support CPU and memory hotplug with our HW reduced ACPI virt machine type.

We have tested the latest Clear Linux cloud image with our custom OVMF binary.

Command line

#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh

VMN=${VMN:=1}

sudo /home/samuel/devlp/hypervisor/nemu/build-x86-64/x86_64-softmmu/qemu-system-x86_64 \
     -bios $HOME/devlp/hypervisor/nemu/clear-cloud/OVMF.fd \
     -nographic \
     -nodefaults \
     -L . \
     -machine virt,accel=kvm,kernel_irqchip \
     -smp sockets=1,cpus=4,cores=2,maxcpus=8 -cpu host \
     -m 512 \
     -device sysbus-debugcon,iobase=0x402,chardev=debugcon -chardev file,path=/tmp/debug-log,id=debugcon \
     -device virtio-blk-pci,drive=image -drive if=none,id=image,file=$HOME/devlp/hypervisor/nemu/clear-cloud/clear-cloud.img \
     -device virtio-serial-pci,id=virtio-serial0 -device virtconsole,chardev=charconsole0,id=console0 -chardev stdio,id=charconsole0 \
     -netdev user,id=mynet0,hostfwd=tcp::${VMN}0022-:22,hostfwd=tcp::${VMN}2375-:2375 -device virtio-net-pci,netdev=mynet0 \
     -monitor telnet:127.0.0.1:55555,server,nowait

Hotplug

Hotplug is done through the QEMU monitoring socket (-monitor telnet:127.0.0.1:55555,server,nowait from the above command lines). The socket is reachable through port 23 (telnet):

# telnet 127.0.0.1 55555

CPU hotplug

Plug

(qemu) device_add host-x86_64-cpu,id=core4,socket-id=1,core-id=1,thread-id=0 

Unplug

(qemu) device_del core4

Memory hotplug

Plug

(qemu) object_add memory-backend-ram,id=mem1,size=1G
(qemu) device_add pc-dimm,id=dimm1,memdev=mem1

Unplug

(qemu) device_del dimm1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment