groundwork for generating configs

This commit is contained in:
HikariKnight 2022-02-27 00:10:21 +01:00
parent 50e97c7aa2
commit 3b6f09ab59
No known key found for this signature in database
GPG key ID: E8B239063B022F5A
5 changed files with 203 additions and 4 deletions

39
lib/get_GPU.sh Executable file
View file

@ -0,0 +1,39 @@
#!/bin/bash
function get_GPU () {
printf "These are your graphic cards, they have to be in separate groups.
The graphic card you want to passthrough cannot be in a group with other devices that
does not belong to itself:
"
echo "#------------------------------------------#"
exec "$SCRIPTDIR/utils/ls-iommu" | grep -i "vga" | cut -d " " -f 1-4,9-
echo "#------------------------------------------#"
printf "
Press q to quit
"
read -p "Which group number do you want to check?: " IOMMU_GROUP
case "${IOMMU_GROUP}" in
[1-9]*)
exec "$SCRIPTDIR/lib/get_GPU_GROUP.sh" $IOMMU_GROUP
;;
[Qq]*)
echo ""
;;
*)
echo ""
;;
esac
}
function main () {
SCRIPTDIR=$(dirname `which $0`)
SCRIPTDIR="$SCRIPTDIR/.."
clear
get_GPU
}
main

54
lib/get_GPU_GROUP.sh Executable file
View file

@ -0,0 +1,54 @@
#!/bin/bash
function get_GROUP () {
clear
printf "
For this card to be passthrough-able, it must contain only:
* The GPU/Graphic card
* The GPU Audio Controller
Optionally it may also include:
* GPU USB Host Controller
* GPU Serial Port
* GPU USB Type-C UCSI Controller
"
echo "#------------------------------------------#"
exec "$SCRIPTDIR/utils/ls-iommu" | grep -i "group $1" | cut -d " " -f 1-4,8- | perl -pe "s/\[[0-9a-f]{4}\]: //"
echo "#------------------------------------------#"
printf "
To use these devices for passthrough please type in ALL their device ids in the format (without brackets or quotes) --> \"xxxx:yyyy,xxxx:yyyy\"
NOTE: The device ID is the part inside the last [] brackets, example: [1002:aaf0]
To return to the previous page just press ENTER without typing in any ids
"
read -p "Enter the ids for all devices you want to passthrough: " GPU_DEVID
if [[ $GPU_DEVID =~ : ]];
then
# Make the directory
mkdir "$SCRIPTDIR/config"
# Get the PCI ids
PCI_ID=$($SCRIPTDIR/utils/ls-iommu | grep -i "group $1" | cut -d " " -f 4 | perl -pe "s/\n/ /" | perl -pe "s/\s$//")
echo "# This is an autogenerated file that stubs your graphic card for use with vfio" > "$SCRIPTDIR/config/vfio.conf"
echo "options vfio_pci ids=$GPU_DEVID" >> "$SCRIPTDIR/config/vfio.conf"
echo "GPU_PCI_ID=($PCI_ID)" > "$SCRIPTDIR/config/qemu-vfio_vars.conf"
echo "USB_CTL_ID=\"\"" >> "$SCRIPTDIR/config/qemu-vfio_vars.conf"
exec "$SCRIPTDIR/lib/get_USB_CTL.sh"
else
exec "$SCRIPTDIR/lib/get_GPU.sh"
fi
}
function main () {
SCRIPTDIR=$(dirname `which $0`)
SCRIPTDIR="$SCRIPTDIR/.."
get_GROUP $1
}
main $1

39
lib/get_USB_CTL.sh Executable file
View file

@ -0,0 +1,39 @@
#!/bin/bash
function get_USB_CTL () {
printf "THIS STEP IS OPTIONAL IF YOU DO NOT PLAN TO USE ANYTHING OTHER THAN MOUSE AND KEYBOARD!
The USB Controller you want to passthrough cannot be in a group with other devices.
Passing through a whole USB Controller (a set of hardwired 1-4 usb ports on the motherboard)
is only needed if you intend to use other devices than just mouse and keyboard with the VFIO enabled VM.
"
echo "#------------------------------------------#"
exec "$SCRIPTDIR/utils/ls-iommu" | grep -i "usb controller" | cut -d " " -f 1-4,8-
echo "#------------------------------------------#"
printf "
Press q to quit
"
read -p "Which group number do you want to check?: " IOMMU_GROUP
case "${IOMMU_GROUP}" in
[1-9]*)
exec "$SCRIPTDIR/lib/get_USB_CTL_GROUP.sh" $IOMMU_GROUP
;;
[Qq]*)
echo ""
;;
*)
echo ""
;;
esac
}
function main () {
SCRIPTDIR=$(dirname `which $0`)
SCRIPTDIR="$SCRIPTDIR/.."
clear
get_USB_CTL
}
main

