3

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
  • 22,082
fixit7
  • 3,399

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.

Daniel G
  • 41
  • 3
-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
  • 20,530
  • 12
  • 78
  • 125