check-kernel-config.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env bash
  2. get_kernel_version() {
  3. r="$(uname -r | cut -f 1 -d '-')"
  4. read -r -a p <<< "$(echo "${r}" | tr '.' ' ')"
  5. printf "%03d%03d%03d" "${p[0]}" "${p[1]}" "${p[2]}"
  6. }
  7. get_rh_version() {
  8. if [ ! -f /etc/redhat-release ]; then
  9. printf "000000000"
  10. return
  11. fi
  12. r="$(cut -f 4 -d ' ' < /etc/redhat-release)"
  13. read -r -a p <<< "$(echo "${r}" | tr '.' ' ')"
  14. printf "%03d%03d%03d" "${p[0]}" "${p[1]}" "${p[2]}"
  15. }
  16. if [ "$(uname -s)" != "Linux" ]; then
  17. echo >&2 "This does not appear to be a Linux system."
  18. exit 1
  19. fi
  20. KERNEL_VERSION="$(uname -r)"
  21. if [ "$(get_kernel_version)" -lt 004014000 ] && [ "$(get_rh_version)" -lt 0070061810 ]; then
  22. echo >&2 "WARNING: Your kernel appears to be older than 4.11 or you are using RH version older than 7.6.1810. This may still work in some cases, but probably won't."
  23. fi
  24. CONFIG_PATH=""
  25. MODULE_LOADED=""
  26. if modprobe configs 2> /dev/null; then
  27. MODULE_LOADED=1
  28. fi
  29. if [ -r /proc/config.gz ]; then
  30. CONFIG_PATH="/proc/config.gz"
  31. elif [ -r "/lib/modules/${KERNEL_VERSION}/source/.config" ]; then
  32. CONFIG_PATH="/lib/modules/${KERNEL_VERSION}/source/.config"
  33. elif [ -r "/lib/modules/${KERNEL_VERSION}.x86_64/source/.config" ]; then
  34. CONFIG_PATH="/lib/modules/${KERNEL_VERSION}.x86_64/source/.config"
  35. elif [ -n "$(find /boot -name "config-${KERNEL_VERSION}*")" ]; then
  36. CONFIG_PATH="$(find /boot -name "config-${KERNEL_VERSION}*" | head -n 1)"
  37. fi
  38. if [ -n "${CONFIG_PATH}" ]; then
  39. GREP='grep'
  40. CAT='cat'
  41. if echo "${CONFIG_PATH}" | grep -q '.gz'; then
  42. CAT='zcat'
  43. fi
  44. REQUIRED_CONFIG="KPROBES KPROBES_ON_FTRACE HAVE_KPROBES BPF BPF_SYSCALL BPF_JIT"
  45. for required_config in ${REQUIRED_CONFIG}; do
  46. # Fix issue https://github.com/netdata/netdata/issues/14668
  47. # if ! "${GREP}" -q "CONFIG_${required_config}=y" "${CONFIG_PATH}"; then
  48. if ! { "${CAT}" "${CONFIG_PATH}" | "${GREP}" -q "CONFIG_${required_config}=y" >&2 >/dev/null; } ;then
  49. echo >&2 " Missing Kernel Config: ${required_config}"
  50. exit 1
  51. fi
  52. done
  53. fi
  54. if [ -n "${MODULE_LOADED}" ]; then
  55. modprobe -r configs 2> /dev/null || true # Ignore failures from CONFIGS being builtin
  56. fi
  57. exit 0