From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59643) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ermiA-0000tv-Mz for guix-patches@gnu.org; Fri, 02 Mar 2018 10:35:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ermi9-0001dC-PN for guix-patches@gnu.org; Fri, 02 Mar 2018 10:35:06 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:33528) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ermi9-0001d5-Le for guix-patches@gnu.org; Fri, 02 Mar 2018 10:35:05 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ermi9-0003e7-Fh for guix-patches@gnu.org; Fri, 02 Mar 2018 10:35:05 -0500 Subject: [bug#30604] [PATCH v7 3/6] linux-boot: Load kernel modules only when the hardware is present. Resent-Message-ID: From: Danny Milosavljevic Date: Fri, 2 Mar 2018 16:34:05 +0100 Message-Id: <20180302153408.14091-4-dannym@scratchpost.org> In-Reply-To: <20180302153408.14091-1-dannym@scratchpost.org> References: <20180302141606.10669-1-dannym@scratchpost.org> <20180302153408.14091-1-dannym@scratchpost.org> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 30604@debbugs.gnu.org * gnu/build/linux-boot.scm (boot-system): Load kernel modules only when the hardware is present. (lookup-module): Delete procedure. * 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..1b16f267a 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! path stat result) + ;; Note: modprobe mutates the tree starting with path. + (let ((modalias-name (string-append path "/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 e7f97bb88..b50d3ff80 100644 --- a/gnu/system/linux-initrd.scm +++ b/gnu/system/linux-initrd.scm @@ -208,7 +208,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 ()