#:use-module (ice-9 match)
#:use-module (ice-9 ftw)
#:use-module (guix build utils)
+ #:use-module (gnu build linux-modules)
#:use-module (gnu build file-systems)
#:export (mount-essential-file-systems
linux-command-line
configure-qemu-networking
bind-mount
- load-linux-module*
device-number
boot-system))
(logand (network-interface-flags sock interface) IFF_UP)))
-(define (load-linux-module* file)
- "Load Linux module from FILE, the name of a `.ko' file."
- (define (slurp module)
- ;; TODO: Use 'mmap' to reduce memory usage.
- (call-with-input-file file get-bytevector-all))
-
- (load-linux-module (slurp file)))
-
(define (device-number major minor)
"Return the device number for the device with MAJOR and MINOR, for use as
the last argument of `mknod'."
\f
(define* (boot-system #:key
(linux-modules '())
+ linux-module-directory
qemu-guest-networking?
volatile-root?
pre-mount
(mounts '()))
"This procedure is meant to be called from an initrd. Boot a system by
-first loading LINUX-MODULES (a list of absolute file names of '.ko' files),
-then setting up QEMU guest networking if QEMU-GUEST-NETWORKING? is true,
-calling PRE-MOUNT, mounting the file systems specified in MOUNTS, and finally
-booting into the new root if any. The initrd supports kernel command-line
-options '--load', '--root', and '--repl'.
+first loading LINUX-MODULES (a list of module names) from
+LINUX-MODULE-DIRECTORY, then setting up QEMU guest networking if
+QEMU-GUEST-NETWORKING? is true, calling PRE-MOUNT, mounting the file systems
+specified in MOUNTS, and finally booting into the new root if any. The initrd
+supports kernel command-line options '--load', '--root', and '--repl'.
Mount the root file system, specified by the '--root' command-line argument,
if any.
mounts)
"ext4"))
+ (define (lookup-module name)
+ (string-append linux-module-directory "/"
+ (ensure-dot-ko name)))
+
(display "Welcome, this is GNU's early boot Guile.\n")
(display "Use '--repl' for an initrd REPL.\n\n")
(start-repl))
(display "loading kernel modules...\n")
- (for-each load-linux-module* linux-modules)
+ (current-module-debugging-port (current-output-port))
+ (for-each (cut load-linux-module* <>
+ #:lookup-module lookup-module)
+ (map lookup-module linux-modules))
(when qemu-guest-networking?
(unless (configure-qemu-networking)
(boot-system #:mounts '#$(map file-system->spec file-systems)
#:pre-mount (lambda ()
(and #$@device-mapping-commands))
- #:linux-modules (map (lambda (file)
- (string-append #$kodir "/" file))
- '#$linux-modules)
+ #:linux-modules '#$linux-modules
+ #:linux-module-directory '#$kodir
#:qemu-guest-networking? #$qemu-networking?
#:volatile-root? '#$volatile-root?))
#:name "base-initrd"
#:modules '((guix build utils)
(gnu build linux-boot)
- (gnu build file-systems)))))
+ (gnu build linux-modules)
+ (gnu build file-systems)
+ (guix elf)))))
;;; linux-initrd.scm ends here