Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
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
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?
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
[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=
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.