#!/bin/bash
# Script to dump GPU vbios from any Unraid GPU
# by SpaceinvaderOne
##### Read the readme for how to use this script #####
##### FILL IN THE VARIABLES BELOW #######################################################################
###################
gpuid="01:00.0"
###################
#####Name the vbios for example gtx2080ti.rom
### 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
# 設(shè)置rom名稱
###################
vbiosname="GTX1060.rom"
###################
##### Location to put vbios (change if you dont want to use below location) if location doesnt exist it will be created for you.
# 設(shè)置rom存儲路徑
###################
vbioslocation="/mnt/user/isos/vbios/"
###################
##### Runs checks on device to see if it is in fact a GPU. Recommended to leave set as "yes"
###################
safety="yes"
###################
########## DO NOT CHANGE BELOW THIS LINE #################################################################
gpuid=$(echo "$gpuid" | sed 's/ *$//')
gpuid=$(echo "$gpuid" | sed 's/^ *//g')
dumpid="0000:$gpuid"
mygpu=$(lspci -s $gpuid)
disconnectid=$(echo "$dumpid" | sed 's?:?\\:?g')
disconnectid2=$(echo "$disconnectid" | sed 's/\(.*\)0/\11/')
vganame=$( lspci | grep -i "$gpuid" )
forcereset="no"
########## Script functions #################################################################
checkgpuiscorrect() {
mygpu=$(lspci -s $gpuid) || { notvalidpci; exit; }
echo "You have selected this device to dump the vbios from"
if grep -i 'VGA compatible controller' <<< "$mygpu" ; then
if grep -i 'Intel' <<< "$mygpu" ; then
echo "This looks like its an integrated INTEL GPU and vbios dump will most likely FAIL"
echo "Please select a dedicated GPU to dump vbios from"
echo "If you really want to try then rerun script changing variable to safety=off"
else
echo
echo "This does look like a valid GPU to me. Continuing ........."
echo
fi
elif grep -i 'Audio Device' <<< "$mygpu" ; then
echo
echo "This doesn't look like a GPU to me. It looks like an AUDIO device"
echo "Maybe you have selected the audio part of your GPU ?"
echo "Please edit the script and make sure to put the id of ONLY the VGA part of your GPU"
echo "If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off"
echo
echo "These are all the GPUs that I can see in your server"
lspci | grep -i 'vga'
exit
elif grep -i 'USB controller' <<< "$mygpu" ; then
echo
echo "This doesn't look like a GPU to me. It looks like a USB controller"
echo "Some GPUs have a USB part to them. Maybe you selected that ?"
echo "Please edit the script and make sure to put the id of ONLY the VGA part of your GPU"
echo "If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off"
echo
echo "These are the GPUs that I can see in your server"
lspci | grep -i 'vga'
exit
elif grep -i 'Serial bus controller' <<< "$mygpu" ; then
echo
echo "This doesn't look like a GPU to me. It looks like a USB type C controller"
echo "Some GPUs have a USB type C part to them. Maybe you selected that ?"
echo "Please edit the script and make sure to put the id of ONLY the VGA part of your GPU"
echo "If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off"
echo
echo "These are the GPUs that I can see in your server"
lspci | grep -i 'vga'
exit
elif grep -i 'Network controller' <<< "$mygpu" ; then
echo
echo "This doesn't look like a GPU to me. It looks like a NETWORK adapter "
echo "Please correct the id and rerun the script."
echo "If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off"
echo
echo "These are the GPUs that I can see in your server"
lspci | grep -i 'vga'
exit
elif grep -i 'Ethernet controller' <<< "$mygpu" ; then
echo
echo "This doesn't look like a GPU to me. It looks like a NETWORK adapter "
echo "Please correct the id and rerun the script."
echo "If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off"
echo
echo "These are the GPUs that I can see in your server"
lspci | grep -i 'vga'
exit
elif grep -i 'SATA controller' <<< "$mygpu" ; then
echo
echo "This doesn't look like a GPU to me. It looks like a SATA controller "
echo "Please correct the id and rerun the script."
echo "If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off"
echo
echo "These are the GPUs that I can see in your server"
lspci | grep -i 'vga'
exit
elif grep -i 'Non-Volatile memory controller' <<< "$mygpu" ; then
echo
echo "This doesn't look like a GPU to me. It looks like a NVME controller "
echo "Please correct the id and rerun the script."
echo "If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off"
echo
echo "These are the GPUs that I can see in your server"
lspci | grep -i 'vga'
exit
elif grep -i 'PCI bridge' <<< "$mygpu" ; then
echo
echo "This doesn't look like a GPU to me. It looks like a PCI bridge "
echo "Please correct the id and rerun the script."
echo "If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off"
echo
echo "These are the GPUs that I can see in your server"
lspci | grep -i 'vga'
exit
elif grep -i 'Host bridge' <<< "$mygpu" ; then
echo
echo "This doesn't look like a GPU to me. It looks like a HOST bridge "
echo "Please correct the id and rerun the script."
echo "If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off"
echo
echo "These are the GPUs that I can see in your server"
lspci | grep -i 'vga'
exit
elif grep -i 'SMBus' <<< "$mygpu" ; then
echo
echo "This doesn't look like a GPU to me. It looks like a SMBus controller "
echo "Please correct the id and rerun the script."
echo "If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off"
echo
echo "These are the GPUs that I can see in your server"
lspci | grep -i 'vga'
exit
elif grep -i 'Encryption controller' <<< "$mygpu" ; then
echo
echo "This doesn't look like a GPU to me. It looks like a Encryption controller "
echo "Please correct the id and rerun the script."
echo "If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off"
echo
echo "These are the GPUs that I can see in your server"
lspci | grep -i 'vga'
exit
else
echo "$mygpu"
echo
echo "This doesn't look like a GPU to me. Please correct the id and rerun the script."
echo "If you are 100 % sure this is the VGA part of your GPU then rerun script changing variable to safety=off"
echo
echo "These are the GPUs that I can see in your server"
lspci | grep -i 'vga'
exit
fi
}
notvalidpci() {
echo "That is NOT a valid PCI device. Please correct the id and rerun the script"
echo
echo "These are all the GPUs that I can see in your server. Please choose one of these"
lspci | grep -i 'vga'
}
checklocation() {
# check if vbios location exists and if not create it
echo
echo "Checking if location to put vbios file exists"
if [ ! -d "$vbioslocation" ] ; then
echo "Vbios folder created at "$mountlocation" "
echo
mkdir -vp "$vbioslocation" # make the directory as it doesnt exist
else
echo "Vbios folder "$mountlocation" already exists"
echo
fi
}
buildtempvm() {
cat > /tmp/dumpvbios.xml << EOF
<?xml version='1.0' encoding='UTF-8'?>
<domain type='kvm'>
<name>dumpvbios</name>
<memory unit='KiB'>1048576</memory>
<currentMemory unit='KiB'>1048576</currentMemory>
<memoryBacking>
<nosharepages/>
</memoryBacking>
<vcpu placement='static'>1</vcpu>
<cputune>
<vcpupin vcpu='0' cpuset='0'/>
</cputune>
<os>
<type arch='x86_64' machine='pc-q35-3.0'>hvm</type>
</os>
<cpu mode='host-passthrough' check='none' >
</cpu>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/local/sbin/qemu</emulator>
<controller type='pci' index='1' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='1' port='0x8'/>
</controller>
<hostdev mode='subsystem' type='pci' managed='yes' xvga='yes'>
<driver name='vfio'/>
<source>
<address domain='0x${dumpid:0:4}' bus='0x${dumpid:5:2}' slot='0x${dumpid:8:2}' function='0x${dumpid:11:1}'/>;
</source>
</hostdev>
</devices>
</domain>
EOF
}
isgpuprimary () {
# Check Primary GPU and wether gpu has already been disconnected
# Disconnect GPU and set server to sleep mode then rescan bus
if [ "$forcereset" = "yes" ] ; then
echo "Disconnecting the graphics card"
echo "1" | tee -a /sys/bus/pci/devices/$disconnectid/remove
echo "Entered suspended (sleep) state ......"
echo
echo " PRESS POWER BUTTON ON SERVER TO CONTINUE"
echo
echo -n mem > /sys/power/state
echo "Rescanning pci bus"
echo "1" | tee -a /sys/bus/pci/rescan
echo "Graphics card has now sucessfully been disconnected and reconnected"
echo "It is now ready to begin the dump vbios process"
echo
elif [ "$forcereset" = "no" ] ; then
echo "I will try and dump the vbios without disconnecting and reconnecting the GPU"
echo "This normally only works if the GPU is NOT the Primary or the only GPU"
echo "I will check the vbios at the end. If it seems wrong I will then retry after disconnecting the GPU"
echo
else
echo "forcereset is set as "$forcereset" this is not a recognised option"
echo "Please set forcereset to either yes or no "
exit
fi
}
startstopvm() {
echo "Defining temp vm with gpu attached"
virsh define /tmp/dumpvbios.xml
echo "Starting the temp vm to allow dump"
virsh start dumpvbios
echo "Waiting for a few seconds ....."
echo
sleep 9
echo "Stopping the temp vm "
virsh destroy dumpvbios
echo "Removing the temp vm"
virsh undefine dumpvbios
}
dumpvbios() {
# if no name was given for vbios then make name from vga name from lspci
if [ "$vbiosname" = "gpu vbios.rom" ] ; then
vbiosname=$( echo "$vganame" | awk 'NR > 1 {print $1}' RS='[' FS=']' )
fi
echo
cd /sys/bus/pci/devices/"$dumpid"/
echo 1 > rom
echo
echo "Okay dumping vbios file named "$vbiosname" to the location "$vbioslocation" "
cat rom > "$vbioslocation""$vbiosname" || needtobind
echo 0 > rom
}
needtobind() {
echo
echo "Um.... somethings gone wrong and I couldn't dump the vbios for some reason"
echo "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"
echo
echo "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"
echo "directly from the gui in Tools/System Devices .....So please do this and run the script again"
echo
exit
}
cleanup() {
if [ -e /tmp/dumpvbios.xml ] ; then
rm /tmp/dumpvbios.xml
fi
}
checkvbios() {
filepath="$vbioslocation""$vbiosname"
if [ -n "$(find "$filepath" -prune -size -2000c)" ]; then
needtobind
elif [ -n "$(find "$filepath" -prune -size -70000c)" ]; then
printf '%s is less than 70kb\n' "$filepath"
echo "This seems too small. Probably the GPU is Primary and needs disconnecting and reconnecting to get proper vbios"
echo
echo "Running again"
forcereset="yes"
buildtempvm
isgpuprimary
startstopvm
dumpvbios
cleanup
if [ -n "$(find "$filepath" -prune -size -70000c)" ]; then
printf '%s is less than 70kb\n' "$filepath"
echo "This seems small but maybe its correct. Please try it. All done !"
exit
fi
echo
echo "vbios seems to be correct. All done :)"
exit
else
echo
echo "vbios seems to be correct. All done :)"
exit
fi
}
########## run functions #################################################################
if [ "$safety" = "no" ] ; then
echo "Safety checks are disabled. Continuing ......"
else
checkgpuiscorrect
fi
checklocation
buildtempvm
isgpuprimary
startstopvm
dumpvbios
checkvbios
exit
DUMP_GPU_vBIOS
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 使用環(huán)信時如果如果出現(xiàn)以下兩個報錯: "_fwrite$UNIX2003", referenced from:和 ...
- 安裝XDebug后,在ajax傳值調(diào)試時,用var_dump()打印變量、TP框架中dump()/halt()打印...
- Mac 執(zhí)行dump.py -l命令出現(xiàn)下面錯誤 先不要慌 去看看Python下面的依賴包是否安裝了路徑 找到了 ...
- 這是一篇學(xué)習(xí)和對比fastq-dump、pfastq-dump和fasterq-dump這三個工具轉(zhuǎn)換SRA文件到...
- 使用maven進行打包install package時報錯 解決方式一:maven的編譯打包檢查:關(guān)閉即可,忽略檢...