39
lib/get_USB_CTL_GROUP.sh Executable file
View file

@ -0,0 +1,39 @@
#!/bin/bash
function get_USB_CTL_GROUP () {
clear
printf "
For this USB controller device to be passthrough-able, it must be the ONLY device in this group!
"
echo "#------------------------------------------#"
exec "$SCRIPTDIR/utils/ls-iommu" | grep -i "group $1" | cut -d " " -f 1-4,8- | perl -pe "s/\[[0-9a-f]{4}\]: //"
echo "#------------------------------------------#"
printf "
To use this device for passthrough please type in the device id in the format (without brackets or quotes) --> \"xxxx:yyyy\"
NOTE: The device ID is the part inside the last [] brackets, example: [1002:aaf0]
To return to the previous page just press ENTER without typing in any ids
"
read -p "Enter the id for the device you want to passthrough: " USB_CTL_DEVID
if [[ $USB_CTL_DEVID =~ : ]];
then
# Get the PCI ids
PCI_ID=$($SCRIPTDIR/utils/ls-iommu | grep -i "group $1" | cut -d " " -f 4)
exec perl -pi -e "s/USB_CTL_ID=\"\"/USB_CTL_ID=\"$PCI_ID\"/" "$SCRIPTDIR/config/qemu-vfio_vars.conf"
else
exec "$SCRIPTDIR/lib/get_USB_CTL.sh"
fi
}
function main () {
SCRIPTDIR=$(dirname `which $0`)
SCRIPTDIR="$SCRIPTDIR/.."
get_USB_CTL_GROUP $1
}
main $1

View file

@ -1,5 +1,9 @@
#!/bin/bash
# Get the scripts directory
SCRIPTDIR=$(dirname `which $0`)
cd $SCRIPTDIR
# Clear the screen
clear
@ -9,6 +13,8 @@ printf "Welcome to the VFIO enabler script!
The setup done by this script is quite complex and is prone to human error or hardware incompatibilities.
It is HIGHLY RECOMMENDED to make a backup/snapshot of your system using something like timeshift or snapper before starting.
Once everything is configured, your 2nd graphic card will hopefully be dedicated for use inside a virtual machine.
Press ENTER to continue once you have made a backup of your system.
"
read ENTER
@ -22,17 +28,39 @@ printf "This script assumes a few things:
NOTE: If your computer no longer fully shut down after enabling IOMMU, then there is possibly a bug
with your motherboard and a piece of hardware in your system, it only prevents you from using
the system in a headless mode and is otherwise just an annoying quirk with IOMMU on some boards.
the system in a headless mode with working shutdown and is otherwise just an annoying
quirk with IOMMU on some boards.
This is a list of prerequisites you will be needing before starting with VFIO:
* 2 GPUs (iGPU/APU included)
* A \"ghost display\" dummy plug for your second graphic card.
* A \"ghost display\" dummy plug for your second graphic card (or having it hooked to a separate input on your monitor).
* If you are planning to use the inegrated GPU on your CPU, make sure your monitor is connected to it before continuing.
* Preferably a motherboard verified to work with IOMMU and with good IOMMU groups.
https://reddit.com/r/vfio is a good resource for this info.
(If you are unsure, you will find out while using this script)
Press ENTER to continue.
Press ENTER to start creating your config.
"
read ENTER
clear
clear
"$SCRIPTDIR/utils/ls-iommu"
printf "
If the above list has everything inside just 1 IOMMU group the please enable
IOMMU, VT-d or AMD-v inside your UEFI/BIOS and re-run this script!
"
read -p "Is there more than 1 group in the output above? [y/N]:" YESNO
case "${YESNO}" in
[Yy]*)
clear
;;
[Nn]*)
exit 1
;;
*)
exit 1
;;
esac
"$SCRIPTDIR/lib/get_GPU.sh"