2

This may be difficult to explain.

The scenario is that I shutdown the computer while there are open programs, for example:

  • a minimized terminal
  • a document I am working on
  • gimp open as well

Is there a method to have all those windows open again after a return from a shutdown?

Please note that I want to restore open windows after a SHUTDOWN.

(I ask for your understanding. Because of frequent neck and back pain, I have some memory problems.)

I tried option #4 from the answer to this question that was suggested as a possible duplicate, but the script did not restore any windows. The perl script was impressive, however.

NotTheDr01ds
  • 17,888
fixit7
  • 3,127
  • 1
    To better understand the context of you question, I'm guessing that you're running on a laptop? If yes, have you considered using suspend/hibernate to achieve your goals? I use hibernate all the time for exactly the same reasons that you state, and it works flawlessly (though, historically, both suspend and hibernate are very sensitive to hardware configurations). – richbl Nov 22 '22 at 15:53

2 Answers2

4

No, that's not feasible. And, in most cases, unsaved changes will be lost.

You need to suspend or hibernate to achieve that. After wake-up applications will be in the state you left them.

  • See Enable Hibernation: https://askubuntu.com/a/1312421/43926 – C.S.Cameron Nov 23 '22 at 03:22
  • 2
    not on newer Ubuntu: saving state of the current desktop is considered a security issue and has been removed a long time ago. – Rinzwind Nov 23 '22 at 11:46
  • @Rinzwind: What do you consider newer? I have set up hibernation on 20.04 and it works fine. Have you tried it? – C.S.Cameron Nov 23 '22 at 15:11
  • @C.S.Cameron regarding this: "After wake-up applications will be in the state you left them." ... "saving state" (ie. saving your session) is no longer part of Ubuntu as it is considered a security risk. – Rinzwind Nov 23 '22 at 15:57
  • @Rinzwind: That is not a quote from anything I have written. I have not tested hibernation on 22.04 but I have added hibernation to a Ubuntu 20.04 install and it does what the OP is asking for. After hibernating I even removed and then replaced a USB drive Ubuntu was Fully installed on. After booting everything looked and acted the same as before I left it, (as long as I plugged it into the same slot). What "newer" version of Ubuntu were you not able to add Hibernation to? – C.S.Cameron Nov 24 '22 at 04:16
  • @C.S.Cameron then don't assume my 1st comment was towards your comment :) – Rinzwind Nov 24 '22 at 08:46
  • @Rinzwind: I did not assume anything. my comment to your first comment was "What do you consider newer"? Your second comment was addressed to me. I was just making it clear that that quote was not from anything I said. I am still wondering what version of Ubuntu you consider "newer" I still have not got hibernation working in 22.04 – C.S.Cameron Nov 24 '22 at 12:01
  • My comment has nothing to do with hibernation and is about the line "After wake-up applications will be in the state you left them." as it is -not- true otherwise this is a security bug. And a big one. It is trivial to create a memory dump of a hibernated system. I do not see why you keep commenting on my comment. – Rinzwind Nov 24 '22 at 13:40
  • @Rinzwind: If your comment has nothing to do with hibernation, what are you waking-up from? When waking-up from hibernation a password is required just like logging in. I have tested adding hibernation to 22.04 and it works very well. – C.S.Cameron Nov 26 '22 at 04:09
-2

To enable Hibernation in 20.04 and 22.04:

Increase swapfile size to match RAM size.

  • Check the swap that is in use:

    sudo swapon -s
    
  • If swap partition(s) are found:

    sudo swapoff -a
    sudo nano -Bw /etc/fstab
    
  • Add # before the UUID of the swap partition(s):

    # UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX   none   swap    sw     0       0
    
  • Add a line for the swapfile, if one does not exist:

    /swapfile   none    swap     sw      0       0
    
  • Create the swapfile:

    sudo fallocate -l XG /swapfile
    

    where X is swapfile's size in GB:

    sudo mkswap /swapfile
    sudo chmod 0600 /swapfile
    sudo swapon /swapfile
    
  • Reboot:

    sudo reboot
    

Add resume location and offset to grub.cfg:

  • Edit /etc/default/grub:

    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX resume_offset=XXXXX"
    
  • Use UUID from root.

  • Use offset from:

    sudo filefrag -v /swapfile |grep " 0:"| awk '{print $4}'
    
  • Update GRUB:

    sudo update-grub
    
  • Test hibernation:

    sudo systemctl hibernate
    

A hibernate button can be added using GNOME extensions.

Note that there is a slight possibility of getting holes in a swapfile when creating it with fallocate. /var/log/syslog can be searched for the phrase swapon: swapfile has holes to ensure there will be no data loss.

A swap file can alternatively be created using dd:

sudo dd if=/dev/zero of=/swapfile bs=1G count=8

An error when using dd may overwrite your HDD.

For added safety do not invoke hibernation when you bank account number, etc, is visible and your root partition is unencrypted.

C.S.Cameron
  • 19,519