<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Bash script to work with pci passthrough on host]]></title><description><![CDATA[<p dir="auto">I wrote a simple script to help those of us who want to do pci passthrough and running into xe limits.<br />
Not responsible for issues/use/etc... use at own risk.<br />
Feel free to github/maintain it, i wont be planning on doing any more on it.<br />
I did this to work with pci passthrough and issues i been having while testing a new build. I found out that adding new devices while enabled pci for devices showing in xe can lead to issues and having to do pci hide reset. So i added that. I also added a enable pci device that is on xe so you can do it via app on host or still do it on gui using XO. Finally added a menu to add non xe pci device directly to vm.<br />
Vm list is my list so you need to update that with what you want to enable.</p>
<p dir="auto">Hope this helps someone else <img src="https://xcp-ng.org/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/1f600.png?v=041a08e19dc" class="not-responsive emoji emoji-android emoji--grinning" style="height:1.4em;width:auto;vertical-align:middle" title=":grinning:" alt="😀" /></p>
<p dir="auto">So grab the code, save it to /root/pcishare.sh and chmod +x it to run it.<br />
This is on the host directly.</p>
<pre><code>#!/bin/bash

# pcieDevices[x] is the name of the  device
# pcieDevicesID[x] is the id of the device from lspci
# pcieDevicesUUID[x] is uuid from xe list if available

######## Add Devices to check and make passthrough #########################
#format pcieDevices[x]='' #make sure to use single quotes are special chars will mess up.
##############################################################################
pcieDevices[0]='USB controller: ASMedia Technology Inc. ASM2142/ASM3142 USB 3.1 Host Controller'
pcieDevices[1]='VGA compatible controller: NVIDIA Corporation GK208 [GeForce GT 720] (rev a1)'
pcieDevices[2]='Audio device: NVIDIA Corporation GK208 HDMI/DP Audio Controller (rev a1)'
pcieDevices[3]='SATA controller: JMicron Technology Corp. JMB58x AHCI SATA controller'
###############################################################################

#Startup
pcieCount=${#pcieDevices[@]}

#load lspci into array lspciDevices#####
mapfile -t lspciDevices &lt; &lt;(lspci)

#####################################################################################
#function to request a reboot
function rebootPC
{
  read -n 1 -p "Need to reboot host. Y/N to reboot?: " doReboot
  case $doReboot in
        y|Y ) reboot;;
        *|n|N ) clear; echo "please reboot"; exit;;
  esac
}

######################################################################################
# remove old hide list / request reboot
function resetDOMPCIE 
{
  echo ""  
  echo " Clearing out xen-pciback list "

  /opt/xensource/libexec/xen-cmdline --delete-dom0 xen-pciback.hide
  
  echo "Completed"
  rebootPC

}
######################################################################################
# List variables to confirm which pcie the script is working with
function confirmPCIList
{
  clear
  echo ""
  echo "***************************************"
  for (( j=0; j&lt;${#pcieDevices[@]}; j++ )); do
    echo "*${pcieDevices[$j]}"
  done
  echo "***************************************"
exit
}
######################################################################################
function enablePCI
{
clear
echo "**************************************************"
echo "* Please select Index to enable pci passthrough  *"
echo "**************************************************"
echo ""

for (( j=0; j&lt;${#pcieDevices[@]}; j++ )); do
  if [ -n "${pcieDevicesUUID[$j]}" ]; then
    echo "Index $j: ${pcieDevicesUUID[$j]}-${pcieDevicesID[$j]}:${pcieDevices[$j]}"
  fi
done
echo ""
echo ""
read -n 1 -p  "Please make a selection or (E)xit: " menuEnablePCIEchoice;

case $menuEnablePCIEchoice in
 [0-99] ) 
     echo ""
     xe pci-disable-dom0-access uuid=${pcieDevicesUUID[$menuEnablePCIEchoice]}
     echo ""
     
     rebootPC
 ;; 
 e|E ) exit;;
 * )  exit ;;
esac
}
#######################################################################################
function addPCIEVM
{
clear
echo "********************************************************"
echo "* Please select Index to enable pci passthrough on VM  *"
echo "********************************************************"
echo ""

for (( j=0; j&lt;${#pcieDevices[@]}; j++ )); do
  if [ -z "${pcieDevicesUUID[$j]}" ]; then
    echo "Index $j: ${pcieDevicesUUID[$j]}-${pcieDevicesID[$j]}:${pcieDevices[$j]}"
  fi
done
echo ""
echo ""
read -n 1 -p  "Please make a selection or (E)xit: " menuAddPCIEchoice;

case $menuAddPCIEchoice in
 [0-99] )
     echo ""
     read -p  "Please provide the VM UUID: " vmID;
     echo ""
     xe vm-param-set other-config:pci=0/0000:${pcieDevicesID[$menuAddPCIEchoice]} uuid=$vmID
     echo ""
 ;;
 e|E ) exit;;
 * )  exit ;;
esac
}
######################################################################################
function setPCIE
{
#########################################
# Fill in pci ID into pcieDevicesID/UUID
# Offer to toggle devices and add non xe device to VM
#########################################

clear

# build list
for (( i=0; i&lt;"${#lspciDevices[@]}"; i++ )); do
 for (( j=0; j&lt;${#pcieDevices[@]}; j++ )); do
  if [[ ${lspciDevices[$i]} ==  *"${pcieDevices[$j]}"*  ]]; then
   pcieDevicesID[$j]="${lspciDevices[$i]%% *}"
   tempUUID=""
   tempUUID=$(xe pci-list |grep -B 3 ${pcieDevicesID[$j]} |head -n 1| cut -d ':' -f2 | tr -d ' ')

   if [ -z "$tempUUID" ]; then
       echo "Index $j UUID not found for Device: ${pcieDevicesID[$j]} - ${pcieDevices[$j]}"
   else
      pcieDevicesUUID[$j]="$tempUUID"
      echo "Index $j Device:${pcieDevicesUUID[$j]}: ${pcieDevicesID[$j]} - ${pcieDevices[$j]} "
   fi
  fi
 done
done

echo "**************************************************"
echo "* Would you like to:                             *"
echo "* (E)nable pcie device for passthrough           *"
echo "* (A)dd pcie directly to VM for non UUID         *"
echo "* (Q)uit                                         *"
echo "**************************************************"

read -n 1 -p  "Please make a selection: " menuPCIEchoice;

case $menuPCIEchoice in
 e|E ) enablePCI;;
 a|A ) addPCIEVM;;
 q|Q ) exit ;;
 * )  exit ;;
esac
}
##################################################
# Menu - App choices below
#################################################
clear
echo "****************************************"
echo "* Please make sure to add your devices *"
echo "* to the varible list before running   *"
echo "*                                      *"
echo "*             Menu                     *"
echo "* Select options below to continue     *"
echo "* 1. Reset PCIE hide list and DOM      *"
echo "* 2. Show PCIE variable list           *"
echo "* 3. Set pci devices                   *"
echo "* Any other key to exit                *"
echo "****************************************"

read -n 1 -p  "Please make a selection: " menuChoice;

case $menuChoice in
 1 ) resetDOMPCIE;;
 2 ) confirmPCIList;;
 3 ) setPCIE ;;
 4 ) echo "" ;;
 * ) clear ; exit ;;
esac

</code></pre>
]]></description><link>https://xcp-ng.org/forum/topic/11225/bash-script-to-work-with-pci-passthrough-on-host</link><generator>RSS for Node</generator><lastBuildDate>Thu, 15 Oct 2026 20:30:32 GMT</lastBuildDate><atom:link href="https://xcp-ng.org/forum/topic/11225.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 28 Aug 2025 20:22:50 GMT</pubDate><ttl>60</ttl></channel></rss>