用sing-box作为服务端总会用到tcp-brutal,但是debian11/ubuntu20等系统安装tcp-brutal总会失败报错
error: Failed to load kernel module, kernel module might not be installed successfully. warning: tcp-brutal is installed but failed to load.
- 安装nix
apt install nix -y
- 在vps你觉得好看的目录下创建文件
touch shell.nix
- 将以下内容写入第二步创建的文件内保存
let nixpkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/refs/tags/24.05.tar.gz") {}; pkgs = nixpkgs.pkgs; lib = nixpkgs.lib; script = '' #!/usr/bin/env bash set -e LDSO="${pkgs.glibc}/lib/ld-linux-x86-64.so.2" RPATH="${lib.makeLibraryPath [ pkgs.glibc pkgs.elfutils ]}" PATCHELF="${pkgs.patchelf}/bin/patchelf" FILE="${pkgs.file}/bin/file" FIND="${pkgs.findutils}/bin/find" is_executable() { local _target="$1" local _mimetype="$("$FILE" --mime-type --brief "$_target")" [[ "$_mimetype" == "application"*"executable"* ]] } patch_kernel_dir() { local _dir="$1" echo "[info] patching dir $_dir" local _saved_IFS="$IFS" IFS="$(echo)" "$FIND" "$_dir" -type f | while read -r f; do if is_executable "$f"; then patch_kernel_elf "$f" fi done IFS="$_saved_IFS" } patch_kernel_elf() { local _target="$1" echo "[info] patching $_target" "$PATCHELF" \ --set-interpreter "$LDSO" \ --set-rpath "$RPATH" \ "$_target" } find_kernel_dir() { local _kernel_version="$1" if [[ -z "$_kernel_version" ]]; then _kernel_version="$(uname -r)" fi echo "/lib/modules/$_kernel_version/build" } show_usage() { echo "usage: $0 [-h] [-k kernel_version] [-d kernel_dir]" >&2 } main() { local _kernel_version="" local _kernel_dir="" while getopts "hd:v:" opt; do case $opt in h) show_usage exit 0 ;; k) _kernel_version="$OPTARG" ;; d) _kernel_dir="$" esac done if [[ -z "$_kernel_dir" ]]; then _kernel_dir="$(find_kernel_dir "$_kernel_version")" fi if [[ ! -e "$_kernel_dir" ]]; then echo "[error] kernel dir $kernel_dir does not exist" >&2 exit 22 fi patch_kernel_dir "$_kernel_dir/tools" patch_kernel_dir "$_kernel_dir/scripts" echo "done." } main "$@" ''; fix-kernel-headers = { stdenv, lib, pkgs }: stdenv.mkDerivation { pname = "fix-kernel-headers"; version = "0.0.2"; unpackPhase = "true"; installPhase = '' mkdir -p "$out/bin" echo '${script}' > "$out/bin/fix-kernel-headers" chmod +x "$out/bin/fix-kernel-headers" ''; }; fix-kernel-headers-pkg = pkgs.callPackage fix-kernel-headers {}; in nixpkgs.mkShell { buildInputs = [ fix-kernel-headers-pkg ]; }
- 在 shell.nix 同级目录下执行以下命令
nix-shell --run fix-kernel-headers
- 第四步完成之后再次执行tcp-bruta安装脚本
bash <(curl -fsSL https://tcp.hy2.sh/)
|