-
Notifications
You must be signed in to change notification settings - Fork 2
/
iommu
72 lines (61 loc) · 1.94 KB
/
iommu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# Function to detect CPU manufacturer
get_cpu_manufacturer() {
if lscpu | grep -q "GenuineIntel"; then
echo "intel"
elif lscpu | grep -q "AuthenticAMD"; then
echo "amd"
else
echo "unknown"
fi
}
# Function to configure GRUB based on CPU type
configure_grub() {
local cpu_type="$1"
local grub_file="/etc/default/grub"
local grub_entry=""
if [ "$cpu_type" == "intel" ]; then
grub_entry="GRUB_CMDLINE_LINUX_DEFAULT=\"quiet intel_iommu=on iommu=pt\""
elif [ "$cpu_type" == "amd" ]; then
grub_entry="GRUB_CMDLINE_LINUX_DEFAULT=\"quiet amd_iommu=on iommu=pt\""
fi
if [ -n "$grub_entry" ]; then
# Use sed to find and replace the desired line
sed -i "s/GRUB_CMDLINE_LINUX_DEFAULT=\"quiet.*/$grub_entry/" "$grub_file"
fi
update-grub
}
# Function to configure /etc/modules
configure_modules() {
local modules_file="/etc/modules"
local vfio_entries=("vfio" "vfio_iommu_type1" "vfio_pci" "vfio_virqfd")
if [ -f "$modules_file" ]; then
# Remove any existing VFIO entries to prevent duplicates
sed -i '/vfio\|vfio_iommu_type1\|vfio_pci\|vfio_virqfd/d' "$modules_file"
# Append each VFIO entry on a separate line
for entry in "${vfio_entries[@]}"; do
echo "$entry" >> "$modules_file"
done
fi
}
# Main script
cpu_type=$(get_cpu_manufacturer)
if [ "$cpu_type" == "intel" ]; then
configure_grub "intel"
configure_modules
echo "Configuration completed for Intel CPU."
elif [ "$cpu_type" == "amd" ]; then
configure_grub "amd"
configure_modules
echo "Configuration completed for AMD CPU."
else
echo "Unsupported CPU type or detection error."
exit 1
fi
read -p "Configuration completed. Reboot now? (y/n): " choice
if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then
echo "Rebooting..."
reboot
else
echo "Please reboot your system later to apply the changes."
fi