unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Ivan Vilata i Balaguer <ivan@selidor.net>
To: 59746@debbugs.gnu.org
Subject: [bug#59746] [DOCUMENTATION] [PATCH] doc: Introduce using Swap Space for hibernation, with an example.
Date: Wed, 21 Dec 2022 13:16:59 +0100	[thread overview]
Message-ID: <Y6L5O7vAqok7+U10@sax> (raw)
In-Reply-To: <handler.59746.B.166991506631585.ack@debbugs.gnu.org>


[-- Attachment #1.1: Type: text/plain, Size: 347 bytes --]

This patch replaces the previous one and enhances it with several minor fixes
and the missing information related to computing the swap file offset, as
discussed [in the guix-devel thread][1].

[1]: https://lists.gnu.org/archive/html/guix-devel/2022-12/msg00028.html

Thanks and cheers!

-- 
Ivan Vilata i Balaguer -- https://elvil.net/

[-- Attachment #1.2: 0001-doc-Introduce-using-swap-space-for-hibernation-with-.patch --]
[-- Type: text/plain, Size: 4134 bytes --]

From e95d79ef8c466e495c730f722b7aefc4d2d5969f Mon Sep 17 00:00:00 2001
From: Ivan Vilata-i-Balaguer <ivan@selidor.net>
Date: Wed, 21 Dec 2022 13:08:48 +0100
Subject: [PATCH] doc: Introduce using swap space for hibernation, with
 examples.

* doc/guix.texi (Swap Space): Add a concise introduction to hibernation and
specifying a swap space to the kernel to make resume work.  Mention space
requirements and the need of an offset for swap files.  Include a trivial
example on how to set up a mapped swap volume for hibernation and another one
for a swap file, including how to compute the file offset.
---
 doc/guix.texi | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/doc/guix.texi b/doc/guix.texi
index aacf748838..f04a541583 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -109,6 +109,7 @@
 Copyright @copyright{} 2022 Simon Streit@*
 Copyright @copyright{} 2022 (@*
 Copyright @copyright{} 2022 John Kehayias@*
+Copyright @copyright{} 2022 Ivan Vilata-i-Balaguer@*
 
 Permission is granted to copy, distribute and/or modify this document
 under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -17072,6 +17073,15 @@ Swap Space
 allocated at disk formatting time (logical volumes notwithstanding),
 whereas files can be allocated and deallocated at any time.
 
+A swap space is also required in order to hibernate a system using the
+Linux kernel.  Hibernation (also called suspend to disk) uses at most
+half the size of the RAM in the configured swap space.  The kernel needs
+to know about the swap space to be used to resume from hibernation on
+boot (via a kernel argument).  When using a swap file, its offset in the
+device holding it also needs to be given to the kernel, but that value
+has to be updated if the file is initialized again as swap (e.g. because
+its size was changed).
+
 Note that swap space is not zeroed on shutdown, so sensitive data (such
 as passwords) may linger on it if it was paged out.  As such, you should
 consider having your swap reside on an encrypted device (@pxref{Mapped
@@ -17157,6 +17167,57 @@ Swap Space
 file system mounted at @file{/btrfs}.  Note how we use Guile's filter to
 select the file system in an elegant fashion!
 
+@lisp
+(swap-devices
+  (list
+    (swap-space
+      (target "/dev/mapper/my-swap")
+      (dependencies mapped-devices))))
+
+(kernel-arguments
+  (cons* "resume=/dev/mapper/my-swap"
+         %default-kernel-arguments))
+@end lisp
+
+The previous snippet of an @code{operating-system} declaration enables
+the mapped device @file{/dev/mapper/my-swap} (which may be part of an
+encrypted device) as swap space, and tells the kernel to use it for
+hibernation via the @code{resume} kernel argument
+(@pxref{operating-system Reference}, @code{kernel-arguments}).
+
+@lisp
+(swap-devices
+  (list
+    (swap-space
+      (target "/swapfile")
+      (dependencies (filter (file-system-mount-point-predicate "/")
+                            file-systems)))))
+
+(kernel-arguments
+  (cons* "resume=/swapfile"
+         "resume_offset=92514304"
+         %default-kernel-arguments))
+@end lisp
+
+This other snippet of @code{operating-system} enables the swap file
+@file{/swapfile} for hibernation by telling the kernel about the file
+(@code{resume} argument) and its offset on disk (@code{resume_offset}
+argument).  The latter value can be found in the output of the command
+@command{filefrag -e} as the first number right under the
+@code{physical_offset} column header (the second command extracts its
+value directly):
+
+@smallexample
+$ sudo filefrag -e /swapfile
+Filesystem type is: ef53
+File size of /swapfile is 2463842304 (601524 blocks of 4096 bytes)
+ ext:     logical_offset:        physical_offset: length:   expected: flags:
+   0:        0..    2047:   92514304..  92516351:   2048:
+@dots{}
+$ sudo filefrag -e /swapfile | grep '^ *0:' | cut -d: -f3 | cut -d. -f1
+   92514304
+@end smallexample
+
 @node User Accounts
 @section User Accounts
 
-- 
2.38.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2022-12-21 12:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-01 17:17 [bug#59746] [DOCUMENTATION] [PATCH] doc: Introduce using Swap Space for hibernation, with an example Ivan Vilata i Balaguer
     [not found] ` <handler.59746.B.166991506631585.ack@debbugs.gnu.org>
2022-12-21 12:16   ` Ivan Vilata i Balaguer [this message]
2023-01-05 22:01     ` bug#59746: " Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y6L5O7vAqok7+U10@sax \
    --to=ivan@selidor.net \
    --cc=59746@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).