insert vfio modules in the correct location

This commit is contained in:
HikariKnight 2022-03-10 15:30:54 +01:00
parent 0512d438cd
commit 3f0c99a2ba
No known key found for this signature in database
GPG key ID: E8B239063B022F5A

View file

@ -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"