From 73f21e5e260f08409ae83b87c9067c6189c1fcdb Mon Sep 17 00:00:00 2001 From: crowetic Date: Wed, 16 Apr 2025 21:02:23 +0000 Subject: [PATCH] fixed service creation, edited method of obtaining nic. --- vm-tool-setup.sh | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/vm-tool-setup.sh b/vm-tool-setup.sh index 70146bb..9d274f0 100755 --- a/vm-tool-setup.sh +++ b/vm-tool-setup.sh @@ -14,13 +14,33 @@ echo "=== [3/5] Trimming filesystems ===" sudo fstrim -av || true echo "=== [4/5] Detecting VM network interfaces ===" -NIC_LIST=$(ls /sys/class/net | grep -Ev '^(lo|docker|br|vmbr|tap|veth)' | xargs) +NIC_LIST=() +for nic in /sys/class/net/*; do + nicname=$(basename "$nic") + if [[ "$nicname" != "lo" && "$nicname" != vmbr* && "$nicname" != tap* && "$nicname" != veth* && "$nicname" != docker* ]]; then + NIC_LIST+=("$nicname") + fi +done -echo "VM NICs detected: $NIC_LIST" +if [[ ${#NIC_LIST[@]} -eq 0 ]]; then + echo "⚠️ No usable NICs detected. Exiting." + exit 1 +fi + +echo "VM NICs detected: ${NIC_LIST[*]}" echo "=== [5/5] Creating persistent systemd service to disable offloads ===" SERVICE_FILE="/etc/systemd/system/disable-vm-nic-offloads.service" +DISABLE_CMDS="" +for nic in "${NIC_LIST[@]}"; do + DISABLE_CMDS+="/usr/sbin/ethtool -K $nic tx off rx off tso off gso off gro off; " + DISABLE_CMDS+="/sbin/ip link set $nic txqueuelen 10000; " +done + +# Escape for ExecStart +DISABLE_CMDS_ESCAPED=$(printf '%q ' "$DISABLE_CMDS") + sudo tee "$SERVICE_FILE" > /dev/null <