Package: tiny-initramfs
Version: 0.1-5
Severity: wishlist
Tags: patch upstream

Dear Maintainer,

I'd like to use tiny-initramfs because it suits my needs very well, and
makes my computer boot a bit faster and thus makes me feel happier :)

The only issue I found with this nice piece of software is that it
doesn't allow me to resume from hibernation. So I looked into the code
of the tiny-initramfs and it turned out that it is very easy to add this
support.

I've made a patch that adds the support for resuming from hibernation,
and I'm attaching it to the bug report. It would be nice if someone
checked it for errors, since last time I wrote something substantial in
C was years ago. Anyway, it works fine for me (built my own package
with this patch) and it would be nice to help someone else who has the
same problem.

I'm aware that this has no chance to be included in bullseye, but oh
well.

Thanks in advace!


-- System Information:
Debian Release: 10.8
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 4.19.0-14-686 (SMP w/4 CPU cores)
Locale: LANG=C.UTF-8, LC_CTYPE=C.UTF-8 (charmap=UTF-8), LANGUAGE=C.UTF-8 
(charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: sysvinit (via /sbin/init)

Versions of packages tiny-initramfs depends on:
ii  tiny-initramfs-core  0.1-5

tiny-initramfs recommends no packages.

tiny-initramfs suggests no packages.

-- no debconf information
Description: Make tirfs able to resume from hibernation 
Author: Mikhail Krylov <sqar...@gmail.com>
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/tiny_initramfs.c
+++ b/tiny_initramfs.c
@@ -64,6 +64,7 @@ static char root_nfsdir[MAX_LINE_LEN];
 static char root_nfsoptions[MAX_LINE_LEN];
 #endif
 static char root_fstype[MAX_FILESYSTEM_TYPE_LEN];
+static char resume_device[MAX_FILESYSTEM_TYPE_LEN];
 static int root_delay;
 static int root_wait_indefinitely;
 static char init_binary[MAX_PATH_LEN];
@@ -112,6 +113,37 @@ int main(int argc, char **argv)
   warn("Parsed ", PROC_CMDLINE_FILENAME, NULL);
 #endif
 
+  if (!strlen(resume_device)){
+
+#ifdef ENABLE_DEBUG
+    warn("No resume device specified");
+#endif
+
+  } else {
+    // We won't need /target on a successful resume
+    r = mount("sysfs", "/target", "sysfs", MS_NODEV | MS_NOEXEC | MS_NOSUID, 
NULL);
+    if (r < 0)
+      panic(errno, "Could not mount /target for hibernation resume", NULL);
+
+#ifdef ENABLE_DEBUG
+    warn("Mounted /target for hibernation resume", NULL);
+#endif
+
+    int fd = open("/target/power/resume", O_WRONLY);
+
+    if (fd < 0) {
+      warn("Couldn't open /target/power/resume", strerror(errno), NULL);
+      // Continue just like nothing happened
+      umount("/target");
+    }
+
+    write(fd, resume_device, strlen(resume_device));
+    close(fd);
+    // If we are still here, that means resume failed, continue booting
+    umount("/target");
+  }
+
+
   if (!strlen(root_device)) {
 #ifdef ENABLE_NFS4
     if (strlen(root_nfshost))
@@ -366,6 +398,11 @@ int parse_cmdline_helper(void *data, const char *line, int 
line_is_incomplete)
       if (strlen(token) > MAX_PATH_LEN - 1)
         panic(0, "Parameter init=", token, " too long", NULL);
       set_buf(init_binary, MAX_PATH_LEN, token, NULL);
+    } else if (!strncmp(token, "resume=", 7)){
+      token += 7;
+      if (strlen(token) > MAX_PATH_LEN - 1)
+        panic(0, "Parameter resume=", token, " too long", NULL);
+      set_buf(resume_device, MAX_PATH_LEN, token, NULL);
     }
 #ifdef ENABLE_NFS4
     else if (!strncmp(token, "nfsroot=", 8)) {

Reply via email to