Advertisement
jintack

KVM VM script to use kernel_irqchip option

Feb 8th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.90 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. CONSOLE=mon:stdio
  4. SMP=4
  5. MEMSIZE=$((14 * 1024))
  6. KERNEL=Image
  7. INCOMING=""
  8. FS=linaro-trusty.img
  9. CMDLINE=""
  10. DUMPDTB=""
  11. DTB=""
  12. IRQ=""
  13.  
  14. usage() {
  15.     U=""
  16.     if [[ -n "$1" ]]; then
  17.         U="${U}$1\n\n"
  18.     fi
  19.     U="${U}Usage: $0 [options]\n\n"
  20.     U="${U}Options:\n"
  21.     U="$U    -c | --CPU <nr>:       Number of cores (default ${SMP})\n"
  22.     U="$U    -m | --mem <MB>:       Memory size (default ${MEMSIZE})\n"
  23.     U="$U    -k | --kernel <Image>: Use kernel image (default ${KERNEL})\n"
  24.     U="$U    -s | --serial <file>:  Output console to <file>\n"
  25.     U="$U    -i | --image <image>:  Use <image> as block device (default $FS)\n"
  26.     U="$U    -a | --append <snip>:  Add <snip> to the kernel cmdline\n"
  27.     U="$U    --dumpdtb <file>       Dump the generated DTB to <file>\n"
  28.     U="$U    --dtb <file>           Use the supplied DTB instead of the auto-generated one\n"
  29.     U="$U    --irq on/off           Turn on/off hardware support for VGIC\n"
  30.     U="$U    -h | --help:           Show this output\n"
  31.     U="${U}\n"
  32.     echo -e "$U" >&2
  33. }
  34.  
  35. while :
  36. do
  37.     case "$1" in
  38.       -c | --cpu)
  39.         SMP="$2"
  40.         shift 2
  41.         ;;
  42.       -m | --mem)
  43.         MEMSIZE="$2"
  44.         shift 2
  45.         ;;
  46.       -k | --kernel)
  47.         KERNEL="$2"
  48.         shift 2
  49.         ;;
  50.       -s | --serial)
  51.         CONSOLE="file:$2"
  52.         shift 2
  53.         ;;
  54.       -i | --image)
  55.         FS="$2"
  56.         shift 2
  57.         ;;
  58.       -a | --append)
  59.         CMDLINE="$2"
  60.         shift 2
  61.         ;;
  62.       --irq)
  63.         IRQ=",kernel_irqchip=$2"
  64.         shift 2
  65.         ;;
  66.       --dumpdtb)
  67.         DUMPDTB=",dumpdtb=$2"
  68.         shift 2
  69.         ;;
  70.       --dtb)
  71.         DTB="-dtb $2"
  72.         shift 2
  73.         ;;
  74.       -h | --help)
  75.         usage ""
  76.         exit 1
  77.         ;;
  78.       --) # End of all options
  79.         shift
  80.         break
  81.         ;;
  82.       -*) # Unknown option
  83.         echo "Error: Unknown option: $1" >&2
  84.         exit 1
  85.         ;;
  86.       *)
  87.         break
  88.         ;;
  89.     esac
  90. done
  91.  
  92. BRIDGE_IF=""
  93. ifconfig | grep -q br0
  94. err=$?
  95.  
  96. tap=/dev/tap$(< /sys/class/net/kvmtap0/ifindex) 2>/dev/null
  97.  
  98. if [[ $err == 0 ]]; then
  99.     echo "Using bridged networking"
  100.         BRIDGE_IF="-netdev tap,id=net1,helper=/srv/vm/qemu/qemu-bridge-helper,vhost=on"
  101.         #BRIDGE_IF="$BRIDGE_IF -device virtio-net-pci,netdev=net1,mac=de:ad:be:ef:f6:cd"
  102.         BRIDGE_IF="$BRIDGE_IF -device virtio-net-pci,netdev=net1"
  103. elif [[ "$tap" != "/dev/tap" ]]; then
  104.     echo "Using macvtap networking"
  105.     macaddr=$(< /sys/class/net/kvmtap0/address) 2>/dev/null
  106.         BRIDGE_IF="-netdev tap,id=net1,vhost=on,fd=3"
  107.         BRIDGE_IF="$BRIDGE_IF -device virtio-net-pci,netdev=net1,mac=$macaddr"
  108.     exec 3<>$tap
  109. fi
  110.  
  111. ./qemu-system-aarch64 \
  112.         -smp $SMP -m $MEMSIZE -machine virt${DUMPDTB}${IRQ} -cpu host \
  113.         -kernel ${KERNEL} -enable-kvm ${DTB} \
  114.         -drive if=none,file=$FS,id=vda,cache=none,format=raw \
  115.         -device virtio-blk-pci,drive=vda \
  116.         -netdev user,id=net0,hostfwd=tcp::2222-:22 \
  117.         -device virtio-net-pci,netdev=net0,mac=de:ad:be:ef:41:49 \
  118.     $BRIDGE_IF \
  119.         -display none \
  120.     -serial $CONSOLE \
  121.     -qmp unix:/var/run/qmp,server,nowait \
  122.     -append "console=ttyAMA0 root=/dev/vda rw $CMDLINE"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement