LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-29-2018, 11:57 PM   #1
epilitimus
Member
 
Registered: Jul 2009
Distribution: Slackware
Posts: 35

Rep: Reputation: 17
Deferred module loading.


What I want to do is load modules on an as needed basis as a regular user. So for example I occasionally use QEMU so the idea is to not load the kvm module until I start QEMU. Same for bluetooth, camera, things I only use rarely.

I know I could use udev to blacklist the modules and load them when I need them but that requires switching to root etc.

The best idea I have been able to come up with so far is to write a daemon that runs as root and does the module loading when a request is made from a regular user, perhaps password protected.

It's been about 8 years since I last did any kernel/system level hacking so I am wondering if there is any existing system in place that can be used for my purpose.

If there is, a pointer to the docs will be appreciated.
 
Old 01-30-2018, 04:34 AM   #2
Brains
Senior Member
 
Registered: Apr 2009
Distribution: All OS except Apple
Posts: 1,591

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
bluetooth, camera,
99.99% Of normal people would have strong negative words for the Linux community if these hardware features were not supported out of the box.

As for software like QEMU, maybe you can put the module in your user home directory, delete the one in /lib/modules and run command: depmod -a. Then try loading the one in your user home directory and see what happens. Just a suggestion.
 
Old 01-30-2018, 08:38 AM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,693
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
I fail to see technical Return-On-Investment (ROI) here ... just sayin' ...
 
Old 01-30-2018, 01:04 PM   #4
epilitimus
Member
 
Registered: Jul 2009
Distribution: Slackware
Posts: 35

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by Brains View Post
99.99% Of normal people would have strong negative words for the Linux community if these hardware features were not supported out of the box.
This is my personal machine, so the other 99.99%...meh.

To refine what I am trying to do. I want to wait to load the module until an attempt to access the device node is made, rather than when the hardware availability is noted. I think I recall there used to be a way to do this, modprobe.conf maybe?

As for why I want to do it. It started as "It would be nice if..." and as such things do became a bit of a quest to see if I could do it. But I am a bit rusty as I said.
 
Old 01-30-2018, 01:55 PM   #5
Brains
Senior Member
 
Registered: Apr 2009
Distribution: All OS except Apple
Posts: 1,591

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Below is an example I used in the past, it's an lsb compliant init script I designed for a Debian live system.

What I wanted, was to have full support for either ATI (now owned by AMD) or Nvidia proprietary support if a supported graphics device was spotted during a device id scan early in the boot process.
I used graphviz to show where all Debian default init scripts were being initiated during the boot and reboot process, this helped me configure the header of this script so it would be initiated at the right time during the boot process. The ATI graphics were installed when the live system was built, if no proprietary graphics devices were found, some of the ATI files had to be removed to allow appropriate Xorg drivers to be loaded and used. The Nvidia modules and files were pre-compiled against the same kernel and were all pumped into place during bootup except the nvidia-settings menu file which was also implemented in the build.

What I ended up with, was full support for any graphics device on demand the USB live system was booted on. I also had similar scripts for other types of hardware, giving me on the fly support for any hardware found on any PC on store shelves at the time. I called it wallawalla-baby. The lists of supported pcids for any device that needed the on the fly configuration were stored in /root

This is what you are looking for, it involves a lot, but as I can attest, it can be done using graphviz and a well designed init script that conforms to your distribution's standards.

Code:
#!/bin/sh
### BEGIN INIT INFO
# Provides:          wallawalla-baby
# Required-Start:    mountkernfs 
# Required-Stop:      
# Should-Start:      udev
# Default-Start:     2 3 4 5
# Default-Stop:      1 0 6
# Short-Description: Configure Xorg to use proprietary if found
### END INIT INFO
if lspci -n | grep -qi -f /root/atiid > /dev/null ; then
        cat > /etc/X11/xorg.conf << EOF
Section "Device"
    Identifier  "ATI"
    Driver      "fglrx"
EndSection

Section "Screen"
    Identifier "Default Screen"
    DefaultDepth     24
EndSection
EOF
	cp /usr/lib/fglrx/libglx.so /usr/lib/xorg/modules/extensions/
	cp -d /usr/lib/fglrx/libGL.so* /usr/lib/
	modprobe -r radeon drm
else
	rm -f /usr/share/menu/fglrx-control
	rm -f /etc/default/fglrx-atieventsd
fi

if lspci -n | grep -qi -f /root/nvid > /dev/null ; then
        cat > /etc/X11/xorg.conf << EOF
Section "Module"
    Load           "bitmap"
    Load	   "dbe"
    Load           "ddc"
    Load	   "evdev"
    Load           "extmod"
    Load           "freetype"
    Load           "glx"
    Load           "int10"
    Load	   "record"
    Load	   "type1"
    Load           "vbe"
EndSection

Section "Monitor"
    Identifier     "Monitor 0"
    HorizSync       28.0 - 64.0
    VertRefresh     43.0 - 60.0
    Option         "DPMS"
EndSection

Section "Device"
    Identifier     "nVidia Corporation"
    Driver         "nvidia"
    Option         "TripleBuffer" "true"
    Option         "RenderAccel" "true"
    Option         "AllowGLXWithComposite" "true"
EndSection

Section "Screen"
    Identifier     "Default Screen"
    Device         "nVidia Corporation"
    Monitor        "Monitor 0"
    Option         "AddARGBGLXVisuals" "On"
    DefaultDepth    24
    SubSection     "Display"
        Depth       24
    EndSubSection
EndSection

Section "Extensions"
    Option "Composite" "Enable"
EndSection
EOF
	cp -d /usr/lib/nvidia/libglx* /usr/lib/xorg/modules/extensions/
	cp -d /usr/lib/nvidia/libGL.so* /usr/lib/
else
	rm -f /usr/share/menu/nvidia-settings
fi
 
Old 01-30-2018, 02:09 PM   #6
Brains
Senior Member
 
Registered: Apr 2009
Distribution: All OS except Apple
Posts: 1,591

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Your situation would require daemons or similar to initiate your scripts for loading modules as required. And boot init scripts to unload modules you don't want loaded at boot, as some modules I have found while playing with this a year ago, still get loaded even after I had removed them from the modules directory, I don't know how it happened, but it happened when I tried to do similar thing with my new laptop that has optimus technology but does not use the technology, the nvidia module was getting loaded because the card was showing up, and I had it deleted, but a copy of it in /root

Last edited by Brains; 01-30-2018 at 02:20 PM.
 
Old 01-30-2018, 02:25 PM   #7
Brains
Senior Member
 
Registered: Apr 2009
Distribution: All OS except Apple
Posts: 1,591

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
You can also initiate your scripts manually via a desktop shortcut launcher, this gets tricky if you use sudo.
 
Old 01-30-2018, 02:34 PM   #8
epilitimus
Member
 
Registered: Jul 2009
Distribution: Slackware
Posts: 35

Original Poster
Rep: Reputation: 17
Writing a root daemon to do what I want is a fall back. What I am looking for is if there is an existing way to do it.

I did find the reference to the way I used to do it, which is what left the worm in my brain that it could be done:

From the devfs FAQ
Quote:
Module autoloading
You will need to configure devfsd to enable module autoloading. The following lines should be placed in your /etc/devfsd.conf file:

LOOKUP .* MODLOAD

As of devfsd-v1.3.10, a generic /etc/modules.devfs configuration file is installed, which is used by the MODLOAD action. This should be sufficient for most configurations. If you require further configuration, edit your /etc/modules.conf file. The way module autoloading work with devfs is:

a process attempts to lookup a device node (e.g. /dev/fred)
if that device node does not exist, the full pathname is passed to devfsd as a string
devfsd will pass the string to the modprobe programme (provided the configuration line shown above is present), and specifies that /etc/modules.devfs is the configuration file
/etc/modules.devfs includes /etc/modules.conf to access local configurations
modprobe will search it's configuration files, looking for an alias that translates the pathname into a module name
the translated pathname is then used to load the module.

If you wanted a lookup of /dev/fred to load the mymod module, you would require the following configuration line in /etc/modules.conf:

alias /dev/fred mymod

The /etc/modules.devfs configuration file provides many such aliases for standard device names. If you look closely at this file, you will note that some modules require multiple alias configuration lines. This is required to support module autoloading for old and new device names.
I know devfs has been replaced by udev but I'm hoping there is still a way to do this. To me the reason to use a kernel module is to only have the code loaded when you want to use it. If the module is always loaded as long as the hardware is present, which it always is for builtin stuff, then what's the point of having loadable modules?

I can see how to set up modprobe as described in above, but how to get udev to make the call? The more I look at this the more it seems like it is probably a trivial thing to do if I could just wrap my head around udev. I found in the udev man page that you can include the DEVPATH in udev rules. Anyone know where the udev gurus hang out?
 
Old 01-30-2018, 02:43 PM   #9
epilitimus
Member
 
Registered: Jul 2009
Distribution: Slackware
Posts: 35

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by Brains View Post
You can also initiate your scripts manually via a desktop shortcut launcher, this gets tricky if you use sudo.
Which gets me back to being root, i.e. entering root password.

Seriously, I do appreciate the suggestions.
 
Old 01-30-2018, 02:48 PM   #10
Brains
Senior Member
 
Registered: Apr 2009
Distribution: All OS except Apple
Posts: 1,591

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by epilitimus View Post
Which gets me back to being root, i.e. entering root password.

Seriously, I do appreciate the suggestions.
I was able to do this also last year to load wireless dongle on my old desktop, had to put one of the scripts that were stored in the user home Desktop directory as an exception in the /etc/sudoers file. Kinda forgot how I did it but it worked, basically needed two scripts to do the job of one script.

EDIT: I guess it appears I kept records
The /etc/sudoers file:
Code:
# User privilege specification
root	ALL=(ALL:ALL) ALL
jo	ALL=(ALL:ALL) ALL

# Allow members of group sudo to execute any command
%sudo	ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d
jo  ALL=(ALL:ALL) NOPASSWD:/home/jo/Desktop/net.sh
jo  ALL=(ALL:ALL) NOPASSWD:/home/jo/Desktop/net2.sh

Last edited by Brains; 01-30-2018 at 02:58 PM.
 
Old 01-30-2018, 02:56 PM   #11
Brains
Senior Member
 
Registered: Apr 2009
Distribution: All OS except Apple
Posts: 1,591

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
The wifi up.desktop file (icon launcher):
Code:
[Desktop Entry]
Categories=Application;Network;
Comment[en_CA]=Connect to Internet
Comment=Connect to Internet
Encoding=UTF-8
Exec=sudo /home/jo/Desktop/net.sh
Icon=
GenericName[en_CA]=Wifi UP
GenericName=Wifi UP
MimeType=
Name[en_CA]=Wifi UP
Name=Wifi UP
Path=
StartupNotify=true
Terminal=true
TerminalOptions=
Type=Application
Version=1.0
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-KDE-SubstituteUID=false
X-KDE-Username=
The net.sh file:
Code:
#!/bin/bash

wpa_supplicant -B -ira0 -c/etc/wpa_supplicant.conf -Dwext
dhclient ra0
echo "We are On-line"
sleep 1
echo "yeeeeee haaaaaah!"
sleep 2
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error while loading a signed kernel module : Request for unknown module key : err -11 manisha.jnu08 Linux - Kernel 3 12-12-2017 08:40 AM
'Invalid module format' loading simple module on Suse Linux Professional 9.1 rocketdude Linux - Distributions 3 07-27-2004 11:40 PM
Finding Module Dependencies...(Still loading...still loading..still loading..HANG!!!) Aeudian Linux - General 3 08-11-2003 03:31 PM
Finding Module Dependencies.....(still loading....Still loading....still loading) Aeudian Linux - Newbie 1 07-28-2003 02:27 PM
module loading? chuchu5 Linux - Newbie 3 01-27-2002 10:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration