initial commit to prepare for rewrite into golang for actual use
This commit is contained in:
parent
0d4f63f371
commit
5da1a88296
21 changed files with 129 additions and 1 deletions
152
old_bash_version/lib/apply_CHANGES.sh
Executable file
152
old_bash_version/lib/apply_CHANGES.sh
Executable file
|
@ -0,0 +1,152 @@
|
|||
#!/bin/bash
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
function make_BACKUP () {
|
||||
local BACKUPDIR
|
||||
BACKUPDIR="$SCRIPTDIR/backup"
|
||||
|
||||
if [ ! -d "$BACKUPDIR" ];
|
||||
then
|
||||
# Make the backup directories and backup the files
|
||||
if [ -d "/etc/initramfs-tools" ];
|
||||
then
|
||||
mkdir -p "$BACKUPDIR/etc/initramfs-tools"
|
||||
cp -v "/etc/initramfs-tools/modules" "$BACKUPDIR/etc/initramfs-tools/modules"
|
||||
cp -v "/etc/modules" "$BACKUPDIR/etc/modules"
|
||||
|
||||
elif [ -d "/etc/dracut.conf" ];
|
||||
then
|
||||
mkdir -p "$BACKUPDIR/etc/dracut.conf.d"
|
||||
if [ -f "/etc/dracut.conf.d/10-vfio.conf" ];
|
||||
then
|
||||
cp -v "/etc/dracut.conf.d/10-vfio.conf" "$BACKUPDIR/etc/dracut.conf.d/10-vfio.conf"
|
||||
|
||||
fi
|
||||
|
||||
elif [ -f "/etc/mkinitcpio.conf" ];
|
||||
then
|
||||
mkdir -p "$BACKUPDIR/etc"
|
||||
cp -v "/etc/mkinitcpio.conf" "$BACKUPDIR/etc/mkinitcpio.conf"
|
||||
|
||||
fi
|
||||
|
||||
if [ -f "/etc/default/grub" ];
|
||||
then
|
||||
mkdir -p "$BACKUPDIR/etc/default"
|
||||
cp -v "/etc/default/grub" "$BACKUPDIR/etc/default/grub"
|
||||
|
||||
fi
|
||||
|
||||
if [ -d "/etc/modprobe.d" ];
|
||||
then
|
||||
mkdir -p "$BACKUPDIR/etc/modprobe.d"
|
||||
|
||||
# If a vfio.conf file exists, backup that too
|
||||
if [ -f "/etc/modprobe.d/vfio.conf" ];
|
||||
then
|
||||
cp -v "/etc/modprobe.d/vfio.conf" "$BACKUPDIR/etc/modprobe.d/vfio.conf"
|
||||
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
printf "Backup completed!\n"
|
||||
|
||||
else
|
||||
echo "
|
||||
A backup already exists!
|
||||
backup skipped.
|
||||
"
|
||||
fi
|
||||
}
|
||||
|
||||
function copy_FILES () {
|
||||
echo "Starting copying files to the system!"
|
||||
|
||||
if [ -d "/etc/modprobe.d" ];
|
||||
then
|
||||
sudo cp -v "$SCRIPTDIR/$MODPROBE/vfio.conf" "/etc/modprobe.d/vfio.conf"
|
||||
|
||||
fi
|
||||
|
||||
if [ -d "/etc/initramfs-tools" ];
|
||||
then
|
||||
sudo cp -v "$SCRIPTDIR/$ETCMODULES" "/etc/modules"
|
||||
sudo cp -v "$SCRIPTDIR/$INITRAMFS/modules" "/etc/initramfs-tools/modules"
|
||||
echo "
|
||||
Rebuilding initramfs"
|
||||
sudo update-initramfs -u
|
||||
|
||||
elif [ -f "/etc/dracut.conf" ];
|
||||
then
|
||||
cp -v "$SCRIPTDIR/$DRACUT/10-vfio.conf" "/etc/dracut.conf.d/10-vfio.conf"
|
||||
echo "
|
||||
Rebuilding initramfs"
|
||||
sudo dracut -f -v --kver "$(uname -r)"
|
||||
|
||||
elif [ -f "/etc/mkinitcpio.conf" ];
|
||||
then
|
||||
cp -v "$SCRIPTDIR/$MKINITCPIO" "/etc/mkinitcpio.conf"
|
||||
echo "
|
||||
Rebuilding initramfs"
|
||||
sudo mkinitcpio -P
|
||||
|
||||
else
|
||||
echo "
|
||||
Unsupported initramfs infrastructure
|
||||
In order to make vfio work, please add these modules to your
|
||||
initramfs and make them load early, then rebuild initramfs.
|
||||
|
||||
vfio
|
||||
vfio_iommu_type1
|
||||
vfio_pci
|
||||
vfio_virqfd
|
||||
|
||||
|
||||
Press ENTER to continue once you have done the above."
|
||||
read -r
|
||||
|
||||
fi
|
||||
|
||||
|
||||
}
|
||||
|
||||
function apply_CHANGES () {
|
||||
clear
|
||||
# Get the config paths
|
||||
source "$SCRIPTDIR/lib/paths.sh"
|
||||
|
||||
echo "Configuration is now complete and these files have been generated for your system:
|
||||
$SCRIPTDIR/$ETCMODULES
|
||||
$SCRIPTDIR/$INITRAMFS/modules
|
||||
$SCRIPTDIR/$MODPROBE/vfio.conf
|
||||
|
||||
By proceeding, a backup of your system's version of these files will be placed in
|
||||
$SCRIPTDIR/backup
|
||||
unless a backup already exist.
|
||||
|
||||
Then the files above will be copied to your system followed by running followed by updating your
|
||||
initramfs and then attempt adding new kernel arguments to your bootloader."
|
||||
|
||||
read -r -p "Do you want to proceed with the installation of the files? (no=quit) [Y/n]: " YESNO
|
||||
|
||||
case "${YESNO}" in
|
||||
[Nn]*)
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
make_BACKUP
|
||||
copy_FILES
|
||||
exec "$SCRIPTDIR/lib/set_CMDLINE.sh"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
function main () {
|
||||
SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
|
||||
|
||||
apply_CHANGES
|
||||
}
|
||||
|
||||
main
|
41
old_bash_version/lib/get_GPU.sh
Executable file
41
old_bash_version/lib/get_GPU.sh
Executable file
|
@ -0,0 +1,41 @@
|
|||
#!/bin/bash
|
||||
|
||||
function get_GPU () {
|
||||
clear
|
||||
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. Both cards must also have unique hardware ids [xxxx:yyyy]!:
|
||||
|
||||
"
|
||||
echo "#------------------------------------------#"
|
||||
"$SCRIPTDIR/utils/ls-iommu" -g -F name,device_id,optional_revision
|
||||
echo "#------------------------------------------#"
|
||||
|
||||
printf "
|
||||
Press q to quit
|
||||
"
|
||||
|
||||
read -r -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 "Aborted, your setup is incomplete!
|
||||
DO NOT use any of the files from $SCRIPTDIR/config !
|
||||
"
|
||||
;;
|
||||
*)
|
||||
exec "$SCRIPTDIR/lib/get_GPU.sh"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function main () {
|
||||
SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
|
||||
|
||||
get_GPU
|
||||
}
|
||||
|
||||
main
|
84
old_bash_version/lib/get_GPU_GROUP.sh
Executable file
84
old_bash_version/lib/get_GPU_GROUP.sh
Executable file
|
@ -0,0 +1,84 @@
|
|||
#!/bin/bash
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
function get_GPU_GROUP () {
|
||||
clear
|
||||
# Get the config paths
|
||||
source "$SCRIPTDIR/lib/paths.sh"
|
||||
|
||||
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
|
||||
* PCI Bridge (if they are in their own IOMMU groups)
|
||||
|
||||
NOTE: If the audio controller is missing, it might be in a separate IOMMU group, please run
|
||||
\"%s/utils/ls-iommu\" -i %s -rr -F \"pciaddr,subclass_name:,name,device_id,optional_revision\"
|
||||
and add the PCI address and deviceID to the config manually (this is not done automatically because the -rr flag is unreliable if the system has 2 cards from the same vendor)
|
||||
|
||||
" "$SCRIPTDIR" "$1"
|
||||
echo "#------------------------------------------#"
|
||||
"$SCRIPTDIR/utils/ls-iommu" -i "$1" -r -F subclass_name:,name,device_id,optional_revision # | cut -d " " -f 1-5,6- | perl -pe "s/\[[0-9a-f]{4}\]: //"
|
||||
echo "#------------------------------------------#"
|
||||
|
||||
printf "
|
||||
To use any of these devices for passthrough ALL of them (except PCI bridges in their own IOMMU groups) has to be passed through to the VMs\
|
||||
|
||||
To return to the previous page just press ENTER without typing in anything.
|
||||
"
|
||||
read -r -p "Do you want to use these devices for passthrough? [y/N]: " YESNO
|
||||
|
||||
case "${YESNO}" in
|
||||
[Yy]*)
|
||||
# Get the hardware ids from the selected group
|
||||
local GPU_DEVID
|
||||
GPU_DEVID=$("$SCRIPTDIR/utils/ls-iommu" -i "$1" -r --id | perl -pe "s/\n/,/" | perl -pe "s/,$/\n/")
|
||||
|
||||
# Get the PCI ids
|
||||
local PCI_ID
|
||||
PCI_ID=$("$SCRIPTDIR/utils/ls-iommu" -i "$1" -r --pciaddr | perl -pe "s/([0-9a-f]{2}:[0-9a-f]{2}.[0-9a-f]{1})\n/\"\1\" /" | perl -pe "s/\s$//")
|
||||
|
||||
# Write the GPU_PCI_IDs to the config that quickemu might make use of in the future
|
||||
echo "GPU_PCI_ID=($PCI_ID)
|
||||
USB_CTL_ID=()" > "$SCRIPTDIR/$QUICKEMU/qemu-vfio_vars.conf"
|
||||
|
||||
# Get the GPU ROM
|
||||
"$SCRIPTDIR/lib/get_GPU_ROM.sh" "$1"
|
||||
|
||||
# Start setting up modules
|
||||
if [ -d "/etc/initramfs-tools" ];
|
||||
then
|
||||
exec "$SCRIPTDIR/lib/set_INITRAMFSTOOLS.sh" "$GPU_DEVID"
|
||||
|
||||
elif [ -d "/etc/dracut.conf" ];
|
||||
then
|
||||
exec "$SCRIPTDIR/lib/set_DRACUT.sh" "$GPU_DEVID"
|
||||
|
||||
elif [ -f "/etc/mkinitcpio.conf" ];
|
||||
then
|
||||
exec "$SCRIPTDIR/lib/set_MKINITCPIO.sh" "$GPU_DEVID"
|
||||
else
|
||||
# Bind GPU to VFIO
|
||||
"$SCRIPTDIR/lib/set_VFIO.sh" "$GPU_DEVID"
|
||||
|
||||
# Configure modprobe
|
||||
"$SCRIPTDIR/lib/set_MODPROBE.sh" "$GPU_DEVID"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
exec "$SCRIPTDIR/lib/get_GPU.sh"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function main () {
|
||||
SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
|
||||
|
||||
get_GPU_GROUP "$1"
|
||||
}
|
||||
|
||||
main "$1"
|
70
old_bash_version/lib/get_GPU_ROM.sh
Executable file
70
old_bash_version/lib/get_GPU_ROM.sh
Executable file
|
@ -0,0 +1,70 @@
|
|||
#!/bin/bash
|
||||
# shellcheck disable=SC1091,SC2024
|
||||
|
||||
function get_GPU_ROM () {
|
||||
clear
|
||||
# Get the config paths
|
||||
source "$SCRIPTDIR/lib/paths.sh"
|
||||
|
||||
VBIOS_PATH=$("$SCRIPTDIR/utils/ls-iommu" -g -i "$1" --rom)
|
||||
echo "We will now attempt to dump the vbios of your selected GPU.
|
||||
Passing a VBIOS rom to the card used for passthrough is required for some cards, but not all.
|
||||
Some cards also requires you to patch your VBIOS romfile, check online if this is neccessary for your card.
|
||||
The VBIOS will be read from $VBIOS_PATH
|
||||
This process will require the use of sudo and will run the following commands:
|
||||
|
||||
echo 1 | sudo tee $VBIOS_PATH
|
||||
sudo cat $VBIOS_PATH > $SCRIPTDIR/$QUICKEMU/vfio_card.rom
|
||||
echo 0 | sudo tee $VBIOS_PATH
|
||||
|
||||
"
|
||||
read -r -p "Do you want to dump the VBIOS, choosing N will skip this step [y/N]: " YESNO
|
||||
case "${YESNO}" in
|
||||
[Yy]*)
|
||||
echo 1 | sudo tee "$VBIOS_PATH"
|
||||
sudo cat "$VBIOS_PATH" > "$SCRIPTDIR/$QUICKEMU/vfio_card.rom"
|
||||
sudo md5sum "$VBIOS_PATH" | cut -d " " -f 1 > "$SCRIPTDIR/$QUICKEMU/vfio_card.rom.md5"
|
||||
local ROM_MD5
|
||||
ROM_MD5=$(sudo md5sum "$VBIOS_PATH" | cut -d " " -f 1)
|
||||
echo 0 | sudo tee "$VBIOS_PATH"
|
||||
local ROMFILE_MD5
|
||||
ROMFILE_MD5=$(md5sum "$SCRIPTDIR/$QUICKEMU/vfio_card.rom" | cut -d " " -f 1)
|
||||
|
||||
if [ -f "$SCRIPTDIR/$QUICKEMU/vfio_card.rom" ];
|
||||
then
|
||||
if [ "$ROM_MD5" == "$ROMFILE_MD5" ];
|
||||
then
|
||||
echo "Checksums match!"
|
||||
echo "Dumping of VBIOS successful!"
|
||||
echo 'GPU_ROMFILE="vfio_card.rom"' >> "$SCRIPTDIR/$QUICKEMU/qemu-vfio_vars.conf"
|
||||
|
||||
read -r -p "Press ENTER to continue."
|
||||
else
|
||||
echo "Checksums does not match!"
|
||||
echo "Dumping of VBIOS failed, skipping romfile"
|
||||
mv "$SCRIPTDIR/$QUICKEMU/vfio_card.rom" "$SCRIPTDIR/$QUICKEMU/vfio_card.rom.fail"
|
||||
echo 'GPU_ROMFILE=""' >> "$SCRIPTDIR/$QUICKEMU/qemu-vfio_vars.conf"
|
||||
|
||||
read -r -p "Press ENTER to continue."
|
||||
fi
|
||||
else
|
||||
echo 'GPU_ROMFILE=""' >> "$SCRIPTDIR/$QUICKEMU/qemu-vfio_vars.conf"
|
||||
fi
|
||||
;;
|
||||
[Nn]*)
|
||||
echo 'GPU_ROMFILE=""' >> "$SCRIPTDIR/$QUICKEMU/qemu-vfio_vars.conf"
|
||||
;;
|
||||
*)
|
||||
echo 'GPU_ROMFILE=""' >> "$SCRIPTDIR/$QUICKEMU/qemu-vfio_vars.conf"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
function main () {
|
||||
SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
|
||||
|
||||
get_GPU_ROM "$1"
|
||||
}
|
||||
|
||||
main "$1"
|
39
old_bash_version/lib/get_USB_CTL.sh
Executable file
39
old_bash_version/lib/get_USB_CTL.sh
Executable file
|
@ -0,0 +1,39 @@
|
|||
#!/bin/bash
|
||||
|
||||
function get_USB_CTL () {
|
||||
clear
|
||||
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 "#------------------------------------------#"
|
||||
"$SCRIPTDIR/utils/ls-iommu" -u -F name,device_id,optional_revision
|
||||
echo "#------------------------------------------#"
|
||||
printf "
|
||||
Press q to quit
|
||||
"
|
||||
|
||||
read -r -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]*)
|
||||
exec "$SCRIPTDIR/lib/apply_CHANGES.sh"
|
||||
;;
|
||||
*)
|
||||
exec "$SCRIPTDIR/lib/apply_CHANGES.sh"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function main () {
|
||||
SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
|
||||
|
||||
get_USB_CTL
|
||||
}
|
||||
|
||||
main
|
48
old_bash_version/lib/get_USB_CTL_GROUP.sh
Executable file
48
old_bash_version/lib/get_USB_CTL_GROUP.sh
Executable file
|
@ -0,0 +1,48 @@
|
|||
#!/bin/bash
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
function get_USB_CTL_GROUP () {
|
||||
clear
|
||||
# Get the config paths
|
||||
source "$SCRIPTDIR/lib/paths.sh"
|
||||
|
||||
printf "
|
||||
For this USB controller device to be passthrough-able, it must be the ONLY device in this group!
|
||||
Passing through more than just the USB controller can in some cases cause system issues
|
||||
if you do not know what you are doing.
|
||||
|
||||
"
|
||||
echo "#------------------------------------------#"
|
||||
"$SCRIPTDIR/utils/ls-iommu" -i "$1" -F subclass_name:,name,device_id,optional_revision
|
||||
echo "#------------------------------------------#"
|
||||
|
||||
printf "
|
||||
To use any of the devices shown for passthrough, all of them have to be passed through
|
||||
|
||||
To return to the previous page just press ENTER.
|
||||
"
|
||||
read -r -p "Do you want to use the displayed devices for passthrough? [y/N]: " YESNO
|
||||
|
||||
case "${YESNO}" in
|
||||
[Yy]*)
|
||||
# Get the PCI ids
|
||||
local PCI_ID
|
||||
PCI_ID=$("$SCRIPTDIR/utils/ls-iommu" -i "$1" --pciaddr | perl -pe "s/([0-9a-f]{4}:[0-9a-f]{2}:[0-9a-f]{2}.[0-9a-f]{1})\n/\"\1\" /" | perl -pe "s/\s$//")
|
||||
|
||||
# Replace the blank USB_CTL_ID with the PCI_ID for the usb controller the user wants to pass through
|
||||
perl -pi -e "s/USB_CTL_ID=\(\)/USB_CTL_ID=\($PCI_ID\)/" "$SCRIPTDIR/$QUICKEMU/qemu-vfio_vars.conf"
|
||||
exec "$SCRIPTDIR/lib/apply_CHANGES.sh"
|
||||
;;
|
||||
*)
|
||||
exec "$SCRIPTDIR/lib/get_USB_CTL.sh"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function main () {
|
||||
SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
|
||||
|
||||
get_USB_CTL_GROUP "$1"
|
||||
}
|
||||
|
||||
main "$1"
|
18
old_bash_version/lib/paths.sh
Executable file
18
old_bash_version/lib/paths.sh
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/bash
|
||||
# shellcheck disable=SC2034
|
||||
MODPROBE="config/etc/modprobe.d"
|
||||
INITRAMFS="config/etc/initramfs-tools"
|
||||
ETCMODULES="config/etc/modules"
|
||||
DEFAULT="config/etc/default"
|
||||
QUICKEMU="config/quickemu"
|
||||
DRACUT="config/etc/dracut.conf.d"
|
||||
MKINITCPIO="config/etc/mkinitcpio.conf"
|
||||
|
||||
READAPI="wget -O-"
|
||||
DOWNLOAD="wget -0 \"$SCRIPTDIR/utils/ls-iommu.tar.gz\""
|
||||
# Get the tool to use for downloading
|
||||
if [ -f "/usr/bin/curl" ];
|
||||
then
|
||||
READAPI="curl"
|
||||
DOWNLOAD="curl -JLo ls-iommu.tar.gz"
|
||||
fi
|
188
old_bash_version/lib/set_CMDLINE.sh
Executable file
188
old_bash_version/lib/set_CMDLINE.sh
Executable file
|
@ -0,0 +1,188 @@
|
|||
#!/bin/bash
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
# Function to configure systemd-boot using kernelstub
|
||||
function set_KERNELSTUB () {
|
||||
# Separator
|
||||
printf "
|
||||
############################################################
|
||||
"
|
||||
|
||||
# Tell what we are going to do
|
||||
echo "Adding vfio kernel arguments to systemd-boot using kernelstub"
|
||||
|
||||
# Get the config paths
|
||||
source "${SCRIPTDIR}/lib/paths.sh"
|
||||
|
||||
# Check if systemd-boot already has vfio parameters from before
|
||||
KERNELSTUB_TEST=$(sudo kernelstub -p 2>&1 | grep "Kernel Boot Options" | perl -pe "s/.+Kernel Boot Options:\..+(vfio_pci.ids=.+ ).+/\1/")
|
||||
|
||||
# If there are already vfio_pci parameters in kernelstub
|
||||
if [[ "$KERNELSTUB_TEST" =~ vfio_pci.ids ]] ;
|
||||
then
|
||||
# Remove the old parameters
|
||||
sudo kernelstub -d "$KERNELSTUB_TEST"
|
||||
sudo kernelstub -d "vfio_pci.disable_vga=1"
|
||||
sudo kernelstub -d "vfio_pci.disable_vga=0"
|
||||
fi
|
||||
|
||||
# Apply new parameters
|
||||
CMDLINE=$(cat "${SCRIPTDIR}/config/kernel_args")
|
||||
sudo kernelstub -a "$CMDLINE"
|
||||
}
|
||||
|
||||
# Function to configure grub
|
||||
function set_GRUB () {
|
||||
# Separator
|
||||
printf "
|
||||
############################################################
|
||||
"
|
||||
|
||||
# Get the config paths
|
||||
source "$SCRIPTDIR/lib/paths.sh"
|
||||
|
||||
local CMDLINE
|
||||
CMDLINE=$(cat "$SCRIPTDIR/config/kernel_args")
|
||||
|
||||
# HIGHLY EXPERIMENTAL!
|
||||
local GRUB_CMDLINE
|
||||
local GRUB_CMDLINE_LINUX
|
||||
|
||||
# Check if there is a GRUB_CMDLINE_LINUX_DEFAULT line in grub config
|
||||
if grep -q "GRUB_CMDLINE_LINUX_DEFAULT=" "$SCRIPTDIR/$DEFAULT/grub" ;
|
||||
then
|
||||
# Update the GRUB_CMDLINE_LINUX_DEFAULT line
|
||||
GRUB_CMDLINE=$(grep -P "^GRUB_CMDLINE_LINUX_DEFAULT" "/etc/default/grub" | perl -pe "s/GRUB_CMDLINE_LINUX_DEFAULT=\"(.+)\"/\1/" | perl -pe "s/(amd|intel)_iommu=(on|1)|iommu=(pt|on)|vfio_pci.ids=.+|vfio_pci.disable_vga=\d{1}//g" | perl -pe "s/(^\s+|\s+$)//g")
|
||||
GRUB_CMDLINE_LINUX=$(grep -P "^GRUB_CMDLINE_LINUX_DEFAULT" "/etc/default/grub")
|
||||
perl -pi -e "s/${GRUB_CMDLINE_LINUX}/GRUB_CMDLINE_LINUX_DEFAULT=\"${GRUB_CMDLINE} ${CMDLINE}\"/" "${SCRIPTDIR}/$DEFAULT/grub"
|
||||
else
|
||||
# Update the GRUB_CMDLINE_LINUX line
|
||||
GRUB_CMDLINE=$(grep -P "^GRUB_CMDLINE_LINUX" "/etc/default/grub" | perl -pe "s/GRUB_CMDLINE_LINUX=\"(.+)\"/\1/" | perl -pe "s/(amd|intel)_iommu=(on|1)|iommu=(pt|on)|vfio_pci.ids=.+|vfio_pci.disable_vga=\d{1}//g" | perl -pe "s/(^\s+|\s+$)//g")
|
||||
GRUB_CMDLINE_LINUX=$(grep -P "^GRUB_CMDLINE_LINUX" "/etc/default/grub")
|
||||
perl -pi -e "s/${GRUB_CMDLINE_LINUX}/GRUB_CMDLINE_LINUX=\"${GRUB_CMDLINE} ${CMDLINE}\"/" "${SCRIPTDIR}/$DEFAULT/grub"
|
||||
fi
|
||||
|
||||
|
||||
echo "The script will now replace your default grub file with a new one.
|
||||
Then attempt to update grub and generate a new grub.cfg.
|
||||
If generating the grub.cfg file fails, you can find a backup of your grub default file here:
|
||||
$SCRIPTDIR/backup/etc/default/grub
|
||||
"
|
||||
read -r -p "Press ENTER to continue"
|
||||
|
||||
sudo cp -v "$SCRIPTDIR/$DEFAULT/grub" "/etc/default/grub"
|
||||
|
||||
# Generate grub.cfg
|
||||
if [ -d "/boot/grub" ];
|
||||
then
|
||||
sudo grub-mkconfig -o "/boot/grub/grub.cfg"
|
||||
else
|
||||
sudo grub-mkconfig -o "/boot/grub2/grub.cfg"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
read -r -p "Please verify there were no errors generating the grub.cfg file, then press ENTER"
|
||||
}
|
||||
|
||||
function show_FINISH () {
|
||||
# Separator
|
||||
printf "
|
||||
############################################################
|
||||
"
|
||||
|
||||
# Get the config paths
|
||||
source "$SCRIPTDIR/lib/paths.sh"
|
||||
|
||||
local CMDLINE
|
||||
CMDLINE=$(cat "$SCRIPTDIR/config/kernel_args")
|
||||
|
||||
echo "Configuration is now complete!"
|
||||
|
||||
if [ "$1" == 0 ];
|
||||
then
|
||||
printf "For VFIO to work properly you need to make sure these kernel parameters are in your bootloader entry:
|
||||
#-----------------------------------------------#
|
||||
%s
|
||||
#-----------------------------------------------#
|
||||
|
||||
" "$CMDLINE"
|
||||
fi
|
||||
|
||||
echo "Restart your system and run
|
||||
\"$SCRIPTDIR/vfio-verify\"
|
||||
to check if your GPU is properly set up.
|
||||
|
||||
If the graphic card is bound to vfio-pci then you can
|
||||
proceed to add it to your virtual machines.
|
||||
|
||||
A backup the files we replaced on your system can be found inside
|
||||
$SCRIPTDIR/backup/
|
||||
In order to restore these files just copy them back to your system and
|
||||
rebuild your initramfs image.
|
||||
|
||||
You can remove the the vfio_pci kernel arguments from the linux line in your bootloader
|
||||
to disable/unbind the graphic card from the vfio driver on boot.
|
||||
|
||||
The files inside \"$SCRIPTDIR/$QUICKEMU\" are currently unused files, however they provide
|
||||
the required information that the QuickEMU project can hook into and use to add support for VFIO enabled VMs.
|
||||
|
||||
The PCI Devices with these IDs are what you should add to your VMs using Virt Manager:
|
||||
NOTE: Some AMD GPUs will require the vendor-reset kernel module from https://github.com/gnif/vendor-reset to be installed!"
|
||||
|
||||
source "${SCRIPTDIR}/config/quickemu/qemu-vfio_vars.conf"
|
||||
|
||||
for dev in "${GPU_PCI_ID[@]}"
|
||||
do
|
||||
echo "* $dev"
|
||||
done
|
||||
for dev in "${USB_CTL_ID[@]}"
|
||||
do
|
||||
echo "* $dev"
|
||||
done
|
||||
|
||||
echo "
|
||||
To add the graphic card to your VM using qemu directly, use the following arguments:"
|
||||
for dev in "${GPU_PCI_ID[@]}"
|
||||
do
|
||||
|
||||
echo -n "-device vfio-pci,host=$dev "
|
||||
done
|
||||
printf "\n"
|
||||
|
||||
echo "
|
||||
For performance tuning and advanced configuration look at:
|
||||
https://github.com/HikariKnight/vfio-setup-docs/wiki"
|
||||
}
|
||||
|
||||
function set_CMDLINE () {
|
||||
# Make a variable to tell if
|
||||
local BOOTLOADER_AUTOCONFIG
|
||||
BOOTLOADER_AUTOCONFIG=0
|
||||
|
||||
# If kernelstub is detected (program to manage systemd-boot)
|
||||
if which kernelstub > /dev/null 2>&1 ;
|
||||
then
|
||||
# Configure kernelstub
|
||||
set_KERNELSTUB
|
||||
BOOTLOADER_AUTOCONFIG=1
|
||||
fi
|
||||
|
||||
# If grub exists
|
||||
if which grub-mkconfig > /dev/null 2>&1 ;
|
||||
then
|
||||
# Configure grub
|
||||
set_GRUB
|
||||
BOOTLOADER_AUTOCONFIG=1
|
||||
fi
|
||||
|
||||
show_FINISH $BOOTLOADER_AUTOCONFIG
|
||||
}
|
||||
|
||||
|
||||
function main () {
|
||||
SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
|
||||
|
||||
set_CMDLINE
|
||||
}
|
||||
|
||||
main
|
30
old_bash_version/lib/set_DRACUT.sh
Executable file
30
old_bash_version/lib/set_DRACUT.sh
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
function set_DRACUT () {
|
||||
# Get the config paths
|
||||
source "$SCRIPTDIR/lib/paths.sh"
|
||||
|
||||
# Write the dracut config
|
||||
echo "add_drivers+=\" vfio_pci vfio vfio_iommu_type1 vfio_virqfd \"" > "$SCRIPTDIR/$DRACUT/10-vfio.conf"
|
||||
|
||||
# Get the kernel_args file content
|
||||
CMDLINE=$(cat "$SCRIPTDIR/config/kernel_args")
|
||||
|
||||
# Update kernel_args to load the vfio_pci module early in dracut (as dracut uses kernel arguments for early loading)
|
||||
echo "$CMDLINE rd.driver.pre=vfio_pci" > "$SCRIPTDIR/config/kernel_args"
|
||||
|
||||
# Bind GPU to VFIO
|
||||
"$SCRIPTDIR/lib/set_VFIO.sh" "$1"
|
||||
|
||||
# Configure modprobe
|
||||
exec "$SCRIPTDIR/lib/set_MODPROBE.sh" "$1"
|
||||
}
|
||||
|
||||
function main () {
|
||||
SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
|
||||
|
||||
set_DRACUT "$1"
|
||||
}
|
||||
|
||||
main "$1"
|
66
old_bash_version/lib/set_INITRAMFSTOOLS.sh
Executable file
66
old_bash_version/lib/set_INITRAMFSTOOLS.sh
Executable file
|
@ -0,0 +1,66 @@
|
|||
#!/bin/bash
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
function insert_INITRAMFSTOOLS() {
|
||||
# Get the header and enabled modules separately from the /etc/modules file
|
||||
local MODULES_HEADER
|
||||
local MODULES_ENABLED
|
||||
local VENDOR_RESET
|
||||
MODULES_HEADER=$(head -n "$1" "$2" | grep -P "^#" | grep -v "# Added by quickpassthrough")
|
||||
MODULES_ENABLED=$(grep -vP "^#" "$2" | grep -v "vendor-reset" | perl -pe "s/^\n//")
|
||||
VENDOR_RESET=0
|
||||
|
||||
# If vendor-reset is present
|
||||
if grep -q "vendor-reset" "$2" ;
|
||||
then
|
||||
VENDOR_RESET=1
|
||||
fi
|
||||
|
||||
# Write header
|
||||
echo "$MODULES_HEADER" > "$2"
|
||||
|
||||
# If vendor-reset existed from before
|
||||
if [ $VENDOR_RESET == 1 ];
|
||||
then
|
||||
# Write vendor-reset as the first module!
|
||||
echo "vendor-reset" >> "$2"
|
||||
fi
|
||||
|
||||
# Append vfio
|
||||
printf "
|
||||
# Added by quickpassthrough #
|
||||
vfio
|
||||
vfio_iommu_type1
|
||||
vfio_pci
|
||||
vfio_virqfd
|
||||
#############################
|
||||
" >> "$2"
|
||||
|
||||
# Write the previously enabled modules under vfio in the load order
|
||||
echo "$MODULES_ENABLED" >> "$2"
|
||||
}
|
||||
|
||||
function set_INITRAMFSTOOLS () {
|
||||
# Get the config paths
|
||||
source "$SCRIPTDIR/lib/paths.sh"
|
||||
|
||||
# Insert modules in the correct locations as early as possible without
|
||||
# conflicting with vendor-reset module if it is enabled
|
||||
insert_INITRAMFSTOOLS 4 "$SCRIPTDIR/$ETCMODULES"
|
||||
insert_INITRAMFSTOOLS 11 "$SCRIPTDIR/$INITRAMFS/modules"
|
||||
|
||||
# Bind GPU to VFIO
|
||||
"$SCRIPTDIR/lib/set_VFIO.sh" "$1"
|
||||
|
||||
# Configure modprobe
|
||||
exec "$SCRIPTDIR/lib/set_MODPROBE.sh" "$1"
|
||||
}
|
||||
|
||||
|
||||
function main () {
|
||||
SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
|
||||
|
||||
set_INITRAMFSTOOLS "$1"
|
||||
}
|
||||
|
||||
main "$1"
|
35
old_bash_version/lib/set_MKINITCPIO.sh
Executable file
35
old_bash_version/lib/set_MKINITCPIO.sh
Executable file
|
@ -0,0 +1,35 @@
|
|||
#!/bin/bash
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
function set_MKINITCPIO () {
|
||||
# Get the config paths
|
||||
source "$SCRIPTDIR/lib/paths.sh"
|
||||
|
||||
# Grab the current modules but exclude vfio and vendor-reset
|
||||
CURRENTMODULES=$(grep -P "^MODULES" "$SCRIPTDIR/$MKINITCPIO" | perl -pe "s/MODULES=\((.+)\)/\1/")
|
||||
MODULES="$(grep -P "^MODULES" "$SCRIPTDIR/$MKINITCPIO" | perl -pe "s/MODULES=\((.+)\)/\1/" | perl -pe "s/\s?(vfio_iommu_type1|vfio_pci|vfio_virqfd|vfio|vendor-reset)\s?//g")"
|
||||
|
||||
# Check if vendor-reset is present
|
||||
if [[ $CURRENTMODULES =~ "vendor-reset" ]];
|
||||
then
|
||||
# Inject vfio modules with vendor-reset
|
||||
perl -pi -e "s/MODULES=\(${CURRENTMODULES}\)/MODULES=\(vendor-reset vfio vfio_iommu_type1 vfio_pci vfio_virqfd ${MODULES}\)/" "$SCRIPTDIR/$MKINITCPIO"
|
||||
else
|
||||
# Inject vfio modules
|
||||
perl -pi -e "s/MODULES=\(${CURRENTMODULES}\)/MODULES=\(vfio vfio_iommu_type1 vfio_pci vfio_virqfd ${MODULES}\)/" "$SCRIPTDIR/$MKINITCPIO"
|
||||
fi
|
||||
|
||||
# Bind GPU to VFIO
|
||||
"$SCRIPTDIR/lib/set_VFIO.sh" "$1"
|
||||
|
||||
# Configure modprobe
|
||||
exec "$SCRIPTDIR/lib/set_MODPROBE.sh" "$1"
|
||||
}
|
||||
|
||||
function main () {
|
||||
SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
|
||||
|
||||
set_MKINITCPIO "$1"
|
||||
}
|
||||
|
||||
main "$1"
|
41
old_bash_version/lib/set_MODPROBE.sh
Executable file
41
old_bash_version/lib/set_MODPROBE.sh
Executable file
|
@ -0,0 +1,41 @@
|
|||
#!/bin/bash
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
function set_MODPROBE () {
|
||||
# Get the config paths
|
||||
source "$SCRIPTDIR/lib/paths.sh"
|
||||
|
||||
# Assign the GPU device ids to a variable
|
||||
GPU_DEVID="$1"
|
||||
|
||||
# If VGA is disabled
|
||||
if grep -q "vfio_pci.disable_vga=1" "$SCRIPTDIR/config/kernel_args" ;
|
||||
then
|
||||
# Modify our GPU_DEVID line to containe disable_vga=1
|
||||
GPU_DEVID="${GPU_DEVID} disable_vga=1"
|
||||
fi
|
||||
|
||||
# Write the vfio modprobe config
|
||||
printf "## This is an autogenerated file that stubs your graphic card for use with vfio
|
||||
## This file should be placed inside /etc/modprobe.d/
|
||||
# Uncomment the line below to \"hardcode\" your graphic card to be bound to the vfio-pci driver.
|
||||
# In most cases this should not be neccessary, it will also prevent you from turning off vfio in the bootloader.
|
||||
#options vfio_pci ids=%s
|
||||
|
||||
# Make sure vfio_pci is loaded before these modules: nvidia, nouveau, amdgpu and radeon
|
||||
softdep nvidia pre: vfio vfio_pci
|
||||
softdep nouveau pre: vfio vfio_pci
|
||||
softdep amdgpu pre: vfio vfio_pci
|
||||
softdep radeon pre: vfio vfio_pci
|
||||
" "${GPU_DEVID}" > "$SCRIPTDIR/$MODPROBE/vfio.conf"
|
||||
|
||||
exec "$SCRIPTDIR/lib/get_USB_CTL.sh"
|
||||
}
|
||||
|
||||
function main () {
|
||||
SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
|
||||
|
||||
set_MODPROBE "$1"
|
||||
}
|
||||
|
||||
main "$1"
|
47
old_bash_version/lib/set_VFIO.sh
Executable file
47
old_bash_version/lib/set_VFIO.sh
Executable file
|
@ -0,0 +1,47 @@
|
|||
#!/bin/bash
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
function set_VFIO () {
|
||||
# Get the config paths
|
||||
source "$SCRIPTDIR/lib/paths.sh"
|
||||
|
||||
# Assign the GPU device ids to a variable
|
||||
GPU_DEVID="$1"
|
||||
|
||||
# Get the kernel_args file content
|
||||
CMDLINE=$(cat "$SCRIPTDIR/config/kernel_args")
|
||||
|
||||
# Ask if we shall disable video output on this card
|
||||
echo "
|
||||
Disabling video output in Linux for the card you want to use in a VM
|
||||
will make it easier to successfully do the passthrough without issues."
|
||||
read -r -p "Do you want to force disable video output in linux on this card? [Y/n]: " DISABLE_VGA
|
||||
case "${DISABLE_VGA}" in
|
||||
[Yy]*)
|
||||
# Update kernel_args file
|
||||
echo "${CMDLINE} vfio_pci.ids=${GPU_DEVID} vfio_pci.disable_vga=1" > "$SCRIPTDIR/config/kernel_args"
|
||||
|
||||
# Update GPU_DEVID
|
||||
GPU_DEVID="$GPU_DEVID disable_vga=1"
|
||||
;;
|
||||
[Nn]*)
|
||||
# Update kernel_args file
|
||||
echo "${CMDLINE} vfio_pci.ids=${GPU_DEVID}" > "$SCRIPTDIR/config/kernel_args"
|
||||
;;
|
||||
*)
|
||||
# Update kernel_args file
|
||||
echo "${CMDLINE} vfio_pci.ids=${GPU_DEVID} vfio_pci.disable_vga=1" > "$SCRIPTDIR/config/kernel_args"
|
||||
|
||||
# Update GPU_DEVID
|
||||
GPU_DEVID="$GPU_DEVID disable_vga=1"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function main () {
|
||||
SCRIPTDIR=$(dirname "$(realpath "$0")" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
|
||||
|
||||
set_VFIO "$1"
|
||||
}
|
||||
|
||||
main "$1"
|
196
old_bash_version/vfio-setup
Executable file
196
old_bash_version/vfio-setup
Executable file
|
@ -0,0 +1,196 @@
|
|||
#!/bin/bash
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
# Get the scripts directory
|
||||
SCRIPTDIR=$(dirname "$(realpath "$0")")
|
||||
cd "$SCRIPTDIR" || exit
|
||||
|
||||
# Get the config paths
|
||||
source "$SCRIPTDIR/lib/paths.sh"
|
||||
|
||||
# Get the CPU Vendor
|
||||
CPU_VENDOR=$(grep "vendor_id" /proc/cpuinfo | head -1 | cut -f 2 | cut -d " " -f 2)
|
||||
CMDLINE="iommu=pt"
|
||||
|
||||
# Adjust our kernel_args based on cpu vendor
|
||||
if [ "$CPU_VENDOR" == "GenuineIntel" ];
|
||||
then
|
||||
CMDLINE="$CMDLINE intel_iommu=on"
|
||||
elif [ "$CPU_VENDOR" == "AuthenticAMD" ];
|
||||
then
|
||||
CMDLINE="$CMDLINE amd_iommu=on"
|
||||
fi
|
||||
|
||||
# Clear the screen
|
||||
clear
|
||||
|
||||
# Show the user a warning before we start
|
||||
printf "Welcome to QuickPassthrough!
|
||||
Written for systems using initramfs.
|
||||
|
||||
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.
|
||||
|
||||
Even though that this script is intended to make this setup easier, it is recommended that you
|
||||
read through a guide and learn what is actually being done so that you can get familiar the process.
|
||||
A full documentation for debian/ubuntu systems can be found here: https://github.com/hikariknight/vfio-setup-docs/wiki
|
||||
|
||||
Press ENTER to continue once you have made a backup of your system.
|
||||
"
|
||||
read -r
|
||||
|
||||
# Separator
|
||||
printf "
|
||||
############################################################
|
||||
"
|
||||
|
||||
echo "This script assumes a few things:
|
||||
* You have already enabled IOMMU, VT-d and/or AMD-v inside your UEFI/BIOS advanced settings.
|
||||
* You have already added \"$CMDLINE\" to your
|
||||
kernel boot arguments and booted your system with these kernel arguments active.
|
||||
* You are comfortable with navigating and changing settings in your UEFI/BIOS.
|
||||
* You know how edit your bootloader configuration and kernel arguments.
|
||||
* Your Linux distribution is an EFI installation (important to get VFIO working).
|
||||
|
||||
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 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 very different GPUs (iGPU/APU included), the easiest combination is to have 2 from different vendors (amd/intel/nvidia)
|
||||
if both cards share the same device id (ex: both are identified as 1022:145c), then passthrough will
|
||||
not be possible unless you swap out one of the cards.
|
||||
* 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 integrated GPU on your CPU, make sure your monitor is connected to it and working/enabled 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)
|
||||
|
||||
* It is also highly recommended to have access to your VM through VNC (RDP will not work) as once you pass through
|
||||
a graphic card, it will most likely not possible to interact with it through spice and the normal qemu display window!
|
||||
|
||||
Press ENTER to start creating your config from scratch.
|
||||
NOTE: continuing will delete the contents of \"$SCRIPTDIR/config\"
|
||||
"
|
||||
read -r
|
||||
|
||||
# Separator
|
||||
printf "
|
||||
############################################################
|
||||
"
|
||||
|
||||
if [ ! -d "$SCRIPTDIR/utils" ];
|
||||
then
|
||||
mkdir "$SCRIPTDIR/utils"
|
||||
fi
|
||||
|
||||
if [ ! -f "$SCRIPTDIR/utils/ls-iommu.tar.gz" ];
|
||||
then
|
||||
printf "Checking for newest version of ls-iommu\n"
|
||||
LS_IOMMU_VERSION=$($READAPI https://api.github.com/repos/hikariknight/ls-iommu/releases/latest | grep "tag_name" | perl -pe "s/.+\"tag_name\"\:\s+\"(\d+\.\d+\.\d+)\",/\1/")
|
||||
printf "Downloading required tool ls-iommu from https://github.com/hikariknight/ls-iommu\n"
|
||||
cd "$SCRIPTDIR/utils" || exit
|
||||
$DOWNLOAD https://github.com/HikariKnight/ls-iommu/releases/download/${LS_IOMMU_VERSION}/ls-iommu_${LS_IOMMU_VERSION}_Linux_x86_64.tar.gz
|
||||
tar -zxf "$SCRIPTDIR/utils/ls-iommu.tar.gz" --directory "$SCRIPTDIR/utils/"
|
||||
else
|
||||
if [ ! -f "$SCRIPTDIR/utils/ls-iommu" ];
|
||||
then
|
||||
tar -zxf "$SCRIPTDIR/utils/ls-iommu.tar.gz" --directory "$SCRIPTDIR/utils/"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -d "$SCRIPTDIR/config" ];
|
||||
then
|
||||
rm -r "$SCRIPTDIR/config"
|
||||
fi
|
||||
|
||||
# Make the directories
|
||||
mkdir -p "$SCRIPTDIR/$MODPROBE"
|
||||
mkdir -p "$SCRIPTDIR/$QUICKEMU"
|
||||
|
||||
# Write the cmdline file
|
||||
echo "$CMDLINE" > "$SCRIPTDIR/config/kernel_args"
|
||||
|
||||
# Copy system configs that exists into our config folder so we can safely edit them
|
||||
if [ -f "/etc/modules" ];
|
||||
then
|
||||
# This copies /etc/modules without the vfio module lines
|
||||
grep -v "vfio" "/etc/modules" > "$SCRIPTDIR/$ETCMODULES"
|
||||
fi
|
||||
|
||||
if [ -f "/etc/default/grub" ];
|
||||
then
|
||||
# Create the default folder
|
||||
mkdir -p "$SCRIPTDIR/$DEFAULT"
|
||||
|
||||
# Copy grub config
|
||||
cp "/etc/default/grub" "$SCRIPTDIR/$DEFAULT/grub"
|
||||
fi
|
||||
|
||||
if [ -f "/etc/initramfs-tools/modules" ];
|
||||
then
|
||||
# Create the initramfs folder
|
||||
mkdir -p "$SCRIPTDIR/$INITRAMFS"
|
||||
|
||||
# This copies /etc/initramfs-tools/modules without the vfio modules
|
||||
grep -v "vfio" "/etc/initramfs-tools/modules" > "$SCRIPTDIR/$INITRAMFS/modules"
|
||||
fi
|
||||
|
||||
if [ -f "/etc/mkinitcpio.conf" ];
|
||||
then
|
||||
# Copy mkinitcpio.conf to our config folder
|
||||
cp "/etc/mkinitcpio.conf" "$SCRIPTDIR/$MKINITCPIO"
|
||||
fi
|
||||
|
||||
if [ -f "/etc/dracut.conf" ];
|
||||
then
|
||||
# Create the dracut folder
|
||||
mkdir -p "$SCRIPTDIR/$DRACUT"
|
||||
# Create a dracut.conf.d file
|
||||
touch "$SCRIPTDIR/$DRACUT/10-vfio.conf"
|
||||
fi
|
||||
|
||||
# Run ls-iommu so we can verify that IOMMU properly working
|
||||
LS_IOMMU=$($SCRIPTDIR/utils/ls-iommu)
|
||||
|
||||
# Detect if IOMMU is disabled (output will be empty)
|
||||
if [[ "$LS_IOMMU" == "" ]];
|
||||
then
|
||||
# Tell user to enable IOMMU then try again
|
||||
echo "IOMMU IS NOT ENABLED!
|
||||
Please enable IOMMU, VT-d or AMD-v inside your UEFI/BIOS and add \"$CMDLINE\"
|
||||
to your kernel boot arguments and reboot your system, then re-run this script!
|
||||
"
|
||||
exit 1
|
||||
|
||||
else
|
||||
# Show the output of ls-iommu for manual verification
|
||||
echo "$LS_IOMMU"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# Have user visually verify that IOMMU is working
|
||||
read -r -p "Is there more than 1 group in the output above? [y/N]: " YESNO
|
||||
case "${YESNO}" in
|
||||
[Yy]*)
|
||||
echo ""
|
||||
;;
|
||||
[Nn]*)
|
||||
echo "Please enable IOMMU, VT-d or AMD-v inside your UEFI/BIOS and add \"$CMDLINE\"
|
||||
to your kernel boot arguments and reboot your system, then re-run this script!
|
||||
"
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
echo "Please enable IOMMU, VT-d or AMD-v inside your UEFI/BIOS and add \"$CMDLINE\"
|
||||
to your kernel boot arguments and reboot your system, then re-run this script!
|
||||
"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exec "$SCRIPTDIR/lib/get_GPU.sh"
|
32
old_bash_version/vfio-verify
Executable file
32
old_bash_version/vfio-verify
Executable file
|
@ -0,0 +1,32 @@
|
|||
#!/bin/bash
|
||||
# shellcheck disable=SC2002,SC2164
|
||||
|
||||
# Get the scripts directory
|
||||
SCRIPTDIR=$(dirname "$(which "$0")")
|
||||
cd "$SCRIPTDIR"
|
||||
|
||||
# If there is a config generated, then $SCRIPTDIR/config/kernel_args
|
||||
# should exist, which contains all the info we need
|
||||
if [ -f "$SCRIPTDIR/config/kernel_args" ];
|
||||
then
|
||||
echo "#------------------------------------------#"
|
||||
# List info about the vfio gpu and what kernel driver is being used
|
||||
"$SCRIPTDIR/utils/ls-iommu" -g -r -k
|
||||
echo "#------------------------------------------#"
|
||||
|
||||
printf "
|
||||
If the \"Kernel driver in use\" for the passed through devices are \"vfio-pci\", then VFIO has been successfully enabled!
|
||||
GPU Devices using \"pcieport\" can be ignored.
|
||||
|
||||
NOTE: If your system freezes when starting a VM that uses your VFIO enabled card..
|
||||
consider adding the below line to your bootloaders kernel arguments:
|
||||
vfio_pci.disable_vga=1
|
||||
|
||||
That will disable video output from the card while it is connected to the Linux host.
|
||||
"
|
||||
|
||||
else
|
||||
# Tell user to run the setup first if the kernel_args file is not found
|
||||
echo "Please run \"$SCRIPTDIR/vfio-setup\" first!"
|
||||
|
||||
fi
|
Loading…
Add table
Add a link
Reference in a new issue