Linux install module at boot

(Buildroot) How to load modules automatically

But I want this done at boot. I’ve tried creating /etc/modules, /etc/modprobe.conf and /etc/modprobe.d/i2c-dev.conf, etc. with the module name in there, but no luck. I’m using a buildroot-2017-08, which I believes uses kmod, with a BusyBox init. I can just create an init.d script, but I think there’s a specific location that should contain the list of modules to load.

3 Answers 3

This depends on which init system you’re using. If you have Buildroot configured to use Busybox init or SysV init, then the correct way to handle this is probably through an init script. If you have it configured to use Systemd though, you can just drop a file with a .conf extension in /etc/modules-load.d/ or /usr/lib/modules-load.d/ with each module you want loaded listed on a line by itself, and systemd will load them at boot.

Forgot to mention, it’s BusyBox, i’ve been doing more research and that seems to be the way to go with BusyBox. Strangly I can barely find any examples of such scripts, I had expected a more ‘beaten path’ here 😉

@svenema A large part of that is the design intent of busybox, they kind of expect you to build in all ‘required’ modules, and leave only optional things modular and then load them on-demand (either based on system configuration, or what you’re actually using at the time).

Couldn’t find many polished and ready scripts. Turns out that Linux From Scratch (LFS) had some scripts that look good and are easy to use.

My solution to loading modules for a plain BusyBox init:

/etc/init.d/S02modules

#!/bin/sh ######################################################################## # # Description : Module auto-loading script # # Authors : Zack Winkles # # Version : 00.00 # # Notes : # ######################################################################## . /etc/sysconfig/functions # Assure that the kernel has module support. [ -e /proc/ksyms -o -e /proc/modules ] || exit 0 case "$" in start) # Exit if there's no modules file or there are no # valid entries [ -r /etc/sysconfig/modules ] && egrep -qv '^($|#)' /etc/sysconfig/modules || exit 0 boot_mesg -n "Loading modules:" $ # Only try to load modules if the user has actually given us # some modules to load. while read module args; do # Ignore comments and blank lines. case "$module" in ""|"#"*) continue ;; esac # Attempt to load the module, making # sure to pass any arguments provided. modprobe $ $ >/dev/null # Print the module name if successful, # otherwise take note. if [ $? -eq 0 ]; then boot_mesg -n " $" $ else failedmod="$ $" fi done < /etc/sysconfig/modules boot_mesg "" $# Print a message about successfully loaded # modules on the correct line. echo_ok # Print a failure message with a list of any # modules that may have failed to load. if [ -n "$" ]; then boot_mesg "Failed to load modules:$" $ echo_failure fi ;; *) echo "Usage: $ " exit 1 ;; esac 

/etc/sysconfig/functions

#!/bin/sh ####################################################################### # # Description : Run Level Control Functions # # Authors : Gerard Beekmans - gerard@linuxfromscratch.org # # Version : 00.00 # # Notes : With code based on Matthias Benkmann's simpleinit-msb # http://winterdrache.de/linux/newboot/index.html # ######################################################################## ## Environmental setup # Setup default values for environment umask 022 export PATH="/bin:/usr/bin:/sbin:/usr/sbin" # Signal sent to running processes to refresh their configuration RELOADSIG="HUP" # Number of seconds between STOPSIG and FALLBACK when stopping processes KILLDELAY="3" ## Screen Dimensions # Find current screen size if [ -z "$" ]; then COLUMNS=$(stty size) COLUMNS=$ fi # When using remote connections, such as a serial port, stty size returns 0 if [ "$" = "0" ]; then COLUMNS=80 fi ## Measurements for positioning result messages COL=$(($ - 8)) WCOL=$(($ - 2)) ## Provide an echo that supports -e and -n # If formatting is needed, $ECHO should be used case "`echo -e -n test`" in -[en]*) ECHO=/bin/echo ;; *) ECHO=echo ;; esac ## Set Cursor Position Commands, used via $ECHO SET_COL="\\033[$G" # at the $COL char SET_WCOL="\\033[$G" # at the $WCOL char CURS_UP="\\033[1A\\033[0G" # Up one line, at the 0'th char ## Set color commands, used via $ECHO # Please consult `man console_codes for more information # under the "ECMA-48 Set Graphics Rendition" section # # Warning: when switching from a 8bit to a 9bit font, # the linux console will reinterpret the bold (1;) to # the top 256 glyphs of the 9bit font. This does # not affect framebuffer consoles NORMAL="\\033[0;39m" # Standard console grey SUCCESS="\\033[1;32m" # Success is green WARNING="\\033[1;33m" # Warnings are yellow FAILURE="\\033[1;31m" # Failures are red INFO="\\033[1;36m" # Information is light cyan BRACKET="\\033[1;34m" # Brackets are blue STRING_LENGTH="0" # the length of the current message #******************************************************************************* # Function - boot_mesg() # # Purpose: Sending information from bootup scripts to the console # # Inputs: $1 is the message # $2 is the colorcode for the console # # Outputs: Standard Output # # Dependencies: - sed for parsing strings. # - grep for counting string length. # # Todo: #******************************************************************************* boot_mesg() < local ECHOPARM="" while true do case "$" in -n) ECHOPARM=" -n " shift 1 ;; -*) echo "Unknown Option: $" return 1 ;; *) break ;; esac done ## Figure out the length of what is to be printed to be used ## for warning messages. STRING_LENGTH=$(($ + 1)) # Print the message to the screen $ $ -e "$$" > boot_mesg_flush() < # Reset STRING_LENGTH for next message STRING_LENGTH="0" >echo_ok() < $-n -e "$$$[$ OK $]" $ -e "$" boot_mesg_flush > echo_failure() < $-n -e "$$$[$ FAIL $]" $ -e "$" boot_mesg_flush > echo_warning() < $-n -e "$$$[$ WARN $]" $ -e "$" boot_mesg_flush > 

/etc/sysconfig/modules

i2c-dev snd-soc-pcm512x snd-soc-wm8804 snd-soc-hifiberry_dac 

(or any module you want to load, obviously)

Читайте также:  Linux монитор загрузки системы

If there are any problems or issues with loading modules this way in a BusyBox init, I'm sure they'll end up in the comments below ;-).

Источник

How do I load a module at boot time?

As stated in Why is my Audio (Sound) Output not working?, to initialise the sound driver, you must run sudo modprobe snd_bcm2835 every time you want to output sound. How do I get this to run on boot? (i.e. before logging in and without any input)

@Jivings: Just because it's on-topic on Unix & Linux doesn't make it off-topic for Raspberry Pi, does it?

@OliverSalzburg: I think that there's too much of an overlap in this particular question. Nothing about this question makes it specific for the Raspberry Pi.

Wouldn't the decision at meta.raspberrypi.stackexchange.com/questions/24/… mean that this question is fine here?

@Jivings Thanks, just wanted to clear that up for any future visitors as the comments were pointing towards closing the question. Maybe all the comments should be deleted instead?

4 Answers 4

Loading modules at boot is a little different to running startup commands.

In Debian:

Add the module name as a new line in /etc/modules

In Arch Linux:

Add the module name to the module array in /etc/rc.conf , the line should look like this:

Or for the new systemd configuration:

echo "snd_bcm2835" | sudo tee -a /etc/modules-load.d/snd_bcm2835.conf 

I added snd_bcm2835 to the /etc/modules file on my Xbian but that created a loop at boot time. this seems not be allowed when starting OSMC

Modprobe on Boot - Debian

To answer the specific question about sudo modprobe snd_bcm2835 , add the module to /etc/modules and reboot. (You will need to be root to do this.)

Читайте также:  Linux open ssh port

Starting services - Debian

Debian using initscripts to initialise the system, and you can use them to run arbitrary commands. You need to install a script similar to the following in /etc/init.d .

#! /bin/sh # /etc/init.d/blah # # Some things that run always touch /var/lock/blah # Carry out specific functions when asked to by the system case "$1" in start) echo "Starting script blah " echo "Could do more here" ;; stop) echo "Stopping script blah" echo "Could do more here" ;; *) echo "Usage: /etc/init.d/blah " exit 1 ;; esac exit 0 

You should ensure it is runnable and owned by root.

sudo chmod 755 /etc/init.d/blah sudo chown root:root /etc/init.d/blah 

Then you need to register it to run at startup.

sudo update-rc.d blah defaults 

References

Источник

How to load a kernel module at boot time on Linux

Loadable kernel modules are a convenient way to modify the running kernel without rebuilding the kernel from scratch. You can also free up memory resources by unloading any unnecessary kernel module.

A kernel module can be loaded or unloaded on the fly by modprobe command. When loading a kernel module with modprobe , the command will also load any prerequisite module(s) automatically. Likewise, modprobe removes a kernel module along with any dependent module(s) that are no longer used.

Any kernel modules that are manually loaded by modprobe will not remain in the kernel after rebooting. If you would like to load a specific kernel module automatically upon reboot, you can follow this instruction. In this example, I assume that loop is the name of the kernel module that needs to be loaded upon boot.

Load a Kernel Module at Boot Time on Ubuntu or Debian

You can specify the module in /etc/modules .

$ sudo echo "loop" >> /etc/modules

Load a Kernel Module at Boot Time on CentOS, RHEL or Fedora

You can specify the module loading command in /etc/rc.modules .

$ sudo echo "modprobe loop" >> /etc/rc.modules $ sudo chmod +x /etc/rc.modules

Now the module loop will be loaded permanently across reboots.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Источник

Load linux kernel module at boot

I have written a kernel module for a study research project that is a driver for seven segment displays connected to a Raspberry Pi (I am pretty new to kernel development). I would like to permanently install the module and load it at boot time when it is compiled, so I added the install target to my Makefile which allows the user to directly compile and install it. I found out that all kernel modules are located somewhere inside /lib/modules//kernel , so I thought I just had to copy the compiled module into a subdirectory and list the module in the modules.order and modules.dep files. However, this approach did not work and since I could not find any resources to that topic, I am a little desperate. This is what my Makefile currently looks like:

# All source files are inside the src directory obj-m := src/sevenseg.o all: make -C /lib/modules/$(shell uname -r)/build EXTRA_CFLAGS=-I$(PWD)/src M=$(PWD) modules mv src/sevenseg.ko . install: make -C /lib/modules/$(shell uname -r)/build EXTRA_CFLAGS=-I$(PWD)/src M=$(PWD) modules mkdir -p /lib/modules/$(shell uname -r)/kernel/drivers/sevenseg cp src/sevenseg.ko /lib/modules/$(shell uname -r)/kernel/drivers/sevenseg echo "kernel/drivers/sevenseg/sevenseg.ko:" >> /lib/modules/$(shell uname -r)/modules.dep echo "kernel/drivers/sevenseg/sevenseg.ko" >> /lib/modules/$(shell uname -r)/modules.order insmod src/sevenseg.ko make clean clean: rm -rf src 

Источник

Оцените статью
Adblock
detector