Skip to content

Instantly share code, notes, and snippets.

@onyxhat
Last active March 10, 2026 00:52
Show Gist options
  • Select an option

  • Save onyxhat/8419b607e9cb8e5f27dc3c43e808832e to your computer and use it in GitHub Desktop.

Select an option

Save onyxhat/8419b607e9cb8e5f27dc3c43e808832e to your computer and use it in GitHub Desktop.
Minisforum MS-S1 Network Driver(s) Install
#!/usr/bin/env bash
# ============================================================
# RTL8125 / RTL8127 10GbE Network Driver Installer
# For Ubuntu 24.04 (Linux 6.8 kernel)
# ============================================================
set -e # Exit immediately on error
DRIVER_NAME="r8125"
DRIVER_VERSION="9.016.08"
DKMS_SRC_DIR="/usr/src/${DRIVER_NAME}-${DRIVER_VERSION}"
REPO_URL="https://github.com/awesometic/realtek-r8125-dkms.git"
CLONE_DIR="/tmp/realtek-r8125-dkms"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
info() { echo -e "${GREEN}[INFO]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; }
# ---- Generate netplan config ---------------------------------
generate_netplan() {
local NETPLAN_FILE="/etc/netplan/10-r8125-interfaces.yaml"
local INTERFACES=()
# Collect all ethernet interfaces that are NOT loopback
while IFS= read -r iface; do
INTERFACES+=("$iface")
done < <(ip -o link show | awk -F': ' '{print $2}' | grep -v lo | grep -v '@')
if [ ${#INTERFACES[@]} -eq 0 ]; then
warn "No network interfaces found — skipping netplan generation."
return
fi
info "Generating netplan config at ${NETPLAN_FILE}..."
cat > "${NETPLAN_FILE}" <<EOF
network:
version: 2
renderer: networkd
ethernets:
EOF
for iface in "${INTERFACES[@]}"; do
cat >> "${NETPLAN_FILE}" <<EOF
${iface}:
dhcp4: true
optional: true
EOF
done
chmod 600 "${NETPLAN_FILE}"
info "Applying netplan configuration..."
netplan apply
info "Netplan applied successfully."
}
# ---- Auto-rerun as root --------------------------------------
detect_current_uid() {
echo $(id -u)
}
rerun_script_as_root() {
if [ $(detect_current_uid) -ne "0" ]; then
local ENVVARS=$(echo $@)
echo "Re-running script as root..."
exec sudo $ENVVARS bash $0
fi
}
rerun_script_as_root "$@"
info "Starting RTL8125/RTL8127 driver installation..."
echo " Driver: ${DRIVER_NAME} Version: ${DRIVER_VERSION}"
echo " Kernel: $(uname -r)"
echo ""
# ---- Step 1: Install dependencies ----------------------------
info "Step 1/8 — Installing dependencies (build-essential, dkms, git, kernel headers)..."
apt install -y build-essential dkms git linux-headers-$(uname -r)
# ---- Step 2: Clone driver source -----------------------------
info "Step 2/8 — Cloning Realtek RTL8125 DKMS driver repository..."
rm -rf "${CLONE_DIR}"
git clone "${REPO_URL}" "${CLONE_DIR}"
# ---- Step 3: Copy source into DKMS tree ----------------------
info "Step 3/8 — Copying driver source to DKMS tree (${DKMS_SRC_DIR})..."
rm -rf "${DKMS_SRC_DIR}"
cp -r "${CLONE_DIR}/." "${DKMS_SRC_DIR}"
# ---- Step 4: Register module with DKMS -----------------------
info "Step 4/8 — Registering module with DKMS..."
dkms add -m "${DRIVER_NAME}" -v "${DRIVER_VERSION}"
# ---- Step 5: Build module ------------------------------------
info "Step 5/8 — Building driver against kernel $(uname -r)..."
dkms build -m "${DRIVER_NAME}" -v "${DRIVER_VERSION}"
# ---- Step 6: Install module ----------------------------------
info "Step 6/8 — Installing compiled module..."
dkms install -m "${DRIVER_NAME}" -v "${DRIVER_VERSION}"
# ---- Step 7: Load module & verify ----------------------------
info "Step 7/8 — Loading driver into running kernel..."
# Unload old/conflicting r8169 module if present
if lsmod | grep -q r8169; then
warn "Unloading existing r8169 module..."
modprobe -r r8169 || true
fi
modprobe "${DRIVER_NAME}"
# ---- Step 8: Generate netplan config -------------------------
echo ""
info "Step 8/8 — Generating netplan config for discovered interfaces..."
generate_netplan
echo ""
info "Verifying module is loaded:"
if lsmod | grep -q "${DRIVER_NAME}"; then
lsmod | grep "${DRIVER_NAME}"
echo ""
info "✔ Driver loaded successfully!"
else
error "Module '${DRIVER_NAME}' is NOT loaded. Check dmesg for errors."
fi
# ---- Show network device info --------------------------------
echo ""
info "PCI network devices detected:"
lspci | grep -i net || true
echo ""
info "Network interface names (enp*):"
ip link | grep -E '^[0-9]+: enp' | awk '{print $2}' || true
echo ""
info "All done! The r8125 driver will be automatically rebuilt by DKMS on kernel upgrades."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment