quickpassthrough/lib/set_MODULES.sh

76 lines
2.1 KiB
Bash
Raw Normal View History

2022-02-27 11:19:22 -05:00
#!/bin/bash
function set_MODULES () {
# Get the config paths
source "$SCRIPTDIR/lib/paths.sh"
# Write "/etc/modules"
printf "
# Generated by vfio-setup
vfio
2022-02-27 11:19:22 -05:00
vfio_iommu_type1
vfio_pci
2022-02-27 11:19:22 -05:00
vfio_virqfd
" >> "$SCRIPTDIR/$MODULES"
2022-02-27 11:19:22 -05:00
# Write "/etc/initramfs-tools/modules"
printf "
# Generated by vfio-setup
vfio
2022-02-27 11:19:22 -05:00
vfio_iommu_type1
vfio_pci
vfio_virqfd
" >> "$SCRIPTDIR/$INITRAMFS/modules"
# Assign the GPU device ids to a variable
GPU_DEVID="$1"
# Get the kernel_args file content
2022-02-27 13:18:09 -05:00
CMDLINE=$(cat "$SCRIPTDIR/config/kernel_args")
2022-02-27 11:19:22 -05:00
# Ask if we shall disable video output on this card
2022-02-27 13:06:18 -05:00
read -p "Do you want to force disable video output in linux on this card? [Y/n]: " DISABLE_VGA
2022-02-27 11:19:22 -05:00
case "${DISABLE_VGA}" in
[Yy]*)
GPU_DEVID="${GPU_DEVID} disable_vga=1"
# Update kernel_args file
echo "${CMDLINE} vfio_pci.ids=${GPU_DEVID} vfio_pci.disable_vga=1" > "$SCRIPTDIR/config/kernel_args"
2022-02-27 11:19:22 -05:00
;;
[Nn]*)
echo ""
;;
*)
GPU_DEVID="${GPU_DEVID} disable_vga=1"
# Update kernel_args file
echo "${CMDLINE} vfio_pci.ids=${GPU_DEVID} vfio_pci.disable_vga=1" > "$SCRIPTDIR/config/kernel_args"
2022-02-27 11:19:22 -05:00
;;
esac
2022-02-27 11:19:22 -05:00
# 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
2022-03-01 03:02:29 -05:00
# Make sure vfio_pci is loaded before these modules: nvidia, nouveau, amdgpu and radeon
2022-02-27 11:19:22 -05:00
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"
2022-02-27 11:19:22 -05:00
exec "$SCRIPTDIR/lib/get_USB_CTL.sh"
}
function main () {
SCRIPTDIR=$(dirname "$(which $0)" | perl -pe "s/\/\.\.\/lib//" | perl -pe "s/\/lib$//")
set_MODULES "$1"
2022-02-27 11:19:22 -05:00
}
main "$1"