Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Kernel & Hardware
  • Search

kernel_cfg - My Kernel configuration script

Kernel not recognizing your hardware? Problems with power management or PCMCIA? What hardware is compatible with Gentoo? See here. (Only for kernels supported by Gentoo.)
Post Reply
Advanced search
16 posts • Page 1 of 1
Author
Message
bell
Guru
Guru
User avatar
Posts: 524
Joined: Tue Nov 27, 2007 8:48 am

kernel_cfg - My Kernel configuration script

  • Quote

Post by bell » Tue Dec 04, 2018 1:23 pm

I want to show up my kernel configuration script I started some months ago and use them on all my Gentoo installations.

Before the script I did always manual configuration and updated by "oldconfig". My issue was I did not know in retrospect why I set any specific setting? Did I set any specific setting? or maybe it's was default in previous kernel?

My solution now: kernel_cfg

https://github.com/bell07/bashscripts-kernel_cfg (GPL-3)

Basically they are config file snippets with additional comments in "cfg" folder, which are processed to the target "/usr/src/linux/.config" file. The base is the kernel provided "defconfig", then the config snippets are applied.
Own adjustments could be done by own snippet files (cfg/99_*.config)

It is possible to select which snippets should be used in CFG_MODULES parameter in "settings.txt" file.
00* Default configuration adjustments that should be in any kernel
10* Disable stuff to get the kernel smaller by default. Useful for non-universal kernels bound to a hardware. Some parameters are re-activated in other config files
20* Try to support all hardware. Useful for live-media kernels that should work with any hardware

30_hwsupport_bluetooth.config Support the bluetooth stack
30_hwsupport_uefi_boot.config UEFI boot and framebuffer
30_hwsupport_wifi.config WIFI stack (Driver needs to be enabled in addition)

30_hardware_intel_MEI.config Support for Intel managemen Engine found on modern Intel devices
40_hardware_mmc_card.config Support for MMC card, found in modern devices
40_hardware_vmware_guest.config All required configuration needed for Vmware guest

50_docker.config Docker server support
50_lxc.config LXC server support

80_net_ebtables.config EBTables Bridge filtering, useful with LXC for example
1. clone the repo
2. copy the settings.txt.example and adjust to settings.txt
3. backup your "/usr/src/linux/.config"
4. run the "kernel_cfg.sh"
5. compare new "/usr/src/linux/.config" with backup
6. Enable additional settings related to your hardware or needs in cfg/99_my.config
7. repeat steps 4-7 if necessary
8. provide feedback

All additional config snippets and feedback to existing snippets welcome!
Top
Hu
Administrator
Administrator
Posts: 24389
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Wed Dec 05, 2018 2:32 am

kernel_cfg.sh should be run under set -e.

Code: Select all

    10	source "$APPL_DIR"/settings.txt
If you source the file, it probably should not have a .txt extension. People tend to expect that .txt files can have relatively freeform text in it.

Code: Select all

    20	ALL_MODULES=$(eval ls -1 $CFG_MODULES | grep '.config$')
Use of eval looks unnecessary here. Use of ls is wrong. Never use ls to produce text for program consumption. In most cases, find is a better choice. If you need the results to be sorted, include sort in the pipeline. I suggest ALL_MODULES=$(find . -maxdepth 1 -name '*.config' -a -name $CFG_MODULES | LC_ALL=C sort). This is still imperfect if you want to handle filenames with unusual characters. For that, use mapfile to load the values into an array:

Code: Select all

find . -maxdepth 1 -name '*.config' -a -name $CFG_MODULES -print0 | LC_ALL=C sort -z | { mapfile -d '' ALL_MODULES;
# Use ${ALL_MODULES[@]}
# ...
; }

Code: Select all

    24	cat "$KERNEL_SOURCE_PATH"/arch/x86/configs/x86_64_defconfig $ALL_MODULES > "$KERNEL_SOURCE_PATH"/.config
This will misbehave if there are spaces in the names of any files listed in $ALL_MODULES.

Code: Select all

    26	cd "$KERNEL_SOURCE_PATH"
    27	make olddefconfig 2> /dev/null
This could be simplified by using make's option -C.
Top
Ant P.
Watchman
Watchman
Posts: 6920
Joined: Sat Apr 18, 2009 7:18 pm
Contact:
Contact Ant P.
Website

  • Quote

Post by Ant P. » Wed Dec 05, 2018 6:34 am

Probably a good idea to `emerge shellcheck-bin` and run it on your code.
Top
Muso
Veteran
Veteran
User avatar
Posts: 1052
Joined: Tue Oct 22, 2002 7:45 am
Location: The Holy city of Honolulu
Contact:
Contact Muso
Website

  • Quote

Post by Muso » Wed Dec 05, 2018 6:46 am

Ant P. wrote:Probably a good idea to `emerge shellcheck-bin` and run it on your code.
Currently emerging shellcheck, any reason to pick bin over source?
"You can lead a horticulture but you can't make her think" ~ Dorothy Parker
2021 is the year of the Linux Desktop!
Top
bell
Guru
Guru
User avatar
Posts: 524
Joined: Tue Nov 27, 2007 8:48 am

  • Quote

Post by bell » Wed Dec 05, 2018 10:06 am

Thank you for the feedback!.

