├── secureboot ├── mokconfig.cnf └── create-key.sh ├── .github └── FUNDING.yml ├── src ├── cachyconfs.sh └── cachyos-deb.sh └── README.md /secureboot/mokconfig.cnf: -------------------------------------------------------------------------------- 1 | # This definition stops the following lines failing if HOME isn't 2 | # defined. 3 | HOME = . 4 | RANDFILE = $ENV::HOME/.rnd 5 | [ req ] 6 | distinguished_name = req_distinguished_name 7 | x509_extensions = v3 8 | string_mask = utf8only 9 | prompt = no 10 | 11 | [ req_distinguished_name ] 12 | countryName = BR 13 | stateOrProvinceName = BR 14 | localityName = BR 15 | 0.organizationName = psygreg 16 | commonName = Secure Boot Signing Key 17 | emailAddress = psygreg@pm.me 18 | 19 | [ v3 ] 20 | subjectKeyIdentifier = hash 21 | authorityKeyIdentifier = keyid:always,issuer 22 | basicConstraints = critical,CA:FALSE 23 | extendedKeyUsage = codeSigning,1.3.6.1.4.1.311.10.3.6 24 | nsComment = "OpenSSL Generated Certificate" -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: CachyOS 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: psygreg 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 12 | polar: # Replace with a single Polar username 13 | buy_me_a_coffee: # Replace with a single Buy Me a Coffee username 14 | thanks_dev: # Replace with a single thanks.dev username 15 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 16 | -------------------------------------------------------------------------------- /src/cachyconfs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | _cfgsource="https://raw.githubusercontent.com/CachyOS/CachyOS-Settings/master/usr" 3 | cd $HOME 4 | mkdir -p sysctl-config 5 | sleep 1 6 | cd sysctl-config 7 | { 8 | echo "${_cfgsource}/lib/udev/rules.d/20-audio-pm.rules" 9 | echo "${_cfgsource}/lib/udev/rules.d/40-hpet-permissions.rules" 10 | echo "${_cfgsource}/lib/udev/rules.d/50-sata.rules" 11 | echo "${_cfgsource}/lib/udev/rules.d/60-ioschedulers.rules" 12 | echo "${_cfgsource}/lib/udev/rules.d/69-hdparm.rules" 13 | echo "${_cfgsource}/lib/udev/rules.d/99-cpu-dma-latency.rules" 14 | } > "udev.txt" 15 | { 16 | echo "${_cfgsource}/lib/tmpfiles.d/coredump.conf" 17 | echo "${_cfgsource}/lib/tmpfiles.d/thp-shrinker.conf" 18 | echo "${_cfgsource}/lib/tmpfiles.d/thp.conf" 19 | } > "tmpfiles.txt" 20 | { 21 | echo "${_cfgsource}/lib/modprobe.d/20-audio-pm.conf" 22 | echo "${_cfgsource}/lib/modprobe.d/amdgpu.conf" 23 | echo "${_cfgsource}/lib/modprobe.d/blacklist.conf" 24 | echo "${_cfgsource}/lib/modprobe.d/nvidia.conf" 25 | } > "modprobe.txt" 26 | { 27 | echo "${_cfgsource}/lib/sysctl.d/99-cachyos-settings.conf" 28 | echo "${_cfgsource}/lib/systemd/journald.conf.d/00-journal-size.conf" 29 | echo "${_cfgsource}/share/X11/xorg.conf.d/20-touchpad.conf" 30 | } > "other.txt" 31 | sleep 1 32 | while read -r url; do wget -P udev "$url"; done < udev.txt 33 | while read -r url; do wget -P tmpfiles "$url"; done < tmpfiles.txt 34 | while read -r url; do wget -P modprobe "$url"; done < modprobe.txt 35 | while read -r url; do wget "$url"; done < other.txt 36 | sleep 1 37 | sudo cp -rf udev/* /usr/lib/udev/rules.d/ 38 | sudo cp -rf tmpfiles/* /usr/lib/tmpfiles.d/ 39 | sudo cp -rf modprobe/* /usr/lib/modprobe.d/ 40 | sudo cp -f 99-cachyos-settings.conf /usr/lib/sysctl.d/ 41 | sudo cp -f 00-journal-size.conf /usr/lib/systemd/journald.conf.d/ 42 | sudo cp -f 20-touchpad.conf /usr/share/X11/xorg.conf.d/ 43 | cd .. 44 | rm -rf sysctl-config 45 | -------------------------------------------------------------------------------- /secureboot/create-key.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # dependency check 3 | depcheck () { 4 | 5 | local _packages=(mokutil sbsigntool wget curl openssl) 6 | _install_ 7 | 8 | } 9 | 10 | # create MOK 11 | mok_creator () { 12 | 13 | mkdir -p $HOME/.sb 14 | sleep 1 15 | cd $HOME/.sb 16 | wget https://raw.githubusercontent.com/psygreg/linux-psycachy/master/secureboot/mokconfig.cnf || { echo "Download failed"; exit 1; } 17 | # create MOK keypair 18 | openssl req -config ./mokconfig.cnf \ 19 | -new -x509 -newkey rsa:2048 \ 20 | -nodes -days 36500 -outform DER \ 21 | -keyout "MOK.priv" \ 22 | -out "MOK.der" 23 | # create PEM 24 | openssl x509 -in MOK.der -inform DER -outform PEM -out MOK.pem 25 | # enroll MOK 26 | whiptail --title "MOK" --msgbox "Your Machine Owner Key will be imported to Secure Boot now. It will require you to create a password. Make sure it is stored somewhere safe!" 12 78 27 | sudo mokutil --import MOK.der 28 | 29 | } 30 | 31 | # sign kernel 32 | sign_upd () { 33 | 34 | local kernel_path="/boot/vmlinuz-${kver_sign}" 35 | [[ -f "$kernel_path" ]] || { echo "Kernel not found: $kernel_path"; exit 3; } 36 | sudo sbsign --key MOK.priv --cert MOK.pem /boot/vmlinuz-${kver_sign} --output /boot/vmlinuz-${kver_sign}.signed 37 | sudo cp /boot/initrd.img-${kver_sign}{,.signed} 38 | sleep 1 39 | sudo mv /boot/vmlinuz-${kver_sign}{.signed,} 40 | sudo mv /boot/initrd.img-${kver_sign}{.signed,} 41 | sleep 1 42 | sudo update-grub 43 | 44 | } 45 | 46 | # run proper iteration 47 | signing () { 48 | 49 | if [[ -f $HOME/.sb/MOK.pem ]]; then 50 | cd $HOME/.sb 51 | sign_upd 52 | exit 0 53 | else 54 | mok_creator 55 | sign_upd 56 | exit 0 57 | fi 58 | 59 | } 60 | 61 | # runtime 62 | source <(curl -s https://raw.githubusercontent.com/psygreg/linuxtoys/refs/heads/master/p3/libs/linuxtoys.lib) || { echo "Unable to source lib."; exit 2; } 63 | depcheck 64 | # version checkers 65 | releases=$(curl -s "https://api.github.com/repos/psygreg/linux-psycachy/releases") 66 | lts_tag=$(echo "$releases" | jq -r '.[].tag_name' | grep -i '^LTS-' | sort -Vr | head -n 1) 67 | std_tag=$(echo "$releases" | jq -r '.[].tag_name' | grep -i '^STD-' | sort -Vr | head -n 1) 68 | kver_lts="${lts_tag#LTS-}" 69 | kver_psycachy="${std_tag#STD-}" 70 | kver_url_latest=$(curl -s https://www.kernel.org | grep -A 1 'id="latest_link"' | awk 'NR==2' | grep -oP 'href="\K[^"]+') 71 | kver_latest=$(echo $kver_url_latest | grep -oP 'linux-\K[^"]+') 72 | # remove .tar.xz from version name 73 | kver_latest=$(basename $kver_latest .tar.xz) 74 | ver_psy="$kver_psycachy-psycachy" 75 | ver_cachy="$kver_latest-cachyos" 76 | ver_psy_lts="$kver_lts-psycachy-lts" 77 | 78 | # flag for linuxtoys bypass 79 | if [ -n "$1" ]; then 80 | case "$1" in 81 | --help | -h) 82 | echo "Usage: $0" 83 | echo "Sign your custom kernel for Secure Boot" 84 | exit 0 85 | ;; 86 | --linuxtoys | -l) 87 | kver_sign="$ver_psy" && signing 88 | ;; 89 | --lts) 90 | kver_sign="$ver_psy_lts" && signing 91 | ;; 92 | esac 93 | fi 94 | 95 | # menu 96 | while :; do 97 | 98 | CHOICE=$(whiptail --title "Secure Boot" --menu "Select your kernel edition:" 25 78 16 \ 99 | "PsyCachy" "$kver_psycachy" \ 100 | "PsyCachy-LTS" "$kver_lts" \ 101 | "CachyOS" "Latest" \ 102 | "Cancel" "" 3>&1 1>&2 2>&3) 103 | 104 | exitstatus=$? 105 | if [ $exitstatus != 0 ]; then 106 | # Exit the script if the user presses Esc 107 | break 108 | fi 109 | 110 | case $CHOICE in 111 | PsyCachy) kver_sign="$ver_psy" && signing;; 112 | PsyCachy-LTS) kver_sign="$ver_psy_lts" && signing;; 113 | CachyOS) kver_sign="$ver_cachy" && signing;; 114 | Cancel | q) break ;; 115 | *) echo "Invalid Option" ;; 116 | esac 117 | 118 | done 119 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PsyCachy Kernel 2 | 3 | This repository contains the releases of the `linux-psycachy` and `linux-psycachy-lts` kernels, and the script for building it. The script may automate the process of configuring and optimizing the kernel build according to your hardware and preferences. 4 | 5 | # What's this about? 6 | PsyCachy is a kernel with improved settings for compatibility and stability across Debian/Ubuntu Linux distributions derived from linux-cachyos. 7 | ### Differences to `linux-cachyos` 8 | - Doesn't include processor architecture-specific optimizations, as they bring too small gains to justify the time compiling them or the confusion caused to newcomers by multiple kernel versions on release - you can include those by building the kernel yourself running `cachyos-deb.sh` with `-b` option if you wish. 9 | - Doesn't include handheld console drivers, as there isn't much of a point on doing it for Debian/Ubuntu. 10 | - OS/-o2 optimization instead of -o3, which caused quite a few problems with Debian/Ubuntu packages. 11 | 12 | # Recommended usage 13 | Install the kernel image of your choice from [Releases](https://github.com/psygreg/linux-psycachy/releases) or through [LinuxToys](https://github.com/psygreg/linuxtoys). 14 | ### Choosing your kernel 15 | - `linux-psycachy` is more up-to-date on features, and follows a predictable release schedule of about every two months, enough time for each kernel release to mature enough to be unproblematic. 16 | - `linux-psycachy-lts` offers a more stable and secure choice, following upstream releases of the latest version marked as ***longterm*** from [The Linux Kernel Archives](https://kernel.org/). 17 | 18 | ## Manual installation 19 | - Download **all three** .deb packages 20 | - Open terminal in the same directory of the packages 21 | - `sudo dpkg -i linux-image-psycachy_6.14.11-1_amd64.deb linux-headers-psycachy_6.14.11-1_amd64.deb linux-libc-dev_6.14.11-1_amd64.deb` 22 | - To install CachyOS SystemD configuration files as well to maximize effectiveness, download and run `cachyconfs.sh` available from *Releases*. 23 | 24 | ## Secure Boot 25 | You can make the kernel compatible with Secure Boot by signing it using `create-key.sh` available from *Releases*. Remember to store the password you set when the keypair is created carefully. 26 | 27 | # Building 28 | ## Prerequisites 29 | 30 | Before running the script, ensure you have the following prerequisites installed: 31 | 32 | - `gcc`: The GNU Compiler Collection is required for detecting the CPU architecture. 33 | - `clang`: Required for compiling the kernel. 34 | - `whiptail`: For displaying dialog boxes in the script. 35 | - `curl`: For fetching the latest kernel version. 36 | - `rustc`: For building newer, Rust-based kernel modules. 37 | - `debhelper`: For packaging. 38 | 39 | You can install these dependencies using your distribution's package manager, or have `cachyos-deb.sh` install them for you. 40 | 41 | ## Features 42 | 43 | The script offers a variety of configuration options: 44 | 45 | - Auto-detection of CPU architecture for optimization. 46 | - Selection of CachyOS specific optimizations. 47 | - Configuration of CPU scheduler, LLVM LTO, tick rate, and more. 48 | - Support for various kernel configurations such as NUMA, NR_CPUS, Hugepages, and LRU. 49 | - Application of O3 optimization and performance governor settings. 50 | 51 | ## Usage 52 | 53 | To use the script, follow these steps: 54 | 55 | 1. Clone the repository to your local machine. 56 | 2. Make the script executable with `chmod +x cachyos-deb.sh`. 57 | 3. Run the script with `./cachyos-deb.sh`. 58 | 4. Follow the on-screen prompts to select your desired kernel version and configurations, for: 59 | - Choose the kernel version. 60 | - Enable or disable CachyOS optimizations. 61 | - Configure the CPU scheduler, LLVM LTO, tick rate, NR_CPUS, Hugepages, LRU, and other system optimizations. 62 | - Select the preempt type and tick type for further system tuning; or 63 | 5. Install with optimized defaults and my custom 'stable' branch, which is updated roughly every two months, with `./cachyos-deb.sh -s`. This has been thoroughly tested on Debian Testing and Ubuntu (with Gnome, the standard Canonical flavour), but should work elsewhere without complications. 64 | 65 | ### Launch options 66 | 67 | - `-b`: builds a `psycachy`-variant kernel with optimizations specific to your CPU `MARCH`. 68 | - `-g`: builds the same `psycachy` generic image found in Releases. Meant just to generate those images. 69 | - `-l`: builds the same `psycachy-lts` generic image found in Releases. Meant just to generate those images. 70 | - `-c`: builds a `linux-cachyos` kernel with latest spec and settings. This is not guaranteed to work, as it uses CachyOS's defaults. 71 | 72 | ## Advanced Configurations 73 | 74 | The script includes advanced configuration options for users who want to fine-tune their kernel: 75 | 76 | - **CachyOS Configuration**: Enable all optimizations from CachyOS. A kernel with this option enabled is not guaranteed to work. 77 | - **CPU Scheduler**: Choose between different schedulers like Cachy, PDS, or none. 78 | - **LLVM LTO**: Select between Thin and Full LTO for better optimization. 79 | - **Tick Rate**: Configure the kernel tick rate according to your system's needs. 80 | - **NR_CPUS**: Set the maximum number of CPUs/cores the kernel will support. 81 | - **Hugepages**: Enable or disable Hugepages support. 82 | - **LRU**: Configure the Least Recently Used memory management mechanism. 83 | - **O3 Optimization**: Apply O3 optimization for performance improvement. 84 | - **Performance Governor**: Set the CPU frequency scaling governor to performance. 85 | - **Modprobed.db**: will use the database built from `modprobed.db` to only build drivers specific to your machine. **WARNING:** use the default kernel with `modprobed.db` up and running for at least a week before building with this option to make sure all drivers you need are on the database, and **always** keep a default (or `psycachy` generic package) kernel as a backup! 86 | 87 | ## Contributing 88 | 89 | Contributions are welcome! If you have suggestions for improving the script or adding new features, please open an issue or submit a pull request. 90 | 91 | ## License 92 | 93 | This project is licensed under the MIT License - see the LICENSE file for details. 94 | -------------------------------------------------------------------------------- /src/cachyos-deb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Description: Script to compile a custom Linux kernel and package it into a .deb file for CachyOS 3 | # Maintainer: Laio O. Seman 4 | 5 | # Initialize variables to store user choices -- defaults 6 | _cachyos_config="none" 7 | _cpusched_selection="bore" 8 | _llvm_lto_selection="thin" 9 | _tick_rate="1000" 10 | _numa="enable" 11 | _hugepage="always" 12 | _lru_config="standard" 13 | _o3_optimization="no" 14 | _os_optimization="no" 15 | _performance_governor="no" 16 | _nr_cpus="320" 17 | _bbr3="yes" 18 | _march="native" 19 | _preempt="preempt" 20 | _tick_type="nohz_full" 21 | _damon="no" 22 | _zfs="no" 23 | 24 | # whiptail color palette 25 | export NEWT_COLORS=' 26 | root=white,black 27 | border=black,lightgray 28 | window=black,lightgray 29 | shadow=black,gray 30 | title=black,lightgray 31 | button=black,red 32 | actbutton=white,red 33 | checkbox=black,lightgray 34 | actcheckbox=black,red 35 | entry=black,lightgray 36 | label=black,lightgray 37 | listbox=black,lightgray 38 | actlistbox=black,red 39 | textbox=black,lightgray 40 | acttextbox=black,red 41 | helpline=white,red 42 | roottext=black,lightgray 43 | ' 44 | 45 | check_deps() { 46 | 47 | # List of dependencies to check 48 | local _packages=(whiptail libdw-dev gcc git libncurses-dev curl gawk flex bison openssl libssl-dev dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf make rustc bc rsync python-is-python3 perl gettext cpio pahole debhelper dwarves zstd) 49 | 50 | # Iterate over dependencies and check each one 51 | _install_ 52 | 53 | } 54 | 55 | # Check if GCC is installed 56 | check_gcc() { 57 | 58 | if ! [ -x "$(command -v gcc)" ]; then 59 | # Display error message if GCC is not installed 60 | echo "Error: GCC is not installed. Please install GCC and try again." >&2 61 | exit 1 62 | fi 63 | 64 | } 65 | 66 | # Original function used in the CachyOS mainline 67 | init_script() { 68 | # Call the function before running the rest of the script 69 | check_gcc 70 | 71 | # Get CPU type from GCC and convert to uppercase 72 | MARCH=$(gcc -Q -march=native --help=target | grep -m1 march= | awk '{print toupper($2)}') 73 | 74 | # Check for specific CPU types and set MARCH variable accordingly 75 | case $MARCH in 76 | ZNVER1) MARCH="ZEN" ;; 77 | ZNVER2) MARCH="ZEN2" ;; 78 | ZNVER3) MARCH="ZEN3" ;; 79 | ZNVER4) MARCH="ZEN4" ;; 80 | BDVER1) MARCH="BULLDOZER" ;; 81 | BDVER2) MARCH="PILEDRIVER" ;; 82 | BDVER3) MARCH="STEAMROLLER" ;; 83 | BDVER4) MARCH="EXCAVATOR" ;; 84 | BTVER1) MARCH="BOBCAT" ;; 85 | BTVER2) MARCH="JAGUAR" ;; 86 | AMDFAM10) MARCH="MK10" ;; 87 | K8-SSE3) MARCH="K8SSE3" ;; 88 | BONNELL) MARCH="ATOM" ;; 89 | GOLDMONT-PLUS) MARCH="GOLDMONTPLUS" ;; 90 | SKYLAKE-AVX512) MARCH="SKYLAKEX" ;; 91 | MIVYBRIDGE) 92 | scripts/config --disable CONFIG_AGP_AMD64 93 | scripts/config --disable CONFIG_MICROCODE_AMD 94 | MARCH="MIVYBRIDGE" 95 | ;; 96 | ICELAKE-CLIENT) MARCH="ICELAKE" ;; 97 | esac 98 | 99 | # Add "M" prefix to MARCH variable 100 | MARCH2=M${MARCH} 101 | 102 | # show whiptail screen for the found CPU and ask if it is correct 103 | whiptail --title "CPU Architecture" --yesno "Detected CPU (MARCH) : ${MARCH2}\nIs this correct?" 10 60 104 | if [ $? -eq 1 ]; then 105 | # if not correct, ask for the CPU type 106 | MARCH2=$(whiptail --title "CPU Architecture" --inputbox "Enter CPU type (MARCH):" 10 60 "$MARCH2" 3>&1 1>&2 2>&3) 107 | fi 108 | 109 | # Display detected CPU and apply optimization 110 | echo "----------------------------------" 111 | echo "| APPLYING AUTO-CPU-OPTIMIZATION |" 112 | echo "----------------------------------" 113 | echo "[*] DETECTED CPU (MARCH) : ${MARCH2}" 114 | 115 | # define _march as MARCH2 116 | _march=$MARCH2 117 | } 118 | 119 | configure_cachyos() { 120 | local selection 121 | 122 | selection=$(whiptail --title "CachyOS Configuration" --checklist \ 123 | "Select optimizations to enable:" 20 78 1 \ 124 | "CachyOS" "Enable CachyOS optimizations" "OFF" \ 125 | 3>&1 1>&2 2>&3) 126 | 127 | # Check if user made a selection (not cancelled) 128 | if [ $? -eq 0 ]; then 129 | [[ "$selection" == *"CachyOS"* ]] && _cachyos_config="CACHYOS" || _cachyos_config="none" 130 | fi 131 | } 132 | 133 | # Function to configure CPU scheduler 134 | configure_cpusched() { 135 | # Show radiolist and capture user selection 136 | _cpusched_selection=$(whiptail --title "CPU Scheduler Configuration" --radiolist \ 137 | "Choose CPU Scheduler (use space to select):" 20 70 5 \ 138 | "cachyos" "CachyOS BORE + SCHED-EXT scheduler" $([ "$_cpusched_selection" = "cachyos" ] && echo "ON" || echo "OFF") \ 139 | "bore" "BORE scheduler" $([ "$_cpusched_selection" = "bore" ] && echo "ON" || echo "OFF") \ 140 | "rt" "Real-time preemption patch" $([ "$_cpusched_selection" = "rt" ] && echo "ON" || echo "OFF") \ 141 | "rt-bore" "Real-time preemption with BORE scheduler" $([ "$_cpusched_selection" = "rt-bore" ] && echo "ON" || echo "OFF") \ 142 | "none" "Do not configure CPU scheduler" $([ "$_cpusched_selection" = "none" ] && echo "ON" || echo "OFF") \ 143 | 3>&1 1>&2 2>&3) 144 | } 145 | 146 | # Function to configure LLVM LTO 147 | configure_llvm_lto() { 148 | _llvm_lto_selection=$(whiptail --title "LLVM LTO Configuration" --radiolist \ 149 | "Choose LLVM LTO (use space to select):" 15 60 3 \ 150 | "thin" "Enable LLVM LTO Thin" $([ "$_llvm_lto_selection" = "thin" ] && echo "ON" || echo "OFF") \ 151 | "full" "Enable LLVM LTO Full" $([ "$_llvm_lto_selection" = "full" ] && echo "ON" || echo "OFF") \ 152 | "none" "Do not configure LLVM LTO" $([ "$_llvm_lto_selection" = "none" ] && echo "ON" || echo "OFF") \ 153 | 3>&1 1>&2 2>&3) 154 | } 155 | 156 | # Function to configure tick rate for 100|250|500|600|750|1000) 157 | configure_tick_rate() { 158 | _tick_rate=$(whiptail --title "Tick Rate Configuration" --radiolist \ 159 | "Choose Tick Rate (use space to select):" 15 60 3 \ 160 | "100" "100 Hz" $([ "$_tick_rate" = "100" ] && echo "ON" || echo "OFF") \ 161 | "250" "250 Hz" $([ "$_tick_rate" = "250" ] && echo "ON" || echo "OFF") \ 162 | "500" "500 Hz" $([ "$_tick_rate" = "500" ] && echo "ON" || echo "OFF") \ 163 | "600" "600 Hz" $([ "$_tick_rate" = "600" ] && echo "ON" || echo "OFF") \ 164 | "750" "750 Hz" $([ "$_tick_rate" = "750" ] && echo "ON" || echo "OFF") \ 165 | "1000" "1000 Hz" $([ "$_tick_rate" = "1000" ] && echo "ON" || echo "OFF") \ 166 | 3>&1 1>&2 2>&3) 167 | 168 | } 169 | 170 | # Function to configure NR_CPUS 171 | configure_nr_cpus() { 172 | _nr_cpus=$(whiptail --title "NR_CPUS Configuration" --inputbox "Enter NR_CPUS value:" 10 60 "$_nr_cpus" 3>&1 1>&2 2>&3) 173 | } 174 | 175 | # Function to configure Hugepages 176 | configure_hugepages() { 177 | _hugepage=$(whiptail --title "Hugepages Configuration" --radiolist \ 178 | "Choose Hugepages (use space to select):" 15 60 3 \ 179 | "always" "Always use hugepages" $([ "$_hugepage" = "always" ] && echo "ON" || echo "OFF") \ 180 | "madvise" "Use hugepages with madvise" $([ "$_hugepage" = "madvise" ] && echo "ON" || echo "OFF") \ 181 | "no" "Do not configure Hugepages" $([ "$_hugepage" = "no" ] && echo "ON" || echo "OFF") \ 182 | 3>&1 1>&2 2>&3) 183 | } 184 | 185 | # Function to configure LRU 186 | configure_lru() { 187 | _lru_config=$(whiptail --title "LRU Configuration" --radiolist \ 188 | "Choose LRU (use space to select):" 15 60 3 \ 189 | "standard" "Standard LRU" $([ "$_lru_config" = "standard" ] && echo "ON" || echo "OFF") \ 190 | "stats" "LRU with stats" $([ "$_lru_config" = "stats" ] && echo "ON" || echo "OFF") \ 191 | "none" "Do not configure LRU" $([ "$_lru_config" = "none" ] && echo "ON" || echo "OFF") \ 192 | 3>&1 1>&2 2>&3) 193 | } 194 | 195 | # Function to configure tick type 196 | configure_tick_type() { 197 | _tick_type=$(whiptail --title "Tick Type Configuration" --radiolist \ 198 | "Choose Tick Type (use space to select):" 15 60 3 \ 199 | "periodic" "Periodic tick" $([ "$_tick_type" = "periodic" ] && echo "ON" || echo "OFF") \ 200 | "nohz_full" "Full dynticks" $([ "$_tick_type" = "nohz_full" ] && echo "ON" || echo "OFF") \ 201 | "nohz_idle" "Idle dynticks" $([ "$_tick_type" = "nohz_idle" ] && echo "ON" || echo "OFF") \ 202 | 3>&1 1>&2 2>&3) 203 | } 204 | 205 | configure_preempt_type() { 206 | _preempt=$(whiptail --title "Preempt Type Configuration" --radiolist \ 207 | "Choose Preempt Type (use space to select):" 15 60 3 \ 208 | "voluntary" "Voluntary Preemption" $([ "$_preempt" = "voluntary" ] && echo "ON" || echo "OFF") \ 209 | "preempt" "Preemptible Kernel" $([ "$_preempt" = "preempt" ] && echo "ON" || echo "OFF") \ 210 | "none" "Do not configure Preempt Type" $([ "$_preempt" = "none" ] && echo "ON" || echo "OFF") \ 211 | 3>&1 1>&2 2>&3) 212 | } 213 | 214 | configure_system_optimizations() { 215 | # Initialize status of each optimization 216 | local o3_status=$([ "$_o3_optimization" = "yes" ] && echo "ON" || echo "OFF") 217 | local os_status=$([ "$_os_optimization" = "yes" ] && echo "ON" || echo "OFF") 218 | local performance_status=$([ "$_performance_governor" = "yes" ] && echo "ON" || echo "OFF") 219 | local bbr3_status=$([ "$_bbr3" = "yes" ] && echo "ON" || echo "OFF") 220 | local damon_status=$([ "$_damon" = "yes" ] && echo "ON" || echo "OFF") 221 | local numa_status=$([ "$_numa" = "enable" ] && echo "ON" || echo "OFF") 222 | local zfs_status=$([ "$_zfs" = "yes" ] && echo "ON" || echo "OFF") 223 | local modprobed_status=$([ "$_modprobed_db" = "enable" ] && echo "ON" || echo "OFF") 224 | local cconfs_status=$([ "$_cachy_confs" = "yes" ] && echo "ON" || echo "OFF") 225 | 226 | # Display checklist 227 | local selection 228 | selection=$(whiptail --title "System Optimizations Configuration" --checklist \ 229 | "Select optimizations to enable:" 20 78 6 \ 230 | "O3 Optimization" "" $o3_status \ 231 | "OS Optimization" "" $os_status \ 232 | "Performance Governor" "" $performance_status \ 233 | "TCP BBR3" "" $bbr3_status \ 234 | "DAMON" "" $damon_status \ 235 | "NUMA" "" $numa_status \ 236 | "ZFS" "" $zfs_status \ 237 | "CachyOS Config Files" "" $cconfs_status \ 238 | "Modprobed.db" "" $modprobed_status \ 239 | 3>&1 1>&2 2>&3) 240 | 241 | # Update configurations based on the selection 242 | if [[ "$selection" == *"O3 Optimization"* ]]; then 243 | _o3_optimization="yes" 244 | _os_optimization="no" # Disable OS Optimization if O3 Optimization is selected 245 | else 246 | _o3_optimization="no" 247 | fi 248 | 249 | if [[ "$selection" == *"OS Optimization"* ]]; then 250 | _os_optimization="yes" 251 | _o3_optimization="no" # Disable O3 Optimization if OS Optimization is selected 252 | else 253 | _os_optimization="no" 254 | fi 255 | 256 | [[ "$selection" == *"Performance Governor"* ]] && _performance_governor="yes" || _performance_governor="no" 257 | [[ "$selection" == *"TCP BBR3"* ]] && _bbr3="yes" || _bbr3="no" 258 | [[ "$selection" == *"DAMON"* ]] && _damon="yes" || _damon="no" 259 | [[ "$selection" == *"NUMA"* ]] && _numa="enable" || _numa="disable" 260 | [[ "$selection" == *"Modprobed.db"* ]] && _modprobed_db="enable" || _modprobed_db="disable" 261 | [[ "$selection" == *"CachyOS Config Files"* ]] && _cachy_confs="yes" || _cachy_confs="no" 262 | 263 | } 264 | 265 | choose_kernel_option() { 266 | 267 | # menu 268 | while :; do 269 | 270 | CHOICE=$(whiptail --title "Kernel Version" --menu "Select:" 25 78 16 \ 271 | "Latest" "$_kv_latest" \ 272 | "Stable" "$_kver_stable" \ 273 | "LTS" "$_kver_lts" \ 274 | "Cancel" "" 3>&1 1>&2 2>&3) 275 | 276 | exitstatus=$? 277 | if [ $exitstatus != 0 ]; then 278 | # Exit the script if the user presses Esc 279 | break 280 | fi 281 | 282 | case $CHOICE in 283 | Latest) _kv_name=$_kv_latest && _kv_url=$_kv_url_latest;; 284 | Stable) _kv_name=$_kver_stable && _kv_url=$_kv_url_stable;; 285 | LTS) _kv_name=$_kver_lts && _kv_url=$_kv_url_lts;; 286 | Cancel | q) break ;; 287 | *) echo "Invalid Option" ;; 288 | esac 289 | done 290 | # show kernel version to the user in a box and ask to confirm 291 | whiptail --title "Kernel Version" --msgbox "The chosen kernel version is $_kv_name" 8 78 292 | 293 | } 294 | 295 | debing() { 296 | #!/bin/bash 297 | # Description: Script to compile a custom Linux kernel and package it into a .deb file for CachyOS 298 | # Maintainer: Laio O. Seman 299 | 300 | KERNEL_VERSION=$(make kernelversion) 301 | ARCH=$(dpkg --print-architecture) 302 | 303 | # Kernel package variables 304 | KERNEL_PKG_NAME=${KERNEL_PKG_VERSION}-psycachy 305 | KERNEL_PKG_VERSION=${KERNEL_VERSION}-1 306 | KERNEL_PKG_DIR=${KERNEL_PKG_NAME} 307 | 308 | # Headers package variables 309 | HEADERS_PKG_NAME=headers-${HEADERS_PKG_VERSION}-psycachy 310 | HEADERS_PKG_VERSION=${KERNEL_VERSION}-1 311 | HEADERS_PKG_DIR=${HEADERS_PKG_NAME} 312 | 313 | # Function to create kernel package 314 | package_kernel() { 315 | # Create directory structure for kernel package 316 | mkdir -p ${KERNEL_PKG_DIR}/DEBIAN 317 | mkdir -p ${KERNEL_PKG_DIR}/boot 318 | mkdir -p ${KERNEL_PKG_DIR}/lib/modules/${KERNEL_VERSION} 319 | mkdir -p ${KERNEL_PKG_DIR}/usr/share/doc/${KERNEL_PKG_NAME} 320 | 321 | # Create control file for kernel package 322 | cat >${KERNEL_PKG_DIR}/DEBIAN/control <${HEADERS_PKG_DIR}/DEBIAN/control <zfs-${KERNEL_VERSION}/DEBIAN/control < /dev/null; then 472 | # snapper -c root create -c pre --description kernel update 473 | # fi 474 | #fi 475 | 476 | # define _major as the first two digits of the kernel version 477 | _major=$(echo $_kv_name | grep -oP '^\K[^\.]+') 478 | 479 | # middle number 480 | _mid=$(echo $_kv_name | grep -oP '^\d+\.\K[^\.]+') 481 | 482 | # download kernel to linux.tar.xz 483 | wget -c $_kv_url -O linux.tar.xz 484 | # extract kernel 485 | tar -xaf linux.tar.xz 486 | # enter kernel directory 487 | 488 | cd linux-$_kv_name 489 | 490 | # get cachyos .config 491 | if [ "$_kv_name" = "$_kv_latest" ]; then 492 | wget -c https://raw.githubusercontent.com/CachyOS/linux-cachyos/master/linux-cachyos/config -O .config 493 | elif [ "$_kv_name" = "$_kver_stable" ]; then 494 | wget -c https://raw.githubusercontent.com/psygreg/linux-psycachy/master/src/gcc/config -O .config 495 | else 496 | wget -c https://raw.githubusercontent.com/psygreg/linux-psycachy/master/src/gcc/config-lts -O .config 497 | fi 498 | 499 | local _patchsource="https://raw.githubusercontent.com/cachyos/kernel-patches/master/${_major}.${_mid}" 500 | 501 | # create empty source array of patches 502 | declare -a patches=() 503 | 504 | # Apply CachyOS configuration 505 | if [ "$_cachyos_config" == "CACHYOS" ]; then 506 | scripts/config -e CACHYOS 507 | patches+=("${_patchsource}/all/0001-cachyos-base-all.patch") 508 | fi 509 | 510 | ## List of CachyOS schedulers 511 | case "$_cpusched_selection" in 512 | cachyos) # CachyOS Scheduler (BORE + SCHED-EXT) 513 | patches+=("${_patchsource}/sched/0001-bore-cachy.patch") ;; 514 | bore) ## BORE Scheduler 515 | patches+=("${_patchsource}/sched/0001-bore.patch") ;; 516 | rt) ## EEVDF with RT patches 517 | patches+=("${_patchsource}/misc/0001-rt-i915.patch") ;; 518 | rt-bore) ## RT with BORE Scheduler 519 | patches+=("${_patchsource}/misc/0001-rt-i915.patch" 520 | "${_patchsource}/sched/0001-bore.patch") ;; 521 | esac 522 | 523 | # Add BBR3 ## check EVERY RELEASE 524 | if [ "$_bbr3" == "yes" ]; then 525 | if [ "$_kv_name" = "$_kver_stable" ]; then 526 | patches+=("${_patchsource}/0002-bbr3.patch") 527 | elif [ "$_kv_name" = "$_kver_lts" ]; then 528 | patches+=("${_patchsource}/0002-bbr3.patch") 529 | fi 530 | fi 531 | 532 | # Add fixes ## check EVERY RELEASE 533 | if [ "$_kv_name" = "$_kver_stable" ]; then 534 | if curl --silent --head --fail "${_patchsource}/0005-fixes.patch" > /dev/null; then 535 | patches+=("${_patchsource}/0005-fixes.patch") 536 | fi 537 | elif [ "$_kv_name" = "$_kver_lts" ]; then 538 | if curl --silent --head --fail "${_patchsource}/0004-fixes.patch" > /dev/null; then 539 | patches+=("${_patchsource}/0004-fixes.patch") 540 | fi 541 | fi 542 | 543 | # Additional patches to 6.12 LTS 544 | if [ "$_kv_name" = "$_kver_lts" ]; then 545 | patches+=("${_patchsource}/0005-ntsync.patch" 546 | "${_patchsource}/0007-zstd.patch" 547 | "${_patchsource}/0003-cachy.patch" 548 | "${_patchsource}/0001-amd-cache-optimizer.patch") 549 | fi 550 | 551 | # Additional patches to stable 552 | if [ "$_kv_name" = "$_kver_stable" ]; then 553 | patches+=("${_patchsource}/0003-block.patch" 554 | "${_patchsource}/0004-cachy.patch") 555 | fi 556 | 557 | # Add ASUS to psycachy ## check EVERY RELEASE 558 | if [ "$_kv_name" = "$_kver_stable" ]; then 559 | if curl --silent --head --fail "${_patchsource}/0001-asus.patch" > /dev/null; then 560 | patches+=("${_patchsource}/0001-asus.patch") 561 | fi 562 | fi 563 | 564 | # improve compatibility with dkms modules 565 | # patches+=("${_patchsource}/misc/dkms-clang.patch") 566 | # enable ACPI calls for modules 567 | patches+=("${_patchsource}/misc/0001-acpi-call.patch") 568 | 569 | # patches for Nvidia kernel modules -- from 6.15 onwards -- check EVERY RELEASE 570 | # patches+=(#"${_patchsource}/misc/nvidia/0001-Enable-atomic-kernel-modesetting-by-default.patch" 571 | #"${_patchsource}/misc/nvidia/0002-Add-IBT-support.patch" 572 | #"${_patchsource}/misc/nvidia/0003-Kbuild-Convert-EXTRA_CFLAGS-to-ccflags-y.patch") 573 | #"${_patchsource}/misc/nvidia/0005-nvidia-uvm-Use-__iowrite64_hi_lo.patch" 574 | #"${_patchsource}/misc/nvidia/0006-nvidia-uvm-Use-page_pgmap.patch" 575 | #"${_patchsource}/misc/nvidia/0007-nvidia-uvm-Convert-make_device_exclusive_range-to-ma.patch") 576 | 577 | # download and apply patches on source 578 | for i in "${patches[@]}"; do 579 | echo "Downloading and applying $i" 580 | wget -c $i 581 | patch -Np1 <$(basename $i) 582 | done 583 | 584 | if [ -n "$_is_generic" ]; then 585 | echo "Building generic CPU kernel." 586 | else 587 | # set architecture if not on generic build mode 588 | ./scripts/config --disable CONFIG_GENERIC_CPU 589 | ./scripts/config --enable CONFIG_${MARCH2} 590 | fi 591 | # ./scripts/config -d CONFIG_MODULE_SIG_ALL -d CONFIG_MODULE_SIG_KEY -d CONFIG_SYSTEM_TRUSTED_KEYS 592 | 593 | case "$_cpusched_selection" in 594 | cachyos) scripts/config -e SCHED_BORE -e SCHED_CLASS_EXT -e BPF -e BPF_SYSCALL -e BPF_JIT -e DEBUG_INFO_BTF -e BPF_JIT_ALWAYS_ON -e BPF_JIT_DEFAULT_ON -e PAHOLE_HAS_SPLIT_BTF -e PAHOLE_HAS_BTF_TAG ;; 595 | bore | hardened) scripts/config -e SCHED_BORE -e SCHED_CLASS_EXT -e BPF -e BPF_SYSCALL -e BPF_JIT -e DEBUG_INFO_BTF -e BPF_JIT_ALWAYS_ON -e BPF_JIT_DEFAULT_ON -e PAHOLE_HAS_SPLIT_BTF -e PAHOLE_HAS_BTF_TAG ;; 596 | eevdf) ;; 597 | rt) scripts/config -e PREEMPT_COUNT -e PREEMPTION -d PREEMPT_VOLUNTARY -d PREEMPT -d PREEMPT_NONE -e PREEMPT_RT -d PREEMPT_DYNAMIC -d PREEMPT_BUILD ;; 598 | rt-bore) scripts/config -e SCHED_BORE -e PREEMPT_COUNT -e PREEMPTION -d PREEMPT_VOLUNTARY -d PREEMPT -d PREEMPT_NONE -e PREEMPT_RT -d PREEMPT_DYNAMIC -d PREEMPT_BUILD ;; 599 | sched-ext) scripts/config -e SCHED_CLASS_EXT ;; 600 | esac 601 | 602 | case "$_preempt" in 603 | full) scripts/config -e PREEMPT_BUILD -d PREEMPT_NONE -d PREEMPT_VOLUNTARY -e PREEMPT -e PREEMPT_COUNT -e PREEMPTION -e PREEMPT_DYNAMIC ;; 604 | voluntary) scripts/config -e PREEMPT_BUILD -d PREEMPT_NONE -e PREEMPT_VOLUNTARY -d PREEMPT -e PREEMPT_COUNT -e PREEMPTION -d PREEMPT_DYNAMIC ;; 605 | server) scripts/config -e PREEMPT_NONE_BUILD -e PREEMPT_NONE -d PREEMPT_VOLUNTARY -d PREEMPT -d PREEMPTION -d PREEMPT_DYNAMIC ;; 606 | esac 607 | 608 | # Apply LLVM LTO configuration 609 | case "$_llvm_lto_selection" in 610 | thin) scripts/config -e LTO_CLANG_THIN ;; 611 | full) scripts/config -e LTO_CLANG_FULL ;; 612 | none) scripts/config -d LTO_CLANG_THIN -d LTO_CLANG_FULL ;; 613 | esac 614 | 615 | # Apply tick rate configuration 616 | case "$_tick_rate" in 617 | 100 | 250 | 500 | 600 | 750 | 1000) 618 | scripts/config -d HZ_300 -e "HZ_${_tick_rate}" --set-val HZ "${_tick_rate}" 619 | ;; 620 | 300) 621 | scripts/config -e HZ_300 --set-val HZ 300 622 | ;; 623 | esac 624 | 625 | case "$_tick_type" in 626 | periodic) scripts/config -d NO_HZ_IDLE -d NO_HZ_FULL -d NO_HZ -d NO_HZ_COMMON -e HZ_PERIODIC ;; 627 | nohz_idle) scripts/config -d HZ_PERIODIC -d NO_HZ_FULL -e NO_HZ_IDLE -e NO_HZ -e NO_HZ_COMMON ;; 628 | nohz_full) scripts/config -d HZ_PERIODIC -d NO_HZ_IDLE -d CONTEXT_TRACKING_FORCE -e NO_HZ_FULL_NODEF -e NO_HZ_FULL -e NO_HZ -e NO_HZ_COMMON -e CONTEXT_TRACKING ;; 629 | esac 630 | 631 | # Apply NUMA configuration 632 | case "$_numa" in 633 | enable) scripts/config -e NUMA ;; 634 | disable) scripts/config -d NUMA ;; 635 | none) ;; # Do nothing for 'none' 636 | esac 637 | 638 | # Apply Hugepages configuration 639 | case "$_hugepage" in 640 | always) scripts/config -d TRANSPARENT_HUGEPAGE_MADVISE -e TRANSPARENT_HUGEPAGE_ALWAYS ;; 641 | madvise) scripts/config -d TRANSPARENT_HUGEPAGE_ALWAYS -e TRANSPARENT_HUGEPAGE_MADVISE ;; 642 | no) ;; # Do nothing for 'no' 643 | esac 644 | 645 | # setting nr_cpus 646 | scripts/config --set-val NR_CPUS "$_nr_cpus" 647 | 648 | # Apply LRU configuration 649 | case "$_lru_config" in 650 | standard) scripts/config -e LRU_GEN -e LRU_GEN_ENABLED -d LRU_GEN_STATS ;; 651 | stats) scripts/config -e LRU_GEN -e LRU_GEN_ENABLED -e LRU_GEN_STATS ;; 652 | none) scripts/config -d LRU_GEN ;; 653 | esac 654 | 655 | # Apply O2 optimization 656 | if [ "$_o3_optimization" == "no" ] && [ "$_os_optimization" == "no" ]; then 657 | scripts/config -d CC_OPTIMIZE_FOR_PERFORMANCE_O3 -d CC_OPTIMIZE_FOR_SIZE -e CC_OPTIMIZE_FOR_PERFORMANCE 658 | fi 659 | 660 | # Apply O3 optimization 661 | if [ "$_o3_optimization" == "yes" ]; then 662 | scripts/config -d CC_OPTIMIZE_FOR_PERFORMANCE -d CC_OPTIMIZE_FOR_SIZE -e CC_OPTIMIZE_FOR_PERFORMANCE_O3 663 | fi 664 | 665 | # Apply OS optimization 666 | if [ "$_os_optimization" == "yes" ]; then 667 | scripts/config -d CC_OPTIMIZE_FOR_PERFORMANCE -d CC_OPTIMIZE_FOR_PERFORMANCE_O3 -e CC_OPTIMIZE_FOR_SIZE 668 | fi 669 | 670 | # Apply performance governor 671 | if [ "$_performance_governor" == "yes" ]; then 672 | scripts/config -d CPU_FREQ_DEFAULT_GOV_SCHEDUTIL -e CPU_FREQ_DEFAULT_GOV_PERFORMANCE 673 | fi 674 | 675 | echo "Configurations applied." 676 | 677 | # Make the kernel calling debing 678 | debing 679 | 680 | } 681 | 682 | install_f () { 683 | 684 | if [ "$_kv_name" == "$_kver_stable" ]; then 685 | _kedition="${KERNEL_VERSION}-psycachy" 686 | else 687 | _kedition="${KERNEL_VERSION}-cachyos" 688 | fi 689 | 690 | # Install compiled kernel 691 | sudo dpkg -i ${_bdir}/linux-image-${_kedition}_${KERNEL_VERSION}_amd64.deb ${_bdir}/linux-headers-${_kedition}_${KERNEL_VERSION}_amd64.deb ${_bdir}/linux-libc-dev-${KERNEL_VERSION}_${KERNEL_VERSION}_amd64.deb 692 | # sign it if Secure Boot is enabled 693 | if sudo mokutil --sb-state | grep -q "SecureBoot enabled"; then 694 | bash <(curl -s https://raw.githubusercontent.com/psygreg/linux-cachyos-deb/refs/heads/master/secureboot/create-key.sh) 695 | fi 696 | 697 | # apply system configs if chosen 698 | if [ "$_cachy_confs" == "yes" ]; then 699 | cachy_confs 700 | fi 701 | 702 | } 703 | 704 | # get and apply cachyos configuration files 705 | cachy_confs () { 706 | 707 | local _cfgsource="https://raw.githubusercontent.com/CachyOS/CachyOS-Settings/master/usr" 708 | mkdir -p sysctl-config 709 | sleep 1 710 | cd sysctl-config 711 | { 712 | echo "${_cfgsource}/lib/udev/rules.d/20-audio-pm.rules" 713 | echo "${_cfgsource}/lib/udev/rules.d/40-hpet-permissions.rules" 714 | echo "${_cfgsource}/lib/udev/rules.d/50-sata.rules" 715 | echo "${_cfgsource}/lib/udev/rules.d/60-ioschedulers.rules" 716 | echo "${_cfgsource}/lib/udev/rules.d/69-hdparm.rules" 717 | echo "${_cfgsource}/lib/udev/rules.d/99-cpu-dma-latency.rules" 718 | } > "udev.txt" 719 | { 720 | echo "${_cfgsource}/lib/tmpfiles.d/coredump.conf" 721 | echo "${_cfgsource}/lib/tmpfiles.d/thp-shrinker.conf" 722 | echo "${_cfgsource}/lib/tmpfiles.d/thp.conf" 723 | } > "tmpfiles.txt" 724 | { 725 | echo "${_cfgsource}/lib/modprobe.d/20-audio-pm.conf" 726 | echo "${_cfgsource}/lib/modprobe.d/amdgpu.conf" 727 | echo "${_cfgsource}/lib/modprobe.d/blacklist.conf" 728 | } > "modprobe.txt" 729 | { 730 | echo "${_cfgsource}/lib/sysctl.d/99-cachyos-settings.conf" 731 | echo "${_cfgsource}/lib/systemd/journald.conf.d/00-journal-size.conf" 732 | echo "${_cfgsource}/share/X11/xorg.conf.d/20-touchpad.conf" 733 | } > "other.txt" 734 | sleep 1 735 | while read -r url; do wget -P udev "$url"; done < udev.txt 736 | while read -r url; do wget -P tmpfiles "$url"; done < tmpfiles.txt 737 | while read -r url; do wget -P modprobe "$url"; done < modprobe.txt 738 | while read -r url; do wget "$url"; done < other.txt 739 | sleep 1 740 | sudo cp -rf udev/* /usr/lib/udev/rules.d/ 741 | sudo cp -rf tmpfiles/* /usr/lib/tmpfiles.d/ 742 | sudo cp -rf modprobe/* /usr/lib/modprobe.d/ 743 | sudo cp -f 99-cachyos-settings.conf /usr/lib/sysctl.d/ 744 | sudo cp -f 00-journal-size.conf /usr/lib/systemd/journald.conf.d/ 745 | sudo cp -f 20-touchpad.conf /usr/share/X11/xorg.conf.d/ 746 | cd .. 747 | rm -rf sysctl-config 748 | 749 | } 750 | 751 | # Write settings to file on first installation 752 | first_install () { 753 | 754 | _bdir="" 755 | _bdir=$(whiptail --inputbox "Enter path for temporary buildfiles. Leave empty to use ${HOME}." 10 30 3>&1 1>&2 2>&3) 756 | if [ -n "$_bdir" ]; then 757 | if [ -d "$_bdir" ]; then 758 | build_dir="$_bdir" 759 | else 760 | whiptail --title "Error" --msgbox "Invalid path for buildfiles, try again." 8 60 761 | return 762 | fi 763 | else 764 | build_dir="$HOME" 765 | fi 766 | cd $build_dir 767 | mkdir cachyos-deb 768 | cd cachyos-deb 769 | do_things 770 | install_f 771 | { 772 | echo "_cachyos_config=${_cachyos_config}" 773 | echo "_cpusched_selection=${_cpusched_selection}" 774 | echo "_llvm_lto_selection=${_llvm_lto_selection}" 775 | echo "_tick_rate=${_tick_rate}" 776 | echo "_numa=${_numa}" 777 | echo "_hugepage=${_hugepage}" 778 | echo "_lru_config=${_lru_config}" 779 | echo "_o3_optimization=${_o3_optimization}" 780 | echo "_os_optimization=${_os_optimization}" 781 | echo "_performance_governor=${_performance_governor}" 782 | echo "_nr_cpus=${_nr_cpus}" 783 | echo "_bbr3=${_bbr3}" 784 | echo "_preempt=${_preempt}" 785 | echo "_tick_type=${_tick_type}" 786 | if [[ "${_kv_name}" == "${_kver_stable}" ]]; then 787 | echo "_psygreg_krn=yes" 788 | fi 789 | if [[ "$build_dir" != "$HOME" ]]; then 790 | echo "_bdir=${build_dir}" 791 | fi 792 | } > "$HOME/.local/kernelsetting" 793 | cd .. 794 | sleep 1 795 | rm -rf cachyos-deb 796 | 797 | } 798 | 799 | # Source settings from existing file for updates 800 | kernel_upd () { 801 | 802 | if [ "$(uname -r)" != "$_kv_name" ]; then 803 | if [ -f "$HOME/.local/kernelsetting" ]; then 804 | source $HOME/.local/kernelsetting 805 | if [ -z "$_bdir" ]; then 806 | build_dir="$HOME" 807 | else 808 | build_dir="$_bdir" 809 | fi 810 | cd $build_dir 811 | mkdir cachyos-deb 812 | cd cachyos-deb 813 | do_things 814 | install_f 815 | cd .. 816 | sleep 1 817 | rm -rf cachyos-deb 818 | else 819 | whiptail --title "Update failed." --msgbox "Settings file missing. Did you install this kernel previously?" 8 78 820 | fi 821 | else 822 | whiptail --title "Update failed." --msgbox "Your kernel is already up to date." 8 78 823 | fi 824 | 825 | } 826 | 827 | # build only 828 | builder () { 829 | 830 | source <(curl -s https://raw.githubusercontent.com/psygreg/linuxtoys/refs/heads/master/p3/libs/linuxtoys.lib) 831 | _bdir="$(pwd)" 832 | if [ -n "$_bdir" ]; then 833 | if [ -d "$_bdir" ]; then 834 | build_dir="$_bdir" 835 | else 836 | whiptail --title "Error" --msgbox "Invalid path for buildfiles, try again." 8 60 837 | return 838 | fi 839 | fi 840 | check_deps 841 | if [ -z "$_is_generic" ]; then 842 | init_script 843 | fi 844 | do_things 845 | 846 | } 847 | 848 | _kv_url_latest=$(curl -s https://www.kernel.org | grep -A 1 'id="latest_link"' | awk 'NR==2' | grep -oP 'href="\K[^"]+') 849 | # extract only the version number 850 | _kv_latest=$(echo $_kv_url_latest | grep -oP 'linux-\K[^"]+') 851 | # remove the .tar.xz extension 852 | _kv_latest=$(basename $_kv_latest .tar.xz) 853 | 854 | # initialize variables for stable kernel 855 | _kver_stable_ref="6" 856 | _kver_stable="6.17.10" 857 | _kv_url_stable="https://cdn.kernel.org/pub/linux/kernel/v${_kver_stable_ref}.x/linux-${_kver_stable}.tar.xz" 858 | 859 | # initialize variables for LTS kernel 860 | _kver_lts_ref="6" 861 | _kver_lts="6.12.60" 862 | _kv_url_lts="https://cdn.kernel.org/pub/linux/kernel/v${_kver_lts_ref}.x/linux-${_kver_lts}.tar.xz" 863 | 864 | # set default kernel setting to stable 865 | _kv_name=$_kver_stable 866 | _kv_url=$_kv_url_stable 867 | 868 | # source linuxtoys lib -- fix when LT5 is out! 869 | source <(curl -s https://raw.githubusercontent.com/psygreg/linuxtoys/refs/heads/master/p3/libs/linuxtoys.lib) 870 | 871 | # check if any argument was passed 872 | 873 | if [ -n "$1" ]; then 874 | case "$1" in 875 | --help | -h) 876 | echo "Usage: $0" 877 | echo "Compile a custom Linux kernel and package it into a .deb file for CachyOS" 878 | exit 0 879 | ;; 880 | --build-stable | -b) 881 | builder 882 | exit 0 883 | ;; 884 | --build-gen | -g) 885 | _is_generic="1" 886 | builder 887 | exit 0 888 | ;; 889 | --build-lts | -l) 890 | _is_generic="1" 891 | _kv_name=$_kver_lts 892 | _kv_url=$_kv_url_lts 893 | builder 894 | exit 0 895 | ;; 896 | --build-cachy | -c) 897 | _kv_name=$_kv_latest && _kv_url=$_kv_url_latest 898 | builder 899 | exit 0 900 | ;; 901 | --stable | -s) 902 | check_deps 903 | init_script 904 | if [ -f "$HOME/.local/kernelsetting" ]; then 905 | kernel_upd 906 | else 907 | first_install 908 | fi 909 | exit 0 910 | ;; 911 | esac 912 | fi 913 | 914 | # run the check_deps function and store the result in dep_status 915 | check_deps 916 | 917 | whiptail --title "CachyOS Kernel Configuration" --msgbox "This is a beta version of the CachyOS Kernel Configuration script. Use at your own risk." 8 78 918 | 919 | # say that the user will lose the ability to use secure boot and ask for confirmation 920 | whiptail --title "Secure Boot Warning" --yesno "This script will disable secure boot. Do you want to continue?" 8 78 921 | 922 | # call init script 923 | init_script 924 | 925 | # Main menu 926 | while :; do 927 | 928 | CHOICE=$(whiptail --title "Kernel Configuration Menu" --menu "Choose an option" 25 78 16 \ 929 | "0" "Choose Kernel Version ($_kv_name)" \ 930 | "1" "Configure CachyOS" \ 931 | "2" "Configure CPU Scheduler" \ 932 | "3" "Configure LLVM LTO" \ 933 | "4" "Configure Tick Rate" \ 934 | "5" "Configure NR_CPUS" \ 935 | "6" "Configure Tick Type" \ 936 | "7" "Configure Preempt Type" \ 937 | "8" "Configure LRU" \ 938 | "9" "Configure Hugepages" \ 939 | "10" "Configure System Optimizations" \ 940 | "11" "COMPILE AND INSTALL KERNEL" \ 941 | "12" "UPDATE KERNEL" \ 942 | "13" "Exit" 3>&1 1>&2 2>&3) 943 | 944 | exitstatus=$? 945 | if [ $exitstatus != 0 ]; then 946 | # Exit the script if the user presses Esc 947 | break 948 | fi 949 | 950 | case $CHOICE in 951 | 0) choose_kernel_option ;; 952 | 1) configure_cachyos ;; 953 | 2) configure_cpusched ;; 954 | 3) configure_llvm_lto ;; 955 | 4) configure_tick_rate ;; 956 | 5) configure_nr_cpus ;; 957 | 6) configure_tick_type ;; 958 | 7) configure_preempt_type ;; 959 | 8) configure_lru ;; 960 | 9) configure_hugepages ;; 961 | 10) configure_system_optimizations ;; 962 | 11) first_install ;; 963 | 12) kernel_upd ;; 964 | 13 | q) cd $HOME 965 | rm -rf cachyos-deb 966 | break ;; 967 | *) echo "Invalid Option" ;; 968 | esac 969 | done 970 | --------------------------------------------------------------------------------