Score:2

Restore previously opened windows after shutdown

kp flag

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.

ec flag
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).
Score:4
cm flag

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.

C.S.Cameron avatar
cn flag
See **Enable Hibernation**: https://askubuntu.com/a/1312421/43926
cn flag
not on newer Ubuntu: saving state of the current desktop is considered a security issue and has been removed a long time ago.
C.S.Cameron avatar
cn flag
@Rinzwind: What do you consider newer? I have set up hibernation on 20.04 and it works fine. Have you tried it?
cn flag
@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.
C.S.Cameron avatar
cn flag
@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?
cn flag
@C.S.Cameron then don't assume my 1st comment was towards your comment :)
C.S.Cameron avatar
cn flag
@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
cn flag
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.
C.S.Cameron avatar
cn flag
@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.
Score:-1
cn flag

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.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.