Skip to content
Snippets Groups Projects
Commit e3ced65a authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

linux-initrd: Use 'call-with-error-handling' when booting.

* guix/build/linux-initrd.scm (canonicalize-device-spec): When label
  resolution fails, call 'error' instead of 'format' + 'start-repl'.
  (boot-system): Wrap most of body in 'call-with-error-handling'.
  Remove 'catch' around 'primitive-load' call.
parent dccab4df
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ (define-module (guix build linux-initrd) ...@@ -20,6 +20,7 @@ (define-module (guix build linux-initrd)
#:use-module (rnrs io ports) #:use-module (rnrs io ports)
#:use-module (rnrs bytevectors) #:use-module (rnrs bytevectors)
#:use-module (system foreign) #:use-module (system foreign)
#:use-module (system repl error-handling)
#:autoload (system repl repl) (start-repl) #:autoload (system repl repl) (start-repl)
#:autoload (system base compile) (compile-file) #:autoload (system base compile) (compile-file)
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
...@@ -250,10 +251,7 @@ (define canonical-title ...@@ -250,10 +251,7 @@ (define canonical-title
;; Some devices take a bit of time to appear, most notably USB ;; Some devices take a bit of time to appear, most notably USB
;; storage devices. Thus, wait for the device to appear. ;; storage devices. Thus, wait for the device to appear.
(if (> count max-trials) (if (> count max-trials)
(begin (error "failed to resolve partition label" spec)
(format (current-error-port)
"failed to resolve partition label: ~s~%" spec)
(start-repl))
(begin (begin
(sleep 1) (sleep 1)
(loop (+ 1 count)))))))) (loop (+ 1 count))))))))
...@@ -615,84 +613,79 @@ (define root-fs-type ...@@ -615,84 +613,79 @@ (define root-fs-type
(display "Welcome, this is GNU's early boot Guile.\n") (display "Welcome, this is GNU's early boot Guile.\n")
(display "Use '--repl' for an initrd REPL.\n\n") (display "Use '--repl' for an initrd REPL.\n\n")
(mount-essential-file-systems) (call-with-error-handling
(let* ((args (linux-command-line)) (lambda ()
(to-load (find-long-option "--load" args)) (mount-essential-file-systems)
(root (find-long-option "--root" args))) (let* ((args (linux-command-line))
(to-load (find-long-option "--load" args))
(when (member "--repl" args) (root (find-long-option "--root" args)))
(start-repl))
(when (member "--repl" args)
(display "loading kernel modules...\n") (start-repl))
(for-each (compose load-linux-module*
(cut string-append "/modules/" <>)) (display "loading kernel modules...\n")
linux-modules) (for-each (compose load-linux-module*
(cut string-append "/modules/" <>))
(when qemu-guest-networking? linux-modules)
(unless (configure-qemu-networking)
(display "network interface is DOWN\n"))) (when qemu-guest-networking?
(unless (configure-qemu-networking)
;; Make /dev nodes. (display "network interface is DOWN\n")))
(make-essential-device-nodes)
;; Make /dev nodes.
;; Prepare the real root file system under /root. (make-essential-device-nodes)
(unless (file-exists? "/root")
(mkdir "/root")) ;; Prepare the real root file system under /root.
(if root (unless (file-exists? "/root")
(mount-root-file-system (canonicalize-device-spec root) (mkdir "/root"))
root-fs-type (if root
#:volatile-root? volatile-root?) (mount-root-file-system (canonicalize-device-spec root)
(mount "none" "/root" "tmpfs")) root-fs-type
#:volatile-root? volatile-root?)
(unless (file-exists? "/root/dev") (mount "none" "/root" "tmpfs"))
(mkdir "/root/dev")
(make-essential-device-nodes #:root "/root")) (unless (file-exists? "/root/dev")
(mkdir "/root/dev")
;; Mount the specified file systems. (make-essential-device-nodes #:root "/root"))
(for-each mount-file-system
(remove root-mount-point? mounts)) ;; Mount the specified file systems.
(for-each mount-file-system
(when guile-modules-in-chroot? (remove root-mount-point? mounts))
;; Copy the directories that contain .scm and .go files so that the
;; child process in the chroot can load modules (we would bind-mount (when guile-modules-in-chroot?
;; them but for some reason that fails with EINVAL -- XXX). ;; Copy the directories that contain .scm and .go files so that the
(mkdir-p "/root/share") ;; child process in the chroot can load modules (we would bind-mount
(mkdir-p "/root/lib") ;; them but for some reason that fails with EINVAL -- XXX).
(mount "none" "/root/share" "tmpfs") (mkdir-p "/root/share")
(mount "none" "/root/lib" "tmpfs") (mkdir-p "/root/lib")
(copy-recursively "/share" "/root/share" (mount "none" "/root/share" "tmpfs")
#:log (%make-void-port "w")) (mount "none" "/root/lib" "tmpfs")
(copy-recursively "/lib" "/root/lib" (copy-recursively "/share" "/root/share"
#:log (%make-void-port "w"))) #:log (%make-void-port "w"))
(copy-recursively "/lib" "/root/lib"
(if to-load #:log (%make-void-port "w")))
(begin
(switch-root "/root") (if to-load
(format #t "loading '~a'...\n" to-load) (begin
(switch-root "/root")
;; Obviously this has to be done each time we boot. Do it from here (format #t "loading '~a'...\n" to-load)
;; so that statfs(2) returns DEVPTS_SUPER_MAGIC like libc's getpt(3)
;; expects (and thus openpty(3) and its users, such as xterm.) ;; Obviously this has to be done each time we boot. Do it from here
(mount "none" "/dev/pts" "devpts") ;; so that statfs(2) returns DEVPTS_SUPER_MAGIC like libc's getpt(3)
;; expects (and thus openpty(3) and its users, such as xterm.)
;; TODO: Remove /lib, /share, and /loader.go. (mount "none" "/dev/pts" "devpts")
(catch #t
(lambda () ;; TODO: Remove /lib, /share, and /loader.go.
(primitive-load to-load)) (primitive-load to-load)
(lambda args
(start-repl)) (format (current-error-port)
(lambda args "boot program '~a' terminated, rebooting~%"
(format (current-error-port) "'~a' raised an exception: ~s~%" to-load)
to-load args) (sleep 2)
(display-backtrace (make-stack #t) (current-error-port)))) (reboot))
(format (current-error-port) (begin
"boot program '~a' terminated, rebooting~%" (display "no boot file passed via '--load'\n")
to-load) (display "entering a warm and cozy REPL\n")
(sleep 2) (start-repl)))))))
(reboot))
(begin
(display "no boot file passed via '--load'\n")
(display "entering a warm and cozy REPL\n")
(start-repl)))))
;;; linux-initrd.scm ends here ;;; linux-initrd.scm ends here
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment