Skip to content

Instantly share code, notes, and snippets.

@karlivory
Created September 30, 2025 08:41
Show Gist options
  • Select an option

  • Save karlivory/9111f906f4eb06370b2b237c62a6b00e to your computer and use it in GitHub Desktop.

Select an option

Save karlivory/9111f906f4eb06370b2b237c62a6b00e to your computer and use it in GitHub Desktop.
bash hotfix for 'perf not found for kernel 6.14.0-24'
#!/usr/bin/env bash
# Usage: sudo bash build-perf.sh
set -euo pipefail
# --- Helpers ---
log() { echo -e "\033[1;32m==>\033[0m $*"; }
err() { echo -e "\033[1;31m[ERR]\033[0m $*" >&2; }
[[ $EUID -eq 0 ]] || {
err "Please run as root (use: sudo bash build-perf.sh)"
exit 1
}
export DEBIAN_FRONTEND=noninteractive
FULLREL="$(uname -r)" # e.g. 6.14.0-29-generic
MAJMIN="$(uname -r | awk -F'[.-]' '{print $1 "." $2}')" # e.g. 6.14
WRAP_DIR="/usr/lib/linux-tools/${FULLREL}"
log "Detected running kernel: ${FULLREL}"
log "Using upstream kernel source line: ${MAJMIN}"
# --- Install deps ---
log "Installing build dependencies..."
apt-get update -y
apt-get install -y \
build-essential make gcc g++ pkg-config flex bison \
curl ca-certificates xz-utils tar \
libelf-dev libdw-dev libdwarf-dev libunwind-dev \
libnuma-dev libssl-dev libcap-dev \
zlib1g-dev liblzma-dev libzstd-dev \
libaio-dev libtraceevent-dev libpfm4-dev \
libslang2-dev systemtap-sdt-dev \
python3 python3-dev python3-setuptools \
binutils-dev libiberty-dev libbabeltrace-dev \
libbfd-dev clang llvm || true
apt-get install -y debuginfod || true
# --- Fetch kernel sources ---
WORKDIR="$(mktemp -d -t perfbuild-XXXXXX)"
trap 'rm -rf "$WORKDIR"' EXIT
pushd "$WORKDIR" >/dev/null
BASE_URL="https://mirrors.edge.kernel.org/pub/linux/kernel/v6.x"
ARCHIVE=""
for f in "linux-${MAJMIN}.tar.xz" "linux-${MAJMIN}.tar.gz"; do
log "Downloading: ${BASE_URL}/${f}"
if curl -fsSLO "${BASE_URL}/${f}"; then
ARCHIVE="$f"
break
fi
done
[[ -n "$ARCHIVE" ]] || {
err "Failed to download linux-${MAJMIN} from ${BASE_URL}"
exit 2
}
log "Extracting ${ARCHIVE} ..."
tar -xf "${ARCHIVE}"
SRC_DIR="${WORKDIR}/linux-${MAJMIN}"
[[ -d "${SRC_DIR}/tools/perf" ]] || {
err "tools/perf not found in sources"
exit 3
}
[[ -d "${SRC_DIR}/tools/bpf/bpftool" ]] || {
err "tools/bpf/bpftool not found in sources"
exit 3
}
# --- Build perf ---
pushd "${SRC_DIR}/tools/perf" >/dev/null
log "Building perf (WERROR=0) ..."
make -j"$(nproc)" WERROR=0
log "Built perf version: $(./perf --version)"
popd >/dev/null
# --- Build bpftool ---
pushd "${SRC_DIR}/tools/bpf/bpftool" >/dev/null
log "Building bpftool ..."
make -j"$(nproc)"
log "Built bpftool version: $(./bpftool version || true)"
popd >/dev/null
# --- Install into wrapper path(s) ---
log "Installing perf to ${WRAP_DIR}/perf"
install -d "${WRAP_DIR}"
install -m 0755 "${SRC_DIR}/tools/perf/perf" "${WRAP_DIR}/perf"
log "Installing bpftool to ${WRAP_DIR}/bpftool"
install -m 0755 "${SRC_DIR}/tools/bpf/bpftool/bpftool" "${WRAP_DIR}/bpftool"
# --- Verify via Ubuntu wrappers ---
log "Verifying /usr/bin/perf (Ubuntu wrapper) ..."
if /usr/bin/perf --version >/dev/null 2>&1; then
/usr/bin/perf --version
log "Success: wrapper found perf at ${WRAP_DIR}/perf"
else
err "Wrapper did not run perf. Check that ${WRAP_DIR}/perf exists and is executable."
ls -l "${WRAP_DIR}/perf" || true
exit 4
fi
log "Verifying /usr/sbin/bpftool (Ubuntu wrapper) ..."
if /usr/sbin/bpftool version >/dev/null 2>&1; then
/usr/sbin/bpftool version
log "Success: wrapper found bpftool at ${WRAP_DIR}/bpftool"
else
err "Wrapper did not run bpftool. Check that ${WRAP_DIR}/bpftool exists and is executable."
ls -l "${WRAP_DIR}/bpftool" || true
exit 5
fi
log "Done."
@SmartKeyerror
Copy link

That’s fantastic — your solution worked perfectly! I really appreciate your help and clear explanation. Thank you!

@MortenLohne
Copy link

This worked for me on Ubuntu 24.04 LTS, thanks!

@benbaarber
Copy link

Worked for me as well on ubuntu 24.04, thanks goat

@K0toulas
Copy link

Worked for me as well on Ubuntu 24.04. Thanks mate you are a life saver for my thesis

@Riku-lou-loup
Copy link

Worked for me on Ubuntu 24.04. Thanks alot !

@YuriRDev
Copy link

Thanks a lot! Worked for me on Ubuntu 24.04 LTS!

@mgarbula
Copy link

mgarbula commented Nov 5, 2025

After reboot I had to install it again. Is there a way to keep it?

@witlethe
Copy link

witlethe commented Nov 6, 2025

thanks alot! it works on my ubuntu24.04LTS

@osa1
Copy link

osa1 commented Nov 9, 2025

Fails on my system with ./bpftool: symbol lookup error: ./bpftool: undefined symbol: LLVMInitializeVETargetMC, version LLVM_18.1.

Probably has to do with the C/C++ toolchains I have installed on my system?

Edit: works if I remove the clang and llvm packages from the apt install line and manually remove them.

@fuzhibo
Copy link

fuzhibo commented Nov 13, 2025

cool! thx! it works for me!

@turtleizzy
Copy link

Cool. Worked on Linux Mint 22 with mainline kernel.

@MakarDev
Copy link

Works! No more perf not found for kernel 6.14.0-1016

@lim-james
Copy link

Beautiful it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment