├── README.md ├── audio.sh ├── audio.sh.desktop ├── gvt_pe.service ├── part_1.sh ├── part_2.sh ├── part_3_optional.sh └── uninstall.sh /README.md: -------------------------------------------------------------------------------- 1 | Intel Single GPU passthrough GVT-g helper for Ubuntu 20.04 2 | 3 | For a guide, visit: https://youtu.be/6-RjFl00QSk 4 | 5 | To display your VM, you'll need to download Looking Glass: https://looking-glass.hostfission.com/ 6 | To hear the audio from your VM, you'll need Scream: https://github.com/duncanthrax/scream 7 | 8 | To install, first run: chmod +x part_1.sh 9 | 10 | Then run: ./part_1.sh 11 | Reboot your computer 12 | run ./part_2.sh 13 | 14 | Optionally, to hear audio through the host, run: 15 | ./part_3_optional.sh 16 | 17 | Sources: 18 | * https://github.com/intel/gvt-linux/wiki/GVTg_Setup_Guide 19 | * https://looking-glass.hostfission.com/wiki/Installation 20 | * https://github.com/duncanthrax/scream 21 | -------------------------------------------------------------------------------- /audio.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | /usr/bin/scream -i virbr0 3 | -------------------------------------------------------------------------------- /audio.sh.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Type=Application 3 | Exec="/usr/bin/scream_audio.sh" 4 | X-GNOME-Autostart-enabled=true 5 | -------------------------------------------------------------------------------- /gvt_pe.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=GVT-g service 3 | 4 | [Service] 5 | Type=idle 6 | ExecStart=/bin/bash /usr/bin/gvt_pe.sh 7 | 8 | [Install] 9 | WantedBy=graphical.target 10 | -------------------------------------------------------------------------------- /part_1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Making sure this script runs with elevated privileges 4 | if [ $EUID -ne 0 ] 5 | then 6 | echo "Please run this as root!" 7 | exit 1 8 | fi 9 | 10 | #Making all necessary parts executable 11 | chmod +x part_2.sh part_3_optional.sh 12 | 13 | #Creating a GRUB variable equal to current content of grub cmdline. 14 | GRUB=`cat /etc/default/grub | grep "GRUB_CMDLINE_LINUX_DEFAULT" | rev | cut -c 2- | rev` 15 | 16 | 17 | #Creating a grub backup for the uninstallation script and making uninstall.sh executable 18 | cat /etc/default/grub > grub_backup.txt 19 | chmod +x uninstall.sh 20 | 21 | #After the backup has been created, add intel_iommu=on kvm.ignore_msrs=1 i915.enable_gvt=1 22 | # to GRUB variable 23 | GRUB+=" intel_iommu=on i915.enable_gvt=1 kvm.ignore_msrs=1\"" 24 | sed -i -e "s|^GRUB_CMDLINE_LINUX_DEFAULT.*|${GRUB}|" /etc/default/grub 25 | 26 | #User verification of new grub and prompt to manually edit it 27 | echo 28 | echo "Grub was modified to look like this: " 29 | echo `cat /etc/default/grub | grep "GRUB_CMDLINE_LINUX_DEFAULT"` 30 | echo 31 | echo "Do you want to edit it? y/n" 32 | read YN 33 | 34 | if [ $YN = y ] 35 | then 36 | nano /etc/default/grub 37 | fi 38 | 39 | 40 | #Updating grub 41 | update-grub 42 | 43 | #Installing required packages for Looking Glass 44 | apt-get install binutils-dev cmake fonts-freefont-ttf libsdl2-dev libsdl2-ttf-dev libspice-protocol-dev libfontconfig1-dev libx11-dev nettle-dev -y 45 | 46 | #Install required packages for virtualization 47 | apt install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virt-manager ovmf -y 48 | 49 | #Backing up /etc/modules for future use by uninstall.sh 50 | cat /etc/modules > modules_backup.txt 51 | 52 | #Adding kernel modules 53 | echo "vfio_mdev" >> /etc/modules 54 | echo "kvmgt" >> /etc/modules 55 | 56 | #Updating initramfs 57 | update-initramfs -u 58 | 59 | #Allowing Looking Glass in app armor 60 | echo "/dev/shm/looking-glass rw," >> /etc/apparmor.d/abstractions/libvirt-qemu 61 | 62 | #Now the computer needs to be rebooted 63 | while [ true ] 64 | do 65 | echo 66 | echo "To reboot your computer now, please enter (r)" 67 | read REBOOT 68 | 69 | if [ $REBOOT = "r" ] 70 | then 71 | reboot 72 | fi 73 | 74 | done 75 | -------------------------------------------------------------------------------- /part_2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | #Making sure this script runs with elevated privileges 5 | if [ $(id -u) -ne 0 ] 6 | then 7 | echo "Please run this as root!" 8 | exit 1 9 | fi 10 | 11 | 12 | GPU= 13 | MAX=0 14 | UUID=\"`uuidgen`\" 15 | VIRT_USER=`logname` 16 | 17 | #Finding the Intel GPU and choosing the one with highest weight value 18 | for i in $(find /sys/devices/pci* -name 'mdev_supported_types'); do 19 | for y in $(find $i -name 'description'); do 20 | WEIGHT=`cat $y | tail -1 | cut -d ' ' -f 2` 21 | if [ $WEIGHT -gt $MAX ]; then 22 | GPU=`echo $y | cut -d '/' -f 1-7` 23 | 24 | #Saving the uuid for future optional verification by the user 25 | echo "ls $GPU/devices" > check_gpu.sh 26 | chmod +x check_gpu.sh 27 | chown $VIRT_USER check_gpu.sh 28 | 29 | fi 30 | done 31 | 32 | done 33 | 34 | 35 | echo " " > virsh.txt 36 | echo " " >> virsh.txt 37 | 38 | echo "
" >> virsh.txt 39 | echo "" >> virsh.txt 40 | echo "" >> virsh.txt 41 | 42 | #Identifying user to set permissions 43 | echo 44 | echo "User: $VIRT_USER will be using Looking Glass on this PC. " 45 | echo "If that's correct, press (y) otherwise press (n) and you will be able to specify the user." 46 | echo 47 | echo "y/n?" 48 | read USER_YN 49 | 50 | 51 | #Allowing the user to manually edit the Looking Glass user 52 | if [ $USER_YN = 'n' ] || [ $USER_YN = 'N' ] 53 | then 54 | USER_YN='n' 55 | while [ '$USER_YN' = "n" ]; do 56 | echo "Enter the new username: " 57 | read VIRT_USER 58 | 59 | 60 | echo "Is $VIRT_USER correct (y/n)?" 61 | read USER_YN 62 | done 63 | fi 64 | echo User $VIRT_USER selected. Press any key to continue: 65 | read ANY_KEY 66 | 67 | 68 | #Initializing virtual GPU on every startup 69 | echo "echo $UUID > $GPU/create" >> gvt_pe.sh 70 | 71 | # Looking Glass requirements: /dev/shm/looking_glass needs to be created on startup 72 | echo "touch /dev/shm/looking-glass && chown $VIRT_USER:kvm /dev/shm/looking-glass && chmod 660 /dev/shm/looking-glass" >> gvt_pe.sh 73 | 74 | #Create a systemd service to initialize the GPU on startup 75 | cp gvt_pe.service /etc/systemd/system/gvt_pe.service 76 | chmod 644 /etc/systemd/system/gvt_pe.service 77 | 78 | mv gvt_pe.sh /usr/bin/gvt_pe.sh 79 | 80 | systemctl enable gvt_pe.service 81 | 82 | systemctl start gvt_pe.service 83 | 84 | chown $VIRT_USER virsh.txt 85 | 86 | 87 | -------------------------------------------------------------------------------- /part_3_optional.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | THE_USER=`logname` 5 | 6 | #Making sure this script runs with elevated privileges 7 | if [ $EUID -ne 0 ] 8 | then 9 | echo "Please run this as root!" 10 | exit 1 11 | fi 12 | 13 | #This script should only run if scream-master is present 14 | if [ -a scream-master ] 15 | then 16 | echo "Continuing with scream installation" 17 | else 18 | echo "Scream-master not found in this directory. Please move scream-master into this directory and try again." 19 | exit 20 | fi 21 | 22 | #Create autostart directory if not already present 23 | #This will be used by gnome to start scream on machine startup 24 | if ! [ -a /home/$THE_USER/.config/autostart ] 25 | then 26 | mkdir /home/$THE_USER/.config/autostart 27 | fi 28 | 29 | chown $THE_USER /home/$THE_USER/.config/autostart 30 | 31 | cp audio.sh.desktop /home/$THE_USER/.config/autostart/ 32 | 33 | chown $THE_USER /home/$THE_USER/.config/autostart/audio.sh.desktop 34 | 35 | #This will be used to autostart scream and can be edited if different parameters are used 36 | cp audio.sh /usr/bin/scream_audio.sh 37 | 38 | #Installing required packages 39 | apt install libpulse-dev make cmake 40 | 41 | #Compiling scream receiver 42 | cd scream-master/Receivers/unix/ 43 | 44 | mkdir build 45 | 46 | cd build 47 | 48 | cmake .. 49 | 50 | make 51 | 52 | #Moving files to their expected locations 53 | mv scream /usr/bin/scream 54 | 55 | chmod +x /usr/bin/scream 56 | 57 | 58 | chmod +x /usr/bin/scream_audio.sh 59 | 60 | -------------------------------------------------------------------------------- /uninstall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ $EUID -ne 0 ] 4 | then 5 | echo "Please run this as root!" 6 | exit 1 7 | fi 8 | 9 | #Remove files related to Intel GPU passthrough 10 | 11 | 12 | 13 | if [ -a grub_backup.txt ] 14 | then 15 | mv grub_backup.txt /etc/default/grub 16 | fi 17 | 18 | if [ -a modules_backup.txt ] 19 | then 20 | mv modules_backup.txt /etc/modules 21 | fi 22 | 23 | update-grub 24 | 25 | update-initramfs -u 26 | 27 | rm /etc/systemd/system/gvt_pe.service 28 | 29 | rm /usr/bin/gvt_pe.sh 30 | 31 | 32 | #Remove Scream Audio if present 33 | 34 | if [ -a /usr/bin/scream ] 35 | then 36 | rm /usr/bin/scream 37 | fi 38 | 39 | 40 | if [ -a /usr/bin/scream_audio.sh ] 41 | then 42 | rm /usr/bin/scream_audio.sh 43 | fi 44 | 45 | 46 | if [ -a /home/$LOGNAME/.config/autostart/audio.sh.desktop ] 47 | then 48 | rm /home/$LOGNAME/.config/autostart/audio.sh.desktop 49 | fi 50 | 51 | rm check_gpu.sh 52 | --------------------------------------------------------------------------------