From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eq9of-0005rQ-T8 for guix-patches@gnu.org; Sun, 25 Feb 2018 22:51:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eq9oe-0001LT-Qo for guix-patches@gnu.org; Sun, 25 Feb 2018 22:51:05 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:53008) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eq9oe-0001LN-MK for guix-patches@gnu.org; Sun, 25 Feb 2018 22:51:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eq9oe-0004J1-Eb for guix-patches@gnu.org; Sun, 25 Feb 2018 22:51:04 -0500 Subject: [bug#30604] [PATCH v2 5/6] vm: Allow qemu-image builder to load Linux kernel modules. Resent-Message-ID: From: Danny Milosavljevic Date: Mon, 26 Feb 2018 04:50:24 +0100 Message-Id: <20180226035025.1698-6-dannym@scratchpost.org> In-Reply-To: <20180226035025.1698-1-dannym@scratchpost.org> References: <20180225114557.816-1-dannym@scratchpost.org> <20180226035025.1698-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/system/vm.scm (%modprobe-wrapper): New variable. (qemu-image): Modify. --- gnu/system/vm.scm | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm index 345cecedd..c64c9678f 100644 --- a/gnu/system/vm.scm +++ b/gnu/system/vm.scm @@ -246,6 +246,17 @@ INPUTS is a list of inputs (as for packages)." #:single-file-output? #t #:references-graphs inputs)) +(define (%modprobe-wrapper modprobe linux-module-directory) + ;; Wrapper for the 'modprobe' command that knows where modules live. + ;; + ;; This wrapper is typically invoked by the Linux kernel ('call_modprobe', + ;; in kernel/kmod.c), a situation where the 'LINUX_MODULE_DIRECTORY' + ;; environment variable is not set---hence the need for this wrapper. + (program-file "modprobe" + #~(begin + (setenv "LINUX_MODULE_DIRECTORY" #$linux-module-directory) + (apply execl #$modprobe (cons #$modprobe (cdr (command-line))))))) + (define* (qemu-image #:key (name "qemu-image") (system (%current-system)) @@ -275,6 +286,8 @@ INPUTS is a list of inputs (as for packages). When COPY-INPUTS? is true, copy all of INPUTS into the image being built. When REGISTER-CLOSURES? is true, register INPUTS in the store database of the image so that Guix can be used in the image." + (let ((modprobe-name (file-append os-drv "/profile/bin/modprobe")) + (linux-module-directory (file-append (file-append os-drv "/kernel/lib/modules")))) (expression->derivation-in-linux-vm name (with-imported-modules (source-module-closure '((gnu build bootloader) @@ -288,7 +301,7 @@ the image." (ice-9 binary-ports)) (let ((inputs - '#$(append (list qemu parted e2fsprogs dosfstools) + '#$(append (list qemu parted e2fsprogs dosfstools kmod) (map canonical-package (list sed grep coreutils findutils gawk)) (if register-closures? (list guix) '()))) @@ -302,6 +315,14 @@ the image." inputs))) (set-path-environment-variable "PATH" '("bin" "sbin") inputs) + ;; It's possible that we need to load nls modules in order to + ;; mount the new partition. + (if (file-exists? #$modprobe-name) + (activate-modprobe #$(%modprobe-wrapper modprobe-name + linux-module-directory)) + (format (current-error-port) + "WARNING: No modprobe found in ~s. \ +Loading kernel modules will be impossible.\n" #$modprobe-name)) (let* ((graphs '#$(match inputs (((names . _) ...) @@ -364,7 +385,7 @@ the image." #:make-disk-image? #t #:disk-image-size disk-image-size #:disk-image-format disk-image-format - #:references-graphs inputs)) + #:references-graphs inputs))) ;;;