@Hu, what do you mean with "run unter set -e"? I am not a noob but not a bash expert :-(.

Renamed settings.txt to settings.env

"eval" is necessary to solve settings like

Code: Select all

CFG_MODULES='01* 02*'

Code: Select all

find . -maxdepth 1 -name '*.config' -a -name $CFG_MODULES
does not work with setting above.

What is wrong with "ls -1" to get files per line?

Code: Select all

-1     list one file per line.  Avoid '\n' with -q or -b
I do not plan to add config snippets with spaces or special charecters in filenames to the cfg/ folder. Plain Ascii only as usual. Therefore prefer readeble instead of strictly code.

emerge -vaj dev-util/shellcheck needs time to compile ghc at the first :-/
Top
NeddySeagoon
Administrator
Administrator
User avatar
Posts: 56085
Joined: Sat Jul 05, 2003 9:37 am
Location: 56N 3W

  • Quote

Post by NeddySeagoon » Wed Dec 05, 2018 11:27 am

bell,

Users migrating away from windows will have windows habits.

The hard bit about interacting with users is all the input checking you need to do to validate user input.
If you do get unexpected symbols in your input stream you need to deal with them or fail gracefully with a useful error message.
Its a lot of work. When you think its complete and correct, the first new user you put in front of it will break it.
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Top
pjp
Administrator
Administrator
User avatar
Posts: 20668
Joined: Tue Apr 16, 2002 10:35 pm

  • Quote

Post by pjp » Wed Dec 05, 2018 6:40 pm

When configuring the kernel using 'make menuconfig' aren't options available or unavailable based on other configuration settings? Doesn't selecting and deselecting options automatically select or deselect other options? I'm asking because I'm wondering how the configuration files are generated to handle those indirect configuration changes.

Muso wrote:
Ant P. wrote:Probably a good idea to `emerge shellcheck-bin` and run it on your code.
Currently emerging shellcheck, any reason to pick bin over source?
My guess is at least in part due to the ghc dependency.
Quis separabit? Quo animo?
Top
bell
Guru
Guru
User avatar
Posts: 524
Joined: Tue Nov 27, 2007 8:48 am

  • Quote

Post by bell » Wed Dec 05, 2018 7:11 pm

pjp wrote:When configuring the kernel using 'make menuconfig' aren't options available or unavailable based on other configuration settings? Doesn't selecting and deselecting options automatically select or deselect other options? I'm asking because I'm wondering how the configuration files are generated to handle those indirect configuration changes.
The script calls "make olddefconfig" and resolve the dependencies this way, like "make oldconfig" does. Eather an option is skipped because the dependencies aren't fullfilled or other depending options are selected automatically
Top
bell
Guru
Guru
User avatar
Posts: 524
Joined: Tue Nov 27, 2007 8:48 am

  • Quote

Post by bell » Wed Dec 05, 2018 8:10 pm

redone the files processing, now it is just simple but more robust

Code: Select all

for file in $CFG_MODULES; do
	if [ -z "${file##*.config}" ]; then
		echo "apply $file"
		cat "$file" >> "$KERNEL_SOURCE_PATH"/.config
	else
		echo "skip $file"
	fi
done
This consturct support spaces and special charecters in filenames, if anyone need it.

Use "make -C" for now.

Shellcheck says only

Code: Select all

$ shellcheck kernel_cfg.sh 

In kernel_cfg.sh line 10:
source "$APPL_DIR"/settings.env
^-- SC1090: Can't follow non-constant source. Use a directive to specify location.
^-- SC2039: In POSIX sh, 'source' in place of '.' is undefined.
I do not understand :-(

Any other optimization hints? Any comments to provided configuration sets?
Top
pjp
Administrator
Administrator
User avatar
Posts: 20668
Joined: Tue Apr 16, 2002 10:35 pm

  • Quote

Post by pjp » Wed Dec 05, 2018 8:12 pm

Interesting, thanks. I may eventually try that approach. For now I'm just managing minor upgrades (primarily compilation) with olddefconfig.
Quis separabit? Quo animo?
Top
Hu
Administrator
Administrator
Posts: 24389
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Thu Dec 06, 2018 3:25 am

bell wrote:@Hu, what do you mean with "run unter set -e"? I am not a noob but not a bash expert :-(.
Add set -e as the first step of any Bash script. For new scripts, consider using also set -u. These make the shell less tolerant of errors. The default behavior is to blunder onward, potentially making a bigger mess than if the script aborted on the first hint of a bug.
bell wrote:"eval" is necessary to solve settings like

Code: Select all

CFG_MODULES='01* 02*'
That was not my experience in testing.

Code: Select all

$ touch ab ac
$ z='a*'
$ echo "$z"
a*
$ echo $z
ab ac
bell wrote:

Code: Select all

find . -maxdepth 1 -name '*.config' -a -name $CFG_MODULES
does not work with setting above.
You need a separate -name before each pattern.
bell wrote:What is wrong with "ls -1" to get files per line?

Code: Select all

-1     list one file per line.  Avoid '\n' with -q or -b
It involves using ls. Using ls to get input for a script is always wrong.
bell wrote:I do not plan to add config snippets with spaces or special charecters in filenames to the cfg/ folder. Plain Ascii only as usual. Therefore prefer readeble instead of strictly code.
The first user who gets burned by this lack of error checking will feel differently. Always plan for users to expect the program to protect them from themselves.
Top
bell
Guru
Guru
User avatar
Posts: 524
Joined: Tue Nov 27, 2007 8:48 am

  • Quote

Post by bell » Thu Dec 06, 2018 5:15 am

The "set -e" does no changes in execution in current version.
Hu wrote:That was not my experience in testing.

Code: Select all

$ export CFG_MODULES='10*'
$ ls "$CFG_MODULES"
ls: cannot access '10*': No such file or directory
$ eval ls "$CFG_MODULES"
10_disable_all_net_vendors.config
But anyway it is solved in other way in the meantime.
Hu wrote:The first user who gets burned by this lack of error checking will feel differently.
Usually I write things for me only, not for any users. If I see it is something useful for other people I show my work. Of course I am interested to optimize and to learn new ways.
Top
Ant P.
Watchman
Watchman
Posts: 6920
Joined: Sat Apr 18, 2009 7:18 pm
Contact:
Contact Ant P.
Website

  • Quote

Post by Ant P. » Thu Dec 06, 2018 6:14 am

Muso wrote:
Ant P. wrote:Probably a good idea to `emerge shellcheck-bin` and run it on your code.
Currently emerging shellcheck, any reason to pick bin over source?
It's a lot to install for, for most people, the only haskell program on the system.
Top
Hu
Administrator
Administrator
Posts: 24389
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Fri Dec 07, 2018 1:29 am

bell wrote:
Hu wrote:That was not my experience in testing.

Code: Select all

$ export CFG_MODULES='10*'
$ ls "$CFG_MODULES"
ls: cannot access '10*': No such file or directory
$ eval ls "$CFG_MODULES"
10_disable_all_net_vendors.config
But anyway it is solved in other way in the meantime.
Yes, as I showed, you must leave the expression unquoted if you want glob expansion to occur.
bell wrote:
Hu wrote:The first user who gets burned by this lack of error checking will feel differently.
Usually I write things for me only, not for any users. If I see it is something useful for other people I show my work. Of course I am interested to optimize and to learn new ways.
If you post something to draw attention to it, you should expect some people will use it. Some of those people may not know about and avoid the quirks in the code. As a courtesy to them, if you don't want to make the code robust, you should document that it is fragile.
Top
bell
Guru
Guru
User avatar
Posts: 524
Joined: Tue Nov 27, 2007 8:48 am

  • Quote

Post by bell » Fri Dec 07, 2018 7:09 am

We talk about issues in code that was writen 2 months ago and changed/fixed a day and 2 posts ago. Any issues with the current implementation?

Unquoted expression had issue it works only if you are already in cfg folder during settings load if I remember correctly. But the cfg-folder setting is in settings file too...

find -name a -name b is "a and b" or "a or b"? In case of "and" the expression '10* 20*' does not work, in case of "or" the -name '*.config' hint always. To add "-name" to each entry in CFG_MODULES in settings.env does affect the useability for me.

I take any reported issue seriously and fix it, if (1) I understand the issue, (2) understand the proposed solution and (3) the solution does not affect useability. "ls is bad" is an explanation I do not understand, I miss the "because".

The script is relatively simple and nothing special, the value of kernel_cfg are the config snippets (i intend to talk about) and the idea to concatenate them, and get clean config file using "make olddefconfig"
Top
bell
Guru
Guru
User avatar
Posts: 524
Joined: Tue Nov 27, 2007 8:48 am

  • Quote

Post by bell » Tue Jan 04, 2022 10:20 am

Since I switched to sys-kernel/gentoo-kernel, I do not use the scripts byself anymore.

But the snippets are still useable with the sys-kernel/gentoo-kernel. The package supports snippets, stored in /etc/kernel/config.d/ folder
# ls -l /etc/kernel/config.d/
insgesamt 4
lrwxrwxrwx 1 root root 42 4. Jan 08:36 00_defaults.config -> /scripts/kernel_cfg/cfg/00_defaults.config
lrwxrwxrwx 1 root root 57 4. Jan 08:35 10_disable_all_net_vendors.config -> /scripts/kernel_cfg/cfg/10_disable_all_net_vendors.config
lrwxrwxrwx 1 root root 54 4. Jan 08:35 10_disable_misc_options.config -> /scripts/kernel_cfg/cfg/10_disable_misc_options.config
lrwxrwxrwx 1 root root 55 4. Jan 08:36 20_enable_boot_nvme_root.config -> /scripts/kernel_cfg/cfg/20_enable_boot_nvme_root.config
-rw-r--r-- 1 root root 524 3. Nov 17:38 99_my_hardware.config
Since the gentoo-kernel default config is more blown-up (more features enabled by default), the most "_enable_" snippets are redundant.

But I still interested for new "_disable_" snippets, to disable features usually not needed on modern desktop computers.
Top
Post Reply

16 posts • Page 1 of 1

Return to “Kernel & Hardware”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic