[
  {
    "path": ".gitignore",
    "content": "\n.DS_Store\n"
  },
  {
    "path": "README.md",
    "content": "## **DUMP_GPU_vBIOS**\n**Script to dump the vBios from any GPU even if a primary GPU**\n\nThis script is designed to be used on an Unraid server (using the user scripts plugin) but could easily be adapted to run on any Linux based OS\nThe script will dump the vBios of any connected GPU. It will dump the vbios wether the GPU is primary sedondary or only GPU etc.\n\n**How the script works.**\n1. It will take take the id of a GPU, make a temporary seabios vm with the card attached, then quickly start and stop the vm with GPU passed through. This will put the GPU in the correct state to dump the vBios.\n2. It will then delete the temporary vm as no longer needed.\n3. It will dump the vbios of the card then check the size of the vbios. \n4. If the vbios looks correct it will finish the process and put the vbios in the location specified in the script (default /mnt/user/isos/vbios) \n5. However if the vbios looks incorrect and the vbios is under 70kb then it was probably dumped from a primary GPU. This is because the vbios was shadowed during the boot process and so the resulting vbios is a small file which is not correct. So the script will now disconnect the GPU then put the server to sleep. Next it will prompt you to press the power button to resume the server from its sleep state. Once server is woken the script will rescan the pci bus reconnecting the GPU. This now allows the primary gpu to be able to have the vbios dumped correctly. Script will then redump the vbios again putting the vbios in the loaction specified in the script (defualt /mnt/user/isos/vbios)\n\n\n**Using the script.**\n\n1. Copy the script from here onto your Unraid server as a userscript.\n2. Run the script first without making any modifications.\n3. Script will report an error saying  \"That is NOT a valid PCI device. Please correct the id and rerun the script\" as no GPU has been selected. It will list the GPUs in your server. From this list take the ID of the GPU from which you want to dump the vbios. For example \"0c:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Ellesmere [Radeon RX 470/480/570/570X/580/580X/590]\" the id is the first block of character ie 0c:00.0\n4. Copy the id and edit the script variable gpuid=\"xx:xx.x\"  removing the contents between the quotations replacing it with the ID for example gpuid=\"0c:00.0\"\n5. Give the vbios a name by replacing the contens of the variable vbiosname=\"gpu vbios.rom\" to the name of your gpu etc.\n  -- *note if no name is given then script will try and name the vbios based on the the info it finds from lspci*\n6. optional - The default location of where the vbios will be dumped is in the isos share in a folder called vbios. You can change this by changing the variable vbioslocation=\"/mnt/user/isos/vbios/\" to the location of your choosing.\n7. Save changes and run the script.\n\n\n**Notes about the script**\n\nThe script will put the server to sleep in order to reset a primary GPU in order for a sucessful dump. So your server must support sleep if you want to dump a primary GPU. For other non primary GPUs this is not necessary.\n\nFor best results power down server then start server (not reboot)  before using script. Make sure whilst running script no vms or containers are running.\n\nThere are some checks the script will make to check that you have in fact put in the id of the gpu and not some other hardware. However these checks can be disabled by changing the varaiable from safety=\"yes\" to safety=\"no\"\n\nChanging the variable forcereset=\"no\" to forcereset=\"yes\" will make the script always forcereset the gpu before dumping vbios (if set to no it will only force reset if it thinks its dumping a primary gpu)\n"
  },
  {
    "path": "dump_vbios.sh",
    "content": "#!/bin/bash\n# Script to dump GPU vbios from any Unraid GPU \n# by SpaceinvaderOne\n\n##### Read the readme for how to use this script #####\n\n##### FILL IN THE  VARIABLES BELOW #######################################################################\n\n###################\ngpuid=\"xxxxxx\"\n###################\n\t\t\n#####Name the vbios for example gtx2080ti.rom\t\n\n### Naming of the vbios is optional ....  if you do not rename it here then the script will name it based off the details found about the gpu dumped\n\n###################\nvbiosname=\"gpu vbios.rom\"\n###################\n\n##### Location to put vbios (change if you dont want to use below location) if location doesnt exist it will be created for you.\n\n###################\nvbioslocation=\"/mnt/user/isos/vbios/\"\n###################\n\n##### Runs checks on device to see if it is in fact a GPU. Recommended to leave set as \"yes\"\n\n###################\nsafety=\"yes\"\n###################\n\n########## DO NOT CHANGE BELOW THIS LINE #################################################################\n\ngpuid=$(echo \"$gpuid\" | sed 's/ *$//')\n\ngpuid=$(echo \"$gpuid\" | sed 's/^ *//g')\n\ndumpid=\"0000:$gpuid\"\n\nmygpu=$(lspci -s $gpuid)\n\ndisconnectid=$(echo \"$dumpid\" | sed 's?:?\\\\:?g')\n\ndisconnectid2=$(echo \"$disconnectid\" | sed 's/\\(.*\\)0/\\11/')\n\nvganame=$( lspci | grep -i \"$gpuid\" )\n\nforcereset=\"no\"\n\n\n\n########## Script functions #################################################################\ncheckgpuiscorrect() {\n\tmygpu=$(lspci -s $gpuid) || { notvalidpci; exit; } \n\techo \"You have selected this device to dump the vbios from\"\n\tif grep -i 'VGA compatible controller' <<< \"$mygpu\"  ; then \n\t\tif grep -i 'Intel' <<< \"$mygpu\"  ; then \n\t\t\techo \"This looks like its an integrated INTEL GPU and vbios dump will most likely FAIL\"\n\t\t\techo \"Please select a dedicated GPU to dump vbios from\"\n\t\t\techo \"If you really want to try then rerun script changing variable to safety=off\"\n\t\telse\n\t\t\techo\n\t\t\techo \"This does look like a valid GPU to me. Continuing .........\"\n\t\t\techo\n\t\tfi\n\telif  grep -i 'Audio Device' <<< \"$mygpu\"  ; then \n\techo\n\techo \"This doesn't look like a GPU to me. It looks like an AUDIO device\"\n\techo \"Maybe you have selected the audio part of your GPU ?\"\n\techo \"Please edit the script and make sure to put the id of ONLY the VGA part of your GPU\"\n\techo \"If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off\"\n\techo\n\techo \"These are all the GPUs that I can see in your server\"\n\tlspci | grep -i 'vga'\n\texit\n\telif  grep -i 'USB controller' <<< \"$mygpu\"  ; then \n\techo\n\techo \"This doesn't look like a GPU to me. It looks like a USB controller\"\n\techo \"Some GPUs have a USB part to them. Maybe you selected that ?\"\n\techo \"Please edit the script and make sure to put the id of ONLY the VGA part of your GPU\"\n\techo \"If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off\"\n\techo\n\techo \"These are the GPUs that I can see in your server\"\n\tlspci | grep -i 'vga'\n\texit\n\telif  grep -i 'Serial bus controller' <<< \"$mygpu\"  ; then \n\techo\n\techo \"This doesn't look like a GPU to me. It looks like a USB type C controller\"\n\techo \"Some GPUs have a USB type C part to them. Maybe you selected that ?\"\n\techo \"Please edit the script and make sure to put the id of ONLY the VGA part of your GPU\"\n\techo \"If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off\"\n\techo\n\techo \"These are the GPUs that I can see in your server\"\n\tlspci | grep -i 'vga'\n\texit\n\telif  grep -i 'Network controller' <<< \"$mygpu\"  ; then \n\techo\n\techo \"This doesn't look like a GPU to me. It looks like a NETWORK adapter \"\n\techo \"Please correct the id and rerun the script.\"\n\techo \"If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off\"\n\techo\n\techo \"These are the GPUs that I can see in your server\"\n\tlspci | grep -i 'vga'\n\texit\n\telif  grep -i 'Ethernet controller' <<< \"$mygpu\"  ; then \n\techo\n\techo \"This doesn't look like a GPU to me. It looks like a NETWORK adapter \"\n\techo \"Please correct the id and rerun the script.\"\n\techo \"If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off\"\n\techo\n\techo \"These are the GPUs that I can see in your server\"\n\tlspci | grep -i 'vga'\n\texit\n\telif  grep -i 'SATA controller' <<< \"$mygpu\"  ; then \n\techo\n\techo \"This doesn't look like a GPU to me. It looks like a SATA controller \"\n\techo \"Please correct the id and rerun the script.\"\n\techo \"If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off\"\n\techo\n\techo \"These are the GPUs that I can see in your server\"\n\tlspci | grep -i 'vga'\n\texit\n\telif  grep -i 'Non-Volatile memory controller' <<< \"$mygpu\"  ; then \n\techo\n\techo \"This doesn't look like a GPU to me. It looks like a NVME controller \"\n\techo \"Please correct the id and rerun the script.\"\n\techo \"If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off\"\n\techo\n\techo \"These are the GPUs that I can see in your server\"\n\tlspci | grep -i 'vga'\n\texit\n\telif  grep -i 'PCI bridge' <<< \"$mygpu\"  ; then \n\techo\n\techo \"This doesn't look like a GPU to me. It looks like a PCI bridge \"\n\techo \"Please correct the id and rerun the script.\"\n\techo \"If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off\"\n\techo\n\techo \"These are the GPUs that I can see in your server\"\n\tlspci | grep -i 'vga'\n\texit\n\telif  grep -i 'Host bridge' <<< \"$mygpu\"  ; then \n\techo\n\techo \"This doesn't look like a GPU to me. It looks like a HOST bridge \"\n\techo \"Please correct the id and rerun the script.\"\n\techo \"If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off\"\n\techo\n\techo \"These are the GPUs that I can see in your server\"\n\tlspci | grep -i 'vga'\n\texit\n\telif  grep -i 'SMBus' <<< \"$mygpu\"  ; then \n\techo\n\techo \"This doesn't look like a GPU to me. It looks like a SMBus controller \"\n\techo \"Please correct the id and rerun the script.\"\n\techo \"If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off\"\n\techo\n\techo \"These are the GPUs that I can see in your server\"\n\tlspci | grep -i 'vga'\n\texit\n\telif  grep -i 'Encryption controller' <<< \"$mygpu\"  ; then \n\techo\n\techo \"This doesn't look like a GPU to me. It looks like a Encryption controller \"\n\techo \"Please correct the id and rerun the script.\"\n\techo \"If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off\"\n\techo\n\techo \"These are the GPUs that I can see in your server\"\n\tlspci | grep -i 'vga'\n\texit\n\telse\n\techo \"$mygpu\"\n\techo\n\techo \"This doesn't look like a GPU to me. Please correct the id and rerun the script.\"\n\techo \"If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off\"\n\techo\n\techo \"These are the GPUs that I can see in your server\"\n\tlspci | grep -i 'vga'\n\texit\n\tfi\n\t\n}\n\nnotvalidpci() {\n\techo \"That is NOT a valid PCI device. Please correct the id and rerun the script\"\n \techo\n \techo \"These are all the GPUs that I can see in your server. Please choose one of these\"\n \tlspci | grep -i 'vga'\n}\n\t\n\nchecklocation() {\n\t# check if vbios location exists and if not create it\n\techo\n\techo \"Checking if location to put vbios file exists\"\n\t\tif [ ! -d \"$vbioslocation\" ] ; then\n \n\t\t\techo \"Vbios folder created at \"$mountlocation\" \"\n\t\t\techo\n\t\t\tmkdir -vp \"$vbioslocation\" # make the directory as it doesnt exist\n\t\telse\n\t\t\techo \"Vbios folder \"$mountlocation\" already exists\"\n\t\t\techo\n\t\tfi\n}\n\nbuildtempvm() {\ncat > /tmp/dumpvbios.xml << EOF\n<?xml version='1.0' encoding='UTF-8'?>\n<domain type='kvm'>\n<name>dumpvbios</name>\n<memory unit='KiB'>1048576</memory>\n<currentMemory unit='KiB'>1048576</currentMemory>\n<memoryBacking>\n<nosharepages/>\n</memoryBacking>\n<vcpu placement='static'>1</vcpu>\n<cputune>\n<vcpupin vcpu='0' cpuset='0'/>\n</cputune>\n<os>\n<type arch='x86_64' machine='pc-q35-3.0'>hvm</type>\n</os>\n<cpu mode='host-passthrough' check='none' >\n</cpu>\n<on_poweroff>destroy</on_poweroff>\n<on_reboot>restart</on_reboot>\n<on_crash>restart</on_crash>\n<devices>\n<emulator>/usr/local/sbin/qemu</emulator>\n<controller type='pci' index='1' model='pcie-root-port'>\n<model name='pcie-root-port'/>\n<target chassis='1' port='0x8'/>\n</controller>\n<hostdev mode='subsystem' type='pci' managed='yes' xvga='yes'>\n<driver name='vfio'/>\n<source>\n<address domain='0x${dumpid:0:4}' bus='0x${dumpid:5:2}' slot='0x${dumpid:8:2}' function='0x${dumpid:11:1}'/>;\n</source>\n</hostdev>\n</devices>\n</domain>\nEOF\n}\n\nisgpuprimary () {\n\t# Check Primary GPU and wether gpu has already been disconnected\n\t# Disconnect GPU and set server to sleep mode then rescan bus\n\tif [ \"$forcereset\" = \"yes\" ] ; then\t\n\t\t\techo \"Disconnecting the graphics card\"\n\t\t\techo \"1\" | tee -a /sys/bus/pci/devices/$disconnectid/remove\n\t\t\techo \"Entered suspended (sleep) state ......\"\n\t\t\techo\n\t\t\techo \" PRESS POWER BUTTON ON SERVER TO CONTINUE\"\n\t\t\techo\n\t\t\techo -n mem > /sys/power/state\n\t\t\techo \"Rescanning pci bus\"\n\t\t\techo \"1\" | tee -a /sys/bus/pci/rescan\n\t\t\techo \"Graphics card has now sucessfully been disconnected and reconnected\"\n\t\t\techo \"It is now ready to begin the dump vbios process\"\n\t\t\techo\n\t\t\t\n\telif [ \"$forcereset\" = \"no\" ] ; then\t\t\t\n\t\t\techo \"I will try and dump the vbios without disconnecting and reconnecting the GPU\"\n\t\t\techo \"This normally only works if the GPU is NOT the Primary or the only GPU\"\n\t\t\techo \"I will check the vbios at the end. If it seems wrong I will then retry after disconnecting the GPU\"\n\t\t\techo\n\n\telse \n\t\t\techo \"forcereset is set as \"$forcereset\" this is not a recognised option\"\n\t\t\techo \"Please set forcereset to either yes or no \"\n\t\t\texit\n\tfi\n}\n\n\nstartstopvm() {\n\t\n\techo \"Defining temp vm with gpu attached\"\n\tvirsh define /tmp/dumpvbios.xml \n\techo \"Starting the temp vm to allow dump\"\n\tvirsh start dumpvbios\n\techo \"Waiting for a few seconds .....\"\n\techo\n\tsleep 9\n\techo \"Stopping the temp vm \"\n\tvirsh destroy dumpvbios\n\techo \"Removing the temp vm\"\n\tvirsh undefine dumpvbios\n\n}\n\ndumpvbios() {\n\t# if no name was given for vbios then make name from vga name from lspci\n\tif [ \"$vbiosname\" = \"gpu vbios.rom\" ] ; then\n\t\tvbiosname=$( echo \"$vganame\" |  awk 'NR > 1 {print $1}' RS='[' FS=']' )\n\tfi\n\techo\n\tcd /sys/bus/pci/devices/\"$dumpid\"/ \n\techo 1 > rom\n\techo\n\techo \"Okay dumping vbios file named \"$vbiosname\" to the location \"$vbioslocation\" \"\n\tcat rom > \"$vbioslocation\"\"$vbiosname\" || needtobind\n\techo 0 > rom\n}\n\nneedtobind() {\n\techo\n\techo \"Um.... somethings gone wrong and I couldn't dump the vbios for some reason\"\n\techo \"Sometimes when this happens all we need to do to fix this is 'stub' or 'bind to the vfio' the gpu and reboot the server\"\n\techo\n\techo \"This can be done in Unraid 6.8.3 with the use of the vfio config plugin or if you are on Unraid 6.9 or above it can be done\"\n\techo \"directly from the gui in Tools/System Devices .....So please do this and run the script again\"\n\techo\n\texit \n}\n\n\ncleanup() {\n\tif [ -e /tmp/dumpvbios.xml ] ; then\n\t\trm /tmp/dumpvbios.xml \n\tfi\n}\n\n\ncheckvbios() {\n\tfilepath=\"$vbioslocation\"\"$vbiosname\"\n\tif [ -n \"$(find \"$filepath\" -prune -size -2000c)\" ]; then\n\t\tneedtobind\n\t\n\t\n\telif [ -n \"$(find \"$filepath\" -prune -size -70000c)\" ]; then\n\t    printf '%s is less than 70kb\\n' \"$filepath\"\n\t\techo \"This seems too small. Probably the GPU is Primary and needs disconnecting and reconnecting to get proper vbios\"\n\t\techo\n\t\techo \"Running again\"\n\t\tforcereset=\"yes\"\n\t\tbuildtempvm\n\t\tisgpuprimary\n\t\tstartstopvm\n\t\tdumpvbios\n\t\tcleanup\n\t\tif [ -n \"$(find \"$filepath\" -prune -size -70000c)\" ]; then\n\t\t    printf '%s is less than 70kb\\n' \"$filepath\"\n\t\t\techo \"This seems small but maybe its correct. Please try it. All done !\"\n\t\t\texit\n\t\tfi\n\t\techo\n\t\techo \"vbios seems to be correct. All done :)\"\n\t\texit\n\t\t\n\telse\n\techo\n\techo \"vbios seems to be correct. All done :)\"\n\texit\t\n\tfi\n}\n\n\n\n########## run functions #################################################################\nif [ \"$safety\" = \"no\" ] ; then\t\necho \"Safety checks are disabled. Continuing ......\"\nelse\ncheckgpuiscorrect\nfi\nchecklocation\nbuildtempvm\nisgpuprimary\nstartstopvm\ndumpvbios\ncheckvbios\nexit\n"
  },
  {
    "path": "vBIOSes/readme.txt",
    "content": "\nHere I will build a collection of dumped vBIOSes to be used to help passthrough a GPU for Linux kvm/qemu virtual machines\n\nAt the moment there are not many here. Over time I hope this will increase. So if you. have dumped a vbios and want to contribute\nplease make sure to name the vbios correctly with type, vendor and model and memory size.\nFor example\n\nRTX 2080ti - Palit GAMING PRO - 11G "
  }
]