Guest User

qemu.sh

a guest
Dec 13th, 2020
107
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/bash
  2.  
  3. NVRAM_IMAGE=$1
  4. VM_IMAGE=$2
  5. DRIVE_IMAGE=$3
  6.  
  7. QEMU_COMMAND_LINE=(
  8.     /usr/bin/qemu-system-x86_64
  9.     # Set name for top qemu process, name individual threads
  10.     -name guest=tests,debug-threads=on
  11.  
  12.     # Do not start CPU at startup
  13.     # -S
  14.  
  15.     # Choose emulated machine type and specify its properties
  16.     # TODO: read about all the options
  17.     -machine pc-q35-4.2,accel=kvm,usb=off,vmport=off,dump-guest-core=off,kernel_irqchip=on,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-format
  18.  
  19.     # Select CPU model and its options
  20.     # TODO: read about all the options
  21.     -cpu "host,topoext=on,svm=off,apic=on,hypervisor=on,migratable=no,invtsc=on,kvm-pv-eoi=on,hv-time,hv-relaxed,hv-vapic,hv-spinlocks=0x1fff,hv-vpindex,hv_time,-x2apic,hv-reset,hv-vendor-id=ASUS X399-A,hv-frequencies,hv-reenlightenment,kvm=off"
  22.  
  23.     # RAM
  24.     -m 8192
  25.  
  26.     # Tells qemu that host will or won't overcommit its resources, so qemu could lock memory and manage power state of host cpus
  27.     -overcommit mem-lock=on,cpu-pm=on
  28.  
  29.     # CPU Topology settings
  30.     -smp 12,sockets=1,cores=6,threads=2
  31.  
  32.     # Spawn IO thread that will serve guest IO requests
  33.     -object iothread,id=iothread1
  34.  
  35.     # Machine UUID that is stored in SMBIOS
  36.     -uuid 43a7c3e6-65f8-46f9-acd7-2661ea29b029
  37.  
  38.     # Do not load configs from sysconfdir
  39.     -no-user-config
  40.  
  41.     # Do not create default devices: serial port, floppy, etc.
  42.     #-nodefaults
  43.  
  44.     # Specify where emulated RTC gets time from. Also enable time drift fix
  45.     -rtc base=localtime,driftfix=slew
  46.  
  47.     # Don’t exit QEMU on guest shutdown
  48.     # -no-shutdown
  49.  
  50.     # -global driver.property=value; e.g. sets value of property "lost_tick_policy" for driver "kvm-pit"
  51.     -global kvm-pit.lost_tick_policy=discard
  52.     -global ICH9-LPC.disable_s3=1
  53.     -global ICH9-LPC.disable_s4=1
  54.  
  55.     # Show EFI menu and use strict boot. TODO: what is strict boot?
  56.     -boot menu=on,strict=on
  57.    
  58.     # Enable the spice remote desktop protoco
  59.     # -spice port=5900,addr=127.0.0.1,disable-ticketing,image-compression=off,seamless-migration=on
  60.     # Enable Seccomp mode 2 system call filter
  61.     -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny
  62.     # Prefix error messages with a timestamp
  63.     -msg timestamp=on
  64.    
  65.     # Configure display. -display help. Also -nographic may be convenient
  66.     -display gtk
  67.     # -nographic
  68.  
  69.     # setup NoCloud cloud-init provider
  70.     -smbios "type=1,serial=ds=nocloud-net;s=http://192.168.17.7:8000/"
  71.    
  72.     # Add monitor tab to gtk window
  73.     # -monitor vc
  74.     # Open command line monitor
  75.     # -monitor stdio
  76.     # Redirect monitor to socket. Then use `socat -,echo=0,icanon=0 unix-connect:qemu-monitor-socket` to open the monitor
  77.     #-monitor unix:qemu-monitor-socket,server,nowait
  78.  
  79.     # Logging
  80.     # -debugcon file:debug.log -global isa-debugcon.iobase=0x402
  81.     # -serial file:serial.log
  82.     #-serial null
  83.    
  84.     # ======================================== DEVICES ========================================
  85.     #
  86.     # -device driver[,prop[=value][,...]]
  87.     #   Add device driver. prop=value sets driver properties.
  88.     #   Valid properties depend on the driver. To get help on possible drivers and properties, use -device help and -device driver,help.
  89.     #   TODO: pcie-root-port, qemu-xhci, virtio-input-host-pci, qxl-vga
  90.     # Add PCI slots
  91.     -device pcie-root-port,port=0x10,chassis=1,id=pci.1,bus=pcie.0,multifunction=on,addr=0x2
  92.     -device pcie-root-port,port=0x11,chassis=2,id=pci.2,bus=pcie.0,addr=0x2.0x1
  93.  
  94.     # Add evdev passthrough
  95.     -device virtio-input-host-pci,id=input2,evdev=/dev/input/qemu-virtual-keyboard,bus=pci.1,addr=0x0
  96.     -device virtio-input-host-pci,id=input3,evdev=/dev/input/qemu-virtual-mouse,bus=pci.2,addr=0x0
  97.  
  98.     # NVMe passthrough
  99.     -device pcie-root-port,port=0x13,chassis=4,id=pci.3,bus=pcie.0,addr=0x2.0x2
  100.     -device vfio-pci,host=0000:09:00.0,id=hostdev0,bus=pci.3,addr=0x0
  101.  
  102.     # GPU passthrough
  103.     -device pcie-root-port,id=gpu-port,chassis=0,slot=0,bus=pcie.0
  104.     -set device.gpu-port.x-speed=8
  105.     -set device.gpu-port.x-width=16
  106.     -device vfio-pci,host=0a:00.0,bus=gpu-port,addr=00.0,multifunction=on
  107.     -device vfio-pci,host=0a:00.1,bus=gpu-port,addr=00.1
  108.  
  109.     # USB passtrhough
  110.     #-usb
  111.     #-device usb-host,vendorid=0x04b8,productid=0x1121
  112.  
  113.     # Configure rootless network using existing TAP
  114.     -netdev tap,id=network0,ifname=qtap,script=no,downscript=no
  115.     -device e1000,netdev=network0,mac=52:54:00:12:34:56
  116.    
  117.     # Configure rootless user mode host network backend
  118.     # -netdev user,id=network0,restrict=off
  119.     # -device e1000,netdev=network0,mac=52:54:00:12:34:56
  120.  
  121.     # Add USB controller
  122.     # -device qemu-xhci,id=usb,bus=pci.2,addr=0x0
  123.    
  124.     # Add vGPU
  125.     #-device qxl-vga,id=video0,ram_size=134217728,vram_size=134217728,vram64_size_mb=0,vgamem_mb=128,max_outputs=1
  126.    
  127.     # Configure root drive
  128.     -device ide-hd,drive=root_disk
  129.     -drive if=none,id=root_disk,cache=none,aio=native,file=${VM_IMAGE}
  130.  
  131.     # Configure cdrom
  132.     #-cdrom ${DRIVE_IMAGE}    
  133.     # -cdrom ${VM_IMAGE}
  134.  
  135.     # Attach program flash drive that stores OVMF UEFI firmware
  136.     -blockdev "{'driver':'file','filename':'/usr/share/OVMF/OVMF_CODE.fd','node-name':'libvirt-pflash0-storage','auto-read-only':true,'discard':'unmap'}"
  137.     -blockdev "{'node-name':'libvirt-pflash0-format','read-only':true,'driver':'raw','file':'libvirt-pflash0-storage'}"
  138.     # Attach program flash drive that stores OVMF UEFI variables
  139.     -blockdev "{'driver':'file','filename': \"${NVRAM_IMAGE}\",'node-name':'libvirt-pflash1-storage','auto-read-only':true,'discard':'unmap'}"
  140.     -blockdev "{'node-name':'libvirt-pflash1-format','read-only':false,'driver':'raw','file':'libvirt-pflash1-storage'}"
  141.  
  142.     # Add characted device. Help: -chardev help. TODO: pty backend
  143.     # -chardev pty,id=charserial0
  144.     # -device isa-serial,chardev=charserial0,id=serial0
  145.    
  146.     # Add characted device. Help: -chardev help. TODO: spicevmc backend
  147.     # -chardev spicevmc,id=charchannel0,name=vdagent
  148.     # -device virtio-serial-pci
  149.     # -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0
  150.    
  151.     # Add characted device. Help: -chardev help. spicevmc: pty backend
  152.     #-chardev spicevmc,id=spicechannel0,name=vdagent
  153.  
  154. )
  155.  
  156. "${QEMU_COMMAND_LINE[@]}"
RAW Paste Data