Skip to content

Instantly share code, notes, and snippets.

@bouroo
Last active September 19, 2024 04:58
Show Gist options
  • Save bouroo/eee9c371a976f5b8a8893d33b3690022 to your computer and use it in GitHub Desktop.
Save bouroo/eee9c371a976f5b8a8893d33b3690022 to your computer and use it in GitHub Desktop.
Intel Gen 12/13 vGPU SR-IOV on Proxmox Host Enabler (Installer)
#!/usr/bin/env bash
# Print header information
cat << "EOF"
+----------------------------------------------------------------------+
| Intel Gen 12/13 vGPU SR-IOV on Proxmox Host Enabler (Installer) |
| https://github.com/Upinel/Intel-vGPU-SRIOV-on-Proxmox |
+----------------------------------------------------------------------+
| This source file is subject to version 2.0 of the Apache license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.apache.org/licenses/LICENSE-2.0.html |
| If you did not receive a copy of the Apache2.0 license and are unable|
| to obtain it through the world-wide-web, please send a note to |
| license@swoole.com so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Nova Upinel Chow <dev@upinel.com> |
| Editor: Kawin Viriyaprasopsook <kawin.v@kkumail.com> |
| Date: 19/Sep/2024 |
+----------------------------------------------------------------------+
EOF
echo "Enable IO-MMU on PVE Server"
# Kernel version check
kernel_version=$(uname -r | awk -F '[.-]' '{print $1"."$2}')
target_version="6.5"
if [[ $(echo "$kernel_version < $target_version" | bc) -eq 1 ]]; then
echo "Current version ($kernel_version) is lower than $target_version. Please upgrade the kernel first and return here."
exit 1
fi
# Install required packages
apt install -y git pve-headers mokutil dkms build-essential sysfsutils unzip
# Clean up previous installations
rm -rf /var/lib/dkms/i915-sriov-dkms* /usr/src/i915-sriov-dkms* ~/i915-sriov-dkms
# Clone the repository and modify dkms.conf
KERNEL=$(uname -r | sed 's/-pve//')
git clone https://github.com/strongtz/i915-sriov-dkms.git ~/i915-sriov-dkms
# Backup and modify dkms.conf
cp ~/i915-sriov-dkms/dkms.conf{,.bak}
sed -i "s/@_PKGBASE@/i915-sriov-dkms/g; s/@PKGVER@/$KERNEL/g; s/ -j\$(nproc)//g" ~/i915-sriov-dkms/dkms.conf
# Get the DKMS version
dkms_ver=$(awk -F '=' '/PACKAGE_VERSION=/{gsub(/"/, "", $2); print $2}' ~/i915-sriov-dkms/dkms.conf)
cat ~/i915-sriov-dkms/dkms.conf
# Add and install the DKMS module
cd ~/i915-sriov-dkms
dkms add .
dkms install -m i915-sriov-dkms -v "$dkms_ver" -k "$(uname -r)" --force -j 1
dkms status
# Update GRUB configuration for IO-MMU
echo ""
echo "********************************************"
echo "*** Enable IO-MMU on proxmox host ***"
echo "********************************************"
cp /etc/default/grub{,.bak}
sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="quiet"/GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt i915.enable_guc=3 i915.max_vfs=7"/' /etc/default/grub
# Update grub
echo ""
echo " Updating GRUB..."
update-grub
update-initramfs -u -k all
pve-efiboot-tool refresh
# Configure sysfs for SR-IOV
echo ""
echo " Installing sysfsutils and setting sriov_numvfs=7"
# Check if the line already exists in /etc/sysfs.conf
line_to_append="devices/pci0000:00/0000:00:02.0/sriov_numvfs = 7"
if ! grep -qF "$line_to_append" /etc/sysfs.conf; then
echo "$line_to_append" >> /etc/sysfs.conf
echo "Added line to /etc/sysfs.conf"
else
echo "Line already exists in /etc/sysfs.conf, skipping."
fi
echo ""
echo " Please verify SR-IOV by running 'lspci | grep VGA' after reboot."
# Interactive prompt for reboot
while true; do
read -p "Do you want to reboot now? (y/n): " answer
case $answer in
[Yy]* )
echo "Rebooting now..."
reboot
break
;;
[Nn]* )
echo "You chose not to reboot. Please remember to reboot later to apply changes."
break
;;
* )
echo "Please answer yes (y) or no (n)."
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment