~ruther/guix-local

42d10464bedb43a9211d8bc187e668fe33272368 — Ludovic Courtès 11 years ago df650fa
linux-initrd: Store Linux modules in a normal store directory.

* gnu/system/linux-initrd.scm (expression->initrd): Remove #:linux and
  #:linux-modules parameters.  Remove call to
  'float-linux-module-directory'.
  (base-initrd): Add call to 'float-linux-module-directory'.  Use it in
  #:linux-modules argument in the gexp.  Remove #:linux and
  #:linux-modules arguments to 'expression->initrd'.
* gnu/build/linux-initrd.scm (build-initrd): Remove
  #:linux-module-directory parameter.  Don't create 'modules'
  sub-directory.
* gnu/build/linux-boot.scm (boot-system): Mentin that LINUX-MODULES is a
  list of absolute file names.  Don't prepend "/modules/" to
  LINUX-MODULES.
* doc/guix.texi (Initial RAM Disk): Adjust accordingly.
4 files changed, 41 insertions(+), 52 deletions(-)

M doc/guix.texi
M gnu/build/linux-boot.scm
M gnu/build/linux-initrd.scm
M gnu/system/linux-initrd.scm
M doc/guix.texi => doc/guix.texi +3 -5
@@ 3616,16 3616,14 @@ program to run in that initrd.

