Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
kernel_cfg - My Kernel configuration script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
bell
Guru
Guru


Joined: 27 Nov 2007
Posts: 482

PostPosted: Tue Dec 04, 2018 1:23 pm    Post subject: kernel_cfg - My Kernel configuration script Reply with quote

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.

Quote:
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!
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 13836

PostPosted: Wed Dec 05, 2018 2:32 am    Post subject: Reply with quote

kernel_cfg.sh should be run under set -e.
kernel_cfg.sh:
    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.
kernel_cfg.sh:
    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:
find . -maxdepth 1 -name '*.config' -a -name $CFG_MODULES -print0 | LC_ALL=C sort -z | { mapfile -d '' ALL_MODULES;
# Use ${ALL_MODULES[@]}
# ...
; }
kernel_cfg.sh:
    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.
kernel_cfg.sh:
    26   cd "$KERNEL_SOURCE_PATH"
    27   make olddefconfig 2> /dev/null
This could be simplified by using make's option -C.
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 5761

PostPosted: Wed Dec 05, 2018 6:34 am    Post subject: Reply with quote

Probably a good idea to `emerge shellcheck-bin` and run it on your code.
Back to top
View user's profile Send private message
Muso
l33t
l33t


Joined: 22 Oct 2002
Posts: 979
Location: The Holy city of Honolulu

PostPosted: Wed Dec 05, 2018 6:46 am    Post subject: Reply with quote

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?
_________________
Time is a great teacher, but unfortunately it kills all its pupils.
Back to top
View user's profile Send private message
bell
Guru
Guru


Joined: 27 Nov 2007
Posts: 482

PostPosted: Wed Dec 05, 2018 10:06 am    Post subject: Reply with quote

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:
CFG_MODULES='01* 02*'


Code:
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:
-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 :-/
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 43186
Location: 56N 3W

PostPosted: Wed Dec 05, 2018 11:27 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 17918

PostPosted: Wed Dec 05, 2018 6:40 pm    Post subject: Reply with quote

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.
_________________
Those who know what's best for us must rise and save us from ourselves.
Back to top
View user's profile Send private message
bell
Guru
Guru


Joined: 27 Nov 2007
Posts: 482

PostPosted: Wed Dec 05, 2018 7:11 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
bell
Guru
Guru


Joined: 27 Nov 2007
Posts: 482

PostPosted: Wed Dec 05, 2018 8:10 pm    Post subject: Reply with quote

redone the files processing, now it is just simple but more robust
Code:
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:
$ 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?
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 17918

PostPosted: Wed Dec 05, 2018 8:12 pm    Post subject: Reply with quote

Interesting, thanks. I may eventually try that approach. For now I'm just managing minor upgrades (primarily compilation) with olddefconfig.
_________________
Those who know what's best for us must rise and save us from ourselves.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 13836

PostPosted: Thu Dec 06, 2018 3:25 am    Post subject: Reply with quote

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:
CFG_MODULES='01* 02*'
That was not my experience in testing.
Code:
$ touch ab ac
$ z='a*'
$ echo "$z"
a*
$ echo $z
ab ac
bell wrote:
Code:
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:
-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.
Back to top
View user's profile Send private message
bell
Guru
Guru


Joined: 27 Nov 2007
Posts: 482

PostPosted: Thu Dec 06, 2018 5:15 am    Post subject: Reply with quote

The "set -e" does no changes in execution in current version.

Hu wrote:
That was not my experience in testing.

Code:
$ 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.
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 5761

PostPosted: Thu Dec 06, 2018 6:14 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 13836

PostPosted: Fri Dec 07, 2018 1:29 am    Post subject: Reply with quote

bell wrote:
Hu wrote:
That was not my experience in testing.
Code:
$ 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.
Back to top
View user's profile Send private message
bell
Guru
Guru


Joined: 27 Nov 2007
Posts: 482

PostPosted: Fri Dec 07, 2018 7:09 am    Post subject: Reply with quote

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"
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum