Hi all,

Is there a method out there that can “save a hibernate state” to disk, and just permanently boot immediately into that state every time?

It would be OK to lose data used after this point. And ot would also be OK if it required building a custom image based on the hardware, similar to embedded systems.

The goal is to be able to, as quickly as possible, spin up a GPU server when needed, but without using suspend/resume.

Thanks.

  • Dave.@aussie.zone
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    2 hours ago

    Firstly, suspend might be an option compared to hibernation for your subsequent startups if you can suffer a slow startup the very first time.

    Otherwise look up “Linux from scratch” .

    A lot of boot time is decompressing and mounting initrd, loading modules there, mounting the root filesystem, jumping to that.

    Build a kernel that has exactly the minimum modules needed for your system, skip initrd and jump straight to a root filesystem and call your init binary (it can be BusyBox even) do exactly what’s needed there to get your network+graphics card up and running with a single shell script, done.

    Also look at COW filesystems. Read only base with an overlay file for writes. Discard that file on each boot and you basically have a system that is always at the same state on startup.

  • mlfh@lm.mlfh.org
    link
    fedilink
    English
    arrow-up
    9
    ·
    edit-2
    5 hours ago

    I was really curious about the possibilities here for a re-usable “saved hibernation state”, and did a lot of digging around and testing in exploration of that idea. Please note that the following is wacky as hell and is not a good way to run a server at all, but is possible:

    1. Set up a swap partition that can fit your full system memory.
    2. Enable swap and set up hibernation (https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Hibernation )
    3. Hibernate your system to the swap partition in the state you want to use as your perpetual checkpoint.
    4. Boot from a live usb, NOT your regular system (when the linux kernel boots with the resume=uuid=xxxx parameter which enables hibernation/resume, it checks that partition for a hibernation signature and immediately clears it, preventing multiple boots of the same hibernated state. You need to preserve this signature).
    5. From the live usb system, copy the swap partition that contains your main system’s hibernated state to an .img file on a filesystem mounted from one of your main disks.
    6. Reboot into your main system.
    7. Set up a scheduled job that triggers every time your system resumes (could use a systemd service with After=hibernate.target and WantedBy=hibernate.target) that does the following:
      1. Disables swap on the swap partition you set up (keeping the resume=uuid=xxxxx kernel parameter that points to it).
      2. Writes the .img file to that partition
    8. Use your system as you want, and power it off when done (do not suspend or hibernated again).

    The next time you boot, the kernel will load the saved hibernation state from the partition specified in the resume= parameter, as if it had just been hibernated instead of halted.

    Now for the downsides:

    • It’s very dangerous to resume a system’s memory to one state with storage in a different state (the official kernel docs for this have a giant red warning banner saying “If you touch anything on disk between suspend and resume… …kiss your data goodbye.” https://docs.kernel.org/power/swsusp.html ).
    • Resuming from hibernation isn’t really that much faster than cold booting a lean system, if speed is your primary goal.
    • The scheduled write job will hit you with a bunch of heavy io every time you boot/resume, probably negating any speed benefits of the whole thing anyway.

    Anyway, now that we know it’s possible, if you really can’t suspend/resume in a non-wacky way I recommend instead just booting normally and trying to make the boot process as fast as possible. A good guide here: https://wiki.archlinux.org/title/Improving_performance/Boot_process

    If booting quickly to a static state is the goal, alpine diskless mode might be a good option: https://wiki.alpinelinux.org/wiki/Diskless_Mode

  • fozid@lem.radiantfig.fyi
    link
    fedilink
    English
    arrow-up
    2
    ·
    4 hours ago

    Baring post, my pc cold boots in 3 seconds. And does a full shutdown in 3 seconds as well.

    Unfortunately my mobo’s slow to post so that takes around 5-6 seconds.

    I moved from arch Linux to void and its init system called runit is amazing. Mega simple and fast.

  • frongt@lemmy.zip
    link
    fedilink
    arrow-up
    3
    ·
    6 hours ago

    Are we talking physical servers like Poweredge or Proliant? Those take a long time to boot, especially with lots of RAM. Why can’t you use suspend/resume?

    And modern servers don’t really consume a lot of power while idle. You can configure them to downclock the CPU and GPU while idle just like a desktop or laptop.

    But if you really wanted it, you could boot an immutable distro and mount user partitions tmpfs. Or use a portable distro and discard the state. Or a filesystem with snapshots and roll back on each shutdown or boot. But none of those are really going to get you instant boot. Linux boots pretty quick, but not instant.

    • HelloRoot@lemy.lol
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      4 hours ago

      Linux boots pretty quick

      I never managed to make linux boot faster than windows (on the same device ofc).

      And to this day I don’t understand why.

      Out of the 3 desktop OSes (lin, win, mac) linux was always the slowest one in my experience.

  • Die4Ever@retrolemmy.com
    link
    fedilink
    English
    arrow-up
    10
    ·
    edit-2
    9 hours ago

    Pretty sure you just have to enable hibernation and give it a file to write to? Then just set your PC to go into hibernate on idle

    I kind of doubt you would have to change distros. What distro are you on now?

    • HelloRoot@lemy.lol
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      4 hours ago

      For my two systems (pc and laptop)with 32GB RAM each it takes ~4 minutes to boot from hibernation.

      Which is expexted afaik.

      Thats the opposite of “instant”.

        • HelloRoot@lemy.lol
          link
          fedilink
          English
          arrow-up
          1
          ·
          edit-2
          4 hours ago

          No not really.

          It’s how long it takes to read 32GB from my swap. 170 MB/s continuous read speed ≈ 188 sec (3 min 8 sec) add the normal boot time to it (bios, grub, kernel initramfs) and you get the 4 minutes.

          When the system boots cold it doesn’t have to read 32GB, just 0.5-2GB maybe.

          • Sims@lemmy.ml
            link
            fedilink
            arrow-up
            2
            ·
            3 hours ago

            Just for the record, Linux can do with less swap-space than the memory you have, also for hibernation. The system doesn’t write every byte to swap, and it uses compression. With 32gb I would choose a default swapsize of ~10gb max, but test it first as it depends on the specific content of your ram, and usage patterns oc. However, its an instant time-saver during boot.

            • HelloRoot@lemy.lol
              link
              fedilink
              English
              arrow-up
              1
              ·
              edit-2
              1 hour ago

              Didn’t work for me, it would cancel the hibernation saying there is not enough space in swap. I followed the setup instructions on arch wiki.

              Do you have a guide for that?