@deffn {Monadic Procedure} expression->initrd @var{exp} @
       [#:guile %guile-static-stripped] [#:name "guile-initrd"] @
       [#:modules '()] [#:linux #f] @
       [#:linux-modules '()]
       [#:modules '()]
Return a derivation that builds a Linux initrd (a gzipped cpio archive)
containing @var{guile} and that evaluates @var{exp}, a G-expression,
upon booting.  All the derivations referenced by @var{exp} are
automatically copied to the initrd.

@var{linux-modules} is a list of @file{.ko} file names to be copied from
@var{linux} into the initrd.  @var{modules} is a list of Guile module
names to be embedded in the initrd.
@var{modules} is a list of Guile module names to be embedded in the
initrd.
@end deffn

@node Invoking guix system

M gnu/build/linux-boot.scm => gnu/build/linux-boot.scm +6 -7
@@ 343,10 343,11 @@ bailing out.~%root contents: ~s~%" (scandir "/"))
                      volatile-root?
                      (mounts '()))
  "This procedure is meant to be called from an initrd.  Boot a system by
first loading LINUX-MODULES, then setting up QEMU guest networking if
QEMU-GUEST-NETWORKING? is true, 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 absolute file names of '.ko' files),
then setting up QEMU guest networking if QEMU-GUEST-NETWORKING? is true,
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.


@@ 384,9 385,7 @@ to it are lost."
         (start-repl))

       (display "loading kernel modules...\n")
       (for-each (compose load-linux-module*
                          (cut string-append "/modules/" <>))
                 linux-modules)
       (for-each load-linux-module* linux-modules)

       (when qemu-guest-networking?
         (unless (configure-qemu-networking)

M gnu/build/linux-initrd.scm => gnu/build/linux-initrd.scm +1 -6
@@ 104,23 104,18 @@ This is similar to what 'compiled-file-name' in (system base compile) does."
(define* (build-initrd output
                       #:key
                       guile init
                       linux-module-directory
                       (references-graphs '())
                       (cpio "cpio")
                       (gzip "gzip"))
  "Write an initial RAM disk (initrd) to OUTPUT.  The initrd starts the script
at INIT, running GUILE.  It contains all the items referred to by
REFERENCES-GRAPHS, plus the Linux modules from LINUX-MODULE-DIRECTORY."
REFERENCES-GRAPHS."
  (mkdir "contents")

  ;; Copy the closures of all the items referenced in REFERENCES-GRAPHS.
  (populate-store references-graphs "contents")

  (with-directory-excursion "contents"
    ;; Copy Linux modules.
    (mkdir "modules")
    (copy-recursively linux-module-directory "modules")

    ;; Make '/init'.
    (symlink init "init")


M gnu/system/linux-initrd.scm => gnu/system/linux-initrd.scm +31 -34
@@ 34,6 34,7 @@
  #:use-module (ice-9 match)
  #:use-module (ice-9 regex)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:export (expression->initrd
            base-initrd))



@@ 53,25 54,19 @@
                             (gzip gzip)
                             (name "guile-initrd")
                             (system (%current-system))
                             (modules '())
                             (linux #f)
                             (linux-modules '()))
                             (modules '()))
  "Return a derivation that builds a Linux initrd (a gzipped cpio archive)
containing GUILE and that evaluates EXP, a G-expression, upon booting.  All
the derivations referenced by EXP are automatically copied to the initrd.

LINUX-MODULES is a list of '.ko' file names to be copied from LINUX into the
initrd.  MODULES is a list of Guile module names to be embedded in the
initrd."
MODULES is a list of Guile module names to be embedded in the initrd."

  ;; General Linux overview in `Documentation/early-userspace/README' and
  ;; `Documentation/filesystems/ramfs-rootfs-initramfs.txt'.

  (mlet* %store-monad ((init       (gexp->script "init" exp
                                                 #:modules modules
                                                 #:guile guile))
                       (module-dir (flat-linux-module-directory linux
                                                                linux-modules)))
  (mlet %store-monad ((init (gexp->script "init" exp
                                          #:modules modules
                                          #:guile guile)))
    (define builder
      #~(begin
          (use-modules (gnu build linux-initrd))


@@ 80,8 75,8 @@ initrd."
          (build-initrd (string-append #$output "/initrd")
                        #:guile #$guile
                        #:init #$init
                        ;; Copy everything INIT refers to into the initrd.
                        #:references-graphs '("closure")
                        #:linux-module-directory #$module-dir
                        #:cpio (string-append #$cpio "/bin/cpio")
                        #:gzip (string-append #$gzip "/bin/gzip"))))



@@ 201,27 196,29 @@ exception and backtrace!)."
            (list unionfs-fuse/static)
            '())))

  (expression->initrd
   #~(begin
       (use-modules (gnu build linux-boot)
                    (guix build utils)
                    (srfi srfi-26))

       (with-output-to-port (%make-void-port "w")
         (lambda ()
           (set-path-environment-variable "PATH" '("bin" "sbin")
                                          '#$helper-packages)))

       (boot-system #:mounts '#$(map file-system->spec file-systems)
                    #:linux-modules '#$linux-modules
                    #:qemu-guest-networking? #$qemu-networking?
                    #:guile-modules-in-chroot? '#$guile-modules-in-chroot?
                    #:volatile-root? '#$volatile-root?))
   #:name "base-initrd"
   #:modules '((guix build utils)
               (gnu build linux-boot)
               (gnu build file-systems))
   #:linux linux-libre
   #:linux-modules linux-modules))
  (mlet %store-monad ((kodir (flat-linux-module-directory linux-libre
                                                          linux-modules)))
    (expression->initrd
     #~(begin
         (use-modules (gnu build linux-boot)
                      (guix build utils)
                      (srfi srfi-26))

         (with-output-to-port (%make-void-port "w")
           (lambda ()
             (set-path-environment-variable "PATH" '("bin" "sbin")
                                            '#$helper-packages)))

         (boot-system #:mounts '#$(map file-system->spec file-systems)
                      #:linux-modules (map (lambda (file)
                                             (string-append #$kodir "/" file))
                                           '#$linux-modules)
                      #:qemu-guest-networking? #$qemu-networking?
                      #:guile-modules-in-chroot? '#$guile-modules-in-chroot?
                      #:volatile-root? '#$volatile-root?))
     #:name "base-initrd"
     #:modules '((guix build utils)
                 (gnu build linux-boot)
                 (gnu build file-systems)))))

;;; linux-initrd.scm ends here