aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Baptiste Note <jean-baptiste.note@m4x.org>2020-04-27 20:42:03 +0000
committerGuix Patches Tester <>2020-05-05 19:09:12 +0100
commitb464d3900f14caaf62940e0eb2ae6d763cdff857 (patch)
treee5bf2fd92f19fc622d1533a7fd5088a0bdbadad2
parentec5c22c2c6d0b0894e1baaa6de439b9c5ccec73a (diff)
downloadpatches-series-3856.tar
patches-series-3856.tar.gz
linux-boot: Add support for resuming from swap device.series-3856
* gnu/build/linux-boot.scm (resume-from-device): Add function. * gnu/build/linux-boot.scm (boot-system): Add hook calling resume-from-device if specified on commandline, before mounting any actual disk filesystems.
-rw-r--r--gnu/build/linux-boot.scm43
1 files changed, 40 insertions, 3 deletions
diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm
index 05e833c0c6..2febe61ec1 100644
--- a/gnu/build/linux-boot.scm
+++ b/gnu/build/linux-boot.scm
@@ -357,6 +357,37 @@ the last argument of `mknod'."
(compose (cut string=? program <>) basename))))
(filter-map string->number (scandir "/proc")))))
+(define (resume-from-device resume-device)
+ "Resume from hibernation state on RESUME-DEVICE. This *must* happen before
+we mount any filesystems on disk. See
+linux-libre/Documentation/power/swsusp.txt. Please note that this function
+will not return if resume happens successfully, and will return if swap device
+does not contain a valid resume signature."
+ (false-if-exception
+ (let* ((device-base-name
+ ;; The base name of the device file, after resolving
+ ;; symlinks.
+ (let loop ((file resume-device))
+ (match (stat:type (lstat file))
+ ('symlink
+ (let ((target (readlink file)))
+ (if (string-prefix? "/" target)
+ (loop target)
+ (loop (string-append (dirname file) "/" target)))))
+ (_ (basename file)))))
+ (major+minor
+ ;; The major:minor string (e.g. "8:2") corresponding
+ ;; to the resume device.
+ (call-with-input-file (string-append "/sys/class/block/"
+ device-base-name
+ "/dev")
+ read-line)))
+ ;; Write the major:minor string to /sys/power/resume
+ ;; to attempt resume from hibernation.
+ (when major+minor
+ (call-with-output-file "/sys/power/resume"
+ (cut display major+minor <>))))))
+
(define* (mount-root-file-system root type
#:key volatile-root? (flags 0) options)
"Mount the root file system of type TYPE at device ROOT. If VOLATILE-ROOT? is
@@ -493,9 +524,10 @@ upon error."
(call-with-error-handling
(lambda ()
(mount-essential-file-systems)
- (let* ((args (linux-command-line))
- (to-load (find-long-option "--load" args))
- (root (find-long-option "--root" args)))
+ (let* ((args (linux-command-line))
+ (to-load (find-long-option "--load" args))
+ (root (find-long-option "--root" args))
+ (resume-device (find-long-option "--resume" args)))
(when (member "--repl" args)
(start-repl))
@@ -528,6 +560,11 @@ upon error."
(unless (pre-mount)
(error "pre-mount actions failed")))
+ (when (and resume-device
+ (file-exists? resume-device)
+ (file-exists? "/sys/power/resume"))
+ (resume-from-device resume-device))
+
(setenv "EXT2FS_NO_MTAB_OK" "1")
(if root