[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#30604] [PATCH v9 4/7] linux-boot: Load kernel modules only when the
From: |
Danny Milosavljevic |
Subject: |
[bug#30604] [PATCH v9 4/7] linux-boot: Load kernel modules only when the hardware is present. |
Date: |
Sun, 4 Mar 2018 02:09:11 +0100 |
* gnu/build/linux-boot.scm (boot-system): Load kernel modules only when
the hardware is present.
* gnu/system/linux-initrd.scm (raw-initrd): Add imports.
---
gnu/build/linux-boot.scm | 42 +++++++++++++++++++++++++++++++++++-------
gnu/system/linux-initrd.scm | 4 +++-
2 files changed, 38 insertions(+), 8 deletions(-)
diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm
index 18d87260a..2236d8971 100644
--- a/gnu/build/linux-boot.scm
+++ b/gnu/build/linux-boot.scm
@@ -469,9 +469,31 @@ upon error."
mounts)
"ext4"))
- (define (lookup-module name)
- (string-append linux-module-directory "/"
- (ensure-dot-ko name)))
+ (define (load-kernel-modules)
+ "Examine /sys/devices to find out which modules to load and load them."
+ (define enter?
+ (const #t))
+ (define (down! directory stat result)
+ ;; Note: modprobe mutates the tree starting with DIRECTORY.
+ (let ((modalias-name (string-append directory "/modalias")))
+ (if (file-exists? modalias-name)
+ (let ((modalias
+ (string-trim-right (call-with-input-file modalias-name
+ read-string)
+ #\newline)))
+ (system* "/sbin/modprobe" "-q" "--" modalias))))
+ #t)
+ (define up
+ (const #t))
+ (define skip
+ (const #t))
+ (define leaf
+ (const #t))
+ (define (error name stat errno result)
+ (format (current-error-port) "warning: ~a: ~a~%"
+ name (strerror errno))
+ result)
+ (file-system-fold enter? leaf down! up skip error #t "/sys/devices"))
(display "Welcome, this is GNU's early boot Guile.\n")
(display "Use '--repl' for an initrd REPL.\n\n")
@@ -486,10 +508,16 @@ upon error."
(when (member "--repl" args)
(start-repl))
- (display "loading kernel modules...\n")
- (for-each (cut load-linux-module* <>
- #:lookup-module lookup-module)
- (map lookup-module linux-modules))
+ (let* ((kernel-release
+ (utsname:release (uname)))
+ (directory
+ (string-append linux-module-directory "/lib/modules/"
+ kernel-release))
+ (old-umask (umask #o022)))
+ (make-static-device-nodes directory)
+ (umask old-umask))
+
+ (load-kernel-modules)
(when qemu-guest-networking?
(unless (configure-qemu-networking)
diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm
index 6ad6d75f7..339ecf754 100644
--- a/gnu/system/linux-initrd.scm
+++ b/gnu/system/linux-initrd.scm
@@ -266,7 +266,9 @@ upon error."
;; this info via gexps.
((gnu build file-systems)
#:select (find-partition-by-luks-uuid))
- (rnrs bytevectors))
+ (rnrs bytevectors)
+ (ice-9 ftw)
+ (ice-9 rdelim))
(with-output-to-port (%make-void-port "w")
(lambda ()
- [bug#30604] [PATCH v9 7/7] linux-initrd: Use module-aliases->module-file-names, too., (continued)
- [bug#30604] [PATCH v9 5/7] vm: Allow qemu-image builder to load Linux kernel modules., Danny Milosavljevic, 2018/03/03
- [bug#30604] [PATCH v9 3/7] linux-initrd: Provide pure-Guile modprobe., Danny Milosavljevic, 2018/03/03
- [bug#30604] [PATCH v9 3/7] linux-initrd: Provide pure-Guile modprobe., Danny Milosavljevic, 2018/03/11
- [bug#30604] [PATCH v9 3/7] linux-initrd: Provide pure-Guile modprobe., Ludovic Courtès, 2018/03/12
- [bug#30604] [PATCH v9 3/7] linux-initrd: Provide pure-Guile modprobe., Danny Milosavljevic, 2018/03/12
- [bug#30604] [PATCH v9 2/7] linux-modules: Add module-aliases->module-file-names., Danny Milosavljevic, 2018/03/03
- [bug#30604] [PATCH v9 1/7] linux-modules: Add "modules.devname" and "modules.alias" writer., Danny Milosavljevic, 2018/03/03
- [bug#30604] [PATCH v9 6/7] vm: Make the virtio-blk uniquely identifiable in /sys., Danny Milosavljevic, 2018/03/03
- [bug#30604] [PATCH v9 4/7] linux-boot: Load kernel modules only when the hardware is present.,
Danny Milosavljevic <=