Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Randomly Loading Modules
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
duane
n00b
n00b


Joined: 03 Jun 2002
Posts: 56
Location: Oklahoma City

PostPosted: Sat May 11, 2019 12:19 pm    Post subject: Randomly Loading Modules Reply with quote

I decided to make a livecd more or less from scratch recently. I wanted something that could boot a 32-bit or 64-bit kernel and had all my favorite software on it, but mostly I just wanted to learn how. I'm running it now, and it's virtually indistinguishable from my regular install, so everything seems to work.

I made both kernels with genkernel, but I wanted to build my own initrds, so I copied the same modules genkernel does, and pieced together a simple init. When it's time to load modules, I put in the following:

Code:
for i in `find /lib/modules/ -iname '*.ko'` ; do
        j=${i##*/}
        modprobe &>/dev/null ${j%%.*}
done


Obviously, it's inefficient, but is this dangerous in any way? Could loading (or trying to load) everything (that genkernel packs) cause problems?
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Sat May 11, 2019 12:56 pm    Post subject: Reply with quote

duane,

Isn't that what genkernel does?

Well behaved hardware driver modules look round for the hardware they are supposed to drive then unload if its not found.

Its not dangerous, unless you count the increased attack surface presented by the bloat.
Then you wouldn't use genkernel though.
_________________
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
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 13855

PostPosted: Sat May 11, 2019 4:41 pm    Post subject: Reply with quote

One of the inefficiencies of the approach shown is that you try to probe a module if it exists for any kernel, but modprobe only loads modules for the current kernel. You can avoid that and improve your loop by doing:
Code:
find "/lib/modules/$(uname -r)" -name '*.ko' -printf '%f\0' | while read -r -d '' i; do
        modprobe &>/dev/null ${i%%.*}
done
I switched to -name because, as far as I know, kernel module extensions are always lowercase.
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