Git Product home page Git Product logo

kumk's People

Contributors

k3dar avatar

Stargazers

 avatar  avatar  avatar  avatar

kumk's Issues

HOWTO: build kernel modules when kernel is installed via glibc hack

I just needed to build a DKMS module for kernel 6.2.2, which needs to be installed via the hack on my system. The hack copies objtool and other helper binaries from kernel 5.11 for them to work with the older system glibc. However, building modules for the newer kernel makes use of many features of objtool the older one doesn't have.

I was seeking for a way to build and load the module and I've found one. Here's a guide. It seems to me it could be generalized to be automatically used by kumk, except for the custom glibc install. But I can imagine even that could become a part of kumk if there is will.

  1. Install a kernel with kumk. In this example, it is 6.2.2.
  2. Build a recent version of glibc and install it in a custom (non-system!) path.
    1. cd /tmp && wget http://archive.ubuntu.com/ubuntu/pool/main/g/glibc/glibc_2.38.orig.tar.xz
    2. mkdir /tmp/glibc && cd /tmp/glibc
    3. tar -xvf /tmp/glibc_2.38.orig.tar.xz
    4. mkdir build && cd build
    5. ../glibc-2.38/configure --prefix=/opt/glibc
    6. make -j8
    7. sudo make -j8 install
  3. Install patchelf utility: sudo apt install patchelf
  4. Backup the upstream objtool: sudo cp /usr/src/linux-headers-6.2.2-060202-generic/tools/objtool/objtool.orig{,.orig}
  5. Backup the older objtool: sudo cp /usr/src/linux-headers-6.2.2-060202-generic/tools/objtool/objtool{,.orig.old}
  6. Overwrite the objtool from hack with the upstream one: sudo cp /usr/src/linux-headers-6.2.2-060202-generic/tools/objtool/objtool{.orig,}
  7. Patch the upstream objtool to use the custom glibc: sudo patchelf --set-interpreter /opt/glibc/lib/ld-linux-x86-64.so.2 --set-rpath /opt/glibc /usr/src/linux-headers-6.2.2-060202-generic/tools/objtool/objtool
  8. objtool also has some dependencies which need to be patched
    1. sudo cp /lib/x86_64-linux-gnu/libz.so.1 /usr/lib/x86_64-linux-gnu/libelf.so.1 /opt/glibc/lib/
    2. sudo patchelf --set-rpath /opt/glibc /opt/glibc/lib/libelf.so.1
    3. sudo patchelf --set-rpath /opt/glibc /opt/glibc/lib/libz.so.1
  9. Try running the objtool: /usr/src/linux-headers-6.2.2-060202-generic/tools/objtool/objtool
    1. You should see help printed by the tool. The newer one has options like --hacks etc. while the old one has only commands check and orc.
  10. Repeat 3-8 for the other tools, too:
    • scripts/basic/fixdep
    • tools/objtool/fixdep
    • tools/bpf/resolve_btfids/fixdep
    • scripts/mod/modpost
    • tools/objtool/objtool (already done, but to keep the list complete)
    • scripts/genksyms/genksyms
    • scripts/sign-file
  11. You will also probably need GCC in the version that was used in the particular kernel. I got it by checking out GCC 13 sources and building them.
    1. mkdir /tmp/gcc && cd /tmp/gcc
    2. export GCC_VERSION=13
    3. git clone -b releases/gcc-${GCC_VERSION} --depth 1 https://gcc.gnu.org/git/gcc.git gcc-source
    4. mkdir build && cd build
    5. sudo apt build-dep gcc-8 # this installs the build-time dependencies; we use an already installed version of gcc; if you're lucky, the dependencies of the newer version are the same
    6. ../gcc-source/configure --prefix=/usr --program-suffix=-${GCC_VERSION} --enable-languages=c,c++ --disable-multilib
    7. make -j8
    8. sudo make -j8 install
  12. Now it's time to build the kernel module. For example, r8152 from wget/realtek-r8152-linux#8 (comment) .
    1. Download the source, copy it to /usr/src/r8152-2.16.3 and create the dkms.conf according to the linked guide.
    2. sudo dkms add -m r8152 -v 2.16.3
    3. sudo dkms build -m r8152 -v 2.16.3
    4. sudo dkms install -m r8152 -v 2.16.3
  13. If you already had the DKMS module installed from before and it failed building during kumk kernel install, you can trigger rebuild of all modules with the patched objtool with sudo dpkg-reconfigure linux-modules-6.2.2-060202-generic

Install linux-tools (perf, cpupower etc.)

The mainline builds do not provide perf, cpupower etc. If you want them for an installed kernel, I use this script:

kernel_install_tools.sh 6.5.3

#!/bin/bash

ver="$1"

cd /tmp
mkdir "$ver"
cd "$ver"
git clone --depth=1 git://git.launchpad.net/~ubuntu-kernel-test/ubuntu/+source/linux/+git/mainline-crack -b cod/mainline/v"$ver" kernel
cd kernel

for tool in perf cpupower; do
  make NO_LIBTRACEEVENT=1 DESTDIR=/usr/lib/linux-tools-${ver} -C tools/ ${tool} -j8 && sudo make NO_LIBTRACEEVENT=1 DESTDIR=/usr/lib/linux-tools-${ver} -C tools/ ${tool}_install -j8
done

Of course, many of the tools required some development libraries to be installed on your system. But once you have them, it should work for subsequent kernels out of the box.

kumk no longer working

Since a few days ago, it seems is no longer working. Error:

  • Server kernel.ubuntu.com or internet connection not available

Seems to be related to the lack of ping to the kernel servers?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.