From 3f0c99a2bad67edcb28477baf4ef05fb94a9c070 Mon Sep 17 00:00:00 2001 From: HikariKnight <2557889+HikariKnight@users.noreply.github.com> Date: Thu, 10 Mar 2022 15:30:54 +0100 Subject: [PATCH] insert vfio modules in the correct location --- lib/set_MODULES.sh | 57 +++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/lib/set_MODULES.sh b/lib/set_MODULES.sh index 9f66a15..648cf28 100755 --- a/lib/set_MODULES.sh +++ b/lib/set_MODULES.sh @@ -1,26 +1,47 @@ #!/bin/bash +function insert_MODULES () { + # Get the header and enabled modules separately from the /etc/modules file + MODULES_HEADER=$(head -n $1 "$2" | grep -P "^#" | grep -v "# Added by quickpassthrough") + MODULES_ENABLED=$(cat "$2" | grep -vP "^#" | grep -v "vendor-reset") + 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_MODULES () { # Get the config paths source "$SCRIPTDIR/lib/paths.sh" - - # Write "/etc/modules" - printf " -# Generated by vfio-setup -vfio -vfio_iommu_type1 -vfio_pci -vfio_virqfd -" >> "$SCRIPTDIR/$MODULES" - - # Write "/etc/initramfs-tools/modules" - printf " -# Generated by vfio-setup -vfio -vfio_iommu_type1 -vfio_pci -vfio_virqfd -" >> "$SCRIPTDIR/$INITRAMFS/modules" + + insert_MODULES 4 "$SCRIPTDIR/$MODULES" + insert_MODULES 11 "$SCRIPTDIR/$INITRAMFS/modules" # Assign the GPU device ids to a variable GPU_DEVID="$1"