Guest User

Untitled

a guest
Nov 3rd, 2014
5,129
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. if [ "${1}" = "nosleep" ]; then
  3.     no_sleep="1"
  4. fi
  5.  
  6. echo -n "Disabling display HDMI2..."
  7. xrandr \
  8.     --output HDMI1 --mode 1920x1080 --pos 0x0 --rotate normal \
  9.     --output HDMI2 --off \
  10.     --output VIRTUAL1 --off \
  11.     --output VGA1 --off
  12. [ -z "${no_sleep}" ] && sleep 2
  13. echo "done"
  14.  
  15. echo -n "Restarting conky..."
  16. killall conky &>/dev/null
  17. [ -z "${no_sleep}" ] && sleep 1
  18. (conky &>/dev/null &) &>/dev/null
  19. [ -z "${no_sleep}" ] && sleep 1
  20. echo "done"
  21.  
  22. echo -n "Disabling power saving..."
  23. sudo mode performance
  24. echo "done"
  25.  
  26. echo -n "Unloading nvidia driver..."
  27. sudo /etc/init.d/nvidia-smi stop > /dev/null
  28. sudo rmmod nvidia
  29. echo "done"
  30.  
  31. echo -n "Binding GTX 770..."
  32. for dev in "0000:01:00.0" "0000:01:00.1"; do
  33.     vendor=$(cat /sys/bus/pci/devices/${dev}/vendor)
  34.     device=$(cat /sys/bus/pci/devices/${dev}/device)
  35.     if [ -e /sys/bus/pci/devices/${dev}/driver ]; then
  36.         echo "${dev}" | sudo tee /sys/bus/pci/devices/${dev}/driver/unbind > /dev/null
  37.         while [ -e /sys/bus/pci/devices/${dev}/driver ]; do
  38.             sleep 0.1
  39.         done
  40.     fi
  41.     echo "${vendor} ${device}" | sudo tee /sys/bus/pci/drivers/vfio-pci/new_id > /dev/null
  42. done
  43. echo "done"
  44.  
  45. # use pulseaudio
  46. export QEMU_AUDIO_DRV=pa
  47.  
  48. echo -n "Starting virtual machine..."
  49. [ -z "${no_sleep}" ] && sleep 0.2
  50. sudo \
  51.     nice -n -1 \
  52.     qemu-system-x86_64 \
  53.     -serial none \
  54.     -parallel none \
  55.     -nodefconfig \
  56.     -nodefaults \
  57.     -enable-kvm \
  58.     -name Nafrayu \
  59.     -cpu host,kvm=off,check \
  60.     -smp threads=2,cores=4,sockets=1 \
  61.     -m 12288 \
  62.     -mem-path /var/lib/hugetlbfs/group/kvm/pagesize-1GB \
  63.     -mem-prealloc \
  64.     -soundhw hda \
  65.     -device ich9-usb-uhci3,id=uhci  \
  66.     -device usb-ehci,id=ehci \
  67.     -device nec-usb-xhci,id=xhci \
  68.     -device usb-host,vendorid=0x06a3,productid=0x0836,bus=uhci.0 `# Saitek Cyborg X` \
  69.     -device usb-host,vendorid=0x0421,productid=0x0106,bus=ehci.0 `# Nokia N96 Flash Mode` \
  70.     -device usb-host,vendorid=0x0421,productid=0x003a,bus=ehci.0 `# Nokia N96 PC Suite Mode` \
  71.     -device usb-host,vendorid=0x0421,productid=0x0037,bus=ehci.0 `# Nokia N96 Mass Memory` \
  72.     -device usb-host,vendorid=0x0421,productid=0x0038,bus=ehci.0 `# Nokia N96 Picture Tansfer` \
  73.     -device usb-host,vendorid=0x0421,productid=0x0039,bus=ehci.0 `# Nokia N96 File Transfer` \
  74.     -netdev type=tap,id=net0,ifname=tap0,vhost=on \
  75.     -device virtio-net-pci,netdev=net0,mac=00:26:18:DF:54:01 \
  76.     -k de \
  77.     -drive if=pflash,format=raw,readonly,file=/home/bluebird/Projects/edk2/Build/OvmfX64/RELEASE_GCC48/FV/OVMF_CODE.fd \
  78.     -drive if=pflash,format=raw,file=/var/lib/ovmf/nafrayu.fd `# /home/bluebird/Projects/edk2/Build/OvmfX64/RELEASE_GCC48/FV/OVMF_VARS.fd` \
  79.     -rtc base=utc \
  80.     -monitor unix:/run/Nafrayu.sock,server,nowait \
  81.     -boot order=c \
  82.     -object iothread,id=iothread0 \
  83.     -drive if=none,id=drive0,file=/dev/mapper/lvm-kvm_nafrayu,format=raw,cache=none,aio=native \
  84.     -device virtio-blk-pci,iothread=iothread0,drive=drive0 \
  85.     -nographic \
  86.     -device vfio-pci,host=01:00.0,addr=09.0,multifunction=on \
  87.     -device vfio-pci,host=01:00.1,addr=09.1 \
  88.     -daemonize
  89. echo "done"
  90.  
  91. # for install
  92.     #-vga std \
  93.     #-sdl \
  94.     #-boot order=d \
  95.     #-device ide-cd,drive=drive-cd-disk1,id=cd-disk1,unit=0,bus=ide.0 \
  96.     #-drive file=/home/bluebird/Downloads/WindowsTechnicalPreview-x64-EN-US.iso,if=none,id=drive-cd-disk1,media=cdrom \
  97.     #-device ide-cd,drive=drive-cd-disk2,id=cd-disk2,unit=0,bus=ide.1 \
  98.     #-drive file=/home/bluebird/Downloads/virtio-win-0.1-81.iso,if=none,id=drive-cd-disk2,media=cdrom \
  99.  
  100. # connect user to monitor
  101. sudo nc.openbsd -U /run/Nafrayu.sock
  102. echo
  103.  
  104. echo -n "Enabling power saving..."
  105. sudo mode powersave
  106. echo "done"
  107.  
  108. echo -n "Unbinding GTX 770..."
  109. for dev in "0000:01:00.0" "0000:01:00.1"; do
  110.     vendor=$(cat /sys/bus/pci/devices/${dev}/vendor)
  111.     device=$(cat /sys/bus/pci/devices/${dev}/device)
  112.     if [ -e /sys/bus/pci/devices/${dev}/driver ]; then
  113.         echo "${dev}" | sudo tee /sys/bus/pci/devices/${dev}/driver/unbind > /dev/null
  114.         while [ -e /sys/bus/pci/devices/${dev}/driver ]; do
  115.             sleep 0.1
  116.         done
  117.     fi
  118. done
  119. echo "done"
  120.  
  121. echo -n "Loading nvidia driver..."
  122. sudo modprobe nvidia
  123. sudo /etc/init.d/nvidia-smi start > /dev/null
  124. echo "done"
  125.  
  126. echo -n "Restoring display HDMI2..."
  127. xrandr \
  128.     --output HDMI2 --mode 1920x1080 --pos 0x0 --rotate normal \
  129.     --output HDMI1 --mode 1920x1080 --pos 1920x0 --rotate normal \
  130.     --output VIRTUAL1 --off \
  131.     --output VGA1 --off
  132. [ -z "${no_sleep}" ] && sleep 2
  133. echo "done"
  134.  
  135. echo -n "Restarting conky..."
  136. killall conky &>/dev/null
  137. [ -z "${no_sleep}" ] && sleep 1
  138. (conky &>/dev/null &) &>/dev/null
  139. [ -z "${no_sleep}" ] && sleep 1
  140. echo "done"
RAW Paste Data