From de2d6aea4dfe1b284ed0d485f0acd16303ff253b Mon Sep 17 00:00:00 2001 From: Fred Loader <145092902+loadfred@users.noreply.github.com> Date: Sat, 4 Nov 2023 23:08:42 +0000 Subject: [PATCH] Resume Hook (Hibernation) (#41) * hook/resume: hibernation support * doc/*: added resume to docs * readme: added resume to readme * hook/resume: replaced stat * hook/resume/resume.init: shellcheck fix --------- Co-authored-by: Fred Loader <16803702-frealo@user.noreply.gitlab.com> --- README.md | 1 + doc/tinyramfs.5 | 8 ++++++++ doc/tinyramfs.5.scd | 6 ++++++ hook/resume/resume | 8 ++++++++ hook/resume/resume.init | 14 ++++++++++++++ 5 files changed, 37 insertions(+) create mode 100644 hook/resume/resume create mode 100644 hook/resume/resume.init diff --git a/README.md b/README.md index 66f78ed..becd4a6 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Tiny initramfs written in POSIX shell - ZFS + native encryption support - LUKS (detached header, key), LVM - mdev, mdevd, eudev, systemd-udevd +- Resume from swap partition ## Dependencies diff --git a/doc/tinyramfs.5 b/doc/tinyramfs.5 index f93ffa1..250b4c7 100644 --- a/doc/tinyramfs.5 +++ b/doc/tinyramfs.5 @@ -144,6 +144,14 @@ lvm_tag The tag of your LVM logical volume.\& .P .RE +.SS RESUME +.P +resume +.P +.RS 4 +The location of your swap partition.\& +.P +.RE .SS ZFS .P zfs_key diff --git a/doc/tinyramfs.5.scd b/doc/tinyramfs.5.scd index ea81ce6..c892218 100644 --- a/doc/tinyramfs.5.scd +++ b/doc/tinyramfs.5.scd @@ -103,6 +103,12 @@ lvm_tag The tag of your LVM logical volume. +## RESUME + +resume + + The location of your swap partition. + ## ZFS zfs_key diff --git a/hook/resume/resume b/hook/resume/resume new file mode 100644 index 0000000..f4137f8 --- /dev/null +++ b/hook/resume/resume @@ -0,0 +1,8 @@ +# vim: set ft=sh: +# shellcheck shell=sh +# +# https://shellcheck.net/wiki/SC2154 +# shellcheck disable=2154 + +copy_exec readlink +copy_exec cat diff --git a/hook/resume/resume.init b/hook/resume/resume.init new file mode 100644 index 0000000..2c3de5e --- /dev/null +++ b/hook/resume/resume.init @@ -0,0 +1,14 @@ +# vim: set ft=sh: +# shellcheck shell=sh +# +# https://shellcheck.net/wiki/SC2154 +# shellcheck disable=2154 + +resolve_device "$resume" + +if [ -n "$device" ]; then + dev_link=$(readlink "$device") + + cat /sys/class/block/"${dev_link##*/}"/dev > /sys/power/resume || \ + panic "failed to resume" +fi