45
submitted 1 month ago by squid_slime@lemm.ee to c/linux@lemmy.ml

been using Arch for years but i am still a novice, yesterday i had found that in order for something to work on my system i will need to edit a few lines in kernel which i did, then removed unnecessary modules > intel, > nvidia, compiled. it worked great but with Arch and its rolling release i am dreading the next update and having to go through this again.
what methods are there to automate this process?

top 17 comments
sorted by: hot top controversial new old
[-] Static_Rocket@lemmy.world 10 points 1 month ago

What modifications were required? The good part of a rolling release is that upstreaming things means you only have to deal with manual fixes for like 2 or 3 updates.

[-] squid_slime@lemm.ee 6 points 1 month ago* (last edited 1 month ago)

set LINK_TRAINING_ATTEMPTS from 5 to 10 in drivers/gpu/drm/amd/display/dc/link/link_dpms.c and set LINK_TRAINING_RETRY_DELAY from 50 to 100 in drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.c.

i doubt this will be added to kernel as its a fix for an issue that isn't wide spread.

[-] Static_Rocket@lemmy.world 19 points 1 month ago

That wouldn't be accepted as is, but those sound like tunables. They could be exposed as kernel parameters. May be worth submitting the patch as an RFC just to call attention to it.

[-] squid_slime@lemm.ee 6 points 1 month ago

thank you i will read up on how to submit this kind of stuff.

[-] squid_slime@lemm.ee 1 points 1 month ago

I followed your advice, Github my edit link_dpms.c, - Github my edit link_dp_training.c how do i submit as RFC. total noob with github lol.

[-] fool@programming.dev 4 points 1 month ago

Successful GitHub pulls are rare; more often, patches live like this. You're better off contacting the maintainer of the subsystem you're editing. See the official submission guide.

Not to be dejecting!

[-] squid_slime@lemm.ee 3 points 1 month ago* (last edited 1 month ago)

thank you and no dejection taken. you're actually very helpful :D

[-] Static_Rocket@lemmy.world 3 points 1 month ago

Ah, so the kernel actually uses mailing lists. You need to use the get maintainers Perl script to get the people you need to send the email TO and then send it to them with the dri-devel list CC'd.

[-] imecth@fedia.io 8 points 1 month ago

Use diff patches and automate with some bash scripting.

[-] squid_slime@lemm.ee 1 points 1 month ago

cheers, I'm using sed to patch the files then auto mated compiling

[-] moreeni@lemm.ee 7 points 1 month ago

You could write a bash script to automate this process. Pacman supports hooks for updates, so after kernel updates you could set it up to automatically run the script.

[-] squid_slime@lemm.ee 3 points 1 month ago

not looked in to pacman hooks but will need to now lol any i made a script that downloads, unzips and patches then compiles so mostly hands free.

[-] kittenz@lemmy.blahaj.zone 6 points 1 month ago* (last edited 1 month ago)

This is the perfect use case for gentoo, there is a documented process for adding kernel patches and saving a kernel build configuration

[-] nmtake@lemm.ee 5 points 1 month ago
[-] noddy@beehaw.org 4 points 1 month ago

I use a custom kernel on my laptop. I just modified the PKGBUILD of the official arch kernel package, and added my patch as a file. Then I could build a proper package with makepkg. I'm planning on setting up my server to automatically build the patched kernel and serve it in a private arch repository, so I don't have to compile the kernel on my laptop regularly. I'm waiting on forgejo (git forge I host on my server) version 9 to be released first, as it should support arch package hosting by then.

[-] squid_slime@lemm.ee 1 points 1 month ago* (last edited 1 month ago)

this sounds very involved initially but hands off after the fact.

Script


#!/bin/bash

cd ~/ || exit

LATEST_KERNEL=$(curl -s https://www.kernel.org | grep -Po 'linux-\d+\.\d+\.\d+\.tar\.xz' | head -1)
echo "Latest Kernel: $LATEST_KERNEL"

KERNEL_URL="https://cdn.kernel.org/pub/linux/kernel/v6.x/$LATEST_KERNEL"
echo "Kernel URL: $KERNEL_URL"

DIR_NAME=$(echo $LATEST_KERNEL | sed 's/\.tar\.xz//')
mkdir -p ./$DIR_NAME

wget -O ./$DIR_NAME/$LATEST_KERNEL "$KERNEL_URL" || exit

tar -xf ./$DIR_NAME/$LATEST_KERNEL -C ./$DIR_NAME || exit

EXTRACTED_DIR=$(tar -tf ./$DIR_NAME/$LATEST_KERNEL | head -1 | cut -f1 -d"/")

cd ./$DIR_NAME/$EXTRACTED_DIR || exit

zcat /proc/config.gz > .config
echo "Kernel config copied."

if [ -f "drivers/gpu/drm/amd/display/dc/link/link_dpms.c" ] && [ -f "drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.c" ]; then
    echo "Files found, proceeding with modifications..."
    
    sed -i 's/#define LINK_TRAINING_RETRY_DELAY 50 \/\* ms \*\//#include <linux\/module.h>\nstatic int link_training_retry_delay = 50;\nmodule_param(link_training_retry_delay, int, 0644);\nMODULE_PARM_DESC(link_training_retry_delay, "Delay between link training retries (ms)");\n#define LINK_TRAINING_RETRY_DELAY link_training_retry_delay/' drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_training.c
    
    sed -i 's/#define LINK_TRAINING_ATTEMPTS 4/#include <linux\/module.h>\nstatic int link_training_attempts = 4;\nmodule_param(link_training_attempts, int, 0644);\nMODULE_PARM_DESC(link_training_attempts, "Number of link training attempts");\n#define LINK_TRAINING_ATTEMPTS link_training_attempts/' drivers/gpu/drm/amd/display/dc/link/link_dpms.c
    
else
    echo "One or both files not found in the kernel source directory."
fi

echo "Kernel modifications complete."

make olddefconfig || exit
#make || exit

echo "Compiling the kernel..."
make -j16 || exit

echo "Building modules..."
sudo make modules_install || exit   

echo "Installing the kernel..."
sudo make install || exit   

echo "Backing up existing kernel files..."
sudo cp /boot/vmlinuz-linux /boot/vmlinuz-linux.bak
sudo cp /boot/initramfs-linux.img /boot/initramfs-linux.img.bak

echo "Moving new kernel files to /boot..."
sudo cp ./arch/x86/boot/bzImage /boot/vmlinuz-fix
sudo mkinitcpio -k $(make kernelrelease) -c /etc/mkinitcpio.conf -g /boot/initramfs-fix.img

if [ -f /boot/vmlinuz-fix ] && [ -f /boot/initramfs-fix.img ]; then
    echo "Kernel and initramfs moved to /boot successfully."
else
    echo "Failed to move kernel or initramfs files to /boot."
    exit 1
fi

echo "Kernel compilation, installation, and file replacement completed successfully."

[-] noddy@beehaw.org 1 points 1 month ago

Yeah the thought is that as long as my patch applies without error, I would get the latest kernel automatically built and can just update my laptop normally with pacman. And since I have a server anyways I might as well use it to compile the kernel at night. I'm also thinking of doing the same with some aur packages as well.

this post was submitted on 08 Sep 2024
45 points (100.0% liked)

Linux

47984 readers
1992 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS