You are not logged in.
I'm posting this here because I feel it's a newbie topic, but I'm not entirely sure if it's appropriate for this forum because [this forum] seems to be focused more on getting help with stuff that isn't working, and I've solved it on my own; I'm putting it here so that it can be found/searched by people looking for it.
Maybe I'm the only person who feels this way, but I hate trying to remember how/where to add new modules for modprobe to run at boot, because I typically do it only about twice/year. A mild irritation, to be sure, but it's like a thin crack in one's curtains early on a summer morning, when all one wants to do is sleep in. So I have concocted a short, simple bash script to alleviate it: modprober.sh.
#!/bin/bash
if [ -f /etc/modules-load.d/$1* ];
then
echo "$1 already exists in /etc/modules-load.d!"
else
echo "adding $1 to /etc/modules-load.d/ ..."
echo -e "$1" >> "/etc/modules-load.d/"$1".conf"
fi
[EDIT]: fixed to take arguments directly from the command line (e.g. sudo bash modprober.sh vboxdrv).
You will need to run it as the superuser for file permissions purposes. Also, one only needs to type the name of the module, such as "vboxdrv" (without quotes) for the vitualbox module.
Please note that what little programming skill I have is extremely rusty, and I have not attempted any type of input sanitation except to avoid overwriting files that already exist, as I feel this could be unwise. Improvements, good ideas, and constructive criticism are always welcome. I would particularly like to be able to put the module on the same line - like an argument (eg. bash modprober.sh vboxdrv), but I haven't managed to figure that out - not even sure if it's possible with simple bash scripting.
Hope this helps the odd lazy person like myself .
~Cronanius
Last edited by Cronanius (2012-11-18 22:45:50)
Perpetually an Arch Newbie. I'm here for the operating system, not the philosophy.
Offline
Hi,
OffTopic:
I normally do only german poetry, so please excuse that the following is rather clumsy:
Fading, staying in the mist,
looking all around,
shadows only on my path,
swallow all that sound.
Bearing, tearing thoughts and tears,
staying in the mist,
only shadows on my path,
shadows in the mist.
I also have problems with the pronounciation... Well, you have to excuse that, too. By the way: What is the origin of the "Cronanius" pseudonym?
Benjamin
Offline
LordBo: that's very nice, the men in white coats will be here for you soon.
Cronanius, no doubt useful to you, but can I assume you're aware that each module does not require a separate *.conf file, and that *.conf files do not have to be named after the module(s) listed in them?
You can use $1 ($2 $3 ...) and/or $@ in your script to process command line arguments. Bash documentation is not eactly hard to find, here's one of many good resources.
Offline
Remembering the name of a script you'd only use a couple times a year is easier than remembering the name of /etc/modprobe.conf and opening it in a text editor?
*shrug*, if it works for you, enjoy - but I can't help but wonder if you are doing something odd in the first place to make this seem like a simpler method.
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
Trilby, see, even you forgot - it's /etc/modules-load.d/ silly.
Offline
Ah, yeah, forgot a directory - tab completion got that pretty quickly though.
And I guess I never used the modules-load.d directory.
Sorry, perhaps I don't know what I'm talking about .... never had any need of this (empty) directory.
I was thinking of mkinitcpio.conf - sorry again for the noise.
Last edited by Trilby (2012-11-18 14:32:18)
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
Yeah, most users don't need anything in there, autodetection takes care of it. It's useful for stuff like virtualbox modules etc.
Offline
LordBo: that's very nice, the men in white coats will be here for you soon.
I can't remember the last time someone was confined for writing a poem.
Cronanius, no doubt useful to you, but can I assume you're aware that each module does not require a separate *.conf file, and that *.conf files do not have to be named after the module(s) listed in them?
Ok, he can use
for i in /etc/modules-load.d/*; do
if grep $module $i; then
...
fi
done
which may still lead to wrong results... . Then one could use sed to define a better fitting condition, and so on. Well, as long as it works: Do not complicate it unnecessarily. I think he knows, how his files in /etc/modules-load.d are structured.
Offline
grep -qFx "$1" /etc/modules-load.d/*.conf || echo "$1" >>"/etc/modules-load.d/$1.conf"
Still don't see the point of it though. It has the word "modules" and "load" in the directory name and it's in /etc. Shell completion for 'man modules<tab>' brings up the manpage. How hard can it really be to remember?
Offline
It can be hard, I know that .
Offline
LordBo: that's very nice, the men in white coats will be here for you soon.
Cronanius, no doubt useful to you, but can I assume you're aware that each module does not require a separate *.conf file, and that *.conf files do not have to be named after the module(s) listed in them?
I actually wasn't aware of this; all of the instructions I've found on setting up new modules have said exactly that I need to have a separate *.conf file for each. Personally, I think that type of setup is completely idiotic, but I'm just a user; who am I to question the powers that be? . I'd rather not even have a folder called modules-load.d, and just type the names of the modules I want loaded at boot into a line in modprobe.conf and forget about it - that would be my preferred solution.
You can use $1 ($2 $3 ...) and/or $@ in your script to process command line arguments. Bash documentation is not exactly hard to find, here's one of many good resources.
I originally overlooked the use of $1, $2, etc, and have subsequently utilized those to reduce clunkiness. Thanks for your help!
Also, thanks for the poetry, Lord Bo.
Perpetually an Arch Newbie. I'm here for the operating system, not the philosophy.
Offline
I actually wasn't aware of this; all of the instructions I've found on setting up new modules have said exactly that I need to have a separate *.conf file for each.
Read the only authoritative instructions then - the man page.
I'd rather not even have a folder called modules-load.d, and just type the names of the modules I want loaded at boot into a line in modprobe.conf
modules-load.d.. modprobe.d.. hmm, I wonder which one should I use for loading modules?
One minor point - calling it modprober could be misleading, as it's not actually modprobing anything. I'd suggest bootmod.
Offline