#! /usr/bin/env bash # Test a virtual machine with KVM. # # -n # Network adapter to use, for example, virtio-net-pci (default), e1000, # or vmxnet3. # # -t # Existing tap interface to use instead of creating a new one (as tap9). # usage="usage: $0 [-n ] [...]" owd="$(pwd)" trap "{ cd '$owd'; exit 1; }" ERR set -o errtrace # Trap in functions. function info () { echo "$*" 1>&2; } function error () { info "$*"; exit 1; } br=br0 mac="de:ad:be:ef:b8:da" arch="$(uname -m)" kvm=("qemu-system-$arch" -enable-kvm) nic=virtio-net-pci etap= while [ "$#" -gt 0 ]; do case "$1" in -n) shift nic="$1" shift ;; -t) shift etap="$1" shift ;; *) break ;; esac done dir="${1%/}" shift if [ -z "$dir" ]; then error "missing machine directory" fi if [ -z "$etap" ]; then tap=tap9 sudo ip tuntap delete "$tap" mode tap || true sudo ip tuntap add "$tap" mode tap user "$(whoami)" sudo ip link set "$tap" up #sleep 0.5s sudo ip link set "$tap" master "$br" else tap="$etap" fi "${kvm[@]}" \ -m 8G \ -cpu host -smp "8,sockets=1,cores=4,threads=2" \ \ -netdev "tap,id=net0,ifname=$tap,script=no" \ -device "$nic,netdev=net0,mac=$mac" \ \ -drive "if=none,id=disk0,file=$dir/disk.img,format=raw" \ -device "virtio-blk-pci,scsi=off,drive=disk0" \ \ -usb \ -device usb-tablet \ \ -monitor stdio \ \ -boot c "$@" #-chardev stdio,id=qmp \ #-mon chardev=qmp,mode=control,pretty=on \ # -chardev socket,id=mon,path=/tmp/test-machine-sock,server,nowait \ # -mon chardev=mon,mode=readline \ # { "execute": "qmp_capabilities" } # -device "virtio-blk-pci,scsi=off,drive=disk0" # # -device "virtio-scsi-pci,id=scsi" \ # -device "scsi-hd,drive=disk0" \ # -vnc "localhost:1" \ # -monitor "telnet::5555,server,nowait" # -vnc "localhost:1" - 5901 # vncviewer localhost:5901 #-vnc "unix:$dir/vnc" \ #-monitor "unix:$dir/monitor,server,nowait" if [ -z "$etap" ]; then sudo ip tuntap delete "$tap" mode tap fi exit 0 sudo "${kvm[@]}" \ -m 8G \ -cpu host -smp "sockets=1,cores=4,threads=2" \ -device "$nic,netdev=net0,mac=$mac" \ -netdev "tap,id=net0,script=./qemu-ifup" \ -device "virtio-scsi-pci,id=scsi" \ -device "scsi-hd,drive=disk1" \ -drive "if=none,id=disk1,file=$dir/disk.img,format=raw" \ -boot c # -kernel buildos-image -initrd buildos-initrd \ # -append "buildos.smtp_relay=build2.org buildos.admin_email=admin@build2.org" #/usr/bin/kvm-spice -name windows10-vc15rc2 -S -machine pc-i440fx-wily,accel=kvm,usb=off -cpu Broadwell,hv_time,hv_relaxed,hv_vapic,hv_spinlocks=0x1fff -m 4096 -realtime mlock=off -smp 2,sockets=2,cores=1,threads=1 -uuid 16237884-61fb-4000-bdca-5c86bb83fe1a -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/domain-windows10-vc15rc2/monitor.sock,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=localtime,driftfix=slew -global kvm-pit.lost_tick_policy=discard -no-hpet -no-shutdown -global PIIX4_PM.disable_s3=1 -global PIIX4_PM.disable_s4=1 -boot strict=on -device ich9-usb-ehci1,id=usb,bus=pci.0,addr=0x5.0x7 -device ich9-usb-uhci1,masterbus=usb.0,firstport=0,bus=pci.0,multifunction=on,addr=0x5 -device ich9-usb-uhci2,masterbus=usb.0,firstport=2,bus=pci.0,addr=0x5.0x1 -device ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pci.0,addr=0x5.0x2 -drive file=/home/vm/windows10-vc15rc2.img,format=raw,if=none,id=drive-virtio-disk0 -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -drive if=none,id=drive-ide0-0-0,readonly=on -device ide-cd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 -netdev tap,fd=26,id=hostnet0,vhost=on,vhostfd=28 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:8f:c4:d5,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -device usb-tablet,id=input0 -vnc 127.0.0.1:0 -device VGA,id=video0,vgamem_mb=16,bus=pci.0,addr=0x2 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6 -msg timestamp=on #/usr/bin/kvm-spice -name debian8 -S -machine pc-i440fx-xenial,accel=kvm,usb=off -cpu Broadwell -m 4096 -realtime mlock=off -smp 2,sockets=2,cores=1,threads=1 -uuid eb483372-8ffe-4c60-8ad9-9c89cb74e314 -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/domain-debian8/monitor.sock,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc,driftfix=slew -global kvm-pit.lost_tick_policy=discard -no-hpet -no-shutdown -global PIIX4_PM.disable_s3=1 -global PIIX4_PM.disable_s4=1 -boot strict=on -device ich9-usb-ehci1,id=usb,bus=pci.0,addr=0x5.0x7 -device ich9-usb-uhci1,masterbus=usb.0,firstport=0,bus=pci.0,multifunction=on,addr=0x5 -device ich9-usb-uhci2,masterbus=usb.0,firstport=2,bus=pci.0,addr=0x5.0x1 -device ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pci.0,addr=0x5.0x2 -drive file=/btrfs/boris/machines/linux_debian_8-gcc_4.9-1.0/disk.img,format=raw,if=none,id=drive-virtio-disk0 -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -netdev tap,fd=27,id=hostnet0,vhost=on,vhostfd=29 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:52:2e:fb,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -device usb-tablet,id=input0 -vnc 127.0.0.1:1 -device cirrus-vga,id=video0,bus=pci.0,addr=0x2 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6 -msg timestamp=on