forked from artix/66-scripts
3 changed files with 79 additions and 84 deletions
@ -0,0 +1,52 @@
|
||||
.Dd June 1, 2016 |
||||
.Dt MODULES-LOAD 8 |
||||
.Os Linux |
||||
.Sh NAME |
||||
.Nm modules-load |
||||
.Nd Configure kernel modules to load at boot |
||||
.Sh SYNOPSIS |
||||
.Nm modules-load |
||||
.Op Fl nv |
||||
.Sh DESCRIPTION |
||||
.Nm |
||||
reads files which contain kernel modules to load during boot from the list of |
||||
locations below. |
||||
.Bl -tag -width indent |
||||
.It Fl n |
||||
dry-run mode. |
||||
This option does everything but actually insert or delete the modules. |
||||
.It Fl v |
||||
verbose mode. |
||||
Print messages about what the program is doing. |
||||
.El |
||||
.Sh FILES |
||||
Configuration files are read from the following locations: |
||||
.Bl -tag -width indent |
||||
.It /etc/modules-load.d/*.conf |
||||
.It /run/modules-load.d/*.conf |
||||
.It /usr/lib/modules-load.d/*.conf |
||||
.El |
||||
.Pp |
||||
The configuration files should simply contain a list of kernel module names |
||||
to load, separated by newlines. |
||||
Empty lines and lines whose first non-whitespace character is # or ; are |
||||
ignored. |
||||
.Sh EXAMPLES |
||||
.Pa /etc/modules-load.d/virtio-net.conf : |
||||
.Bd -literal -offset indent |
||||
# Load virtio-net.ko at boot |
||||
virtio-net |
||||
.Ed |
||||
.Sh SEE ALSO |
||||
.Xr modprobe 8 |
||||
.Sh HISTORY |
||||
This program is a replacement for the |
||||
.Nm modules-load |
||||
utility provided by |
||||
.Nm systemd . |
||||
.Sh AUTHOR |
||||
.An Leah Neukirchen , |
||||
.Mt leah@vuxu.org . |
||||
.Sh LICENSE |
||||
.Nm |
||||
is in the public domain. |
@ -1,82 +1,19 @@
|
||||
#!@BINDIR@/sh |
||||
# |
||||
# This scripts is a pure-POSIX sh version |
||||
# |
||||
# Copyright (c) 2015-2021 Eric Vidal <eric@obarun.org> |
||||
# All rights reserved. |
||||
# |
||||
# This file is part of Obarun. It is subject to the license terms in |
||||
# the LICENSE file found in the top-level directory of this |
||||
# distribution. |
||||
# This file may not be copied, modified, propagated, or distributed |
||||
# except according to the terms contained in the LICENSE file. |
||||
|
||||
|
||||
# Configuration files are read from directories in |
||||
# /etc/modules-load.d, /run/modules-load.d, and /usr/lib/modules-load.d, |
||||
# in order of precedence |
||||
|
||||
MODULES_PATH='/etc/modules-load.d /run/modules-load.d /usr/lib/modules-load.d' |
||||
MODULES_NAME="" |
||||
MODULES_RESULT="" |
||||
|
||||
check_elements(){ |
||||
for e in $2; do [ "$e" = "$1" ] && return 0; done; return 1; |
||||
} |
||||
|
||||
build_array() { |
||||
printf "%s %s" "$1" "$2" |
||||
} |
||||
|
||||
check_file(){ |
||||
|
||||
tidy_loop="" conf="" |
||||
|
||||
for tidy_loop in $MODULES_PATH; do |
||||
if [ -d "${tidy_loop}" ]; then |
||||
for conf in "${tidy_loop}"/*.conf ; do |
||||
if [ -f "${conf}" ]; then |
||||
if ! check_elements "${conf##*/}" "${MODULES_NAME}"; then |
||||
MODULES_NAME=$(build_array "${MODULES_NAME}" "${conf##*/}") |
||||
fi |
||||
fi |
||||
done |
||||
fi |
||||
done |
||||
|
||||
unset tidy_loop conf |
||||
} |
||||
check_path(){ |
||||
path="" tidy_loop="" |
||||
for path in ${MODULES_PATH}; do |
||||
for tidy_loop in ${MODULES_NAME}; do |
||||
if [ -f "${path}/${tidy_loop}" ]; then |
||||
if ! check_elements "${tidy_loop}" "${MODULES_RESULT##*/}";then |
||||
MODULES_RESULT=$(build_array "${MODULES_RESULT}" "${path}/${tidy_loop}") |
||||
fi |
||||
fi |
||||
done |
||||
done |
||||
unset path tidy_loop |
||||
} |
||||
|
||||
check_file |
||||
if [ -n "${MODULES_NAME}" ]; then |
||||
check_path |
||||
else |
||||
printf "$0: %s\n" "No modules found -- nothing to do" |
||||
exit 0 |
||||
fi |
||||
for mod in ${MODULES_RESULT}; do |
||||
while read -r line; do |
||||
comment=$(printf "%s" "$line" | awk '{ string=substr($0, 0, 1); print string; }' ) |
||||
if [ "${comment}" = "#" ] || [ -z "${line}" ];then |
||||
continue |
||||
fi |
||||
for check in ${line};do |
||||
modprobe -b "${check}" -v | sed 's:insmod [^ ]*/:Load modules :g; s:\.ko\(\.gz\)\? ::g' |
||||
done |
||||
done < "${mod}" |
||||
done |
||||
|
||||
exit 0 |
||||
#!/bin/sh |
||||
# modules-load [-n] [-v] - modules-load.d(8) compatible kernel module loader |
||||
|
||||
export PATH=/bin:/sbin |
||||
|
||||
{ |
||||
# Parameters passed as modules-load= or rd.modules-load= in kernel command line. |
||||
sed -nr 's/,/\n/;s/(.* |^)(rd\.)?modules-load=([^ ]*).*/\3/p' /proc/cmdline |
||||
|
||||
# Find files /{etc,run,usr/lib}/modules-load.d/*.conf in that order. |
||||
find -L /etc/modules-load.d /run/modules-load.d /usr/lib/modules-load.d \ |
||||
-maxdepth 1 -name '*.conf' -printf '%p %P\n' 2>/dev/null | |
||||
# Load each basename only once. |
||||
sort -k2 -s | uniq -f1 | cut -d' ' -f1 | |
||||
# Read the files, output all non-empty, non-comment lines. |
||||
tr '\012' '\0' | xargs -0 -r grep -h -v -e '^[#;]' -e '^$' |
||||
} | |
||||
# Call modprobe on the list of modules |
||||
tr '\012' '\0' | xargs -0 -r modprobe -ab "$@" |
||||
|
Loading…
Reference in new issue