How I Restore My Session Every Time I Start Linux Mint
Tagged with cinnamon, hibernation, linux, sessions, workspaces, x11, zram on October 23, 2024
Consider this a tutorial of sorts. I’m recounting the steps I took to make sure my computer boots up into the same type of session every time, regardless of whether it’s a new session or resuming from hibernation. I’m using the Cinnamon Edition of Linux Mint, and it doesn’t support session restore. It doesn’t support hibernation either, but hibernation can be enabled.
As I wrote about here, my laptop computer won’t work without a battery. I’m waiting on a replacement to arrive in November. When I get it running again, I’ll be following the same steps I’m recounting here. I tested hibernation on it before the battery went bad, and it works with only eight gigabytes of memory.
Workspaces
If you want to use workspaces, you have to figure out how many workspaces you need and which applications will reside on each of them. I’m currently using three. You then have to assign hotkeys to each one of them. I use “control-alt-[number]” for each of mine. It makes sense, since “control-alt-left” moves to the previous workspace, while “control-alt-right” moves to the next one.
I know Cinnamon supports a lot of workspaces, but numbering them only works with the first 10, using the 1 through 0 keys. You have to assign hotkeys, or you can’t use the command-line tools that simulate key presses.
Simulated Key Presses
I’m not using the experimental Wayland session, so any tool I use has to work with the X11 server environment. There are only two that I know of, xdotool and wmctrl. Either of them can be installed from the repository, and either one will do the job, but I prefer xdotool.
I placed this script in my home directory and then added it to my startup applications:
#!/bin/bash geany & google-chrome-stable & quiterss & sleep 3 # xdotool key ctrl+alt+2 kate -b & google-chrome-stable --app=http://localhost/ --class=WebApp-Localhost4224 --name=WebApp-Localhost4224 --start-maximized & sleep 3 # xdotool key ctrl+alt+3 rhythmbox & sleep 3 xdotool key ctrl+alt+1
The last line sends me back to the first workspace when all the applications have finished opening. I tested this several times before moving on.
Hibernation
There is a drawn out tutorial at UbuntuHandbook, and the one thing you need to know is that hibernation won’t work with secure boot enabled. You have to disable it in the BIOS/EFI settings. The rest of the tutorial works, but I prefer using a script I found on the Linux Mint Forum, which adapts the tutorial.
The best way to start is to save this script in your home directory. Don’t worry, it’s just a text file. Next, disable swap with “sudo swapoff -a”. Then, delete the swap line in “/etc/fstab”, as well as “/swapfile” in the root directory. Finally, run the script from the terminal command line in the home directory:
sudo /home/username/setup-hibernate.txt 16 (or whatever size in gigabytes you want)
If this is the only swap file being set up, I recommend making it double the size of your installed memory. If you’re going to set up zram, like me, you only need it to be the same size as your installed memory.
Install zram, following the instructions at this GitHub page. You can also install “zram-config” from the repository, but I like the GitHub method better. The normal swapping will occur with the zram partition, while hibernation will occur with the swap file.
Normal swapping uses the swap area with the highest priority. If you enter “sudo swapon -s” at a terminal command line, you’ll see that the swap file has a negative priority, while the zram partition will have a positive priority, making it the highest priority. This is why you have to set up the swap file with hibernation first, so that the system knows which swap area to resume from.
Resume or Restore the Session
Most web browsers can be set up to restore the previous pages loaded. So can Geany and Kate. Ever since I set this up on my own system, I hibernate when I’m done for the day if there’s anything at all that I’m still working on. If I’m sure I don’t have anything pending, I’ll shut it down normally. There are times, however, when I have the monitor off and forget to hibernate or shut down.
In any case, I always end up with the same applications on the correct workspaces every time my desktop is visible again. Unless something weird happens, I’m looking at the same web pages and text files I was formerly working on.
As I previously mentioned, I’ll be doing all of this with my laptop computer when I get it up and running again. I’m heading to the United States (from the Philippines) in March for an undetermined amount of time, but less than a year. I don’t want to lug around any other electronics except my phone.
Image by [email protected] Larry Ewing and The GIMP, CC0, via Wikimedia Commons
← Previous ArticleNext Article →