fixed service creation, edited method of obtaining nic.

This commit is contained in:
crowetic 2025-04-16 21:02:23 +00:00
parent a04c4f552a
commit 73f21e5e26

View File

@ -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 <<EOF
[Unit]
Description=Disable all VM NIC offloads at boot
@ -28,12 +48,7 @@ After=network.target
[Service]
Type=oneshot
ExecStart=/bin/bash -c '
$(for nic in $NIC_LIST; do
echo "/usr/sbin/ethtool -K $nic tx off rx off tso off gso off gro off;"
echo "/sbin/ip link set $nic txqueuelen 10000;"
done)
'
ExecStart=/bin/bash -c "$DISABLE_CMDS_ESCAPED"
RemainAfterExit=yes
[Install]
@ -41,11 +56,12 @@ WantedBy=multi-user.target
EOF
echo "=== Enabling and starting NIC offload disable service ==="
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable --now disable-vm-nic-offloads.service
echo "=== ✅ VM NIC setup complete ==="
for nic in $NIC_LIST; do
for nic in "${NIC_LIST[@]}"; do
echo "--- $nic ---"
ethtool -k "$nic" | grep -E 'segmentation|offload|scatter|checksum'
ip link show "$nic" | grep txqueuelen